-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgate.go
54 lines (43 loc) · 742 Bytes
/
gate.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
package gobls
import (
"math/rand"
)
type point struct {
x, y int
}
type gate struct {
state bool
slowState float32
in, out point
inIdx, outIdx int
inGates []int
}
func (g *gate) setState(newState bool) {
g.state = newState
if newState {
g.slowState = 1
} else {
g.slowState = 0
}
}
func (g *gate) updateState(newState bool) {
if newState {
if g.state && g.slowState >= 1 {
return
}
g.slowState += TIME_RAISE + TIME_RANDOM*rand.Float32()
if g.slowState >= 1 {
g.slowState = 1
g.state = true
}
} else {
if !g.state && g.slowState <= 0 {
return
}
g.slowState -= TIME_FALL + TIME_RANDOM*rand.Float32()
if g.slowState <= 0 {
g.slowState = 0
g.state = false
}
}
}