-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerstate.go
139 lines (110 loc) · 3.09 KB
/
playerstate.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
"github.com/autovelop/playthos"
"github.com/autovelop/playthos/animation"
"github.com/autovelop/playthos/render"
"github.com/autovelop/playthos/std"
)
type PlayerState struct {
engine.Component
cableBlocks []*engine.Entity
startPos *std.Vector3
camera *engine.Entity
entity *engine.Entity
walkingWSprite *render.Texture
walkingDownSprite *render.Texture
walkingUpSprite *render.Texture
idleSprite *render.Texture
idleAnimation *animation.AnimationClip
walkingWAnimation *animation.AnimationClip
walkingUpAnimation *animation.AnimationClip
walkingDownAnimation *animation.AnimationClip
running bool
vertical bool
levels []*Level
currentLevel uint
}
func (p *PlayerState) Set(cb []*engine.Entity, s *std.Vector3, r bool, e *engine.Entity, c *engine.Entity, ls []*Level) {
p.cableBlocks = cb
p.startPos = s
p.running = r
p.entity = e
p.camera = c
p.levels = ls
p.currentLevel = 0
if len(p.levels) > 0 {
p.levels[p.currentLevel].Load(p)
}
}
func (p *PlayerState) Camera() *engine.Entity {
return p.camera
}
func (p *PlayerState) Player() *engine.Entity {
return p.entity
}
func (p *PlayerState) Running() bool {
return p.running
}
func (p *PlayerState) SetRunning(r bool) {
p.running = r
}
func (p *PlayerState) Vertical() bool {
return p.vertical
}
func (p *PlayerState) SetVertical(v bool) {
p.vertical = v
}
func (p *PlayerState) AddCableBlock(e *engine.Entity) {
p.cableBlocks = append(p.cableBlocks, e)
}
func (p *PlayerState) CableBlocks() []*engine.Entity {
return p.cableBlocks
}
func (p *PlayerState) StartPos() *std.Vector3 {
return p.startPos
}
func (p *PlayerState) SetStartPos(pos *std.Vector3) {
p.startPos = pos
}
func (p *PlayerState) Idle() (*render.Texture, *animation.AnimationClip) {
return p.idleSprite, p.idleAnimation
}
func (p *PlayerState) WalkingW() (*render.Texture, *animation.AnimationClip) {
return p.walkingWSprite, p.walkingWAnimation
}
func (p *PlayerState) WalkingUp() (*render.Texture, *animation.AnimationClip) {
return p.walkingUpSprite, p.walkingUpAnimation
}
func (p *PlayerState) WalkingDown() (*render.Texture, *animation.AnimationClip) {
return p.walkingDownSprite, p.walkingDownAnimation
}
func (p *PlayerState) Completed() bool {
return p.levels[p.currentLevel].Completed()
}
func (p *PlayerState) SetLevelCompleted(l uint) {
p.levels[l].SetCompleted(true)
}
func (p *PlayerState) CurrentLevel() uint {
return p.currentLevel
}
func (p *PlayerState) ResetLevel() {
p.levels[p.currentLevel].Load(p)
}
func (p *PlayerState) NextLevel() {
p.currentLevel++
if int(p.currentLevel) <= len(p.levels)-1 {
p.levels[p.currentLevel].Load(p)
}
}
func (p *PlayerState) SetSprites(i *render.Texture, w *render.Texture, u *render.Texture, d *render.Texture) {
p.idleSprite = i
p.walkingWSprite = w
p.walkingUpSprite = u
p.walkingDownSprite = d
}
func (p *PlayerState) SetAnimations(i *animation.AnimationClip, w *animation.AnimationClip, u *animation.AnimationClip, d *animation.AnimationClip) {
p.idleAnimation = i
p.walkingWAnimation = w
p.walkingUpAnimation = u
p.walkingDownAnimation = d
}