3 ms·
Did some really cool stuff with "pixel-perfect bitmask collision" back in the day: 1. You treat 64-bit unsigned longs as 8x8 pixel squares. 2. You do "bit mag
by zamalek 11y ago
Did some really cool stuff with "pixel-perfect bitmask collision" back in the day:
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.).
- fenomas 11y agoA bit OT, but I recall being surprised to read somewhere that some chess engines do the very same thing. 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.
- Galanwe 11y agoThese are called bitboards: https://chessprogramming.wikispaces.com/Bitboards https://chessprogramming.wikispaces.com/Bitboards
- Drakim 11y ago> 64-bit unsigned longs > 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.
- zamalek 11y agoI have no retort, simply, thanks for the reality check. We come up with all these hypothetical optimization scenarios for nothing more than the challenge - my trick is probably useless, but it was fun to code.
- qrmn 11y agoI used it. It's not as fast an approach as it sounds; you want to do hitbox collision first. But if there's a better way to really do pixel-perfect collision, I couldn't figure it out - maybe subdividing hitboxes would have been, but how does that work when the sprites change? I always thought of plain old hitboxes as being unnecessarily cruel - the player can't see them - but if you were on the NES, you probably wouldn't have CPU time for much of anything better. 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.
- davedx 11y ago> 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!). 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.