/
torpedo.go
49 lines (42 loc) · 1.17 KB
/
torpedo.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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package main
import glfw "github.com/go-gl/glfw3"
type Torpedo struct {
Entity
MaxLifetime float64
}
func NewTorpedo(x, y, angle, vX, vY float64) *Torpedo {
shape := Polygon{
[]Vector{
Vector{0, 1},
Vector{-1, -3},
Vector{1, -3},
},
[]Color{
Color{1, 0, 1},
Color{1, 0, 1},
Color{1, 0, 1},
},
}
return &Torpedo{*NewEntity(shape, x, y, angle, 0, vX, vY, 0, 5), 1.5}
}
func (torpedo *Torpedo) Update() {
if paused {
timediff := (glfw.GetTime() - torpedo.Entity.lastUpdatedTime)
torpedo.MaxLifetime = torpedo.MaxLifetime + timediff
}
torpedo.Entity.Update()
}
func (torpedo *Torpedo) IsAlive() bool {
if glfw.GetTime() > torpedo.createdTime+torpedo.MaxLifetime {
torpedo.Destroy()
}
return torpedo.Entity.IsAlive()
}
func (torpedo *Torpedo) Destroy() {
torpedo.Entity.Destroy()
explosions = append(explosions, NewExplosion(torpedo.PosX, torpedo.PosY, 10))
bigExplosions = append(bigExplosions, NewBigExplosion(torpedo.PosX, torpedo.PosY, 2))
}