FrameLimit 40
DrawToWorld ON
'Load the map
map=LoadMap("Media\cdm2.til","Media\tileset.bmp")
'Load player
soldier=LoadObject("Media\soldier.bmp",72)
ObjectRange soldier,32
'Load "bullet"
bullet=LoadObject("Media\fireball.bmp",9)
ShowObject bullet,OFF
'setup some collisions
SetupCollision soldier,map,1,4,2
SetupCollision bullet,map,2,4,1
AddText "Arrows to move, SPACE to shoot"
Repeat
'Update controls
If LeftKey() Then TurnObject soldier,5
If RightKey() Then TurnObject soldier, -5
If UpKey() Then MoveObject soldier,3.5
If DownKey() Then MoveObject soldier, -2
'shooting
If KeyDown(cbkeyspace) And alive=0 Then
ShowObject bullet,ON 'create bullet again
ResetObjectCollision bullet
CloneObjectPosition bullet,soldier
CloneObjectOrientation bullet,soldier
bulletplusx#=Cos(ObjectAngle(bullet))*6
bulletplusy#=Sin(ObjectAngle(bullet))*6
alive=120
EndIf
'update bullet if alive
If alive Then
TranslateObject bullet,bulletplusx#,bulletplusy#
TurnObject bullet,40
If CountCollisions(bullet) Then
angle=CollisionAngle(bullet,1)
'mirror movement components
If angle=0 Or angle=180 Then
bulletplusx#= -bulletplusx#
EndIf
If angle=90 Or angle=270 Then
bulletplusy#= -bulletplusy#
EndIf
TranslateObject bullet,bulletplusx#,bulletplusy#
EndIf
'update bullet life state
alive=alive-1
If alive=0 Then 'death
ShowObject bullet,OFF
EndIf
EndIf
'Camera follow
CloneCameraPosition soldier
DrawScreen
Until EscapeKey()
|
|