aboutsummaryrefslogtreecommitdiff
path: root/game/player
diff options
context:
space:
mode:
Diffstat (limited to 'game/player')
-rw-r--r--game/player/PlayerScript.cpp35
-rw-r--r--game/player/PlayerScript.h3
2 files changed, 37 insertions, 1 deletions
diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp
index 1c388f5..874324e 100644
--- a/game/player/PlayerScript.cpp
+++ b/game/player/PlayerScript.cpp
@@ -1,11 +1,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 (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;
+ }
+ }
+ }
}
diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h
index 84c4f7f..dfd02eb 100644
--- a/game/player/PlayerScript.h
+++ b/game/player/PlayerScript.h
@@ -5,4 +5,7 @@
class PlayerScript : public crepe::Script {
public:
void fixed_update(crepe::duration_t dt);
+
+private:
+ int prev_anim = 0;
};