If anybody can tell me why my collision detection routine doesn't work all the time I'd really appreciate it.
For this post I'm adding REMs that aren't in the program just in case anybody doesn't know what what I'm doing.
For this example we'll assume I pushed 12 player2y player2x. 12 is the height of a turtle.
Mario_Crash rem stack should have height, Y pos, X pos
rem All sprites have a max of 8 pixels wide. TempB holds player player2x
TempA=player0x+7: pull TempB: TempC=TempB+7
rem TempD = player2x to player2x+7
for TempD=TempB to TempC
rem If any player2 pixel has the same x position as any player0 pixel then check for y position match.
if TempD>=player0x&&TempD<=TempA then goto Check_Y
next
rem The other two values on the stack aren't going to be used, but they still need to be pulled.
pull TempA: pull TempA
rem Since player2 is in front of or behind player0 then return that the sprites aren't touching.
TempE=False: return
rem Now check the y positions. This is pretty much the same process as checking the x positions.
Check_Y
if Mario_is_Large then TempA=player0y+15 else TempA=player0y+9
pull TempB: pull TempC: TempC=TempC+TempB
for TempD=TempB to TempC
if TempD>=player0y&&TempD<=TempA then TempE=True: return
next
TempE=False: return
Now, Mario touching the plant always works, but Mario touching the turtle doesn't always work. Here's some of the code for when Mario touches the turtle.
Again, I've added REMs for this post so you know what I'm trying to accomplish.
Turtle_Collision
if !Mario_is_Falling then goto Common_Collision_Options
rem if Mario is falling, then he flips the turtle upside down or rightside up.
if !Turtle_UpsideDown then Turtle_UpsideDown=True else Turtle_UpsideDown=False
rem Get the upside down or right-side up sprite for the turtle.
if Turtle_UpsideDown then gosub Turtle_U bank5 else gosub Turtle_A bank5
rem Since Mario was falling, stop the fall and make him jump up 8 pixels.
Mario_is_Falling=False: Mario_is_Jumping=True: player0y=player0y-1
rem Shrink_Timer makes Mario invincible while it is >0. In the main routine it gets reduced by 1 until it reaches 0.
Jump_Height=8: Shrink_Timer=24
return
And finally, if Common_collision_Options is called then if Mario is large he's shrunk and given some Shrink_Timer time. If Mario is small, then he dies.
Edited by jbs30000, Mon Nov 7, 2011 11:30 PM.