Const gravity=0.05
'Prevent the game from running too fast
FrameLimit 40
'Load the ammunation, but hide it
fireball=LoadObject("Media\fireball.bmp",18)
ShowObject fireball,OFF
'load the cannon
cannon=LoadObject("Media\cannon.bmp",180)
'load the turret
turret=LoadObject("Media\turret.bmp")
PositionObject turret, -160, -35
PositionObject cannon, -160, -35
AddText "Use arrows to aim"
AddText "SPACE to shoot"
'Make "sky"
ClsColor cbdarkblue
'Initialize the game engine
permission=True
Repeat
'update controls
If LeftKey() Then angle=angle+2
If RightKey() Then angle=angle-2
If angle<10 Then angle=10
If angle>170 Then angle=170
'update SHOOTING
If KeyHit(cbkeyspace) And permission=True
ShowObject fireball,ON 'show the fireball
'position and tilt it according to the cannon
CloneObjectPosition fireball,cannon
CloneObjectOrientation fireball,cannon
'move a little bit away from the center
MoveObject fireball,16
permission=False
'Calculate the movement (speed 2)
plusx#=Cos(angle)*3
plusy#=Sin(angle)*3
EndIf
'Update moving fireball
If permission=False Then
TranslateObject fireball,plusx#,plusy#
plusy#=plusy-gravity
'rotate the fireball to left
TurnObject fireball,20
'if the fireball goes outside screen, remove it
If ObjectX(fireball)< -200 Or ObjectX(fireball)>200 Or ObjectY(fireball)>150 Or ObjectY(fireball)< -50 Then
ShowObject fireball,OFF
permission=True
EndIf
EndIf
'Turn the cannon
RotateObject cannon,angle
'draw ground
Color cbgreen
Box 0,200,400,100
Color cbwhite
Line 0,200,400,200
DrawScreen
Until EscapeKey()
|
|