forked from JochenHeizmann/asteroidgame
/
explosion.monkey
59 lines (46 loc) · 1.03 KB
/
explosion.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
Strict
Import mojo
Import invalidaterect
Import soundplayer
Class Explosion
Global list:List<Explosion>
Global img:Image
Field frame:Int
Field x:Float, y:Float
Field scale:Float
Method New()
scale = 1
End
Function Init:Void()
If (Not img) Then img = LoadImage("asteroidgame/explosion.png", 32, Image.MidHandle)
If (Not list) Then list = New List<Explosion>
End
Method Update:Void()
frame += 1
If frame >= 32 Then Destroy()
End
Method Render:Void()
InvalidateRect.Draw(img, x, y, 0, scale, scale, frame Mod 32)
End
Function UpdateAll:Void()
For Local e:Explosion = Eachin list
e.Update()
Next
End
Function RenderAll:Void()
For Local e:Explosion = Eachin list
e.Render()
Next
End
Function Spawn:Void(x:Float, y:Float, scale:Float)
Local e:Explosion = New Explosion()
e.x = x
e.y = y
e.scale = scale
list.AddLast(e)
SoundPlayer.PlayFx(SoundPlayer.soundXplode)
End
Method Destroy:Void()
list.Remove( Self )
End
End