/
entities.go
131 lines (90 loc) · 2.49 KB
/
entities.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package engine
const NE int = 4
var static [NE]bool = [NE]bool{false, true, false, false} //if entity is static, it cannot move
var position [NE][2]float64 = [NE][2]float64{{0.0, 0.0}, {26.0, 0.0}, {256.0, 32.0}, {300.0, 32.0}} //this must be defined inline for some reason
var inertia [NE][2]float64 = [NE][2]float64{{0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}} //this must be defined inline for some reason
var size [NE][2]float64 = [NE][2]float64{{20.0, 32.0}, {32.0, 32.0}, {32.0, 32.0}, {32.0, 32.0}} // X and Y - width and height
/*
Todo:
add ability to remove entities
- auto shrink array to fit entities
add ability for array to extend to accomodate more entities
*/
// a simple hack because these will be synced
func GetNumberOfEntities() int {
return len(static)
}
//static getters and setters
func GetStatic(index int) bool {
return static[index]
}
func SetStatic(index int, state bool) {
static[index] = state
}
//position getters
func GetPosition(index int) [2]float64 {
return position[index]
}
func GetPositionX(index int) float64 {
return position[index][0]
}
func GetPositionY(index int) float64 {
return position[index][1]
}
//position setters
func SetPosition(index int, x float64, y float64) {
position[index] = [2]float64{x, y}
}
func SetPositionX(index int, x float64) {
position[index][0] = x
}
func SetPositionY(index int, y float64) {
position[index][1] = y
}
//inertia getters
func GetInertia(index int) [2]float64 {
return inertia[index]
}
func GetInertiaX(index int) float64 {
return inertia[index][0]
}
func GetInertiaY(index int) float64 {
return inertia[index][1]
}
//inertia setters
func SetInertia(index int, x float64, y float64) {
inertia[index] = [2]float64{x, y}
}
func SetInertiaX(index int, x float64) {
inertia[index][0] = x
}
func SetInertiaY(index int, y float64) {
inertia[index][1] = y
}
//size getters
func GetSize(index int) [2]float64 {
return size[index]
}
func GetWidth(index int) float64 {
return size[index][0]
}
func GetHeight(index int) float64 {
return size[index][1]
}
//size setters
func SetSize(index int, x float64, y float64) {
size[index] = [2]float64{x, y}
}
func SetWidth(index int, x float64) {
size[index][0] = x
}
func SetHeight(index int, y float64) {
size[index][1] = y
}
//this is a bolt on hack to move the camera with the player
func getCameraPositionX() float64 {
return -(position[0][0] - (640 / 2) - (size[0][0] / 2))
}
func getCameraPositionY() float64 {
return -(position[0][1] - (480 / 2) - (size[0][1] / 2))
}