I'm making a little game for fun but I've run into a little problem.
I need to make boxes jump to set heights in increments of 32px even after changing gravity on the fly. Currently i have manualy set the jump heights but this is not accurate and I cannot change the gravity becuase these fix values are for a set gravity value.
phew... any way heres some code. I have set the jump heights for the boxes in the Makeboxes() function.
so for example I would like to tell a box to jump 5 squares which is 5*32px = 160px and it would do that too exactly 160px no matter what the gravity was set too, and the same forumla can be used to tell a box to jump 1 sqaure or even a 100 squares.
So a function like GetJumpheight(squares,gravity) would return the correct value to attached b.JumpHeight or somthing along those lines.
I need to make boxes jump to set heights in increments of 32px even after changing gravity on the fly. Currently i have manualy set the jump heights but this is not accurate and I cannot change the gravity becuase these fix values are for a set gravity value.
phew... any way heres some code. I have set the jump heights for the boxes in the Makeboxes() function.
so for example I would like to tell a box to jump 5 squares which is 5*32px = 160px and it would do that too exactly 160px no matter what the gravity was set too, and the same forumla can be used to tell a box to jump 1 sqaure or even a 100 squares.
So a function like GetJumpheight(squares,gravity) would return the correct value to attached b.JumpHeight or somthing along those lines.
Graphics 640,480,0,60 ' Grabity applied to boxes Global Gravity# = 0.60 ' declare box type Global L_Box:TList=New TList Type T_Box Field xPos , yPos#=480-64 Field JumpYVel# , JumpHeight# = 6.50 Field id End Type ' make the boxes MakeBoxes() '=============================== Repeat ; Cls UpdateBoxes() ' Just the pink lines to show how high the box should jump. For x=640-64 To 64 Step -64 SetColor 255 , 0 , 255 ; DrawLine x , i*32 , x+32 , i*32 ; i=i+1 Next ; i = 5 DrawText "Mouse over a box to make it jump",0,0 Flip ; Until KeyDown(KEY_ESCAPE) ; End '=============================== Function UpdateBoxes() For b:T_Box = EachIn L_Box ' draw box and its id. SetColor 255,0,0 ; DrawRect b.xPos , b.yPos , 32 , 32 SetColor 255 , 255 , 255 ; DrawText b.id , b.xPos + 8 , b.yPos + 8 ' mouse over a box to make it jump If MouseX() => b.xPos And MouseX() =< b.xPos + 32 And MouseY() => b.yPos And MouseY() =< b.yPos + 32 b.JumpYVel=b.JumpHeight EndIf ' apply gravity to jumping boxes b.JumpYVel# = b.JumpYVel# - Gravity ' update bos Y position b.yPos:- b.JumpYVel ' Stop box falling off bottom of screen If b.yPos => 480 - 64 Then b.JumpYVel = 0.0 ; b.yPos = 480 - 64 Next EndFunction Function MakeBoxes() ' make 8 boxes and give a jump height based on its given ID For i=1 To 8 b:T_Box = New T_Box ListAddFirst L_Box , b b.xPos = i * 64 b.id = i '------------------- Not an ideal method, its not accurate and if I change gravity its all wronge '------------------- must be a fancy formula that could be used? to apply accurate jump height to '------------------- boxes even after chnaging Gravity on the fly. Boxes ment to jump in 32px increments. If b.id = 1 Then b.JumpHeight# = 6.50 If b.id = 2 Then b.JumpHeight# = 9.00 If b.id = 3 Then b.JumpHeight# = 11.00 If b.id = 4 Then b.JumpHeight# = 12.70 If b.id = 5 Then b.JumpHeight# = 14.10 If b.id = 6 Then b.JumpHeight# = 15.50 If b.id = 7 Then b.JumpHeight# = 16.70 If b.id = 8 Then b.JumpHeight# = 17.80 '------------------- '------------------- '------------------- Next End Function