-
Notifications
You must be signed in to change notification settings - Fork 5
/
map.go
63 lines (52 loc) · 1.38 KB
/
map.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
package rog
type Map struct {
w, h int
blocked, seen [][]bool
}
func NewMap(width, height int) *Map {
blocked := make([][]bool, height)
seen := make([][]bool, height)
for y := 0; y < height; y++ {
blocked[y] = make([]bool, width)
seen[y] = make([]bool, width)
}
return &Map{width, height, blocked, seen}
}
// In returns whether the coordinate is inside the map bounds.
func (this *Map) In(x, y int) bool {
return x >= 0 && x < this.w && y >= 0 && y < this.h
}
// Update runs the give fov alogrithm on the map.
func (this *Map) Fov(x, y, radius int, includeWalls bool, algo FOVAlgo) {
for y := 0; y < this.h; y++ {
for x := 0; x < this.w; x++ {
this.seen[y][x] = false
}
}
algo(this, x, y, radius, includeWalls)
}
// Block sets a cell as blocking or not.
func (this *Map) Block(x, y int, blocked bool) {
this.blocked[y][x] = blocked
}
// Look indicates if the cell at the coordinate can be seen.
func (this *Map) Look(x, y int) bool {
return this.seen[y][x]
}
// Clear resets the map to completely unblocked but unviewable.
func (this *Map) Clear() {
for y := 0; y < this.h; y++ {
for x := 0; x < this.w; x++ {
this.blocked[y][y] = false
this.seen[y][x] = false
}
}
}
// Width returns the width in cells of the map.
func (this *Map) Width() int {
return this.w
}
// Height returns the height in cells of the map.
func (this *Map) Height() int {
return this.h
}