aboutsummaryrefslogtreecommitdiff
path: root/game/preview/NpcScript.cpp
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2025-01-08 14:10:27 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2025-01-08 14:10:27 +0100
commitb445a1716a46dc875e0b2180c1a1b6022ec7a6d3 (patch)
tree1395518417ef02ca8adfa961e0734ea7aeb71a6d /game/preview/NpcScript.cpp
parentc9c9702edc58ff8f40b13dc6b86b216421f79e9b (diff)
missile/preview/schedular/PreviewScene
Diffstat (limited to 'game/preview/NpcScript.cpp')
-rw-r--r--game/preview/NpcScript.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/game/preview/NpcScript.cpp b/game/preview/NpcScript.cpp
new file mode 100644
index 0000000..c4148f2
--- /dev/null
+++ b/game/preview/NpcScript.cpp
@@ -0,0 +1,32 @@
+#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::init() {}
+void NpcScript::fixed_update(duration_t dt) {
+ auto & rb = this->get_component<Rigidbody>();
+ auto & npc = this->get_component<Sprite>();
+ auto & transform = this->get_component<Transform>();
+
+ if (transform.position.x < -990) {
+ rb.data.linear_velocity.x *= -1;
+ }
+ if (transform.position.x > 990) {
+ rb.data.linear_velocity.x *= -1;
+ }
+
+ if (rb.data.linear_velocity.x < 0) {
+ npc.data.flip = {true, false};
+ } else {
+ npc.data.flip = {false, false};
+ }
+
+ auto & savemgr = this->get_save_manager();
+ savemgr.set("npc_x", transform.position.x);
+ savemgr.set("npc_y", transform.position.y);
+}