Jump-routine question
BlitzPlus Forums/BlitzPlus Programming/Jump-routine question
| ||
Hi I´m working on a 2d-platformgame and i have a problem whit "Delta time" in my jumproutine,the X movement is ok, X speed is always the same no matter what Fps the game is running at,but the jumpspeed follows the Fps,i know i also should calculate the Jumpspeed whit Delta,but how? Here is some code to run.It´s not from my game but it shows you the problem.(try different delay´s) Thanks Henrik:) Graphics 640,480 SetBuffer BackBuffer() y#=300 yd#=10 Global speed#,oldms#,delta#,ms2#,xd#,curfps2#,x# While Not KeyDown(1) Cls ;delta If curfps2=0 curfps2=75 oldms=ms2-oldms delta=oldms xd=75/curfps2 oldms=ms2 ms2=MilliSecs() speed=xd ;jump y=y-yd yd=yd-(0.2);calculate whit delta here If yd<-10 yd=10;and here i think Rect 320,y,10,10 Rect x+speed,330,10,10 x=x+speed If x>640 x=0 Line 0,315,640,315 Line 0,45,640,45 Text 10,10,"yd "+yd Text 10,20,"fps "+curfps2 Text 10,350,"x speed(delta) "+speed ;fpscounter curTime = MilliSecs() If curTime > checkTime Then checkTime = curTime + 1000 curFPS2 = fpscounter fpscounter = 0 Else fpscounter = fpscounter + 1 End If Flip False Delay 13 ;try "flip false" and different ;delays to simulate different Fps. ;Delay 13=75fps(13.33333/1000)=75 Wend |
| ||
here's what I do:MaxFallSpeed# = 6.0 : FallSpeed# = 0 : FallSpeedAccel# = 0.1 JumpSpeed# = 5.7 : JumpSpeedDec# = 0.1 Function ResetJumpSpeed() JumpSpeed# = 5.7 End Function ;----------------------------------------------------------- ; StartJump() -- Starts the jumping process ;----------------------------------------------------------- Function StartJump() If OnGround() = True And JUMPING = False Then ;play sound PlaySound JumpSound JUMPING = True FALLING = False End If End Function ;----------------------------------------------------------- ; Jump() -- Jump ;----------------------------------------------------------- Function Jump() Samus\y = Samus\y - JumpSpeed# If Samus\y < 0 Then Samus\y = 0 ;prevent from jumping into nowhere JumpSpeed# = JumpSpeed# - JumpSpeedDec# If (JumpSpeed# < 0) Or (BumpHead() = True) Then ResetJumpSpeed() JUMPING = False FALLING = True JumpBoost = False End If End Function Samus is of course, Samus Aran from Metroid. This routine works really well if I do say so myself. -cb |
| ||
Cbmeeks Your routine looks good. what do you use for game timing? Delta time,Wait timer(),or.. (yes i remember Metroid,great game) Henrik |
| ||
Well, I am actually experimenting with different timers...especially since the 1.34 patch. (B+) -cb |
| ||
I'll post some timing and jump code for ya when I get off work. :o> |
| ||
Chroma I´m looking forward to that! Henrik :) |