From f31bd86ae5d7df21b788a273d4f2e530136ec184 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 7 Jan 2025 14:42:11 +0100 Subject: Added Script suffix --- game/workers/PanicFromPlayerScript.cpp | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 game/workers/PanicFromPlayerScript.cpp (limited to 'game/workers/PanicFromPlayerScript.cpp') diff --git a/game/workers/PanicFromPlayerScript.cpp b/game/workers/PanicFromPlayerScript.cpp new file mode 100644 index 0000000..1e49aaa --- /dev/null +++ b/game/workers/PanicFromPlayerScript.cpp @@ -0,0 +1,45 @@ +#include "PanicFromPlayerScript.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +void PanicFromPlayerScript::fixed_update(duration_t dt) { + Animator & anim_player = this->get_components_by_name("player").front(); + + if (anim_player.data.col == 1) { + Transform & trans_player = this->get_components_by_name("player").back(); + Transform & trans_worker = this->get_components().back(); + + float result_x = trans_player.position.x - trans_worker.position.x; + + if (result_x < 100 && result_x > -20) { + RefVector anim_worker = this->get_components(); + RefVector sprite_worker = this->get_components(); + Rigidbody & rb_worker = this->get_components().back(); + + if (anim_worker.front().get().data.col != 1) { + anim_worker.front().get().set_anim(1); + anim_worker.back().get().set_anim(1); + + anim_worker.front().get().data.fps = 10; + anim_worker.back().get().data.fps = 10; + } + + if (result_x < 0) { + rb_worker.data.linear_velocity.x = 10000 * dt.count(); + sprite_worker.front().get().data.flip.flip_x = false; + sprite_worker.back().get().data.flip.flip_x = false; + } else { + rb_worker.data.linear_velocity.x = -5000 * dt.count(); + sprite_worker.front().get().data.flip.flip_x = true; + sprite_worker.back().get().data.flip.flip_x = true; + } + } + } +}; -- cgit v1.2.3