blob: 874324ea74b0efb3dad59cd3878f8f17b169d960 (
plain)
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
|
#include "PlayerScript.h"
#include <crepe/api/Animator.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Transform.h>
#include <crepe/types.h>
using namespace crepe;
using namespace std;
void PlayerScript::fixed_update(crepe::duration_t dt) {
RefVector<Animator> animators = this->get_components_by_name<Animator>("player");
Transform & transform = this->get_components_by_name<Transform>("player").front();
Rigidbody & rb = this->get_components_by_name<Rigidbody>("player").front();
if (this->get_key_state(Keycode::SPACE)) {
rb.add_force_linear(vec2(0, -10));
if (prev_anim != 1) {
for (Animator & anim : animators) {
anim.active = true;
anim.set_anim(1);
anim.data.looping = true;
prev_anim = 1;
}
}
} else if (transform.position.y == 195) {
if (prev_anim != 0) {
for (Animator & anim : animators) {
anim.active = true;
anim.set_anim(0);
anim.data.looping = true;
prev_anim = 0;
}
}
} else {
if (prev_anim != 2) {
for (Animator & anim : animators) {
anim.set_anim(2);
anim.data.looping = false;
prev_anim = 2;
}
}
}
}
|