Simple Plaform?

Blitz3D Forums/Blitz3D Beginners Area/Simple Plaform?

Hotshot2005(Posted 2008) [#1]
Hiya all,

I have made Plaform but he keep dropping off the screen and how do I make stay on the Screen?

; Specail thanks to Andres

Graphics 640,480,16,2
SetBuffer BackBuffer()
BLOCK   =LoadImage("BLOCK.PNG")
BLOCK2  =LoadImage("BLOCK2.PNG")
FIREMAN =LoadImage("FIREMAN2.PNG")

MaskImage FIREMAN,255,0,255

PX =10
PY =90

Gravity# = .7
YSpeed#  = 0
Jump#    = -3.0

While Not KeyDown(1)
      YSpeed# = YSpeed# + Gravity#
      Ypos# = Ypos# + YSpeed#

      If KeyHit(57) Then YSpeed# = Jump#

      If KeyDown(205) Then PX=PX+2
      If KeyDown(203) Then PX=PX-2
      
	  DrawImage BLOCK  ,150,150
	  DrawImage BLOCK  ,450,250
	  DrawImage BLOCK  ,250,300
	
	  ; GROUND
	  DrawImage BLOCK2 ,0  ,455
	
	  ;If FIREMAN ON THE Floor Then STAY ON THE Floor
	
	  If ImagesCollide (FIREMAN,PX,PY,0,BLOCK2,0,455,0) Then PY=390: GRAVITY#=0 ; <<<< PROBLEM
	  DrawImage FIREMAN,PX,PY+YPOS#
	
      Flip:Cls
Wend



GfK(Posted 2008) [#2]
I think you're confusing yourself - you seem to have two separate variables for the Y axis; PY and YPos. You're checking the collision against PY, and drawing the actual image elsewhere (PY+yPos).

Try using PY = PY + ySpeed instead.

Also on the line marked "PROBLEM", you need to set ySpeed to 0 rather than gravity.


Hotshot2005(Posted 2008) [#3]
thank you GFK :)