Collision Detection in FB Game
Posted: Mon Jun 08, 2009 7:54 pm
Hello everyone. I'm working on an RPG and I've nearly got the colission detection right. My problem is when you hit the object that is specified as a wall, you are blocked, but you also can't move in any other direction until you let go of the key. I use MULTIKEY to get the character moving. This is the collision detection code:
columns and rows are the number of columns and rows in the current map.
spritemode is the status of each tile (whether or not you can go through them)
map(a,b) is the map, of course.
the cmin, cmax, rmin, and rmax es specify the boundaries the character has to cross before any collision action is taken.
If there is a collision, the game will move the character in the opposite direction 1 pixel, according to what button was pushed.
Any suggestions? Thanks and God Bless!
Code: Select all
for a = 0 to columns-1
for b = 0 to rows-1
if spritemode(map(a,b)) = 1 then
cmin = (a*16)-15: cmax = (a*16)+15
rmin = (b*16)-15: rmax = (b*16)+15
if r >= rmin and r <rmax>= cmin and c <= cmax then
if MULTIKEY(&h48) then r = r + 1
if MULTIKEY(&h4D) then c = c - 1
if MULTIKEY(&h50) then r = r - 1
if MULTIKEY(&h4B) then c = c + 1
end if
end if
next b
next a
spritemode is the status of each tile (whether or not you can go through them)
map(a,b) is the map, of course.
the cmin, cmax, rmin, and rmax es specify the boundaries the character has to cross before any collision action is taken.
If there is a collision, the game will move the character in the opposite direction 1 pixel, according to what button was pushed.
Any suggestions? Thanks and God Bless!