From b445a1716a46dc875e0b2180c1a1b6022ec7a6d3 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 8 Jan 2025 14:10:27 +0100 Subject: missile/preview/schedular/PreviewScene --- game/scheduler/ObjectsScheduler.cpp | 41 +++++++++++++++++++++++++++++++++++++ game/scheduler/ObjectsScheduler.h | 34 ++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 game/scheduler/ObjectsScheduler.cpp create mode 100644 game/scheduler/ObjectsScheduler.h (limited to 'game/scheduler') diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp new file mode 100644 index 0000000..f354e70 --- /dev/null +++ b/game/scheduler/ObjectsScheduler.cpp @@ -0,0 +1,41 @@ + + +#include "ObjectsScheduler.h" + +#include "../Random.h" +#include "../missile/SpawnEvent.h" +#include "api/Transform.h" +#include + +using namespace crepe; + +void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); } +void ObjectsScheduler::preset_1() { trigger_event(MissileSpawnEvent {}); } +void ObjectsScheduler::preset_2() {} +void ObjectsScheduler::preset_3() {} +void ObjectsScheduler::preset_4() {} +void ObjectsScheduler::boss_fight_1() { std::cout << "Boss fight" << std::endl; } + +void ObjectsScheduler::init() { + this->obstacles.push_back([this]() { preset_0(); }); + this->obstacles.push_back([this]() { preset_1(); }); + this->obstacles.push_back([this]() { boss_fight_1(); }); + + // subscribe to battlewonevent +} + +void ObjectsScheduler::fixed_update(duration_t dt) { + int pos_x + = (int) this->get_components_by_name("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[2](); + 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..d2d0f55 --- /dev/null +++ b/game/scheduler/ObjectsScheduler.h @@ -0,0 +1,34 @@ +#pragma once + + + +#include "api/Script.h" +#include +#include + + +class ObjectsScheduler : public crepe::Script { + +private: + std::vector> obstacles; + + int last_boss_check = 0; + int last_obstacle_check = 0; + + int boss_fight_interval = 2000; + int obstacle_interval = 300; + int start_offset = 1300; + + + void preset_0(); + void preset_1(); + void preset_2(); + void preset_3(); + void preset_4(); + void boss_fight_1(); + +public: + void init(); + void fixed_update(crepe::duration_t dt); + +}; -- cgit v1.2.3