diff options
Diffstat (limited to 'game/preview/NpcScript.cpp')
-rw-r--r-- | game/preview/NpcScript.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/game/preview/NpcScript.cpp b/game/preview/NpcScript.cpp new file mode 100644 index 0000000..86117d4 --- /dev/null +++ b/game/preview/NpcScript.cpp @@ -0,0 +1,29 @@ +#include "NpcScript.h" + +#include <crepe/api/Sprite.h> +#include <crepe/api/Transform.h> +#include <crepe/manager/SaveManager.h> + +using namespace std; +using namespace crepe; + +void NpcScript::fixed_update(duration_t dt) { + auto & rb = this->get_component<Rigidbody>(); + auto npc = this->get_components<Sprite>(); + auto & transform = this->get_component<Transform>(); + + if (transform.position.x < 200) { + rb.data.linear_velocity.x *= -1; + } + if (transform.position.x > 700) { + rb.data.linear_velocity.x *= -1; + } + + if (rb.data.linear_velocity.x < 0) { + npc.front().get().data.flip = {true, false}; + npc.back().get().data.flip = {true, false}; + } else { + npc.front().get().data.flip = {false, false}; + npc.back().get().data.flip = {false, false}; + } +} |