-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.go
56 lines (45 loc) · 1002 Bytes
/
entity.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
package spacegame
import "github.com/faiface/pixel"
// TODO: Rotate(float64), replaces Turn for Ship etc.
// An Entity describes a
type Entity interface {
Name() string
Angle() float64
Bounds() pixel.Rect
Coordinates() pixel.Vec
Velocity() pixel.Vec
Translate(pixel.Vec)
}
type BaseEntity struct {
name string
angle float64
coordinates pixel.Vec
bounds pixel.Rect
}
func NewBaseEntity(name string, rect pixel.Rect) *BaseEntity {
entity := BaseEntity{
name: name,
angle: 0.0,
coordinates: pixel.ZV,
bounds: rect,
}
return &entity
}
func (be BaseEntity) Name() string {
return be.name
}
func (be BaseEntity) Angle() float64 {
return be.angle
}
func (be BaseEntity) Bounds() pixel.Rect {
return be.bounds
}
func (be BaseEntity) Coordinates() pixel.Vec {
return be.coordinates
}
func (be BaseEntity) Velocity() pixel.Vec {
return pixel.ZV
}
func (be BaseEntity) Translate(vec pixel.Vec) {
be.coordinates = be.coordinates.Add(vec)
}