-
Notifications
You must be signed in to change notification settings - Fork 0
/
direction.go
85 lines (77 loc) · 1.2 KB
/
direction.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
type Direction uint8
const (
DirNorth Direction = iota
DirSouth
DirWest
DirEast
DirNone
)
func (d Direction) MoveEG2(s Supertile) (Supertile, bool) {
if s < 0x100 {
return s, false
}
switch d {
case DirNorth:
return s - 0x10, s&0xF0 > 0
case DirSouth:
return s + 0x10, s&0xF0 < 0xF0
case DirWest:
return s - 1, s&0x0F > 0
case DirEast:
return s + 1, s&0x0F < 0x02
}
return s, false
}
func (d Direction) Opposite() Direction {
switch d {
case DirNorth:
return DirSouth
case DirSouth:
return DirNorth
case DirWest:
return DirEast
case DirEast:
return DirWest
}
return d
}
func (d Direction) String() string {
switch d {
case DirNorth:
return "north"
case DirSouth:
return "south"
case DirWest:
return "west"
case DirEast:
return "east"
}
return ""
}
func (d Direction) RotateCW() Direction {
switch d {
case DirNorth:
return DirEast
case DirEast:
return DirSouth
case DirSouth:
return DirWest
case DirWest:
return DirNorth
}
return d
}
func (d Direction) RotateCCW() Direction {
switch d {
case DirNorth:
return DirWest
case DirWest:
return DirSouth
case DirSouth:
return DirEast
case DirEast:
return DirNorth
}
return d
}