top | item 24305834

Show HN: 3D first person game rendered in CSS/HTML

285 points| pantelisk | 5 years ago |pantel.is | reply

92 comments

order
[+] pantelisk|5 years ago|reply
Hello HackerNews! Super excited to read all your comments (last time I was here with audiomass.co).

This is meant to be an experiment of rendering a full 3D scene in html/css. Of course there is a ton of (vanilla) JS to handle pretty much everything - but the main point is to explore what good ol' divs can do in a 3D context.

It might seem a bit off, because I am not a good artist/world builder, but it contains various features such as lights and shadows calculation (rendered on divs though background images + blend modes -- try clicking on the candle). Billboarding and sprite effects, geometry culling etc, as well as scalene triangle computation (which allows us to convert actual 3d models to html elements - https://pantelis.s3-us-west-2.amazonaws.com/0/css3d/readme/t...)

-----

If this interests you, I am giving a presentation on how it is built and lessons learnt this coming Wednesday (2nd of September) at CascadiaJS 2020 ( https://2020.cascadiajs.com/ ), among a line up of awesome speakers!

[+] OzzyB|5 years ago|reply
- Brightness check [y]

- Audio on/off switch [y]

- Mouse axis inversion switch [x]

My brain hursts using the mouse to look around that way, I'm too old to learn new tricks!

Great game and proof of concept w/ CSS/HTML, you get 10/10 xD

[+] pwfisher|5 years ago|reply
This is super cool! Love it.

Love that the layout is responsive and has mobile, tablet and desktop versions in good web UI style. (FYI, if you close the sidebar and resize to desktop, it's missing.)

[+] wiz21c|5 years ago|reply
I've played it to the end, good times !
[+] adamredwoods|5 years ago|reply
I'll be 'at' cascadiajs. I really look forward to this.
[+] s_fischer|5 years ago|reply
I just looked up the topics for cascadiajs and it looks awesome! I was disappointed to find out that all the tickets are sold out even though it's a virtual conference. I know you are just a speaker, but do you have any insight into why there's a hard cap on attendees? Is it simply to avoid potential infrastructure problems that could occur from delivering live video content to an unforseen number of attendees?
[+] raobit|5 years ago|reply
Great game sir!! However i am not able to complete the first level itself I ate the food but still not able to lift the sewer in dark as it shows i am weak
[+] s_gourichon|5 years ago|reply
Thanks a lot for sharing! Very interesting experiment.

That said, please please, no "WASD". This is very uncomfortable on non-QWERTY keyboard layouts.

There are two solutions to this.

# Best solution

Game programmer always mean "the group of physically-positioned keys that happen to be labelled WASD on the programmer's keyboard", not "whatever keys that are actually labelled WASD on the player's keyboard".

So, wherever possible, use an API that refers to key position, not key symbol. This is possible in most programming environments, e.g. in Javascript using https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEve...

# Alternative solution

Alternatively, use keys that are stable across most common Latin keyboards layout, which means no AMQWYZ.

ESDF is fine, as are RDFG, TFGH, or the traditional IJKL (see https://en.wikipedia.org/wiki/Arrow_keys for more).

If you want to be kind to Dvorak, Bepo, Colemak and other users, prefer the first solution!

https://en.wikipedia.org/wiki/Keyboard_layout#QWERTY-based_L...

[+] codetrotter|5 years ago|reply
To be really pedantic, keycodes only help when the layout is being remapped in software by the operating system. There are dozens of us that use hardware Dvorak mapping. Dozens! :p

So to be clear, the ideal thing to do is to allow the player to define in-game which keys should do what. But realistically speaking, I’m not going to complain because I brought this on myself when I chose to use a hardware controlled Dvorak layout. Still worth it btw ^^

I do note however, that the project is open source on GitHub, so if any of my fellow hardware controlled alternate keyboard layout peoples want to take a stab at submitting a PR for a keyboard binding config menu for the game I say go for it :)

[+] rangewookie|5 years ago|reply
Given that WASD is a standard in gaming I'm surprised by this approach. Do many games / game engines use key position? Isn't it easier to just add key remapping so outliers can configure freely?
[+] tomc1985|5 years ago|reply
> ESDF is fine, as are RDFG, TFGH, or the traditional IJKL (see https://en.wikipedia.org/wiki/Arrow_keys for more).

Ugh, no. FPS has standardized on WASD over the last 20 years and people trying to reinterpret this are the bane of a positive experience.

Positional keys? Sure. Whatever's in WASD's place is fine. But splitting hairs for the <1% of users using nonstandard stuff (like a dvorak keyboard, which after a lifetime of computer nerditry I still have never seen in-the-wild) will lose you a huge chunk of your audience.

WASD or die

[+] pantelisk|5 years ago|reply
Woaah.. this never occurred to me. Thank you, for the suggestion. Didn't know about "KeyboardEvent.code". And of course.. arrowkeys, kinda ashamed I didn't think of that!
[+] kleiba|5 years ago|reply
...or just install the US keyboard layout as an alternative to the one you typically use.
[+] p1necone|5 years ago|reply
"Alternatively, use keys that are stable across most common Latin keyboards layout, which means no AMQWYZ."

No no no no no this is a terrible idea. Don't make 99% of peoples experience non standard just so that people with non qwerty keyboards (who are probably expecting to need to remap controls anyway) have automagic defaults. Just default to the most common thing (WASD) and let people remap keybinds to whatever they want in case that doesn't fit.

I'm a pretty avid gamer and I've literally never opened a PC first person/third person shooter (or other real time genres with a similar perspective) released in the last 15 years or so that didn't have movement mapped to WASD by default. Not doing so would make your game feel very unpolished.

If you care about accessibility at all you need to allow button remapping anyway, even if you go with positional keybinding.

[+] FullyFunctional|5 years ago|reply
Funny. I had to look for WASD on my Dvorak keyboard, but that said, we are a minority. My bigger recommendation would just be to quickly mention which keys are relevant as I was left wondering if I was missing something.
[+] wilsonrocks|5 years ago|reply
I did not know about key codes and physical position! Thank you!
[+] flockonus|5 years ago|reply
Really interesting! But why is the scene so dark? Gave up sooner than I'd like because had to squint really hard on the phone screen.
[+] laksdjfkasljdf|5 years ago|reply
Pretty sure that is on purpose for the theme of the game.

I would probably give up if the game had OSHA approved flood lightning in a medieval dungeon prison cell.

[+] arxpoetica|5 years ago|reply
I agree, it could be brighter. SUPER DARK.
[+] coding123|5 years ago|reply
Very awesome. In 1989 a game like that would have been an AAA title (well if given the resources to make it 40+ hours) And it brings back memories of so many games I played when I was 10-15. Wow nice job.
[+] jonny_eh|5 years ago|reply
Super impressive! I'd love to see a write up on how it was done. Do you think this is more performant that webgl?
[+] pantelisk|5 years ago|reply
Performance for simple things is adequate, but relying on 2-point rectangles (origin(x,y), dimensions(width,height)) for geometry is extremely cumbersome. Also everything is hack piled on top of hack (for example there is no concept of a camera, the whole world moves around you instead to simulate the camera effect!).

So... webgl is still the way! This is meant to be an experiment to show what css/html is capable of!

[+] pcwalton|5 years ago|reply
It won't be faster than WebGL in most cases. Browser CSS rendering stacks have gotten pretty fast but are not really optimized for this. In practice WebGL gives you more chances for optimization, because CSS rendering has to handle lots of edge cases that games don't. For example, a CSS renderer must split self-intersecting partially-transparent 3D polygons on CPU to render correctly, whereas a game engine just tells the artists "don't do that".
[+] randtrain34|5 years ago|reply
I think it's pretty hard to get more performant than webgl, especially as the number of vertices increases/geometry complexity increases.
[+] eldilibra|5 years ago|reply
Great demo! This was super inspiring. I haven't touched game dev stuff in a couple of years (after a bit of a Unity rabbit hole before that). Just might have to get back into tinkering after playing through this...
[+] 51Cards|5 years ago|reply
One possible bug... playing in Firefox and I went F11 / full screen. Reached the end of the game I was locked out of all F keys in Firefox and thus couldn't restore my screen. Ended up having to kill the Firefox task. Possibly something in how you're capturing keystrokes? Not sure.

Overall great job! Agree with the comments about it being a little dark.. am on a laptop in daylight and it was hard to see with everyting maxed. Looking forward to more.

[+] fortyseven|5 years ago|reply
I was having trouble with keys mid-game, full-screened, and I couldn't exit either. But I was able to hit CTRL-W to close the tab, then I could F11 back to sanity.
[+] tester756|5 years ago|reply
Damn I didn't manage to hack it and make that game box on the full screen

I think it'd be way better user experience if this window wasn't that small

is the size performance related?

[+] pantelisk|5 years ago|reply
it should be possible - you can check how it is rendered on mobile portrait and landscape modes (which is basically fullscreen). However, more intricate sizing might be hard to achieve since I 'm using pixel values so some things will probably look terrible in higher res. (this isn't the same as upscaling res let's say in canvas or webgl - it would be more like viewing an old website in a newer bigger monitor! But in theory it can be improved :) )
[+] sydd|5 years ago|reply
Awesome, I really like that it works on mobile, the controls are cool. Well almost the text flows out of the screen. I'm using Firefox mobile.
[+] pmontra|5 years ago|reply
I can look around on mobile but I didn't figure out how to move. I tried tapping and double tapping everything but nothing happened. Only some "object is out of reach".
[+] i-am-curious|5 years ago|reply
Agreeed. I finished the game on mobile ;) Though the story could use some work !
[+] randtrain34|5 years ago|reply
Has anyone tested with different browsers? Would love to see if there are differences between rendering this in Chrome/FF/Safari, etc.
[+] butz|5 years ago|reply
First room has serious rendering issues on Firefox (Fedora Linux) with walls disappearing and some geometry becoming lines going to some point in infinity. Otherwise atmosphere and quality looks great, especially for a tech demo.
[+] fxleach|5 years ago|reply
Awesome! Played it on my desktop and didn't have any issues with it being too dark as others have suggested. Keep up the good work.
[+] paul7986|5 years ago|reply
Very cool and just a suggestion ... have the keys that move the character ..overlay the game window at the bottom right of it (make it transparent and or give the user to the option to turn it off). I quickly saw them before playing, but forget what each does.
[+] dubcanada|5 years ago|reply
Interesting, tried it on my 1980x1080 monitor and I had to scroll down to read the text. It doesn't seem to adapt very well to non-square browser sizes.

Also when viewing videos (such as the candle) I get a picture-in-picture icon.

Quiet enjoyed the game though.

[+] zamadatix|5 years ago|reply
It's not a resolution/aspect ratio issue it's a viewport vertical size issue. Anything with less than 768 absolute CSS pixels (not display pixels) will not fit the content. This includes 1080p at 150% DPI/zoom.
[+] rkagerer|5 years ago|reply
The text overflows off the right edge of my screen on my mobile too.
[+] Kelamir|5 years ago|reply
This is cool! Thank you for making this.

The game gets stuck on Firefox, Linux, at the scene "Suddenly, a devilish creature appears...". Nothing appears, and I can no longer look around, just walk.

[+] frabbit|5 years ago|reply
Works for me on Linux with Firefox 70.
[+] terrycody|5 years ago|reply
Man, this is really promising and bring back the 80s memories, btw, do you think this will be the future of browser game? How about webGL? Or web assembly?
[+] tsarlatanos|5 years ago|reply
Great work, very impressive and creative project.
[+] smithmayowa|5 years ago|reply
I bet JavaScript was thrown in the mix, can’t quite see how this was made without it, I just might be wrong though.
[+] pantelisk|5 years ago|reply
Yup, vanilla JS. Only the rendering is html/css. State, navigation etc, is all js.
[+] kickling|5 years ago|reply
Amazing. Worked well on mobile, except the text went out of the screen a few time.
[+] cwkoss|5 years ago|reply
Very impressive, great work! Got to the current end, looking forward to more :-D