/
Missle.go
54 lines (46 loc) · 1.18 KB
/
Missle.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
package game
import (
"github.com/vova616/GarageEngine/engine"
"math/rand"
//"reflect"
)
type Missle struct {
engine.BaseComponent
Speed float32
Explosion *engine.GameObject
exploded bool
}
func NewMissle(speed float32) *Missle {
return &Missle{BaseComponent: engine.NewComponent(), Speed: speed}
}
func (ms *Missle) OnComponentAdd() {
ms.GameObject().Tag = MissleTag
}
func (ms *Missle) OnHit(enemey *engine.GameObject, damager *DamageDealer) {
}
func (ms *Missle) OnDie(byTimer bool) {
if ms.Explosion == nil {
ms.GameObject().Destroy()
return
}
if ms.GameObject() == nil {
return
}
if !byTimer {
for i := 0; i < 2; i++ {
n := ms.Explosion.Clone()
n.Transform().SetParent2(GameSceneGeneral.Layer1)
n.Transform().SetWorldPosition(ms.Transform().WorldPosition())
s := n.Transform().Scale()
n.Transform().SetScale(s.Mul2(rand.Float32() + 0.5))
n.AddComponent(engine.NewPhysics(false))
n.Transform().SetRotationf(rand.Float32() * 360)
rot := n.Transform().Direction()
n.Physics.Body.SetVelocity(-rot.X*10, -rot.Y*10)
n.Physics.Body.SetMass(1)
n.Physics.Shape.Group = 1
n.Physics.Shape.IsSensor = true
}
}
ms.GameObject().Destroy()
}