/
player.go
98 lines (75 loc) · 1.42 KB
/
player.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
86
87
88
89
90
91
92
93
94
95
96
97
98
package core
import (
"github.com/Zyko0/GameOff2021/logic"
)
const (
DefaultPlayerRadius = 0.0425
DefaultJumpDuration = 0.5 * logic.TPS
)
type jump struct {
icd uint
duration uint
cooldown uint
currentDuration uint
y float64
}
func newJump() *jump {
return &jump{
icd: 0,
duration: DefaultJumpDuration,
currentDuration: DefaultJumpDuration,
y: DefaultPlayerRadius,
}
}
func (m *jump) Update(intent bool) {
if m.currentDuration < m.duration {
d := float64(m.currentDuration) / float64(m.duration)
c := (-(d * d) + d)
m.y = DefaultPlayerRadius + c
m.currentDuration++
} else if m.cooldown > 0 {
m.cooldown--
} else if intent {
m.currentDuration = 1
m.cooldown = m.icd
}
}
type Player struct {
x, y, z float64
radius float64
intentX float64
intentJump bool
jump *jump
}
func NewPlayer() *Player {
return &Player{
x: RoadWidth / 2,
y: DefaultPlayerRadius,
z: 2.5,
radius: DefaultPlayerRadius,
intentX: 0,
intentJump: false,
jump: newJump(),
}
}
func (p *Player) SetIntentX(x float64) {
p.intentX = x
}
func (p *Player) SetIntentJump(intent bool) {
p.intentJump = intent
}
func (p *Player) GetRadius() float64 {
return p.radius
}
func (p *Player) GetX() float64 {
return p.x
}
func (p *Player) GetY() float64 {
if p.jump.currentDuration < p.jump.duration {
return p.jump.y
}
return p.y
}
func (p *Player) GetZ() float64 {
return p.z
}