-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
101 lines (82 loc) · 1.89 KB
/
common.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
package main
// Direction is a type for the direction enum [for player/enemies]
type Direction int
const (
// Up ... DIRECTION ENUM [1]
Up Direction = iota + 1
// Down ... DIRECTION ENUM [2]
Down
// Left ... DIRECTION ENUM [3]
Left
// Right ... DIRECTION ENUM [4]
Right
// UpLeft ... DIRECTION ENUM [5]
UpLeft
// UpRight ... DIRECTION ENUM [6]
UpRight
// DownLeft ... DIRECTION ENUM [7]
DownLeft
// DownRight ... DIRECTION ENUM [8]
DownRight
)
func (d Direction) String() string {
return [...]string{"Unknown", "Up", "Down", "Left", "Right",
"UpLeft", "UpRight", "DownLeft", "DownRight"}[d]
}
// ^ DIRECTION ENUM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Movement is a type for the movement enum [for player/enemies]
type Movement int
const (
// Idle ... MOVEMENT ENUM [1]
Idle Movement = iota + 1
// Walking ... MOVEMENT ENUM [2]
Walking
// Running ... MOVEMENT ENUM [3]
Running
)
func (m Movement) String() string {
return [...]string{"Unknown", "Idle", "Walking", "Running"}[m]
}
// ^ MOVEMENT ENUM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const (
// Pi is pi
Pi = 3.14159265358979323846264338327950288419716939937510582097494459 // https://oeis.org/A000796
)
// Vec2f is a vector of 2 float64's
type Vec2f struct {
x float64
y float64
}
func newVec2f(x float64, y float64) Vec2f {
return Vec2f{x, y}
}
// Vec2i is a vector of 2 int's
type Vec2i struct {
x int
y int
}
func newVec2i(x int, y int) Vec2i {
return Vec2i{x, y}
}
// Vec2b is a vector of 2 bool's
type Vec2b struct {
x bool
y bool
}
func newVec2b(x bool, y bool) Vec2b {
return Vec2b{x, y}
}
func vec2f(x Vec2i) Vec2f {
return newVec2f(float64(x.x), float64(x.y))
}
func vec2i(x Vec2f) Vec2i {
return newVec2i(int(x.x), int(x.y))
}
// Rolumn is a row/column vector
type Rolumn struct {
row int
column int
}
func newRolumn(row int, column int) Rolumn {
return Rolumn{row, column}
}