-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.go
More file actions
79 lines (68 loc) · 1.66 KB
/
Copy pathrender.go
File metadata and controls
79 lines (68 loc) · 1.66 KB
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
package main
import (
"fmt"
"github.com/rthornton128/goncurses"
)
func (g *GameState) drawWindow() {
// Draw level
for y := 0; y < LevelHeight; y++ {
for x := 0; x < LevelWidth; x++ {
var ch rune
var attr goncurses.Char
switch CellType(g.Level[y][x]) {
case CellBlank:
ch = ' '
g.Win.ColorOn(int16(ColorNormal))
case CellWall:
ch = ' '
g.Win.ColorOn(int16(ColorWall))
case CellPellet:
ch = '.'
g.Win.ColorOn(int16(ColorPellet))
case CellPowerup:
ch = '*'
g.Win.ColorOn(int16(ColorPowerup))
attr = goncurses.A_BOLD
case CellGhostWall:
ch = ' '
g.Win.ColorOn(int16(ColorGhostWall))
}
g.Win.MoveAddChar(y, x, goncurses.Char(ch)|attr)
}
}
g.updateStatus()
// Draw ghosts
if !g.Invincible {
for i := range g.Ghosts {
g.Win.ColorOn(g.Ghosts[i].Color)
g.Win.MoveAddChar(g.Ghosts[i].Pos.Y, g.Ghosts[i].Pos.X, goncurses.Char(g.Ghosts[i].Char))
}
} else {
// Draw vulnerable ghosts
g.Win.ColorOn(int16(ColorBlueGhost))
for i := range g.Ghosts {
g.Win.MoveAddChar(g.Ghosts[i].Pos.Y, g.Ghosts[i].Pos.X, '&')
}
}
// Draw Pacman
g.Win.ColorOn(g.Pacman.Color)
g.Win.MoveAddChar(g.Pacman.Pos.Y, g.Pacman.Pos.X, goncurses.Char(g.Pacman.Char))
g.Win.Refresh()
}
func (g *GameState) updateStatus() {
g.Status.Move(0, 0)
g.Status.ClearToEOL()
// Lives and score on same line
g.Status.ColorOn(int16(ColorPacman))
for i := 0; i < g.Lives; i++ {
g.Status.Print("C ")
}
g.Status.ColorOn(int16(ColorNormal))
g.Status.Print(fmt.Sprintf(" Score: %d", g.Points))
g.Status.Refresh()
}
func (g *GameState) clearStatus() {
g.Status.Move(0, 0)
g.Status.ClearToEOL()
g.updateStatus()
}