by zamalek · 11y ago · 0 comments
1. You treat 64-bit unsigned longs as 8x8 pixel squares.
2. You do "bit magic" (shifts etc.) to align the mask of your character/entities with the landscape.
3. AND the two masks.
4. Nonzero = collision.
I never really used it for anything (wasn't sure if it was faster than more naive approaches), but it was a neat concept/challenge. I guess it would help if you were on a resource-constrained environment (NES etc.).
Fortunately, I was on something less basic. Unfortunately, I was working on a bitplane mode (for my sins); the CPU didn't have a barrel shifter (so, for speed, one needed to store pre-shifted copies of sprites and masks); and, because the assembly instruction of course wants to modify the output, I ended up copying the dest mask and doing the source as self-modifying code with chains of unrolled andi.l #<character mask>,-(a0) / bne.w pairs; if the chain falls through, the player's just scraped by a mob.
This was of course back in the day that one didn't have to worry about pipeline or cache invalidation, because one simply didn't have the luxury of such things. The naïve loop/temp register implementation would be faster now (and, thanks to µcode and register renaming, would be what the CPU really does inside anyway).
Incidentally, you want to really look out for your animation code in games like this, because it impacts directly on game logic. Anything that might reset the animation counters will have side effects. I'm not sure if it was intended that Tiki - despite being a flightless kiwi - from Taito's The NewZealand Story actually can fly with repeated pushes of up mid-jump, for example (although the presence of secret level design elements catering for it suggests it may be, and could actually be a huge easter egg considering it wasn't documented!).
Similarly, Turrican II has a trick involving what happens if you fire and let off a smart bomb (space) at the same time while jumping, and then jump again - and I don't know if that's intended, but there's at least a couple of platforms with some nice goodies I don't think you can get to any other way.
Surely it was intentional. I remember very early in the game was a section where you fell just far enough to reverse your fall by rapidly tapping into flight (a very subtle tutorial), and several secret parts where a fall onto spikes could be turned into flight to a secret area.
IIRC, you could fly in the flying saucer too, but it was 2 tiles wide so many places could only be reached by flying "unassisted".
It's been a very long time since I played that game though! Arcades back in the 90s. Fantastic, difficult game.
Err on the side of the player. Ie give the player sprite a little smaller hitbox than would be warranted by pixel perfect collision detection, and the enemy sprites a little bigger one. That will feel very fair, and you can ramp up the difficulty in other ways.
Following the same principle, Canabalt famously allows you to jump a little bit after you already left the rooftop.
> resource-constrained environment (NES etc.)
While it's a cool technique, the NES could definitely not do it. It used an 8 bit architecture (so no 64-bit unsigned longs), and didn't have nearly enough memory to store the landscape in pixel perfect format.
That is, if one pictures the board as a 64bit bitmask, one can store masks for the locations of each side's pieces, as well as masks for the legal moves of each piece type when in each position. Then tasks like determining if a move is legal can be done with ANDs and so on.