Code: Select all
Type BULLETS
Field obj
End Type
FrameLimit 40
map= LoadMap("Media\cdm2.til","Media\tileset.bmp")
PlayObject map,0,0,0.5
ObjAuto=LoadObject("media/car.bmp",72)
SetupCollision ObjAuto,map,2,4,1
guy=LoadObject("Media\guy.bmp",72)
SetupCollision guy,map,2,4,2
bullet=LoadObject("Media\bullet.bmp")
ShowObject bullet,OFF
AddText "Tää on minun oma tekemä."
Obj=guy
autossa=False
Repeat
nopeus#=1.2
If UpKey() Then nopeus = nopeus + 0.1
If LeftKey() Then TurnObject obj,5
If RightKey() Then TurnObject obj,-5
If UpKey() Then MoveObject obj,2
If DownKey() Then MoveObject obj,-2
If autossa=False And KeyDown(28) Then 'Jos painetaan enteriä
PointObject guy,ObjAuto ' Osoitetaan kohti ObjAutoa
MoveObject guy,5 'Liikutetaan objektia pelaaja kohti autoa
RotateObject guy,GetAngle2(guy,ObjAuto) 'Käännetään pelaaja auton kulmaan
If ObjectsOverlap (guy,ObjAuto) And KeyHit(28) Then 'Jos pelaaja ja auto objekti koskettavat toisiaan
CloneObjectPosition guy,ObjAuto 'niin kloonataan pelaajan paikka auton paikkaan
ShowObject guy,OFF ' ja piilotetaan pelaaja
Obj=ObjAuto
autossa=True
ClearKeys
EndIf
EndIf
If autossa=True And KeyHit(28) Then
autossa=False
CloneObjectPosition guy,Obj
ShowObject guy,ON
Obj=guy
ClearKeys
EndIf
'Shoot?
If KeyDown(cbkeyspace) And reload=0
newBullet.BULLETS= New(BULLETS)
newBullet\obj=CloneObject(bullet)
CloneObjectPosition newBullet\obj,ObjAuto
CloneObjectOrientation newBullet\obj,ObjAuto
'put the bullet at the end of the barrel
MoveObject newBullet\obj,24
reload=4
EndIf
'Update all BULLETS (move them forward)
i=0
For iBullet.BULLETS= Each BULLETS
MoveObject iBullet\obj,6 'speed=6
'delete bullet from collection if it
'gets too far away
If Distance2(iBullet\obj,ObjAuto)>200 Then
DeleteObject iBullet\obj
Delete iBullet
EndIf
i=i+1
Next iBullet
'Update reloading
If reload>0 Then reload=reload-1
Text 30,30,"Bulets to update: "+i
CloneCameraPosition obj
DrawScreen
Until EscapeKey()