-
Notifications
You must be signed in to change notification settings - Fork 10
/
bullet.monkey
64 lines (51 loc) · 1.21 KB
/
bullet.monkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Strict
Import mojo
Import spaceobject
Import soundplayer
Import invalidaterect
Class Bullet Extends SpaceObject
Global img:Image
Global list:List<Bullet>
Const SPEED:Float = 6.0
Const COOLDOWN:Int = 15
Global cdown:Int = 0
Function Init:Void()
If (Not img) Then img = LoadImage("asteroidgame/bullet.png", 1, Image.MidHandle)
If (Not list) Then list = New List<Bullet>
End
Function Spawn:Void(x:Float, y:Float, r:Float, speedx:Float, speedy:Float)
If cdown>COOLDOWN
Local s:Bullet = New Bullet
s.x = x
s.y = y
s.dx = Cos(r) * SPEED + speedx
s.dy = Sin(r) * SPEED + speedy
s.rotation = -r
list.AddLast(s)
cdown = 0
SoundPlayer.PlayFx(SoundPlayer.soundLaser)
End
End
Method Update:Void()
x += dx
y += dy
If (x < -20 Or x > DeviceWidth()+20 Or y < -20 Or y > DeviceHeight()+20) Then Destroy()
End
Method Render:Void()
InvalidateRect.Draw(img, x, y, rotation, 1, 1, 0)
End
Function UpdateAll:Void()
cdown += 1
For Local b:=Eachin list
b.Update()
Next
End
Function RenderAll:Void()
For Local b:=Eachin list
b.Render()
Next
End
Method Destroy:Void()
list.Remove( Self )
End
End