View Single Post
Old 11 June 2018, 17:21   #69
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,214
Quote:
Originally Posted by NorthWay View Post
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.

Last edited by E-Penguin; 11 June 2018 at 17:41.
E-Penguin is offline  
 
Page generated in 0.04329 seconds with 11 queries