UDSKRIFT 🔗
WEBVTT
00:00:02.240 --> 00:00:04.480
So hi everybody.
00:00:04.799 --> 00:00:10.080
My name is Niels and it's so lovely to be back here in Vienna.
00:00:11.759 --> 00:00:22.079
This morning in his introduction, Dylan mentioned a talk I did years ago where all of my live demos failed.
00:00:24.640 --> 00:00:38.560
So just in case if anything fails today, I'm well prepared.
00:00:43.119 --> 00:00:47.439
So this talk is about how I created Doom in CSS.
00:00:48.960 --> 00:00:54.320
And I wanted to go over some of the CSS details and features that I used.
00:00:55.039 --> 00:00:56.479
And we're still gonna do that.
00:00:56.799 --> 00:01:11.760
But I also want to share a bit about my process and the story behind CSS Doom, how it was created, because it started out something completely different, and I think just as interesting as the nitty-gritty CSS code.
00:01:12.239 --> 00:01:17.519
So, first of all, um today we heard a lot about AI.
00:01:18.000 --> 00:01:25.840
And yes, uh for sure, all of our jobs has changed a lot over the last uh year or two years.
00:01:25.920 --> 00:01:29.760
Uh for my day job, I hardly write code anymore.
00:01:30.799 --> 00:01:35.599
And to be honest, I don't want to go back.
00:01:37.200 --> 00:01:39.359
But but I I love coding.
00:01:40.000 --> 00:01:45.519
Um, I love writing JavaScript, but also HTML and very much CSS.
00:01:46.319 --> 00:01:53.120
And what AI allows me to do is automate the things that I don't want to do.
00:01:53.680 --> 00:02:00.879
And focus on the things I do want to do and spend more time being creative and challenging myself.
00:02:02.079 --> 00:02:06.159
Now this story starts with an obsession of mine.
00:02:07.840 --> 00:02:09.919
Making a laser clock.
00:02:11.280 --> 00:02:20.080
Ever since I've seen SAP Hugh Delisle talk about lasers ten years ago, I've been fascinated by laser projectors.
00:02:20.240 --> 00:02:25.520
But I know nothing about them, how they work, and and could I connect them to the web?
00:02:26.319 --> 00:02:34.719
Now SEP explained some of the issues he ran into recreating a classic 1979 game called Asteroids.
00:02:36.000 --> 00:02:45.199
Now, that original game used a special display system called the Quadra scan, which uses a CRT.
00:02:45.759 --> 00:02:52.080
But but instead of pixels, it it directly steered the electron beam to draw these vector shapes.
00:02:52.240 --> 00:02:56.800
It's really simple, but it worked amazing.
00:02:57.199 --> 00:03:05.360
Now, before you get excited about me showing a laser clock, um laser projectors are expensive.
00:03:06.240 --> 00:03:10.159
They well, it's not not my my name is not Seb Lee Delisle.
00:03:10.240 --> 00:03:13.759
I don't have a couple of spare ones stacked up behind the couch or something.
00:03:14.080 --> 00:03:30.639
So I started thinking that that game of asteroids kept lingering in the back of my head, and I figured that an oscilloscope could function in pretty much the same way as that original quadra scan display.
00:03:31.120 --> 00:03:33.360
And they are really cool too.
00:03:33.610 --> 00:03:41.449
And it's uh oscilloscope is like a lab equipment and it visualizes electrical signals, any signal.
00:03:41.689 --> 00:03:44.400
Um I just love the aesthetic.
00:03:45.840 --> 00:03:54.080
It really feels like you've wandered into the lab of a mad scientist with all of these buttons.
00:03:58.240 --> 00:04:18.959
Um I think well, if you think of it, it literally is just a small particle accelerator that that fires electrons at about a quarter of the speed of light right at your face.
00:04:20.240 --> 00:04:23.680
And only be stopped by a very thin layer of phosphor.
00:04:25.279 --> 00:04:32.319
Now, of course I wanted to use web technology to make my clock.
00:04:33.199 --> 00:04:41.279
So this part of the tight of the talk is titled How I Use CSS Animations to Draw a Clock on an Oscilloscope.
00:04:44.560 --> 00:04:47.279
Well, not really accurate.
00:04:47.360 --> 00:04:56.079
Uh it's more how I used web audio to blow up a 1980s oscilloscope and almost cost a fire.
00:04:57.279 --> 00:04:59.600
Hence the fire extinguisher.
00:05:01.199 --> 00:05:04.959
So start let's start with it what a clock really is.
00:05:05.120 --> 00:05:08.240
Uh to me, a clock is a simple analog dial.
00:05:08.399 --> 00:05:10.399
It's a circle and three lines.
00:05:10.800 --> 00:05:13.600
And on the web we can use SVG for that.
00:05:13.759 --> 00:05:19.519
Uh simple shapes, vectors, and um just like that asteroids game.
00:05:20.879 --> 00:05:25.600
Now we only need to animate them over time, and we can use CSS for that.
00:05:26.000 --> 00:05:29.040
Now we need to draw these shapes on the scope.
00:05:29.279 --> 00:05:40.480
So the phase melting electron beam is tiered, or better deflected, uh by two electrically charged plates called the X plate and the Y plate.
00:05:40.800 --> 00:05:47.920
Um and by deflecting that beam vertically and horizontally, we can basically trace the image that we want.
00:05:48.240 --> 00:05:52.319
And do that multiple times per second, and you get an image.
00:05:53.439 --> 00:05:57.680
So we need two signals, X and Y.
00:05:58.639 --> 00:06:00.800
And we need to trace the image that we want to draw.
00:06:00.879 --> 00:06:03.199
So let's start with the clock phase, the circle.
00:06:04.480 --> 00:06:06.480
This is that circle.
00:06:07.680 --> 00:06:08.319
Uh
00:06:09.040 --> 00:06:11.920
to create this, you need some high school math.
00:06:12.480 --> 00:06:16.560
Turns out my math professor was right all along, all those years ago.
00:06:17.040 --> 00:06:20.480
I did need math later in life.
00:06:21.279 --> 00:06:28.319
Um if you look at this circle, it actually kind of starts to make sense.
00:06:28.560 --> 00:06:33.680
We just make a waveform directly from the x and the y coordinates of the circumference of the circle.
00:06:34.399 --> 00:06:40.879
And we can make any shape with that method: squares, triangles, even clocks.
Load full transcript
00:06:41.439 --> 00:06:44.560
Um, and any line drawing that you can trace.
00:06:44.720 --> 00:06:49.120
We can take the x-coordinates and the y-coordinates and create a waveform.
00:06:49.759 --> 00:06:52.000
But how do we get those coordinates?
00:06:53.120 --> 00:06:56.879
Well, we start with our SVG and insert it into the DOM.
00:06:57.519 --> 00:07:06.480
And uh with all of the CSS transformed and animations applied, we can get the total length of the paths and point at length to get the raw coordinates.
00:07:06.560 --> 00:07:09.839
And we end up with, well, two arrays.
00:07:10.480 --> 00:07:12.399
Two arrays of numbers.
00:07:13.040 --> 00:07:19.120
Um if we plot those in a graph, we get our waves.
00:07:19.360 --> 00:07:21.439
One for X, one for Y.
00:07:21.839 --> 00:07:29.120
And we do this 30 times per second, and because SVG exists in the DOM, we just get the CSS animations for free.
00:07:29.439 --> 00:07:37.120
Because every time we sample uh the vectors, uh we get the current state.
00:07:38.240 --> 00:07:42.959
Now we only need to generate a signal for the oscilloscope.
00:07:43.120 --> 00:07:45.759
And turns out that is actually pretty simple.
00:07:46.000 --> 00:07:55.759
The only thing we need to do is uh give web audio or coordinates, and it will create the audio waveform for us.
00:07:56.399 --> 00:08:10.800
So we simply plug in a cable to the headphone port of the computer, hook it up to the oscilloscope, and well, two audio channels left and right, two signals, X and Y.
00:08:11.199 --> 00:08:14.160
It it just matches up, it works perfect.
00:08:15.680 --> 00:08:18.480
So I build a web app that does exactly this.
00:08:18.639 --> 00:08:28.959
Uh it has a small editor where I can use uh to to edit your SVGs and your uh CSS, and it will just inject it into DOM, sample it, and output the waveforms using web audio.
00:08:29.839 --> 00:08:39.279
We've connected the computer's audio output to the X and the Y channel uh of the scope, and and well, let's see how it looks.
00:08:39.519 --> 00:08:43.600
Set it to XY mode, and there it is.
00:08:45.840 --> 00:08:46.480
Yeah.
00:08:49.279 --> 00:08:50.799
Then this happened.
00:08:51.120 --> 00:08:53.759
The oscilloscope decided to explode.
00:08:54.000 --> 00:08:56.240
Um so this is the aftermath.
00:08:56.480 --> 00:09:10.799
Um I was too busy finding the power plug and and and scrambling to find my phone to film it, of course, but uh smoke was rising up and sparks went flying everywhere, and yeah.
00:09:11.840 --> 00:09:18.799
I I was fine, I did not get electrocuted, uh, but the scope was dead.
00:09:19.919 --> 00:09:20.960
So now what?
00:09:23.679 --> 00:09:24.879
Redundancy.
00:09:25.759 --> 00:09:27.840
I I may have overreacted here.
00:09:28.000 --> 00:09:30.320
Um but I have a new one.
00:09:30.720 --> 00:09:32.799
One that fits in a suitcase.
00:09:33.759 --> 00:09:38.240
And I brought it with me uh through airport security.
00:09:39.360 --> 00:09:40.639
Three times.
00:09:41.039 --> 00:09:46.399
First to Brighton last week, and yesterday from Brighton via Frankfurt to Vienna.
00:09:47.440 --> 00:09:48.080
Yeah.
00:09:48.960 --> 00:09:55.200
Um so in Amsterdam, my scope, my back, and even I was swept for explosives.
00:09:55.759 --> 00:10:01.039
Uh take another suitcase, uh, another time to the x-ray.
00:10:01.600 --> 00:10:03.519
Fine, fair enough, fair enough.
00:10:03.600 --> 00:10:06.240
Then yesterday at Gedwick, I was swapped again.
00:10:06.879 --> 00:10:12.080
And then at Frankfurt, uh, well, I was the only one at the security lane.
00:10:12.240 --> 00:10:16.080
Um, I I I could see the guy looking at the x-ray.
00:10:18.960 --> 00:10:20.879
To the suitcase, back to the x-ray.
00:10:21.039 --> 00:10:23.120
Then he was looking at me, going, huh?
00:10:23.519 --> 00:10:25.440
I said, just oscilloscope.
00:10:25.600 --> 00:10:29.039
Uh he nodded approvingly, uh, yeah, makes sense.
00:10:29.200 --> 00:10:33.039
Uh and then just let me leave with the suitcase without even opening it.
00:10:34.080 --> 00:10:38.240
Apparently in Germany they travel with oscilloscopes?
00:10:38.480 --> 00:10:39.440
I don't know.
00:10:39.919 --> 00:10:46.000
Anyway, um it's time for the demo.
00:10:48.240 --> 00:10:48.559
Okay.
00:10:49.840 --> 00:11:03.360
Now this is scary because I haven't tried it yet.
00:11:05.200 --> 00:11:05.519
Um
00:11:06.320 --> 00:11:11.840
so let's just turn on the generator, set it to the clock.
00:11:12.720 --> 00:11:23.679
Let's go.
00:11:23.759 --> 00:11:24.720
There is the button.
00:11:28.000 --> 00:11:33.519
Now, if everything survived the trip, we should see a clock.
00:11:33.600 --> 00:11:34.799
Well, it's a little bit.
00:11:44.559 --> 00:11:45.919
Something like that.
00:11:46.480 --> 00:11:47.440
It works.
00:11:51.120 --> 00:11:55.360
No explosions yet, so okay.
00:11:55.600 --> 00:12:04.559
Um, so I built this clock, which isn't really useful because it's kind of dangerous to let it run.
00:12:05.360 --> 00:12:08.879
Uh I don't want to leave the house with this just on.
00:12:09.039 --> 00:12:14.000
And it's environmentally very unfriendly because it takes a lot of power.
00:12:14.240 --> 00:12:18.159
But I figured what can I else what what else can you do with this?
00:12:18.399 --> 00:12:24.720
So uh I basically already said we can use this to visualize any SVG.
00:12:25.440 --> 00:12:32.879
Um we can do, for example, uh where is it?
00:12:33.200 --> 00:12:33.840
Love tech.
00:12:37.600 --> 00:12:41.840
Um but it doesn't have to be a static image.
00:12:42.080 --> 00:12:43.840
It can be any animation.
00:12:44.799 --> 00:12:50.080
It could be that game of asteroids, for example.
00:12:52.960 --> 00:12:53.600
All right.
00:12:54.159 --> 00:13:03.519
Let's try it again, asteroids.
00:13:14.639 --> 00:13:16.159
Sound effects, yes.
00:13:17.600 --> 00:13:19.759
Well, I'm really bad at this.
00:13:20.080 --> 00:13:27.120
But of course, I have a I have a eleven-year-old son.
00:13:27.440
--> 00:13:33.200
And he has a Chromebook at school, and one of the things he loves to play is the Dino game.
00:13:33.279 --> 00:13:34.879
So I made it for him.
00:13:35.120 --> 00:13:36.480
The Dino Game.
00:13:40.480 --> 00:13:41.759
He's very good at this.
00:13:41.840 --> 00:13:43.919
I I I well.
00:13:50.639 --> 00:13:50.960
Um
00:13:52.720 --> 00:13:56.639
then I thought, what else can I do with this?
00:13:57.279 --> 00:14:10.159
Is there some game that everybody tries to port to a platform, to any platform like fridges or thermometers or or whatever?
00:14:10.320 --> 00:14:12.320
And it's of course it's Doom.
00:14:13.519 --> 00:14:20.159
So I spent some time quite a bit of time
00:14:20.960 --> 00:14:21.279
on
00:14:21.919 --> 00:14:23.360
making this work.
00:14:26.080 --> 00:14:29.840
So this is level one of the game of Doom.
00:14:30.080 --> 00:14:36.559
I can just walk around here and it just works.
00:14:37.759 --> 00:14:43.759
It's it isn't using CSS, it's directory drawing uh lines.
00:14:44.080 --> 00:14:47.120
Uh and actually the scope
00:14:47.519 --> 00:14:47.840
uh
00:14:48.720 --> 00:14:51.600
it works, but isn't really optimal.
00:14:51.759 --> 00:15:00.000
I have to remove a lot of lines and it doesn't have any gameplay, but still, I thought it was so cool to make this.
00:15:01.360 --> 00:15:04.799
Now let's go back to the talk.
00:15:06.320 --> 00:15:08.320
Turn it off for safety.
00:15:09.840 --> 00:15:10.159
Um
00:15:12.960 --> 00:15:14.639
back to the talk.
00:15:16.559 --> 00:15:20.240
So we have Doom on our oscilloscope and it looks great.
00:15:20.480 --> 00:15:34.480
If you keep in mind that we're just generating lines and encoding this with audio and showing it on an old dumb device that's 50-year-old technology, um, but it isn't the real Doom game.
00:15:34.799 --> 00:15:37.919
We can move around, and that's pretty much it.
00:15:38.639 --> 00:15:42.320
Um this is where the second part of the story uh starts.
00:15:43.039 --> 00:15:58.799
Earlier this year I was at a conference in Brighton, and if you know anything about Brighton, it's a it's the coast, it's it's a coastal city, and anytime outside of uh summer, it's freezing cold.
00:15:59.600 --> 00:16:06.240
So I had an extra day and I had nothing planned, and I was walking around and I was pretty quickly done with that.
00:16:06.960 --> 00:16:11.120
Um so I went back to the hotel and I suddenly had this idea.
00:16:11.600 --> 00:16:14.240
We have all this data from Doom.
00:16:14.799 --> 00:16:27.840
I I uh discovered how I could uh decode uh all of the maps and everything, and and I learned about how to render frames in 3D.
00:16:28.000 --> 00:16:38.879
And well, so we could use that data and project those walls with CSS 3D transforms.
00:16:39.679 --> 00:16:45.679
We could add textures, and within a day I had something where I could walk around.
00:16:46.559 --> 00:16:52.720
Uh I posted a little video of that on social media and and went somewhere to get a
drink.
00:16:52.879 --> 00:17:06.319
And then my phone blew up because thousands of likes came in and reposted, and and and so I started adding more and and more, such as doors and pickups and enemies and fireballs.
00:17:06.400 --> 00:17:10.720
Um uh, well, this isn't fully CSS, of course.
00:17:10.960 --> 00:17:27.200
There's a considerable bit of JavaScript ported from the original original game, and yes, I did use AI for that, because I was interested in the CSS, and the renderer is almost 100% CSS.
00:17:27.920 --> 00:17:28.880
But why?
00:17:30.880 --> 00:17:41.839
Well, first of all, JavaScript should only do what only JavaScript can do, because the browser is much better at optimizing than you are.
00:17:44.400 --> 00:17:54.480
So there is this this small layer of JavaScript that does basically nothing more than create DOM elements and set classes and custom properties.
00:17:55.200 --> 00:17:58.160
And every wall, floor, or ceiling is a div.
00:18:00.160 --> 00:18:03.839
Simple divs that are 3D animated, uh transformed.
00:18:04.799 --> 00:18:19.039
And we're not using JavaScript to position every div, but instead the JavaScript extracts the raw coordinates from the Doom game file, the bot file, and those raw coordinates and then pass to the CSS as custom properties.
00:18:20.720 --> 00:18:23.440
So these are all the discs we created for level one.
00:18:24.559 --> 00:18:27.200
And this is one of the smaller levels.
00:18:28.000 --> 00:18:32.640
And we insert this in the DOM and we let CSS handle the rest.
00:18:33.039 --> 00:18:37.039
And and all the complicated math is done by CSS itself.
00:18:38.480 --> 00:18:40.319
It's actually not that bad.
00:18:40.480 --> 00:18:46.160
Um it basically boils down to the theorem of Pythagoras.
00:18:46.480 --> 00:18:51.920
And the reason why is that DOOM isn't fully 3D, it's actually like two and a half D.
00:18:52.480 --> 00:18:56.240
It's a flat map with heights, and it's not a full 3D scene.
00:18:56.319 --> 00:18:58.400
And that's why it fits so perfectly with CSS.
00:18:59.839 --> 00:19:01.440
So this is our top view.
00:19:01.599 --> 00:19:08.480
We have our start coordinate and our end coordinates, and and what we want to do is position our wall on these coordinates.
00:19:08.799 --> 00:19:11.279
We have to set a width and an angle.
00:19:12.160 --> 00:19:25.119
Um it's basically along the side of the triangle, uh, which is the square root of x uh squared plus y squared, and the angle is the inverse tangent of y divided by x.
00:19:27.680 --> 00:19:28.559
Everybody with me?
00:19:28.799 --> 00:19:29.440
Yeah?
00:19:30.000 --> 00:19:32.640
Just not, just fine, just not.
00:19:32.880 --> 00:19:34.559
Uh pretend it makes sense.
00:19:34.720 --> 00:19:39.759
Um so in our CSS it looks like this.
00:19:40.079 --> 00:19:48.640
And thanks to the CSS trigonometry functions, we can now just calculate the width and the height uh that we need, or the the width and the angle that we need.
00:19:48.960 --> 00:19:51.920
No need for JavaScript or to pre-calculate everything.
00:19:52.079 --> 00:19:55.440
We're just setting properties for straight from the DOM what file.
00:19:55.519 --> 00:19:57.759
And CSS does the calculations.
00:19:59.519 --> 00:20:12.079
And this is them where we simply set the width and we position the div in 3D space and using translate 3D and with the start coordinates, and finally rotate it on the angle that we had just calculated.
00:20:12.319 --> 00:20:16.720
We do that for every wall in our scene, which can be a couple of thousands.
00:20:17.279 --> 00:20:20.240
And of course, ceilings and floors too.
00:20:20.480 --> 00:20:29.839
They are just square divs that use the same positioning uh logic, uh, except we need to rotate them 90 degrees flat on the floor.
00:20:30.079 --> 00:20:34.160
Now, this works if you have a square sector.
00:20:34.720 --> 00:20:40.160
A sector is basically a group of walls and floors and ceilings that belong to each other.
00:20:42.160 --> 00:20:45.839
But rooms are not squares.
00:20:48.000 --> 00:20:49.759
So how do we do this?
00:20:49.920 --> 00:20:52.079
Almost none of the rooms are squares.
00:20:52.240 --> 00:20:55.200
And and diffs are very much squares.
00:20:55.839 --> 00:20:58.240
So how are we dealing with this floors?
00:20:58.480 --> 00:21:00.880
Um here we can see two sectors.
00:21:00.960 --> 00:21:05.680
Uh, one is a simple octagon and the other is a polygon with a hole cut out of it.
00:21:05.920 --> 00:21:08.079
Well, these are diffs too.
00:21:08.319 --> 00:21:10.640
These are diffs with a clipping path.
00:21:11.279 --> 00:21:15.759
Um involves a bunch of extra math that we have to do in JavaScript.
00:21:15.920 --> 00:21:22.640
It isn't feasible to do this in CSS, and that little bit of JavaScript is just what we're gonna add to the renderer.
00:21:22.799 --> 00:21:28.240
Um, but we pre-calculate this uh and and CSS does the rendering.
00:21:28.880 --> 00:21:46.720
Now, simple shit like Octagon have been possible for a while now, but thanks to the shape function, that's relatively new, you can even uh write a path, a clipping path, in a uh human readable uh format instead of SVG paths, which are horrible.
00:21:47.119 --> 00:21:58.480
Um, and thanks to even odd, we can even have two paths, uh, one that cuts off the triangles at the outer edge, and one that creates the hole in the middle.
00:22:03.599 --> 00:22:08.559
Now, if we turn around and look at the lighting of the scene, we can see two things.
00:22:08.720 --> 00:22:15.440
First of all, we're standing on a light platform, a dark room, with in the distance another light room.
00:22:15.759 --> 00:22:17.519
And those are all static lights.
00:22:17.680 --> 00:22:22.880
Those are defined in the Doom game file, and they are not calculated by the game.
00:22:23.039 --> 00:22:25.359
They're just preset.
00:22:26.319 --> 00:22:28.400
And we set a light per sector.
00:22:28.720 --> 00:22:31.519
That means this room
contains many different sectors.
00:22:31.680 --> 00:22:33.440
Like all the stairs.
00:22:34.079 --> 00:22:39.119
Each stair is a different sector with a different height, with a different floor.
00:22:39.759 --> 00:22:44.640
And because they are staggering, it just appears as stairs.
00:22:47.119 --> 00:22:50.799
And you can see that the light for the whole sector is the same.
00:22:50.880 --> 00:22:54.720
So even the ceiling above the stairs have the same light as the floor.
00:22:55.119 --> 00:22:57.519
Now, how do we set the light level?
00:22:57.920 --> 00:23:05.440
It's a custom property again on the sector itself, and then that property is inherited by all the floors and ceilings and whatever.
00:23:07.759 --> 00:23:12.799
Now we just apply a filter to it, to our whole scene.
00:23:13.039 --> 00:23:14.960
Every light is a filter.
00:23:16.349 --> 00:23:22.029
And but if you look closely here, you can see those pillars, that those are pillars.
00:23:22.190 --> 00:23:23.390
Those are pulsating.
00:23:23.470 --> 00:23:24.430
That's a lighting effect.
00:23:24.509 --> 00:23:26.430
Those are also defined by the Watt file.
00:23:26.640 --> 00:23:30.640
And Doom supports different types of lightings.
00:23:31.200 --> 00:23:35.440
And those are a little more just animated brightness changes.
00:23:36.400 --> 00:23:45.759
So the pillar has a simple class on it, and it runs with an infinite animation that changes the light custom property.
00:23:46.240 --> 00:23:49.200
Now some of you will say that this isn't possible.
00:23:50.480 --> 00:23:51.519
And you're right.
00:23:52.480 --> 00:23:53.599
This doesn't work.
00:23:54.240 --> 00:23:58.079
Because CSS does not know what the light custom property is.
00:23:59.039 --> 00:24:02.960
It can't translate or or or morph between values.
00:24:03.279 --> 00:24:11.759
So we need to use add property to tell that light is actually a number, then it can make those smooth animations.
00:24:13.359 --> 00:24:17.200
Now we can change that animation to anything that we want.
00:24:17.359 --> 00:24:22.799
We only have to change one class and then it has a completely different lighting effect.
00:24:23.920 --> 00:24:28.559
Now, one more very important part of Doom is the textures.
00:24:29.200 --> 00:24:34.720
So the textures of the original game are uh well just images.
00:24:34.799 --> 00:24:40.319
I extracted them from the Doom what file, converted them to PNG, they're really tiny.
00:24:43.680 --> 00:24:49.599
Every wall ceiling of forgives has a data texture attribute that we use to load the image.
00:24:52.319 --> 00:24:57.599
Oh uh yeah, that wasn't supposed to happen.
00:24:57.680 --> 00:24:58.480
Let's try again.
00:24:58.640 --> 00:25:00.720
Uh right, here we go.
00:25:00.960 --> 00:25:02.559
Um okay.
00:25:05.599 --> 00:25:10.559
Well, you need a version where every service has pictures of a cat.
00:25:13.440 --> 00:25:15.119
Okay, we can do that.
00:25:15.359 --> 00:25:20.480
Um this is just CSS, we can
load any image that we want.
00:25:21.680 --> 00:25:25.920
Um so this time uh cat Swan Dylan.
00:25:29.200 --> 00:25:36.880
Um okay, um so we've been walking around in this world, but but how do we actually do that?
00:25:37.359 --> 00:25:39.359
Uh of course there's JavaScript involved here.
00:25:39.440 --> 00:25:51.839
We read keystrokes and and and mouse events and touch events and gamepad buttons and and then a lot of more JavaScript because we're not you don't want to walk through the walls, we want to be stopped by the walls, so there's collision detection, it's all JavaScript.
00:25:52.079 --> 00:26:02.880
And well the Doom source code is open source, and I really don't like writing C code and translating to JavaScript, so AI helped me with that.
00:26:02.960 --> 00:26:06.160
So I could focus on the fun parts, the CSS.
00:26:07.759 --> 00:26:11.440
Um but there's no camera in CSS.
00:26:12.319 --> 00:26:16.960
And and and we we can move around, we can't move around the world.
00:26:17.200 --> 00:26:20.880
Um instead, we move the world around us.
00:26:21.839 --> 00:26:29.119
We don't move through the world, the world revolves around us, which is how it should be.
00:26:30.559 --> 00:26:31.200
I think.
00:26:32.240 --> 00:26:48.240
No, um so we just set a couple of custom properties on on the viewport on on our scene, and and that makes the world uh change, uh move around us.
00:26:48.480 --> 00:26:58.559
And and whenever the player uh moves, those properties are updated, and uh the world then moves using translate 3D and and rotate y.
00:26:58.880 --> 00:27:02.720
We don't need to recalculate every wall, everything stays the same, it's static.
00:27:03.759 --> 00:27:06.240
So if we zoom out a bit, we can actually see this.
00:27:06.640 --> 00:27:08.720
The world moves around us.
00:27:09.519 --> 00:27:13.200
So if we move up the stairs, the world moves down.
00:27:13.359 --> 00:27:16.160
But the player stays always centered in the middle, it's static.
00:27:16.240 --> 00:27:19.039
And if we move back down, the world moves back up.
00:27:20.880 --> 00:27:23.279
And CSS gives us this for free.
00:27:23.359 --> 00:27:28.559
Uh what we're seeing right here, that that's spectator mode, and it's just a couple of overrides in the CSS.
00:27:29.039 --> 00:27:30.079
Nothing more.
00:27:32.480 --> 00:27:39.440
Like you may have noticed sprites such as barrels and pickups, they are always directed at the player.
00:27:39.599 --> 00:27:41.440
It's called billboarding.
00:27:41.920 --> 00:27:45.039
Um from above, it's very clearly visible.
00:27:45.279 --> 00:27:48.559
And again, that's something that CSS will do for free for us.
00:27:48.799 --> 00:27:54.640
We already have the player angle, and we can just apply that to every sprite.
00:27:55.519 --> 00:27:57.759
Um that's it.
00:28:04.880 --> 00:28:05.200
No.
00:28:07.759 --> 00:28:10.400
This angle also gives us a good look at the door.
00:28:11.279 --> 00:28:12.319
Let's open it.
00:28:17.759 -->
00:28:18.400
Yeah.
00:28:20.240 --> 00:28:21.200
That's it.
00:28:22.240 --> 00:28:25.839
Uh I wish it I could show some more interesting code here.
00:28:26.000 --> 00:28:27.440
Uh but but no.
00:28:27.839 --> 00:28:29.759
Doors are actually really boring.
00:28:30.000 --> 00:28:32.880
Uh it's just a transition between heights.
00:28:33.039 --> 00:28:39.039
Uh the offset is defined by the game data, and and and just set that as a custom property when we generate the door.
00:28:39.599 --> 00:28:43.119
Um difficult part is the game loop.
00:28:43.279 --> 00:28:51.440
Uh it needs to check collision detection again and make sure that enemies don't see through doors, and that's not interesting.
00:28:52.079 --> 00:29:01.519
The rendering doesn't need to know about any of that, it just responds to uh an attribute, the door state.
00:29:04.880 --> 00:29:06.880
Next thing we should talk about is sprites.
00:29:07.039 --> 00:29:15.680
Uh, we have all kinds of objects that we can pick up, like barrels that we can shoot and monsters, and those are 2D animated images.
00:29:15.839 --> 00:29:27.680
For example, um for in them for for enemies we have images for walking, from the front, from the side, from the other side, from the back.
00:29:27.839 --> 00:29:33.279
Um and those are all combined into one image, uh, a sprite sheet.
00:29:33.759 --> 00:29:39.680
And if we go into this room, we can actually see those sprite sheets.
00:29:39.920 --> 00:29:44.960
And the yellow box, that is the active image, the active sprite.
00:29:46.960 --> 00:29:51.680
You can see the selection when that sprite sheet is constantly changing.
00:29:56.960 --> 00:30:06.960
And by clever orientation uh of the images, we couldn't change in the background position, we can have the sprites, just the the images fully animated.
00:30:07.200 --> 00:30:10.319
One important detail is that we're using stepped animations.
00:30:10.640 --> 00:30:14.720
In case of the helmet, we are stepping over four different images.
00:30:15.920 --> 00:30:21.680
It's not a smooth transition, it's just uh the size of the image is the step.
00:30:22.720 --> 00:30:26.160
And that gives us the appearance of the helmet pulsating.
00:30:26.319 --> 00:30:37.359
Um and and while in reality that image is moving around, and it looks really good, uh, free uh automatic again, and and powered by CSS.
00:30:38.480 --> 00:30:41.200
Now, fireballs are also sprites.
00:30:41.440 --> 00:30:45.200
They are animated and billboarded just like the other sprites.
00:30:45.599 --> 00:30:52.480
But they are quite special because they are flying through space using a simple CSS animation.
00:30:56.799 --> 00:31:10.240
Whenever an imp uh launches a fireball, a new div is added to the DOM with a couple of custom properties, um, such as the start point and and the calculated endpoint and the time it needs to reach the endpoint.
00:31:10.400 --> 00:31:13.440
And then we let's let CSS run the animation.
00:31:13.759 --> 00:31:15.759
It's incredibly effective.
00:31:15.920 --> 00:31:19.920
Uh we don't need to update the position of the fireball from the game loop.
00:31:20.000 --> 00:31:21.920
It CSS does it all for free.
00:31:22.240 --> 00:31:33.359
And if you look closely here, um we use the standalone translate properties, not transform, uh, and that that's for a very good reason because um it's billboarding.
00:31:33.680 --> 00:31:41.759
Well, we'd use the transform property, we could not independently run the animation and have the billboarding effect.
00:31:41.920 --> 00:31:47.039
By using the standalone properties, we can set them without overriding each other.
00:31:47.759 --> 00:31:53.599
So here, animation controls the positioning and the player angle controls the rotation.
00:31:55.519 --> 00:32:04.240
Now we do need to tell the renderer that when there's an impact to remove it, perhaps even mid-flight, and and and then show the explosion sprite, which are normal sprites.
00:32:04.400 --> 00:32:13.519
They are just added to the DOM at the moment, and then run its course and then remove themselves again from the DOM using the uh animation and event.
00:32:13.599 --> 00:32:15.599
They're literally fire and forget.
00:32:17.680 --> 00:32:24.480
So let's talk a lot about another animation uh technique that's used throughout this project.
00:32:24.720 --> 00:32:33.599
Um the player is moving around, you can see the weapon bob around.
00:32:33.839 --> 00:32:36.240
And it's a nice little CSS animation.
00:32:37.839 --> 00:32:44.799
Um, and originally we just apply the animation when the player was moving using a class set on the viewport.
00:32:45.039 --> 00:32:48.160
But that kind of breaks the illusion when you stop moving.
00:32:48.319 --> 00:32:52.720
It just the weapon would just jerk back to the default position.
00:32:53.680 --> 00:32:57.200
Now, the solution is to always have the animation.
00:32:58.160 --> 00:33:01.440
Uh, but the default play state is set to pause.
00:33:02.000 --> 00:33:08.799
Yeah, it just paused somewhere in the animation, and we don't care where, and whenever the player is moving, we set the state to running.
00:33:08.960 --> 00:33:15.759
And so we continue where it was last stopped, and and the transition between walking and stopping is now seamless.
00:33:16.640 --> 00:33:23.759
Now, one of the last things I want to show you, because this is the web.
00:33:25.599 --> 00:33:28.960
CSS Doom is responsive.
00:33:30.480 --> 00:33:43.200
Um that creates some challenges because the gun here needs to be aligned with the top of the status bar, and whenever the status bar wraps over two or three rows, we need to move the gun upwards.
00:33:43.519 --> 00:33:47.839
So anchor positioning, that's new, that's amazing.
00:33:48.000 --> 00:33:56.880
Uh the status bar is the anchor, and we just make sure that the bottom of the gun is is anchored to the top of the status bar.
00:33:57.440 --> 00:34:04.720
It's probably not something that the spec authors intended, but I'll take it.
00:34:05.920 --> 00:34:11.519
So, yeah, that was just some of the details of how CSO and CSS Doom works.
00:34:11.920 --> 00:34:16.960
Uh it's actually amazing that it works at all.
00:34:17.519 --> 00:34:21.280
We're pretty close to the limit of what the browser can do here.
00:34:23.280 --> 00:34:31.119
And like I said, everything you've seen here, uh everything is a div.
00:34:33.199 --> 00:34:34.960
Thousands of divs.
00:34:35.920 --> 00:34:42.159
Still, probably less than a React app, but still thousands of divs and some CSS.
00:34:43.039 --> 00:34:47.440
But there's one exception, and that's this one.
00:34:48.000 --> 00:34:49.360
This is a button.
00:34:51.039 --> 00:34:52.559
As it should be.
00:34:52.960 --> 00:34:58.320
And if I can do that in Doom, what excuse do you have in your apps?
00:34:58.719 --> 00:35:00.320
Div is not a button.
00:35:01.119 --> 00:35:04.960
Um, yeah.
00:35:07.119 --> 00:35:08.800
So is this useful?
00:35:09.440 --> 00:35:16.639
No! Well, e even if Dylan says yes, don't do this.
00:35:17.199 --> 00:35:19.760
Uh CSS were never intended for this.
00:35:20.400 --> 00:35:20.719
Um,
00:35:21.760 --> 00:35:25.199
but it has been an amazing experience just making this.
00:35:26.079 --> 00:35:26.400
Um
00:35:27.039 --> 00:35:39.920
I loved working on the CSS and finding new ways to implement uh or or let's say finding new ways to abuse CSS to get this working.
00:35:40.719 --> 00:35:54.000
Um of course I did try AI for this a little bit, but then you give it a prompt and tell it to make something, and we'll just remove half of your CSS and replace it with Canvas.
00:35:54.480 --> 00:35:56.480
So that wasn't really feasible.
00:35:56.719 --> 00:35:58.719
But it's been an amazing experience.
00:35:58.960 --> 00:36:12.159
When I launched it, I I I got almost 10,000, uh hundred thousand plays in like a week and a half, and people started posting videos on YouTube about run throughs.
00:36:12.320 --> 00:36:14.719
It was just crazy.
00:36:15.519 --> 00:36:20.400
Uh so I just wanted to say um I love to code.
00:36:21.440 --> 00:36:24.639
Even nowadays with AI, I love to code.
00:36:24.880 --> 00:36:26.880
And CSS is awesome.
00:36:27.119 --> 00:36:29.280
So thank you.