I'm working on a side-view 2D platformer and I'm having trouble getting collisions between the player and the level to work. Reading through both BlitzBasic and BlitzCoder, there are plenty of examples of 2D platform code that can easily be ported but don't help. The player is a PNG file and so is the level, and I can't get them to collide properly. Here's the source I'm working with (that actually works to an extent):
How can I do the player collisions properly? (btw this is all temporary code, reason why I don't have object methods and functions)
While Not KeyDown(KEY_ESCAPE) Cls ResetCollisions Update() DrawImage(lyr3,lx,ly,0) DrawImage(lyr2,lx,ly,0) DrawImage(plyr1,lx+X,ly+Y) DrawImage(lyr1,lx,ly) Flip FlushMem Wend EndGraphics() End Function Update() If KeyDown(KEY_D) Xvel = 2 ElseIf KeyDown(KEY_A) Xvel = -2 Else Xvel = 0 EndIf If KeyHit(KEY_F) Then Falling = True If ImagesCollide(plyr1,X,Y+1,0,lyr2,lx,ly,0) = False Falling = True FallSpeed:+accel Yvel:+FallSpeed Else Yvel = 0 Falling = False FallSpeed = grav EndIf If KeyHit(KEY_SPACE) And Yvel = 0 Yvel = -18 EndIf X:+Xvel Y:+Yvel End FunctionThe first layer is the foreground drawn on top of everything, the third is the background drawn first. The second layer is a simple image comprised only of pure red pixels and some heavily dark yellow pixels (for ground), simple so there's no messy problems occuring in collision checks. The player is an alpha-blended 32-bit PNG.
How can I do the player collisions properly? (btw this is all temporary code, reason why I don't have object methods and functions)