Page 1 of 1

Problem with collision top down grid based game

Posted: October 6th, 2016, 4:43 pm
by Robotnick
So first a little breakdown of what I am doing. The game screen is divided up into 8x8 pixel tiles. the player can move one pixel at a time so not grid based movements. The map is made up of a 2D array(the 8x8 tile grid) so far with only floor wall and void tile spaces. I want to make it so the player cannot move onto walls or void space of course. The issue I am having is the player currently can move around fine but the collisions are not being detected properly and eventually the game crashes when it finds the collision.

The 'algorithm' for the collision detection is to get the players real x and y position and divide it by 8. Use the quotient from this to determine which tile/s the player is currently on top of. If the player is moving then check if the space the player is about to move into is a wall and to not move if this is the case...

Here is a link to the code so far. I am gonna keep going at it and see if I can figure it out. I've been trying to figure this part out for a few hours now and am starting to get sad( which is why i want help now)

https://paste.ee/p/rvJhg#

Re: Problem with collision top down grid based game

Posted: October 6th, 2016, 5:58 pm
by Robotnick
Made it do the thing. player can now hit the grid walls. :D

here is the code if anyone want to compare to the above for some reason.

https://paste.ee/p/mGmD0

Re: Problem with collision top down grid based game

Posted: October 7th, 2016, 1:17 am
by chili
Hey, welcome to the forums! Glad to see you could sort your shit out.

Can't wait to see what you're making. :)