-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirection.go
58 lines (52 loc) · 1.01 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
package main
import (
"github.com/ByteArena/box2d"
"math"
)
type Direction string
const (
DirectionDown Direction = "D"
DirectionLeft Direction = "L"
DirectionUp Direction = "U"
DirectionRight Direction = "R"
)
func (d Direction) GetAng() float64 {
switch d {
case DirectionRight:
return 0
case DirectionDown:
return math.Pi / 2
case DirectionLeft:
return math.Pi
case DirectionUp:
return math.Pi + math.Pi/2
default:
panic("bad direction: " + d)
}
}
func (d Direction) GetVec() box2d.B2Vec2 {
switch d {
case DirectionRight:
return box2d.MakeB2Vec2(1, 0)
case DirectionDown:
return box2d.MakeB2Vec2(0, 1)
case DirectionLeft:
return box2d.MakeB2Vec2(-1, 0)
case DirectionUp:
return box2d.MakeB2Vec2(0, -1)
}
panic("bad direction")
}
func (d Direction) Negative() Direction {
switch d {
case DirectionRight:
return DirectionLeft
case DirectionDown:
return DirectionUp
case DirectionLeft:
return DirectionRight
case DirectionUp:
return DirectionDown
}
panic("bad direction")
}