fake physics jumping
Blitz3D Forums/Blitz3D Programming/fake physics jumping
| ||
If i press right it dissapears, why? man.png could be an oval if you dont got a small PNG. [bbcode] AppTitle "JUMPING JACK by ROLS GOLD www.tallymoney.com" Graphics 555,355,32,2 h=LoadImage("man.png") x=155 While 1 If KeyHit(203) Then x=x-1 End If If KeyDown(205) Then x=x+1 End If Cls DrawImage(h,x, Abs((Sin(MilliSecs()*2 / 11)*100)+200)) Flip Wend FreeImage(h) [/bbcode] |
| ||
heres the man.png in the ZIP. Go here for the ZIP Last edited 2012 |
| ||
with an RECT instead of the picture it works at me..... The x value risies very fast, so i think the image leaves the screen, because x gets>555. Why do you use a KEYHIT() of left, but a KEYDOWN() for right? You could add a DEBUGLOG line to see what happens: While 1 If KeyHit(203) Then x=x-1 End If If KeyDown(205) Then x=x+1 End If Cls DebugLog x ..... The physic is not much realistic. I would prefer to add gravity to the y value. It is not as complicated as your sinus: Graphics 555,355,32,2 SetBuffer BackBuffer() x=155 y#=-0.1 SpeedY#=0 FPS=CreateTimer(60) Repeat If KeyDown(203) Then x=x-1 ElseIf KeyDown(205) Then x=x+1 End If Cls If Y<0 Then SpeedY=5 SpeedY=SpeedY-0.1 Y=Y+SpeedY Rect x, 200-y,10,10 Flip 0 WaitTimer fps Until KeyHit(1) Also the x could be more realistic by adding a acceleration: Graphics 555,355,32,2 SetBuffer BackBuffer() x#=155 y#=-0.1 SpeedY#=0 SpeedX#=0 AccX#=0 FPS=CreateTimer(60) Repeat If KeyDown(203) Then AccX=-0.1 ElseIf KeyDown(205) Then AccX=+0.1 Else AccX=0 End If Cls If Y<0 Then SpeedY=5 SpeedY=SpeedY-0.1 Y=Y+SpeedY SpeedX=SpeedX+AccX SpeedX=SpeedX*0.99 X=X+SpeedX Rect x, 200-y,10,10 Flip 0 WaitTimer fps Until KeyHit(1) |
| ||
thank you so much. muy bien. |