Jos ostat panokset pistoolin, tulee oikein. Jos ostat haulikkoon, tulee miten sattuu ja sama rynnäkkökiväärissä. Aseet on tehty tyypeillä ja ne siis käyttävät samaa funktiota. Se, missä järjestyksessä aseet luo tyyppeihin, ei vaikuta tähän ongelmaan.
Kiitos, jos voisitte auttaa.
Koodia:
Code: Select all
SCREEN 800, 600, 0, cbFullScreen
ClsColor 255, 255, 255
Type ENEMY
Field obj
Field health
End Type
Type BULLET
Field objekti
End Type
Type ASE
Field spread As Float
Field reloadtime Integer
Field name As String
Field bulletspershot As Integer
Field damage As Float
Field mag As Integer
Field changemag As Integer
Field bulletsleft As Integer
Field magsize As Integer
Field leftsize As Integer
End Type
FrameLimit 30
asekauppa = LoadObject ("Media\asekauppa.bmp", 36)
pelaaja = LoadObject ("Media\soldier.bmp", 72)
vastus = LoadObject ("Media\ukkeli.bmp", 72)
panos = LoadObject ("Media\bullet.bmp")
mouseobj = LoadObject ("Media\mouseimg.bmp")
ShowObject panos, OFF
ShowObject vastus, OFF
haulikko.ASE = New (ASE)
haulikko\spread = Rnd (16)
haulikko\reloadtime = 500
haulikko\name = "Spas 12"
haulikko\bulletspershot = 8
haulikko\damage = 1
haulikko\mag = 64
haulikko\changemag = 7000
haulikko\bulletsleft = 128
haulikko\magsize = 64
haulikko\leftsize = 128
pistooli.ASE = New (ASE)
pistooli\spread = Rnd (2)
pistooli\reloadtime = 500
pistooli\name = "USP .45"
pistooli\bulletspershot = 1
pistooli\damage = 10
pistooli\mag = 8
pistooli\changemag = 3000
pistooli\bulletsleft = 32
pistooli\magsize = 8
pistooli\leftsize = 32
sarjatuli.ASE = New (ASE)
sarjatuli\spread = Rnd (2)
sarjatuli\reloadtime = 120
sarjatuli\name = "M4A1 Sopmod"
sarjatuli\bulletspershot = 1
sarjatuli\damage = 2
sarjatuli\mag = 30
sarjatuli\changemag = 4000
sarjatuli\bulletsleft = 60
sarjatuli\magsize = 30
haulikko\leftsize = 60
current.ASE = First (ASE)
tapot = 0
aika = 60
raha = 0
health2 = 100
ClsColor 255, 255, 255
ScreenPositionObject asekauppa, 50, 500
Repeat
Gosub Tekstit
Gosub Makebullet
Gosub Checkbullets
Gosub Moveplayer
Gosub Mouse
Gosub Makebot
Gosub Checkbot
Gosub Chooseweapon
Gosub CheckMagazine
Gosub CheckPlayer
Gosub Ammunition
DrawScreen
Until EscapeKey()
Tekstit:
Color 0, 0, 0
Text 20, 20, "Ase: "+current\name
If current.ASE = haulikko.ASE
Text 600, 500, "Lipas: "+current\mag / 8
Else
Text 600, 500, "Lipas: "+current\mag
EndIf
If current.ASE = haulikko.ASE
Text 600, 520, "Panoksia jäljellä: "+current\bulletsleft / 8
Else
Text 600, 520, "Panoksia jäljellä: "+current\bulletsleft
EndIf
Text 20, 80, "Raha: "+raha
Text 20, 100, "Tapot: "+tapot
Text 20, 120, "Health: "+health2
Text 20, 140, "Aikaa jäljellä: "+aika+" sek"
Return
Makebullet:
If MouseDown (1) And current\mag > 0 And Reloading = False Then
For i = 1 To current\bulletspershot
luoti.BULLET = New (BULLET)
luoti\objekti = CloneObject (panos)
current\mag = current\mag - 1
CloneObjectPosition luoti\objekti, pelaaja
CloneObjectOrientation luoti\objekti, pelaaja
TurnObject luoti\objekti, Rnd(-current\spread, current\spread)
Next i
Reloading = True
Reloadtimer = Timer ()
EndIf
If Reloading = True And Timer () > Reloadtimer + current\reloadtime Then Reloading = False
Return
Checkbullets:
For luoti.BULLET = Each BULLET
MoveObject luoti\objekti, 15
If ObjectX (luoti\objekti) < -400 Or ObjectX (luoti\objekti) > 400 Or ObjectY (luoti\objekti) < -300 Or ObjectY (luoti\objekti) > 300 Then
DeleteObject luoti\objekti
Delete luoti
EndIf
Next luoti
Return
Moveplayer:
If KeyDown (17) Then MoveObject pelaaja, 6
If KeyDown (31) Then MoveObject pelaaja, -w6
Return
Mouse:
ScreenPositionObject mouseobj, MouseX (), MouseY ()
PointObject pelaaja, mouseobj
ShowMouse OFF
Return
Makebot:
If vihut < 2 Then
botti.ENEMY = New (ENEMY)
botti\obj = CloneObject (vastus)
botti\health = 10
PositionObject botti\obj, Rand (-ScreenWidth () / 2, ScreenWidth () / 2), Rand (-ScreenHeight () / 2, ScreenHeight () / 2)
PointObject botti\obj, pelaaja
vihut = vihut + 1
EndIf
Checkbot:
For botti.ENEMY = Each ENEMY
PointObject botti\obj, pelaaja
MoveObject botti\obj, 1
If ObjectsOverlap (botti\obj, pelaaja) Then
health2 = health2 - 10
DeleteObject botti\obj
Delete botti
vihut = vihut - 1
EndIf
If botti\health < 1 Then
DeleteObject botti\obj
Delete botti
vihut = vihut - 1
tapot = tapot + 1
raha = raha + 10
EndIf
Next botti
For botti.ENEMY = Each ENEMY
For luoti.BULLET = Each BULLET
If ObjectsOverlap (botti\obj, luoti\objekti) Then
botti\health = botti\health - current\damage
DeleteObject luoti\objekti
Delete luoti
EndIf
Next luoti
Next botti
Return
Chooseweapon:
If KeyHit (cbKeySpace) Then
If current <> Last (ASE) Then
current.ASE = After (current)
Else
current.ASE = First (ASE)
EndIf
EndIf
Return
CheckMagazine:
If current\mag = 0 And KeyHit (19) Then
current\bulletsleft = current\bulletsleft - current\magsize
current\mag = current\magsize
EndIf
Return
CheckPlayer:
If health2 < 1 Then Goto loppu
Return
loppu:
Cls
Color 0, 0, 0
Repeat
Text 20, 20, "Sait tapettua "+tapot+" jotain ihme tyyppiä :DDDD"
DrawScreen
Until EscapeKey()
Ammunition:
If ObjectsOverlap (pelaaja, asekauppa) Then
Text 20, 180, "Osta ammuksia painamalla x (hinta 100)"
If KeyHit (45) And raha > 99 Then
current\bulletsleft = current\leftsize
current\mag = current\magsize
raha = raha - 100
EndIf
EndIf
Return