aboutsummaryrefslogtreecommitdiff
path: root/game/enemy/EnemyScript.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2025-01-11 21:32:30 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2025-01-11 21:32:30 +0100
commita6803980f1e74ecf1abb007b7c77f00d2cd92c43 (patch)
tree425ca961b27117d6e5d5fa0ae5cfca93351e0b33 /game/enemy/EnemyScript.h
parent6bc0025e4c24ed6659d993f3469c10615fb0e273 (diff)
parent525636bb2158ecea68ebb9d6b8d2dc722524c5e5 (diff)
merge master into loek/doxygen
Diffstat (limited to 'game/enemy/EnemyScript.h')
-rw-r--r--game/enemy/EnemyScript.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/game/enemy/EnemyScript.h b/game/enemy/EnemyScript.h
new file mode 100644
index 0000000..be71a78
--- /dev/null
+++ b/game/enemy/EnemyScript.h
@@ -0,0 +1,37 @@
+#pragma once
+#include <chrono>
+#include <crepe/api/Camera.h>
+#include <crepe/api/Event.h>
+#include <crepe/api/Script.h>
+#include <random>
+struct SpawnEnemyEvent : public crepe::Event {
+ float speed = 0;
+ int column = 0;
+};
+class EnemyScript : public crepe::Script {
+public:
+ EnemyScript();
+ void init() override;
+ void fixed_update(crepe::duration_t dt) override;
+ void shoot(const crepe::vec2 & position);
+ bool on_collide(const crepe::CollisionEvent & collisionData);
+ void despawn_enemy();
+ bool spawn_enemy(const SpawnEnemyEvent & e);
+ void death();
+ void set_hit_blink(bool status);
+
+private:
+ std::random_device rd;
+ std::default_random_engine engine;
+ bool alive = false;
+ bool spawned = false;
+ float speed = 50;
+ int health = 2;
+ const float MIN_SPEED = 20;
+ const float MAX_SPEED = 150;
+ const float MAX_DISTANCE = 200;
+ std::chrono::time_point<std::chrono::steady_clock> last_fired;
+ std::chrono::time_point<std::chrono::steady_clock> last_hit;
+ std::chrono::duration<float> shot_delay = std::chrono::duration<float>(0);
+ std::chrono::duration<float> blink_time = std::chrono::duration<float>(0.1);
+};