Quote:
Originally Posted by NorthWay
For every object find which place in the grid the upper left corner belongs to and link in a pointer to the object. (Simple AND and shift operations.)
In the end check player against all objects in all the grid squares it can overlap.
|
This is a variation on the tile approach - assign every object to a tile and check collisions against the surrounding tiles when doing a move?
Imagine a 20x16 byte array, each cell representing a 16 pixel tile. Write into that byte the shape number (or sprite number) representing the object, 0=empty. As an object moves, check if the destination cell is occupied, and if so, by whom. Destination cell = (x >> 4, y >> 4).
It limits movement/collisions to the cell size though. Small cells take up more memory.