Ok im having some wierd problems trying to get my ships to fly right. Get the code and exe here http://mars.walagata.com/w/schragnasher/Fighttest.zip
For the most part the acceleration equations work out alright, but i get really choppy movement, you have to see it to understand. Im sure i did something stupid, but im lost o.0
Here is the code again, in case youl see the problem right away.
Const g_ScreenWidth=800, g_ScreenHeight=600 ; Call the BB "Graphics" routine to initialize DirectX
Graphics g_ScreenWidth, g_ScreenHeight,32,1 ; Set up BB to support page-flipping
SetBuffer BackBuffer()
TFormFilter Enable
Global bg_image1
bg_image1=LoadImage("bg.bmp")
Type player
Field shipdirs
Field shipdir
Field shipx
Field shipy
Field shipxinertia#
Field shipyinertia#
Field shipdirection
Field turnspeed
Field health
Field shields
Field timer
Field maxspeed
Field shipacc#
End Type
Global oldtime
Global newtime
Global player1.player=New player
Global player2.player=New player
player1\shipx=50
player1\shipy=50
player2\shipx=200
player2\shipy=200
initplayers()
While Not KeyHit(1)
newtime=MilliSecs()
drawbg()
updateplayers()
drawplayers()
Text 0,0,fps
Flip
Cls
Wend
Function initplayers()
For players.player=Each player
players\shipdir=0
players\maxspeed=3
players\shipdirs=LoadAnimImage("ship1.bmp",50,50,0,64)
MaskImage players\shipdirs,255,0,255
players\turnspeed= 20
players\timer=0
players\shipxinertia#=0
players\shipyinertia#=0
players\shipacc#=.05
Next
End Function
Function drawbg()
DrawImage bg_image1,0,0
End Function
Function updateplayers()
;///////////////////player 1/////////////
If KeyDown(17) Then ;W
player1\shipxinertia#=player1\shipxinertia#+(Sin(player1\shipdir*5.625)*(player1\shipacc#))
player1\shipyinertia#=player1\shipyinertia#+(Cos(player1\shipdir*5.625)*(player1\shipacc#))
If player1\shipxinertia# > player1\maxspeed Then player1\shipxinertia#=player1\maxspeed
If player1\shipxinertia# < -player1\maxspeed Then player1\shipxinertia#=-player1\maxspeed
If player1\shipyinertia# > player1\maxspeed Then player1\shipyinertia#=player1\maxspeed
If player1\shipyinertia# < -player1\maxspeed Then player1\shipyinertia#=-player1\maxspeed
End If
If KeyDown(31) Then ;s
End If
If newtime-player1\timer>player1\turnspeed Then
If KeyDown(32) Then ;d
If player1\shipdir=63 Then
player1\shipdir=0
End If
player1\shipdir=player1\shipdir+1
player1\timer=MilliSecs()
End If
If KeyDown(30) Then ;a
If player1\shipdir=0 Then
player1\shipdir=63
End If
player1\shipdir=player1\shipdir-1
player1\timer=MilliSecs()
End If
End If
;///////////////////player 2/////////////
If newtime-player2\timer>player2\turnspeed Then
If KeyDown(205) Then ;right
If player2\shipdir=63 Then
player2\shipdir=0
End If
player2\shipdir=player2\shipdir+1
player2\timer=MilliSecs()
End If
If KeyDown(203) Then ;left
If player2\shipdir=0 Then
player2\shipdir=63
End If
player2\shipdir=player2\shipdir-1
player2\timer=MilliSecs()
End If
End If
;////debug test////////////////
Text 500,0,player1\shipdir
Text 500,10,player1\shipdir*5.625
Text 500,20,player1\shipxinertia#
Text 500,30,player1\shipyinertia#
Text 500,40,player1\shipx
Text 500,50,player1\shipy
;//////update ship x/y /////////////////////////
player1\shipx=player1\shipx+player1\shipxinertia#
player1\shipy=player1\shipy-player1\shipyinertia#
End Function
Function drawplayers()
DrawImage player1\shipdirs,player1\shipx,player1\shipy,player1\shipdir
DrawImage player2\shipdirs,player2\shipx,player2\shipy,player2\shipdir
End Function
|