I have a problem. I'm making a side scrolling shooter, and when I move sideways and jump, everythings fine. However, if I keep holding the spacebar after the character has jumped, the animation of the character will stop. Any suggestions? I'm including my code.
'-------------------------------------------------------------------GAME SETUP
Graphics 510,300,0
Global Gravity:Float = 0.60
Global Position:Int = 2
Global Jumped:Int = 0
Local Background:TBackground = TBackground.Create("background.png",0,0)
Local Player:THero = THero.Create("guywalking.png",15,142)
'--------------------------------------------------------------------MAIN LOOP
Repeat
Cls
DrawText "The Big One",200,250
DrawText "For MacOS X",200,262
Background.DrawSelf()
Player.UpdateState()
Player.DrawSelf()
Flip
Until KeyDown(KEY_ESCAPE) Or AppTerminate()
End
'----------------------------------------------------------------------TYPES
Type THero
Field X:Int=15
Field Y:Int=142
Field Speed:Int=3
Field Frame:Int=0
Field AnimSpeed:Int=3
Field JumpHeight:Float=10.00
Field JumpYVel:Float
Field Image:TImage
Function Create:THero(File:String,xstart:Int,ystart:Int)
Local WalkImage:THero=New THero
WalkImage.X=xstart
WalkImage.Y=ystart
WalkImage.Frame=animframe
AutoImageFlags MASKEDIMAGE
SetMaskColor 255,255,255
WalkImage.image=LoadAnimImage(LoadBank(File),64,64,0,12,MASKEDIMAGE)
If WalkImage.image=Null
Print "Image file not found. Quitting..."
End
End If
Return WalkImage
End Function
Method DrawSelf()
DrawImage Image,X,Y,Frame
End Method
Method UpdateState()
If KeyDown(KEY_LEFT) And Not KeyDown(KEY_RIGHT)
Position = 1
If X>-15 Then X:- Speed
If AnimSpeed < 0 And Not KeyDown(KEY_SPACE)
If Frame = 2 And Y = 142 Then Frame = 3 Else Frame = 2
AnimSpeed = 3
ElseIf KeyDown(KEY_SPACE) And Not KeyDown(KEY_LEFT)
Frame = 11
Else
AnimSpeed:-1
EndIf
EndIf
If KeyDown(KEY_RIGHT)
Position = 2
If X<460 Then X:+ Speed
If AnimSpeed < 0 And Not KeyDown(KEY_SPACE)
If Frame = 1 And Y = 142 Then Frame = 0 Else Frame = 1
AnimSpeed = 3
ElseIf KeyDown(KEY_SPACE) And Not KeyDown(KEY_RIGHT)
Frame = 6
Else
AnimSpeed:-1
EndIf
EndIf
If Position = 1 And KeyHit(KEY_SPACE)
If Y = 142
JumpYVel = JumpHeight
Frame = 11
Jumped = 1
EndIf
EndIf
If Position = 2 And KeyHit(KEY_SPACE)
If Y = 142
JumpYVel = JumpHeight
Frame = 6
Jumped = 2
EndIf
EndIf
If Jumped = 1
JumpYVel:-Gravity
Y:-JumpYVel
If Y => 142 Then JumpYVel = 0.0; Y = 142
If Y=142 Then Frame = 3; Jumped = 0
EndIf
If Jumped = 2
JumpYVel:-Gravity
Y:-JumpYVel
If Y => 142 Then JumpYVel = 0.0; Y = 142
If Y=142 Then Frame = 0; Jumped = 0
EndIf
End Method
End Type
Type TBackground
Field X:Int
Field Y:Int
Field Image:Timage
Function Create:TBackground(File:String,xstart:Int,ystart:Int)
Local Background:TBackground=New TBackground
Background.X = xstart
Background.Y = ystart
Background.image = LoadImage(LoadBank(File))
If Background.image=Null
Print "Image file not found. Quitting..."
End
End If
Return Background
End Function
Method DrawSelf()
DrawImage Image,X,Y,Frame
End Method
End Type
|