forked from blampe/goat
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.go
51 lines (39 loc) · 857 Bytes
/
index.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
package goat
// Index represents a position within an ASCII diagram.
type Index struct {
x int
y int
}
// Pixel represents the on-screen coordinates for an Index.
type Pixel Index
func (i *Index) asPixel() Pixel {
return Pixel{x: i.x * 8, y: i.y * 16}
}
func (i *Index) asPixelXY() (int, int) {
p := i.asPixel()
return p.x, p.y
}
func (i *Index) east() Index {
return Index{i.x + 1, i.y}
}
func (i *Index) west() Index {
return Index{i.x - 1, i.y}
}
func (i *Index) north() Index {
return Index{i.x, i.y - 1}
}
func (i *Index) south() Index {
return Index{i.x, i.y + 1}
}
func (i *Index) nWest() Index {
return Index{i.x - 1, i.y - 1}
}
func (i *Index) nEast() Index {
return Index{i.x + 1, i.y - 1}
}
func (i *Index) sWest() Index {
return Index{i.x - 1, i.y + 1}
}
func (i *Index) sEast() Index {
return Index{i.x + 1, i.y + 1}
}