From 8f8d579389303184038addc77c1acffdb2081f91 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 10:52:36 +0100 Subject: Added correct animations --- game/player/PlayerScript.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'game/player/PlayerScript.cpp') 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 #include +#include +#include using namespace crepe; using namespace std; void PlayerScript::fixed_update(crepe::duration_t dt) { + RefVector animators = this->get_components_by_name("player"); + Transform & transform = this->get_components_by_name("player").front(); + Rigidbody & rb = this->get_components_by_name("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; + } + } + } } -- cgit v1.2.3