-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplay.go
47 lines (36 loc) · 845 Bytes
/
play.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
package main
import (
"strconv"
"github.com/firefly-zero/firefly-go/firefly"
)
// updatePlay updates the game play
func updatePlay() {
frames += 1
buttons = firefly.ReadButtons(firefly.Combined)
if buttons.N || buttons.S || buttons.E || buttons.W {
gopher.jump()
}
// add additional walls?
if frames%newWallsInterval == 0 {
walls.add()
}
// current score
score = gopher.score(walls)
gopher.move()
walls.move()
switch {
case gopher.hitWalls(walls):
scene = gameOver
case gopher.hitBottom():
scene = gameOver
case gopher.hitTop():
scene = gameOver
}
}
// renderPlay renders the game play onto the screen
func renderPlay() {
firefly.ClearScreen(firefly.ColorWhite)
gopher.draw()
walls.draw()
firefly.DrawText("Score: "+strconv.Itoa(score), titleFont, firefly.Point{X: 10, Y: 10}, firefly.ColorDarkBlue)
}