Problem with collision top down grid based game

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Robotnick
Posts: 2
Joined: October 6th, 2016, 4:27 pm

Problem with collision top down grid based game

Post by Robotnick » October 6th, 2016, 4:43 pm

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#

Robotnick
Posts: 2
Joined: October 6th, 2016, 4:27 pm

Re: Problem with collision top down grid based game

Post by Robotnick » October 6th, 2016, 5:58 pm

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

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Problem with collision top down grid based game

Post by chili » October 7th, 2016, 1:17 am

Hey, welcome to the forums! Glad to see you could sort your shit out.

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

Post Reply