-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.go
72 lines (54 loc) · 1.97 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import "github.com/go-gl/glfw/v3.2/glfw"
// entity represents a non-descript object that does operations on every frame.
type entity interface {
// uid returns a unique identifier.
uid() int
// tick is called once per frame. Returned entities are added to the entity
// registry.
tick() []entity
// deletable returns true if the entity should be deleted.
deletable() bool
}
// physicalEntity represents an entity that takes on some physical, usually
// viewiable presence.
type physicalEntity interface {
entity
// draw is called once per frame. Implementations should draw to the
// screen.
draw()
// location returns the entity's location.
location() vertex
// collisions returns all owned collisions of the entity.
collisions() []collision
// collision is called when a collision happens against this entity.
collision(yours, other collision)
// mass returns some arbitrary value giving callers an idea of how "heavy"
// the entity is.
mass() float64
}
// inFrameEntity is an entity that should always be in frame. A player entity,
// for instance. Entities need to physically exist to effect camera location.
type inFrameEntity interface {
physicalEntity
// inFrame means nothing, but should be implemented by those who want to be
// always in frame.
inFrame()
}
// inputEntity represents an entity that needs to know about user input.
type inputEntity interface {
entity
// joystickAxis is called when a joystick axis value changes.
joystickAxis(joystick glfw.Joystick, axes []float32)
// joystickButton is called when a joystick button value changes.
joystickButton(joystick glfw.Joystick, buttons []byte)
}
// snoopingEntity represents an entity that needs to respond to the changing
// state of other entities.
type snoopingEntity interface {
entity
// entityDestruction is called right before an entity is destroyed.
entityDestruction(e entity)
// entityMove is called when an entity moves around.
entityMove(e physicalEntity, loc vertex)
}