-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwalls.go
62 lines (52 loc) · 1.06 KB
/
walls.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
package main
import (
"math/rand/v2"
"github.com/firefly-zero/firefly-go/firefly"
)
var (
wallImage firefly.Image
)
// wallData represents all of the walls in the current game
type wallsData struct {
walls []*wallData
}
func newWalls() *wallsData {
wallImage = firefly.LoadFile("wall", nil).Image()
return &wallsData{
walls: []*wallData{},
}
}
// reset clears all walls
func (w *wallsData) reset() {
w.walls = []*wallData{}
}
// draw draws all walls
func (w *wallsData) draw() {
for _, wall := range w.walls {
wall.draw()
}
}
// score returns the current score of the player based on the gopher's position
func (w *wallsData) score(l int) int {
score := 0
for i, wall := range w.walls {
if wall.wallX < int(l) {
score = i + 1
}
}
return score
}
// move moves all walls
func (w *wallsData) move() {
for _, wall := range w.walls {
wall.move()
if frames%4 == 0 {
wall.move()
}
}
}
// hitWalls returns true if the gopher hits any walls
func (w *wallsData) add() {
wall := &wallData{wallStartX, rand.N(holeYMax)}
w.walls = append(w.walls, wall)
}