aboutsummaryrefslogtreecommitdiff
path: root/game/scheduler
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2025-01-08 18:40:11 +0100
committerJAROWMR <jarorutjes07@gmail.com>2025-01-08 18:40:11 +0100
commitef3f5b0845ba127c0bfcda8c2fce37013fef3878 (patch)
treee5690ff875a662ee7603844e858d82428d973a78 /game/scheduler
parent424da5eb1500d90389d939cd0b3e6e75d729578d (diff)
parent2ad15f3efab481659543a1c03cd70a36fd297538 (diff)
Merge branch 'master' of github.com:lonkaars/crepe into jaro/game
Diffstat (limited to 'game/scheduler')
-rw-r--r--game/scheduler/ObjectsScheduler.cpp65
-rw-r--r--game/scheduler/ObjectsScheduler.h32
2 files changed, 97 insertions, 0 deletions
diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp
new file mode 100644
index 0000000..60e3f47
--- /dev/null
+++ b/game/scheduler/ObjectsScheduler.cpp
@@ -0,0 +1,65 @@
+
+
+#include "ObjectsScheduler.h"
+
+#include "../Config.h"
+#include "../Random.h"
+#include "../missile/SpawnEvent.h"
+#include "api/Rigidbody.h"
+#include "api/Transform.h"
+#include "enemy/BattleScript.h"
+#include "prefab/ZapperPoolSubScene.h"
+
+using namespace crepe;
+void ObjectsScheduler::preset_0() {
+ trigger_event<MissileSpawnEvent>(MissileSpawnEvent {});
+ trigger_event<MissileSpawnEvent>(MissileSpawnEvent {});
+}
+void ObjectsScheduler::preset_1() { trigger_event<MissileSpawnEvent>(MissileSpawnEvent {}); }
+void ObjectsScheduler::preset_2() { trigger_event<CreateZapperEvent>(CreateZapperEvent {}); }
+void ObjectsScheduler::preset_3() { trigger_event<CreateZapperEvent>(CreateZapperEvent {}); }
+void ObjectsScheduler::preset_4() {}
+void ObjectsScheduler::boss_fight_1() {
+ this->get_components_by_name<Rigidbody>("camera").front().get().data.linear_velocity.x = 0;
+ this->get_components_by_name<Rigidbody>("player").front().get().data.linear_velocity.x = 0;
+ this->trigger_event<BattleStartEvent>(BattleStartEvent {.num_enemies = 2});
+}
+
+bool ObjectsScheduler::boss_fight_1_event() {
+ this->get_components_by_name<Rigidbody>("camera").front().get().data.linear_velocity.x
+ = PLAYER_SPEED * 0.02;
+ this->get_components_by_name<Rigidbody>("player").front().get().data.linear_velocity.x
+ = PLAYER_SPEED * 0.02;
+ return false;
+}
+
+void ObjectsScheduler::init() {
+ this->obstacles.push_back([this]() { preset_0(); });
+ this->obstacles.push_back([this]() { preset_1(); });
+ this->obstacles.push_back([this]() { preset_2(); });
+ this->obstacles.push_back([this]() { preset_3(); });
+ this->obstacles.push_back([this]() { preset_4(); });
+
+ this->obstacles.push_back([this]() { boss_fight_1(); });
+
+ // subscribe to battlewonevent
+ this->subscribe<BattleWonEvent>([this](const BattleWonEvent & ev) -> bool {
+ return this->boss_fight_1_event();
+ });
+}
+
+void ObjectsScheduler::fixed_update(duration_t dt) {
+ int pos_x
+ = (int) this->get_components_by_name<Transform>("camera").front().get().position.x;
+
+ int boss_check = (pos_x - this->start_offset) / this->boss_fight_interval;
+ if (boss_check > this->last_boss_check) {
+ this->obstacles.back()();
+ this->last_boss_check = boss_check;
+ }
+ int obstacle_check = (pos_x - this->start_offset) / this->obstacle_interval;
+ if (obstacle_check > this->last_obstacle_check) {
+ this->obstacles[Random::i(this->obstacles.size() - 1, 0)]();
+ this->last_obstacle_check = obstacle_check;
+ }
+}
diff --git a/game/scheduler/ObjectsScheduler.h b/game/scheduler/ObjectsScheduler.h
new file mode 100644
index 0000000..bd0701b
--- /dev/null
+++ b/game/scheduler/ObjectsScheduler.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "api/Script.h"
+#include <functional>
+#include <vector>
+
+class ObjectsScheduler : public crepe::Script {
+
+private:
+ std::vector<std::function<void()>> obstacles;
+
+ int last_boss_check = 0;
+ int last_obstacle_check = 0;
+
+ int boss_fight_interval = 5000;
+ int obstacle_interval = 350;
+ int start_offset = 1300;
+
+private:
+ void preset_0();
+ void preset_1();
+ void preset_2();
+ void preset_3();
+ void preset_4();
+ void boss_fight_1();
+
+ bool boss_fight_1_event();
+
+public:
+ void init();
+ void fixed_update(crepe::duration_t dt);
+};