-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
explosive.go
104 lines (91 loc) · 2.35 KB
/
explosive.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"github.com/faiface/pixel"
)
// explosive implements different types of explosives
type explosive struct {
object
eType objectType
power int
countDown bool
delayTime float64
light *light
}
func (e *explosive) newExplosive(x, y float64, eType objectType) {
e.eType = eType
switch eType {
case explosiveRegularMine:
e.sheetFile = fmt.Sprintf("%v%v", wAssetObjectsPath, "regularMine.png")
e.name = "Regular Mine"
e.animated = false
e.rotation = 0
e.power = 20
e.delayTime = 2
e.scale = 0.5
e.light = &light{}
e.light.create(x, y, 360, 360, 10, pixel.RGBA{R: 0.8, G: 0, B: 0, A: 0.3}, true, 0)
e.light.unlimitedLife = true
e.light.ownerBounds = e.bounds
e.light.blinkFrequency = 1
e.AddLight(5, 6, e.light)
case explosiveClusterMine:
e.sheetFile = fmt.Sprintf("%v%v", wAssetObjectsPath, "regularMine.png")
e.name = "Cluster Mine"
e.animated = false
e.rotation = 0
e.power = 5
e.delayTime = 2
e.scale = 0.5
e.light = &light{}
e.light.create(x, y, 360, 360, 10, pixel.RGBA{R: 0.9, G: 0.3, B: 0, A: 0.2}, true, 0)
e.light.unlimitedLife = true
e.light.ownerBounds = e.bounds
e.light.blinkFrequency = 1
e.AddLight(5, 6, e.light)
}
e.countDown = false
e.light.objectCD = false
e.create(x, y)
// Animate up/down when idle
e.animateIdle = false
// Must change entity type in bounds for QT lookup
e.bounds.entity = entity(e)
}
func (e *explosive) draw(dt, elapsed float64) {
e.object.draw(dt, elapsed)
if distance(global.gPlayer.getPosition(), pixel.Vec{X: e.bounds.X, Y: e.bounds.Y}) < 10 {
e.countDown = true
e.light.blinkFrequency = 0.1
}
if e.countDown {
e.delayTime -= dt
if e.delayTime <= 0 {
e.light.destroy()
global.gWorld.qt.Remove(e.bounds)
global.gWorld.Explode(e.bounds.X, e.bounds.Y, e.power)
switch e.eType {
case explosiveClusterMine:
for i := 0; i < 10; i++ {
shot := ammo{
color: 0xFF0000FF,
size: 0.5,
life: 1,
fx: 10.0,
fy: 10.0,
power: 10,
}
shot.x = e.bounds.X + e.bounds.Width/2
shot.y = e.bounds.Y + e.bounds.Height
shot.vx = 10.0 * (0.5 - global.gRand.randFloat())
shot.vy = 10.0 * global.gRand.randFloat()
shot.mass = global.gRand.randFloat() * 4
shot.owner = e
global.gAmmoEngine.newAmmo(shot)
}
}
}
}
}
func (e *explosive) explode() {
}