nanoMMO

MMORPG combat feel in C++ with hit-stop, knockback and a sword combo

Blows that push monsters back, a moment's hold as each one lands, monsters that flash and rock back, a lit blade and cuts in the air, and a chain of three swings on Space, in our C++ MMORPG.

Watch on YouTube

Our MMORPG's fights get some weight. The C++ server lets a skill land more than once, and each blow pushes the monster back over a fifth of a second, eased out, instead of moving it in one tick. The raylib client adds hit-stop on its own clock: each blow that lands holds the player and the monster still for a few frames, longer for a heavier hit, and they catch up after it, so the skill still ends when the server says. The monster lights up through the shader's emission and rocks back away from whoever hit it, the blade lights along its edge, cuts hang in the air with sounds made from code, and Space goes round a chain of three swings. This is episode 61 of a series about building an MMORPG from scratch in C++, with the focus on the engineering around the game.

Topics: Graphics, Gameplay

The code

Each step on screen is a tag in the game's repository. The code at the end of the episode is ep061/end.

  1. 2:42ep061/step-1Blows that pushBrowseChanges
  2. 11:13ep061/step-2A hold on each hitBrowseChanges
  3. 19:02ep061/step-3The monster reactsBrowseChanges
  4. 25:00ep061/step-4A lit edge and cutsBrowseChanges
  5. 31:56ep061/step-5Three swings on SpaceBrowseChanges

Transcript

Intro

0:00 Hello, and welcome to episode sixty-one, where we're going to give our fights some weight, so that a sword feels like it hits something. We'll add blows that push, a moment's hold as each one lands, and a chain of swings on Space. Before we build it, let's see where it's going.

0:16 By the end of the episode, our fights have some weight to them. Space goes round a chain of three swings, two quick ones and a heavy one from overhead, and each blow that lands holds both fighters still for a moment, lights the skeleton up and rocks it back. Whirlwind lands a blow each time its blade comes round in front, and each one pushes the skeleton back a little. And Earthsplitter's blade glows as it's raised, with a cut left hanging in the air as it lands.

0:45 There's more on the project's website, with a link to the code on GitHub, which is open source, and a page for each episode, where you can browse the code at each of its steps.

Last time

0:55 A quick reminder of where we left off, first. The people got a rig of our own, a skeleton of twenty-four joints in the content, with two builds, which the client builds each person on. Their legs reach for their feet, as two bones bent at the knee, and the walk and the run come from where the feet go, so the feet don't slide. The death is keys over the stance, with the ground holding the body up, and with all of that, Mixamo's files went, so a fresh clone builds and draws everyone without anything to download.

Today

1:25 Here's a fight as the game stands, before today's work. Space is a single swing of the sword, two seconds long, which the server lands nine tenths of a second in. The hit reaches the client as an event, which shows the damage done over the skeleton, while the skeleton's figure carries on as it was, as if nothing had touched it. Whirlwind's blade goes round twice, and it lands once, half way through. And the kick pushes three metres, which the server does in a single tick, so the skeleton jumps there.

2:00 So today, a blow is going to feel like one, in five steps. First, a skill can land more than once, and each blow pushes the monster back over a fifth of a second. Then each blow that lands holds the player and the monster still for a moment, which is called hit-stop, and they catch up after it. The monster lights up and rocks back from the hit, the blade lights up along its edge, and cuts hang in the air, each with a sound. And Space becomes a chain of three quicker swings. The damage and the pushes stay the server's, as it decides what happens, while the hold, the light and the rocking are the client's, as they're about how it looks. Right, let's start with the blows, in the content.

Blows that push

2:42 Episode sixty-one's code gets a version of its own, so in the top CMake file, the game goes up to zero point sixty-one point zero, the version the login server will expect from each client. So far, a skill lands once, at its hit, and two of them push: the kick and Earthsplitter. In our proto file, a new message, blow, is a moment a skill lands, for a skill that lands more than once, such as a spin that goes round twice. A blow has how far into the skill it lands, in milliseconds, as the skill's hit does, and how far it knocks a monster back, in metres, as the effect's push does. Further down, in the effect, which is the server's part of a skill, a skill gets a list of blows, field ten, in order. A skill with blows uses them in place of its hit and its push, and they share its damage out between them, so a skill that lands twice doesn't hurt twice as much. In the skills file, Thrust gets a push of four tenths of a metre. Whirlwind's single hit goes, and it gets two blows instead, one on each spin, as the blade comes round in front, at six hundred and ninety milliseconds and at nine hundred and ninety, each pushing a quarter of a metre. The swing on Space pushes a quarter of a metre too, Frost Nova and Searing Arc a little more, and the lightning nearly half a metre. In the skills' header file, parse skills now refuses blows that go back in time, or land after the skill's over, as it does a move's keys. In skills, where the file is read, we go through a skill's blows, keeping the time of the one before. A blow earlier than the one before it is an invalid argument error, whose message says the skill's blows go back in time. So is a blow after the skill's cast is over, which says it lands a blow after it's over. Either would be a slip in the content, which is better found as the server starts than in the middle of a fight. The content's test of skills that don't add up gets two more cases, each of them refused with its own message, as parse skills returns. The first is a spin that lasts nine hundred milliseconds, with its first blow at six hundred and its second at three hundred, so its blows go back in time. The second lands its first blow at three hundred milliseconds, which is fine, and its second at twelve hundred, after the nine hundred millisecond cast is over.

5:00 Now for the server's side of the push. A push used to move the monster all the way in a single tick, a twentieth of a second, which reads as a jump on screen. So in the world's header file, a push takes two hundred milliseconds, four ticks, fast at first and slowing, as a shove does. Each monster keeps its push, as it plays out over a few ticks: where the push started, along x and along z, how far it goes along each, in metres, and how long it's been going. That starts at the whole push time, so a new monster isn't being pushed. While a push goes on, the monster doesn't hunt, though a swing it started still runs to its end. Land, which hurts and pushes what a skill reaches, now takes the blow, its index and how many there are. A skill that lands more than once shares its damage out between its blows, and heals with the first. Push starts a push away from the player, by metres, and slide, which is new, moves the monster on along its push, and says whether one's going on. In world, where a player's skill runs each tick, the skill used to land once, as its cast passed its hit. Now, a skill without blows of its own gets one, made from its hit and its push, so the code after it sees blows either way. The count is the skill's blows, or one, and for each, we take the skill's own blow, or the one we made. A blow whose time the cast has just passed this tick lands, with its index and the count, so two blows that fall in one tick both land. In land, the heal comes with the first blow, so a skill that lands twice doesn't heal twice. The blows share the damage, and the last one takes what doesn't divide. The total is worked out as the damage was, from the skill, the player's level and their stats, and each one gets its share, in whole numbers, with the last taking the remainder. Whirlwind's twenty-five comes out as twelve and then thirteen. Each monster it reaches is pushed by the blow's own push, and then hurt. Push doesn't move the monster any more, and notes where it is instead, then the push along x and along z, away from the player and as long as the metres, and it starts the push's clock at zero. So a push that comes while another is going on starts again from where the monster is. Slide plays the push out, a tick at a time, like a walk, so where the sea or a tree is in the way, the monster slides along it, or stays put. Each tick, it goes to where the push has reached by then, eased out. Once the push time's gone by, there's no push going on, and slide says so. Otherwise its clock moves on by the tick, up to the whole push, and done is how far through it we are, from zero to one, by dividing the two durations as floats. That share is bent so it slows down towards the end, as one less the square of what's left. So the shove covers three quarters of the way in half its time, and slows to a stop at its whole length. Then slide walks it, as a walk would, from where it is now to where the shove started, plus that share of it, along x and along z. Each is kept inside the land's edge, and slide says that one's going on. In the monster's act, a dead monster's push ends, as the killing blow may have started one, so a monster that comes back to life doesn't carry on sliding. A living one is moved on by its push first, and a swing it started still runs to its hit and its end. While it's being pushed, it stays idle and doesn't hunt, so it doesn't walk back at the player in the middle of the push.

8:32 Now, let's bring the world's tests up to date. The test of skills that players use once they're ready has a kick, which pushes a skeleton three metres, from one metre away to four. Right after the kick lands, the skeleton has taken the damage, the kick's ten and five more for the player's level, and it's on its way, short of four metres. Three ticks later, it's there, at four metres, as the test checked before. Then a new test, of a skill that lands more than once. Its world has the sword, and a skill parsed from text, in the skills file's format: a whirlwind of its own, at level one, which lasts a second, reaches five metres and does twenty-five damage, to all that it reaches. It has two blows, at three hundred and at seven hundred milliseconds, each pushing a whole metre. That's easy to measure, as a skeleton stays put while it's pushed, and doesn't walk. A player who knows the skill joins, with a skeleton two metres away. The player uses the skill, and the first tick starts it. Its first blow is due three hundred milliseconds in, with half the damage, and it should push the skeleton a metre further away over the ticks after it, from wherever the skeleton has walked to by then. Five more ticks take the cast to two hundred and fifty milliseconds, just short of the first blow, and the test notes where the skeleton is. One more tick, and the blow lands: the skeleton has lost twelve, half the damage, rounded down. Three ticks after that, the push is done, and the skeleton is a metre further away than it was, wherever it had walked to by then. Four more ticks take the cast to six hundred and fifty milliseconds, just short of the second blow, and the test notes where the skeleton is again. The second blow takes the other thirteen, and three ticks later, it's pushed the skeleton another metre, measured from where it was this time.

10:25 We build the server's tests at this step, in Docker, and run the kick's test and the new one, which need neither MySQL nor Redis. The kick's push plays out over its ticks, and the two blows share the damage and push a metre each, so both of them pass.

10:41 Let's see it in the game at this step, from the spot the fight before started at. Each swing pushes the skeleton a quarter of a metre over four ticks, and the client eases each figure towards where the server says it is, as before, so the skeleton slides back a little with each hit. Whirlwind lands twice now, with a number for each blow, twelve and then thirteen, and a push for each. And the kick's three metres take a fifth of a second, fast at first and slowing, where they used to be a jump.

A hold on each hit

11:14 A blow that lands in a frame and moves straight on doesn't feel like it met anything. So when a blow lands, we're going to hold the player and what they hit almost still for a few frames, and then let them catch up. In our proto file, the look gets stop milliseconds, field six, how long each blow that lands holds them. It's in the look, as it's the client's part: the server's clock doesn't stop, and neither do the damage and the push. A blow that pushes further holds longer, up to two and a half times as long, and they catch up after it, so that the skill ends when the server says. In the skills file, Thrust and Kick hold for eighty milliseconds, Whirlwind's two lighter blows for fifty-five each, and the swing on Space for sixty. Earthsplitter holds for ninety, the heaviest, the frost and the fire for seventy, and the lightning for eighty. Second Wind heals, so it lands on nothing, and has none.

12:08 The client does this on its own clock, in the fx, which already follow each skill a player is using, from how long ago it started. In the fx header file, we include set, for the monsters a cast's blows land on, and the items' header, as a swing lands when the weapon in the hand says. While a blow that's landed holds things, they go at a twentieth of their speed, and after it, they catch up, faster than usual, over one and a half times as long as the hold. Slowing them right down, instead of stopping them dead, keeps a little life in the pose. The constructor takes the items too, to know each weapon's swing. They default to none, so the fx test, which makes its fx without any items, still builds. Hold is the new step, which comes after update. It holds back each player whose blow has just landed, and what it landed on with them, for the weight of the hit, by pulling their clips' times back. A cast had one time, the seconds since it started. Now it has two: the clock, which runs as the server's does, and the time, how far its move and fx have got, which the blows that land hold back. A cast keeps whether each blow it's come to so far landed, in order, and what its blows landed on, by id, to hold still with the player. A beat is when one of the skill's blows lands, in seconds, for this player, and its weight, which is how many times the skill's stop it holds things still for. Blows of gives a skill's beats for a player, as a vector, since a swing's depends on the weapon the player holds. Lag gives how far a cast's held back now, in seconds. And lands decides whether a blow lands, as we see it: what it goes for is alive and within its reach. What it lands on goes into the cast's struck. Last, the fx keep each weapon's swing, by its item's id, from the items the constructor gets. In fx, the constructor takes the items, and goes through them, keeping the weapon of each item that has one, with its reach and its hit. Update moves each cast's clock on by the frame's seconds, where it used to move its time. A cast starts afresh for another skill, or when the player's clip is further back than the clock was a frame ago, which is the skill starting again. A fresh cast has a seed of its own, and none of the old one's blows, or what they struck. Then the clock takes the time of the player's clip, which follows the server. A second loop goes through the casts, and looks up each one's skill. It gets the cast's beats, the moments its blows land, in order. Then it decides each blow that the clock has come to, and that it hasn't decided yet. Each lands or doesn't, as we see it then, and that's kept for good, so a monster that dies or steps away a moment later doesn't take the hold back. The cast's time is its clock less its lag, and the copy of the player the fx are drawn from takes that time, so the trail follows the held blade. Blows of comes next, and gives each blow its weight. A blow is half as heavy again for each metre it pushes, up to two and a half times the skill's stop, in a small lambda, as we need it twice. So the kick's three metres and Earthsplitter's two weigh in at two and a half and two. Each of the skill's blows becomes a beat, at its time in seconds, with its weight. A skill without blows of its own lands once. For a swing, that's at the hit of the weapon in the player's hand, from the figure, and for any other skill, at its hit, as the server does, with the skill's push for its weight. Blows of returns the beats, in the order they land. Lag works out how far a cast is held back. Each blow that's landed holds it back while it's still, and then less and less as it catches up. To start with, lag looks up the cast's skill. The skill's stop is in milliseconds, so we turn it into seconds, and a skill without one isn't held at all. It gets the skill's beats for the player, and the lag starts at zero, and each blow the cast has come to adds to it. Since is how long ago the blow landed, and held is how long it holds, the stop times its weight. A blow that didn't land, or hasn't come yet, adds nothing. The most it can hold the cast back by is nineteen twentieths of the hold. While the hold lasts, the lag grows by nineteen twentieths of the time since the blow, so the cast moves on at a twentieth of its speed. Then, over one and a half holds, the lag shrinks back to nothing in a straight line, so the cast runs faster than its clock until it's caught up, and the skill ends when the server says. Lands decides it on the client's side, from the figures. We give it some slack, half a metre further than the server's reach, as we see everyone a moment late. The player is the cast's figure, and we find the weapon in their hand among the fx's weapons. The reach is the weapon's for a swing, or else the skill's, plus the slack. A skill that does no damage, like Second Wind, lands on nothing. Otherwise, we go through the figures, and skip any that isn't a monster, or is dead, or isn't the one picked, for a skill that doesn't hit all. The distance across the ground, from hypot, has to be within the reach, and for a skill with an arc, the monster's direction, against the way the player faces, has to be within half the arc either side. A monster that passes is struck, and the blow has landed. It's what we see, not what the server decides, as the hold is about how it looks, while the damage stays the server's. Hold then goes through the figures the renderer draws. A monster is held back by the most that any cast that struck it is held, and a player in a skill by their own cast's lag, which is the gap between the clock of the cast and its time. The times of both its clips go back by the lag, the one it blends from and the one it blends to. They don't go back past zero, where they started, as a clip that's just changed is hardly into its own yet. In draw solid, the shards and the spikes are thrown out by a blow, so they fly on through its hold, on the cast's clock. In draw light, what goes with the body, the trail and anything on the blade, is held back with it, and takes the cast's time. What a blow throws out in light, such as its sparks, flies on through the hold too, on the clock, and so does the camera's shake. In the renderer's header file, animate moves the fx on each frame, and then holds the figures, before they're drawn. And in the renderer, the fx get the content's items when they're made.

18:33 Here's the hold in the game at this step. A swing's blow holds both figures for about sixty-seven milliseconds, four of the game's frames or so, which reads more as the sword meeting something than as a pause. The kick pushes three metres, so it holds for two and a half times its eighty milliseconds, a fifth of a second. Earthsplitter holds for twice its ninety milliseconds, as its push is two metres. The pushes and the numbers carry on through the hold, as they come from the server.

The monster reacts

19:02 Next, the monster is going to react to each hit it takes. In the animator's header file, a figure gets a lean, how far it's tipped over, in radians, and which way it tips, as a yaw. It gets a flash too, how lit up it is from a blow that's just landed, from zero to one. Reactions get a header file of their own, which brings in fixed-width integers, for the ids, maps, vectors, and the animator's header, for the figures. The class keeps how the monsters take the blows that land on them: each one lights up, and rocks back away from whoever hit it. A flash takes a hundred and fifty milliseconds to fade, written in seconds, as the frame's time comes in seconds. A blow rocks a monster back by three tenths of a radian at most, about seventeen degrees. It gets there in thirty milliseconds, and comes back upright with a time constant of a hundred and twenty milliseconds. A blow's kept for a second, by when it's done rocking. Hit says the player hit the monster, both by their ids, update moves each blow's reaction on, by the frame's seconds, and apply lights up and rocks the monsters among the figures, as their blows have them now. Under private, a blow keeps the player who struck it, the seconds since it landed, and the way away from the player, as a yaw. A flag says whether we've seen where they are yet, as the player who struck may be out of sight. And the class keeps the last blow on each monster, in a map, by the monster's id, as a new blow on a monster replaces the one before. In reactions, we include algorithm, for max, c math, for atan two and the exponential, maps and vectors. Hit puts a fresh blow on the monster, with the player who struck, in place of any blow it had, so a second blow starts the flash and the rock again from the top. Update goes through the blows, ageing each by the frame's seconds, and erase if, from C plus plus twenty, lets go of each blow older than a second, by when its monster's done rocking. Apply needs to know where each player is, as a blow names the player who struck it. So first, it maps each player's id to its figure, with a pointer, leaving out the monsters and the NPCs. Then it goes through the figures again, for the monsters, and looks for a blow on each one. While we can see the player who struck, the way to tip is away from where they stand, along the line from the player to the monster, which atan two turns into a yaw, and the blow is aimed. A blow keeps the last way we saw, if the player goes out of sight. Then comes the rock, worked out from the blow's age. It goes up in a straight line over thirty milliseconds, as the blow lands, then dies away exponentially, so the monster snaps back fast, and comes upright slowly. The flash falls from one to zero over its hundred and fifty milliseconds, the lean is the rock times the most it tips, once we know which way, and the way it tips is away from the player. In the client's CMake file, reactions go into the client's core library, next to the fx.

22:02 Drawing the flash and the lean is the characters' job. In their header file, they keep the shader they draw with, and where its emission uniform is. Emission is light a figure gives off of its own, which the shader adds to the sun's and the ambient light, and until now nothing set it for the figures. In characters, a flash at its brightest gives off two and a half on top of the sun's and the ambient light, which takes a figure's colours well past white, so the bloom picks it up. Both constructors keep the shader, and look up the emission uniform's location once, instead of by its name each time a figure is drawn. Placed, which makes a figure's matrix, now tips it over after the scale and the turn about up. It turns about an axis that lies flat, across the way the figure leans, by the lean, before the move to where it stands, so it tips about its feet, where its origin is. In draw, the shader's emission is set from the figure's flash, before any part of it is drawn. The draw lambda gave raylib a position, a turn about up and a scale, which can't tip a figure over. So it takes a copy of the model now, multiplies the placed matrix into its transform, and draws it at the origin, at a scale of one, as the matrix has the scale in it. The weapon was drawn last, after an early return when there's none. Now it's drawn inside an if, which holds when there's a weapon in the hand and the character has a hand to hold it. The weapon goes in the hand, by the grip, with the placed matrix after it, so it tips over with the figure. It gets its outline when there is one, and it's drawn, as before. Either way, at the end, the emission goes back to zero, so the next figure doesn't glow. In the renderer's header file, which brings in the reactions' header, animate gets two more steps, between moving the fx on and the hold. The client's main calls animate once a frame, with the frame's time, before the renderer draws. The reactions come first, and the hold from earlier stays the last thing animate does, so it can hold back a monster's clips as well as a player's. So each frame, after the fx have moved on, the reactions move on too, and they're applied to the figures, and after that, the hold pulls their clips back. Struck hands a hit on to the reactions, with the monster and the player, and the renderer keeps them as a member, next to the fx. In the client's main, the events from the server already go to the combat text. Each hit among them goes to the renderer too, with the monster that was hit and the player who hit it.

24:34 And here are the reactions in the game at this step. Each hit the server sends lights the skeleton up, a flash that blooms and fades in a few frames, and tips it back, away from arthur, about its feet, while the hold keeps both still. Both come from the hit event the server sent, a moment after it decided the blow. Whirlwind's two blows are two hit events, so the skeleton flashes and rocks back twice.

A lit edge and cuts

25:01 Now the sword gets some light of its own. In our proto file, the kinds of fx get two more. Edge is the blade, lit along its edge, and slash is cuts that hang in the air. Each is drawn across in a flash, as long as the fx's size, and then fades, and there are as many as its count, each at a slant of its own about the fx's angle. So an fx's count can be how many cuts there are now. An fx gets up, how far above where it is, in metres, so a cut can land across a monster's chest, a metre up from its feet. And angle, in degrees, is how a cut slants, where none is level and ninety is straight down, as the player sees it. In fx, draw edge takes the moment, the blade's hilt and tip, and the camera, and lights the blade along its length: a bright core down the middle, flickering a little, and a glow at the tip. It comes on fast, in sixty milliseconds, and goes slowly, over a hundred and fifty, which is the smallest of the two ramps and one, from the time it's been on and the time it has left. It flickers a little, between seventy percent and full strength, with a sine, fast enough to read as a shimmer. The light starts a little up from the hilt, at the guard, and it's eight centimetres wide, unless the fx gives a size. A wide, faint streak down the blade, three times that width and at about a third of full strength, is the glow, and a narrow one, nearly white, at full strength, is the core, which blooms. And a blob of light sits at the tip of the blade, two and a half times as wide as the core, which fades with the edge. Draw slash takes the moment and the camera. It draws the cuts across the air, flat to the camera, so that each one reads as the stroke that made it, drawn across from one end in a flash, then thinning away. A cut is sixteen steps along its length, drawn across in seventy milliseconds. A cut after the first comes sixty milliseconds after the one before, and slants its own way, up to fifty degrees off the fx's angle, one way and then the other. From the way the camera looks, we get its right and its up, as the blobs of light do, so the cuts lie in the view's plane. For each cut, its age is the fx's less its stagger, and its life is the fx's span less the last cut's stagger, so the last cut ends as the fx does. How much of it's drawn goes from none of it to all of it in the first seventy milliseconds, and it fades over its life, quickly at first. The first cut is at the fx's angle, and the others go either side of it in turn, by a random share of the spread, from the cast's random numbers, which come out alike in each frame. Along is the cut's direction on screen, from its slant, and bow is across it, in the view's plane, which the cut is bowed and widened along. Its middle is where the fx is, moved a little at random, up to fifteen centimetres each way, so each cut is a little off the middle. It's seven percent of its length thick in the middle, and thinner as it fades, down to about a third of that. Point gives a spot on the cut, from zero to one along it, and a side across it. Its width goes with a sine along it, so it's widest in the middle and sharp at both ends, and it bows out by eight percent of its length, with a sine as well. Light over the grass takes on its green, so the glow around a cut is faint, and the bloom does the rest, around a white-hot middle that's nearly solid. So for each of the sixteen steps, a and b are where the step starts and ends along the cut, as far as it's drawn so far. Two wide quads, one on each side of the middle, go out to two point two times the width, in the fx's colour, from about a fifth of full strength in the middle to nothing at their edge. And two narrow ones inside them go out to point eight times the width, in the hot colour, at full strength in the middle and a third of it at their edge, which is the core that blooms. In draw light, the edge goes with the blade, so it's held back with the body through a hold, like the trail. An fx that isn't on the blade is lifted by its up, above the ground where it is. For the edge, we pose a copy of the player at the cast's time, to find where its blade is, and draw the edge along it, and for a slash, we draw its cuts. In the skills file, Thrust's blade lights up pale blue from a quarter of a second in, for the lunge, and a cut goes across the monster as the thrust lands, a metre up and nearly level. Whirlwind's blade burns orange all the way through both of its spins. Earthsplitter's lights up as it's raised, and its cut comes down nearly straight, two metres long, as the blade slams into the ground.

29:33 Each kind of fx has a sound of its own, made in foley from noise, tones and filters, and the new two need theirs. In level, which sets how loud each kind is against the others, the edge is quiet, at fifteen hundredths, as it plays under the swing's own sounds, and a cut is a little louder than most, at fifty-five. In fx sound, which makes the sound for an fx, the lit blade sings. Its note is two octaves above the one its colour gives, so a blade's song is high, and a cold colour's is higher still. A second, quieter note isn't a whole multiple of the first, so the two ring like metal, and a ping starts it off as it lights. The song lasts a fifth of a second longer than the fx, with an oscillator for each of its two notes. For each sample, we take its time in seconds, and a waver of six thousandths of the pitch, up and down five and a half times a second, like a vibrato. The second note is at two point seven six times the first, at about a third of its loudness, and the envelope swells the song in over eighty milliseconds, and lets it die away as the fx goes on. Its end fades out, so it doesn't click, and it's mixed in, with a ping, an octave higher still, as the blade lights. A slash is a sound for each of its cuts: a hiss of air, high up, a snap and a short ring of metal, each a little after the one before, as they're drawn. The cuts are the fx's count, and at least one, as draw slash draws them, so a slash without a count sounds once. There's a sound for each cut, up to eight, made in a loop, each sixty milliseconds after the one before, as they're drawn. Each has a hiss of air, about an eighth of a second of noise through a high pass at six kilohertz, and a snap, which is a click. Then comes a short ring of metal, a tone somewhere between two thousand eight hundred and three thousand six hundred hertz, picked by the noise's random numbers, and falling a little, with a fainter partial over it.

31:29 Now the lit blades and the cuts in the game at this step, with the game's sound. Thrust's blade lights pale blue for the lunge, and a cut hangs across the skeleton as it lands, with its hiss and its snap. Whirlwind's blade glows orange through both spins, singing as it goes round. Earthsplitter's blade lights up as it's raised, and its cut comes down nearly straight as the blade meets the ground.

Three swings on Space

31:56 Last, let's turn to the swing on Space. A single swing of two seconds, over and over, is slow, and it looks alike each time. So Space is going to go round a chain of three swings: a quick cut down across, a quick one back the other way, and a heavy one from overhead. In our proto file, the effect gets a pace, for a swing of the weapon. It's the share of the weapon's own swing that it takes, and its timing and its damage with it, where zero, protobuf's default, is the whole swing. That way, a chain of quick swings does as much of the weapon's damage over a second as one slow one, and the weapon's numbers stay in one place, the items file. A skill gets next, the swing it goes on into, by its id, and window milliseconds, how long after its end Space goes on into that one. Holding Space uses it again as soon as each swing is over, so it goes round the chain. And everyone knows the swing on Space, and now the swings it goes on into as well. In the skills' header file, parse skills also refuses a swing that goes on into a skill that isn't there, as it does a swing on Space that isn't. In skills, once all the skills have been read, we check each skill's next. One that names a skill the file doesn't have is an invalid argument error, which says the skill goes on into a skill that isn't there. Then, to start everyone with the whole chain, we follow next from the swing on Space, adding each to the starting skills. It stops when there's none, or when it comes to one that's already there, so a chain that comes back round to its start doesn't go on for good.

33:30 In the skills file, Strike becomes the chain's first swing. It takes fifty-five percent of the weapon's swing, so with the sword, it lasts eleven hundred milliseconds and lands at four hundred and ninety-five, with eight of the sword's fifteen damage. It holds a little more briefly too, for fifty milliseconds. Its move is quicker to match, with all four of its keys earlier. The wind-up gathers by two hundred and seventy milliseconds, with the chest turned forty degrees and the sword arm raised and drawn back. The cut snaps across by four hundred and eighty, with the chest turning the other way, and both knees bend as the right leg steps into it. It doesn't step forward any more, so it stays where it stands from one swing to the next. It follows through by seven hundred and twenty, with the sword arm not dropping as far as it did, and the knees still bent, ready for the next swing. It's back by ten fifty, before the swing's eleven hundred are up. Its trail is shorter, from three hundred milliseconds for two hundred, while the blade's moving fastest. As it lands, a cut slants across the monster, thirty-five degrees up from level, a metre up. The sparks fly from nine tenths of a metre up the monster's body, where the blade meets it, instead of from its feet. After its end, Strike goes on into skill fifteen, if Space is used within six hundred milliseconds of it. Skill fifteen, Return Cut, is the swing back. It's at level one, like Strike, and it's as quick as Strike, at fifty-five percent of the weapon's swing, pushes as far and holds for as long. Its keys go the other way round from Strike's, and from the cut on, they're timed like Strike's. It gathers by two hundred and twenty milliseconds, crouching six centimetres. It winds up on the side where Strike's cut ended, with the chest turned fifty degrees that way. The sword arm is wound up further across than Strike's cut left it, with the hand bent back to keep the blade out flat. The left arm is held out from the side, by forty degrees. The legs stand as Strike's cut left them too, the right one forward and both knees bent. The cut snaps back across by four hundred and eighty, to fifty degrees the other way, leaning a little into it. The sword arm swings across to the other side, with the forearm bent a little and the hand bent back, and the left arm comes forward a little. The body drops twelve centimetres, and the right leg reaches further forward, its knee bent more. By seven hundred and twenty, it eases back a little, holding the follow-through. The chest is still turned forty degrees, the sword arm is out to the side and the left arm held a little out. The legs are back as they were at the wind-up, the right one forward and both knees bent, and it's back by ten fifty, like Strike. Its trail is on the blade from two hundred and sixty milliseconds, as the cut gets going. Its cut across the monster is nearly level, at five degrees, a little longer than Strike's, with the sparks where the blade meets it. It goes on into skill sixteen, within six hundred milliseconds too. Overhead Cut is the heavy one, at ninety percent of the weapon's swing, so it lasts eighteen hundred milliseconds and lands at eight hundred and ten, with fourteen of the sword's damage. It pushes eight tenths of a metre, and holds for seventy milliseconds, which its push makes longer, about a tenth of a second. Its wind-up gathers by four hundred and fifty milliseconds, rising four centimetres, with both arms raised right up over the head, the elbows bent, and the chest leaning back a little. Then it snaps down by seven hundred and ninety, the body dropping thirty centimetres and lunging thirty-five forward. It bends thirty degrees at the spine and thirty more at the chest, with the arms brought down in front of it, and the sword hand bent at sixty degrees. The legs go into a deep lunge, the right one forward with its knee bent seventy-five degrees, and the left knee sixty. It holds that until twelve fifty, just a little higher and further back, with the spine and the chest bent twenty-five degrees each, and the arms and the legs as they were. So the heavy blow stays down for a moment, which gives the hit time to read, and it's back up by seventeen fifty, a twentieth of a second before the swing's over. Its blade lights gold as it's raised, and it leaves a trail on the way down. As it lands, a cut comes down nearly straight, two metres long, at eighty-five degrees. There are twenty sparks, from nine tenths of a metre up the monster, a ring of light on the ground around it, spreading out a metre and six tenths, and a small, short shake of the camera. It has no next, so after it, Space starts again from Strike.

38:07 The server keeps where each player is in the chain. In the world's header file, a player gets chain, the swing that Space goes on into next, by its id, or zero for the first, and how long there's left to use it. In world, where a skill runs, when a player's skill is done, we look up the skill that's just ended, as a swing in a chain leaves a moment to use the next one. The chain moves on to the swing it goes on into, with its window to use it in. A skill that isn't in a chain has no next, so the chain goes back to zero. Each tick, the window runs down by the tick's time, and stops at zero. With Space down, a player now gets the next swing in the chain, while there's time left to use it. With Space down and nothing else asked for, when there's a next swing and time left for it, that's the skill Space asks for, and otherwise it's the swing on Space, from the start. Holding Space asks again each tick, so the next swing starts in the tick the last one ends. In effect of, which takes a swing's numbers from the weapon, the pace scales them, with a lambda that captures the pace and rounds to the nearest whole millisecond, or point of damage. The damage is paced, and kept to one at least, so a quick swing of a weak weapon still hurts, and so are how long the swing lasts and when it lands. And starting any skill uses up the chain, which the swing's end starts again. So a skill in between, or a pause longer than the window, sends Space back to Strike. In land, a blow's damage was the skill's, plus all of what the player's level and gear add. For a quick swing, that would add the level's damage in full as often as it swings, so the chain would hurt more over a second than the slow swing, the higher the level. So the blows still share the damage, with the last taking what doesn't divide, and now a quick swing takes its share of what the level and the gear add, as it does of the weapon's. The pace is the swing's own, for a swing of the weapon that has one, and one, the whole of it, for any other skill. The total is the skill's damage, which effect of has already paced, plus the pace times what the level and the gear add, rounded to a whole point. That way, holding Space hurts about as much over a second at any level. On the client, in fx, blows of works out when a swing's blow lands, for the hold, and it has to agree with the server's. A quick swing of the weapon lands as much sooner as it's quicker, so the pace is read the way the server reads it, with none as the whole swing. The hit is the weapon's hit times the pace, as a float, in milliseconds. Other skills land at their own hit, as before, so the hold lands with the server's blow. In the hotbar, which brings in set, the constructor lays out a slot for each skill, apart from the swing on Space. The swings Space goes on into are Space's too, so they get no slot of their own. We gather the swing each skill goes on into, in a set, going through all the skills, and leave those out of the slots, along with the swing on Space, which has its own.

41:07 Now, a quick test that holding Space goes round the chain, which brings in set, for the skills everyone starts with, and our levels' header, for a second test. It parses three swings of its own from text, in the format of the content, with the first one on Space. They're a Strike, a Return Cut and an Overhead Cut, with the ids one, two and three. The first two are quick ones, each half the sword's swing, so a second long, and each goes on into the next if Space is used within half a second of its end. The third is a whole swing, two seconds long, at the end. The skills have to parse, and everyone starts with all three, from the swing on Space alone. The world's content is the sword and these skills, and a player joins, with nothing but what everyone starts with. The test keeps the skills that start, in order, and the count of casts it's seen. The player holds Space for ninety ticks, four and a half seconds, which is long enough for all three swings and the start of the first again. Each time the count of casts goes up, the test notes which skill started. They come in order, and back round to the first. Then the player lets go of Space, for two seconds, which is longer than the moment the first swing leaves to use the next. The swing that started last runs to its end, and its moment runs out. Then the player holds Space down again, for a single tick, and the swing that starts is the first again, and the player is using it. The second test checks that a quick swing takes its share of what the level adds too. It parses a single skill, a Strike on Space at half pace, which has to parse. Its world has that Strike and the sword, as in the test before it. The player joins with three hundred experience, which the test makes sure is level three, as the levels' table says. At level three, a whole swing does ten more damage than the weapon's. The skeleton is made a metre away, within the sword's reach, and it gets a thousand health, so the swing can't kill it. It's spawned there, and the player picks it as the target. Then Space is held for twelve ticks, six hundred milliseconds, past the half swing's hit at four hundred and fifty. The skeleton loses half the sword's fifteen and half the level's ten, each rounded, which is eight and five.

43:24 We build the server's tests at this step and run the chain's two, with the blows' test from earlier, as the chain changes how a player's skill runs each tick. Holding Space goes round the three swings and back to the first, a quick swing takes its share of the level's damage, and all three tests pass.

43:42 Here's Space at this step, with the game's sound. Held down, it goes round the three swings: the quick cut down across, the one back, and the heavy one from overhead, with its gold blade and a cut nearly straight down. Each blow lands with its hold, its flash and its push, the quick two with smaller numbers, as they take a share of the sword's damage, and then the chain goes round again, from Strike. The hotbar has Strike on Space, and no slots for the two that follow it. After a pause longer than the window, Space starts the chain from Strike again.

Wrap-up

44:17 So, today, a skill got blows of its own, which share its damage, and each blow pushes the monster back over a fifth of a second, eased out, on the server. The client holds the player and what a blow lands on for a few frames, the heavier the blow the longer, on its own clock, and lets them catch up after. The monster lights up through the shader's emission and rocks back, away from whoever hit it, the blade lights along its edge, and cuts hang in the air, each with a sound made from code. And Space goes round a chain of three swings, which take their share of the weapon's swing, and of what the level and the gear add.

Playing it

45:47 Let me know in the comments what you'd like to see next, and if you want to follow along with the series, subscribe to the channel. I hope you find this useful, and thanks for watching.