/
export.go
71 lines (59 loc) · 1.64 KB
/
export.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
package simnpcs2
import (
"image/color"
)
var (
colorWaypoint = color.RGBA{0xFF, 0xFF, 0x00, 255}
colorWaypointDead = color.RGBA{0xAA, 0xAA, 0xAA, 255}
colorBeing = color.RGBA{0xFF, 0x00, 0x00, 255}
colorBeingDead = color.RGBA{0x66, 0x66, 0x66, 255}
colorDestination = color.RGBA{0x00, 0xFF, 0x00, 255}
colorHome = color.RGBA{0xAD, 0xD8, 0xE6, 255}
colorObstacle = color.RGBA{0x00, 0x00, 0xFF, 255}
colorItem = color.RGBA{0xFF, 0x00, 0xFF, 255}
)
type imageIf interface {
Set(x, y int, c color.Color)
}
func (w *World) renderFrame(img imageIf) {
// Draw all entities and their paths.
for _, c := range w.Beings {
ai := c.(*AI)
// Determine the colors to use.
cWay := colorWaypoint
cBeing := colorBeing
if ai.Dead() {
cWay = colorWaypointDead
cBeing = colorBeingDead
}
// Draw the path.
if ai.Pathfinding.Waypoints != nil {
for _, wpIdx := range ai.Pathfinding.Waypoints[ai.Pathfinding.WaypointIdx:] {
wp := w.CellIdxToPos(wpIdx)
img.Set(int(wp.X), int(wp.Y), cWay)
}
}
// Draw the being.
pos := c.Pos()
img.Set(int(pos.X), int(pos.Y), cBeing)
// Draw the destination.
if dst := ai.Destination; dst != nil {
img.Set(int(dst.X), int(dst.Y), colorDestination)
}
// Draw the home.
img.Set(int(ai.Home.X), int(ai.Home.Y), colorHome)
}
// Draw all obstacles.
for i, c := range w.Cells {
if c {
pos := w.CellIdxToPos(i)
img.Set(int(pos.X), int(pos.Y), colorObstacle)
}
}
// Draw all items that are visible.
for _, c := range w.Items {
pos := c.Pos()
img.Set(int(pos.X), int(pos.Y), colorItem)
}
// TODO: Draw a list of all entities and their needs.
}