-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdata.go
86 lines (74 loc) · 1.1 KB
/
data.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
package pacman
type direction int
type ghostType int
type powerType int
type Data struct {
grid [][Columns][4]rune
active [][Columns]bool
lifes int
score int
pacman Pacman
ghosts []Ghost
powers []Power
gridOffsetY float64
invincible bool
}
const (
North direction = iota
East
South
West
)
const (
Ghost1 ghostType = iota
Ghost2
Ghost3
Ghost4
)
const (
Life powerType = iota
Invincibility
)
func NewData() *Data {
return &Data{
lifes: 5,
score: 1,
}
}
type Position struct {
cellX, cellY int
posX, posY float64
direction direction
}
type Pacman struct {
Position
}
type Ghost struct {
Position
kind ghostType
}
func NewGhost(x, y int, kind ghostType, dir direction) Ghost {
return Ghost{
Position{
cellX: x,
cellY: y,
posX: float64((x * CellSize) + CellSize/2),
posY: float64((y * CellSize) + CellSize/2),
direction: dir,
},
kind,
}
}
type Power struct {
Position
kind powerType
}
func NewPower(x, y int, kind powerType) Power {
return Power{
Position{
cellX: x,
cellY: y,
},
kind,
}
}