sionleroux / cr1ckt

There is more than 1 bug in this game and some of them are intentional! 🦗 Entry for the 2021 Game Off jam.
https://sinisterstuf.itch.io/cr1ckt
MIT License
4 stars 1 forks source link

Optimise the collision checking not to check all the tiles #35

Open sionleroux opened 2 years ago

sionleroux commented 2 years ago

Right now the collision logic starts by looping through all 8100 tiles to check to see if the cricket is colliding with any of them. Really it should only need to check the (at most) 4 tiles it's touching at the moment. Last time I tried it with ldtk's Tile At function but then I found out that that is internally looping over all the tiles so that made it worse because we were doing that 4 times instead of one, but I think this should be possible if you use some simple maths knowing:

this should let let you be able to convert a given coordinate in pixels to a row and column number for the tiles and look up only those for you're interested in from the tiles arrays without having to loop through them.