Implementing the Medusa Gang - Part 2
When we last met, we talked about implementing Medusa, who freezes our hero in place on line of sight:
You forgot about this image, didn’t you? I’m not mad, just disappointed. |
We decided to check for whether Lolo’s x coordinate or y coordinate is equal to Medusa’s as a quick preliminary check. When that was true, we created a Rectangle between Medusa and Lolo and verified that there are no obstacles covering Medusa’s line of sight. There’s not much more to say about Medusa at the moment.
There is, however, an even badder mofo we should discuss:
Don Medusa, who immediately freezes Lolo by line of sight just like Medusa, but unlike Medusa, Don’s got places to be. |
This is Don Medusa. You can think of Don as a Medusa who moves side to side (or alternatively, up and down). We can reuse a lot of Medusa logic to implement Don, but there is a corner case we haven’t covered yet; what happens if Lolo moves fast enough that he blows right by a Medusa without their coordinates ever perfectly lining up?
All video games operate in discrete frames. One “frame” is a snapshot of all the game world data at one individual point in time, including every entity’s position, facing, size, health, etc. The next “frame” occurs once every entity has updated its properties once, for example updating its position based on how it’s supposed to move. If you play back every frame and draw them one by one at, say, 60 frames per second, each entity should simulate continuous movement like a flipbook.
If Don Medusa moves far enough during one frame update and Lolo moves far enough in the opposite direction on that same update, then they might breeze right by each other. I tried my naive first-pass at line-of-sight checking and I encountered this bug.
There he is, and there he goes. They never quite line up. |
Well, I guess HAL Laboratory is smarter than I, because they figured this out! This obviously doesn’t happen in HAL’s official games… right?
Pictured: a Thing happening in Eggerland for the Famicom Disk System. |
So that’s a Thing. Under the right circumstances, Lolo could walk right past a Don Medusa in HAL’s Eggerland for the FDS. I did try this in other games but the bug must have been fixed in subsequent titles because I couldn’t get it to happen elsewhere. They must have figured out Don Medusa by the time we got to…
Adventures of Lolo. Pictured: Don taking a cheap shot and a low blow. |
Through a half-space? That can’t be! I just spent an entire post talking about how Emerald Frames give half-cover! Yet here we are, Don taking potshots through a half-space. The good news is that we can beat Don with Heart Frames because Heart Frames provide cover too. Way more cover than you might think:
Lolo’s butt is out in the open and Don’s just gonna pretend they didn’t see it. |
That’s good to know, it could save me a life in one of my future playthroughs.
Or not |
Okay, what’s going on here? We’ve seen that:
Don will shoot Lolo unless Lolo walks too hard in the opposite direction,
Don can’t shoot through half-spaces except when it can, and
Don can’t shoot Lolo when he’s standing on a Heart Frame except on Tuesdays.
Well, dear reader of mine, I have not looked at any Eggerland source code or raw data, but I have enough knowledge of computer programming and game design to speculate. So let’s make guesses, shall we?
My official guess for walking right by Don Medusa is that Lolo and Don are never pixel-perfect next to each other to trigger the rest of the logic. It’s almost definitely an oversight in the Eggerland FDS line of sight check. HAL fixed the pixel-perfect check in future games, and I would guess they did it by performing Don Medusa’s line of sight check twice during Don Medusa’s movement, once before it moves and once after it moves. Checking twice works as long as Lolo doesn’t move faster than 1 pixel per frame.
You don’t need to be a better shot, you just need to shoot more bullets. |
This works, but it’s not the solution I recommend for Eggerworld. My idea is a bit more robust, and it will solve the problem even if Lolo some day moves faster than 1 pixel per frame (there is an ability to do that in some Eggerland games, after all). If we know where Lolo is and where he was, we can produce a Rectangle representing the whole area Lolo traversed. If Don’s shot can hit anywhere in that Rectangle without obstruction, then Don detects a possible shot even if Lolo’s update has already put him past Don.
You didn’t see nothin’ |
With our revised line of sight check complete, there’s one last thing to do. Like the original Medusa’s freak-out mechanics it’s more cosmetic than anything, but if Lolo moves past Don Medusa as in the scenario described above, then Don Medusa should align itself to look like it’s taking a fair shot. We could move Don Medusa backward to match where Lolo ended up, but that could lead to corner cases where Don Medusa shifts backward INTO cover if Lolo moves far enough on one frame. We could move Don forward to match Lolo’s “previous” position, but then Don would seem to warp forward faster than it usually moves. Eggerworld deserves more polish than that, so instead, we can calculate the pixel-perfect line between Lolo’s and Don’s movement where they would meet without either seeming to shift around just to get hit. And once we have that, everything is in place.
Boom! Told you! … Wait, what am I celebrating? |
Another outstanding question: why does Don Medusa shoot between Emerald Frames in the Eggerland games? You’re also probably wondering if Eggerworld Dons do that. For that, I will talk about hitboxes. In most games, graphics and collision detection are abstracted away from each other, meaning an entity’s graphics don’t necessarily represent its collision hitbox. In Eggerland, tile graphics are 16x16 pixels, but the collision boxes are more like 12x12 pixel boxes centered within the tile’s graphic. This smaller hitbox is more obvious when we look at the way another enemy, Alma, overlaps Lolo by 4 pixels before registering a “hit”.
Frame by frame analysis of Adventures of Lolo being forgiving with hitboxes so gamers can’t pretend it’s not their fault. |
I believe that Don Medusa probably uses a collision box that’s only 12x12 pixels to detect if it can see Lolo. Consequently, two Emerald Frames which are half a space from each other have hitboxes just small enough for Don’s projectile to sneak through. Let’s make sure Eggerworld doesn’t do that, eh? Let’s tentatively note that we should use a 16-pixel rectangle for line of sight checks.
Lastly, we must ask what the heck is going on with Heart Frames and why overlapping them blocks Don Medusa’s shots but only sometimes. It seems obvious that Heart Frames have their own collision box that blocks Medusa lines of sight, but I’m struggling to settle on my favorite explanation for why only sometimes. My research has found that players hanging off Heart Frames are safe from Dons or Medusas above or to the right, but not safe from Dons or Medusas below the player or to the left. It could simply be that some if-statement used a > when it should have used a >= instead. Hell, it could be Integer rounding for all I know; I am getting that distinct flavor from the problem, but we may never know.
Collision and line of sight in games can be weird, and it turns out making two things collide or even just pass each other can introduce a bounty of bugs and funny behavior. This weirdness appears in all kinds of other games too; anyone who messed with their speed attribute in an Elder Scrolls game knows that if you go fast enough, you can phase right through obstacles. Dark Souls was locked at 30fps for a long time because the collision detection simply did not account for a higher framerate. The original 1993 Doom and its sequel Doom II have collision issues all over the place in their code, and YouTuber Decino does an excellent and entertaining job covering one hilarious example in this video: Why Can Mancubus Fireballs Go Through Walls?.
Don’t worry though, our Rectangle math seems pretty darn secure for now, so Lolo won’t be getting past any Don Medusas in this game. Which… trust me, it’s a good thing no matter how heart-stopping that Medusa sound is.
Comments
Post a Comment