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 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 game/scheduler/ObjectsScheduler.cpp (limited to 'game/scheduler/ObjectsScheduler.cpp') 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; + } +} -- cgit v1.2.3 From d989c1c51bf4d4fbb301493e73bc77e1873143b2 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 8 Jan 2025 14:51:10 +0100 Subject: working zapper, missilies with scheduler --- game/CMakeLists.txt | 7 +------ game/menus/MenusConfig.h | 1 - game/prefab/ZapperPoolScript.cpp | 4 ---- game/scheduler/ObjectsScheduler.cpp | 6 ++++-- game/scheduler/ObjectsScheduler.h | 2 +- 5 files changed, 6 insertions(+), 14 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index dec161d..d1f49ed 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -10,7 +10,7 @@ add_subdirectory(../src crepe) add_executable(main) -add_executable(main PUBLIC +target_sources(main PUBLIC #background background/AquariumSubScene.cpp background/AquariumScript.cpp @@ -43,13 +43,8 @@ add_executable(main PUBLIC preview/NpcScript.cpp preview/PrevPlayerSubScene.cpp preview/PrevPlayerScript.cpp - main.cpp # scripts - -add_executable(main) - -target_sources(main PUBLIC GameScene.cpp MoveCameraManualyScript.cpp StartGameScript.cpp diff --git a/game/menus/MenusConfig.h b/game/menus/MenusConfig.h index 968f8cc..3e357a5 100644 --- a/game/menus/MenusConfig.h +++ b/game/menus/MenusConfig.h @@ -3,7 +3,6 @@ //generic menu config static constexpr int STARTING_SORTING_IN_LAYER = 7; -static constexpr const char * CAMERA_NAME = "camera"; //Scene names static constexpr const char * START_SCENE = "scene1"; static constexpr const char * PREVIEW_SCENE = "preview scene"; diff --git a/game/prefab/ZapperPoolScript.cpp b/game/prefab/ZapperPoolScript.cpp index ac6ce96..b9b2a76 100644 --- a/game/prefab/ZapperPoolScript.cpp +++ b/game/prefab/ZapperPoolScript.cpp @@ -30,10 +30,6 @@ void ZapperPoolScript::fixed_update(crepe::duration_t) { if (zapper.transform.position.x < threshold) zapper.set_active(false); } - - if (i-- > 0) return; - i = 200; - queue_event(); } void ZapperPoolScript::spawn_random() { diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index f354e70..21465e3 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -5,13 +5,13 @@ #include "../Random.h" #include "../missile/SpawnEvent.h" #include "api/Transform.h" +#include "prefab/ZapperPoolSubScene.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_2() { trigger_event(CreateZapperEvent {}); } void ObjectsScheduler::preset_3() {} void ObjectsScheduler::preset_4() {} void ObjectsScheduler::boss_fight_1() { std::cout << "Boss fight" << std::endl; } @@ -19,6 +19,8 @@ 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]() { preset_2(); }); + this->obstacles.push_back([this]() { boss_fight_1(); }); // subscribe to battlewonevent diff --git a/game/scheduler/ObjectsScheduler.h b/game/scheduler/ObjectsScheduler.h index d2d0f55..7bc9337 100644 --- a/game/scheduler/ObjectsScheduler.h +++ b/game/scheduler/ObjectsScheduler.h @@ -15,7 +15,7 @@ private: int last_boss_check = 0; int last_obstacle_check = 0; - int boss_fight_interval = 2000; + int boss_fight_interval = 2500; int obstacle_interval = 300; int start_offset = 1300; -- cgit v1.2.3 From 17a587ee6ded6d51c678fcd89bf0d28dc60db43d Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 8 Jan 2025 15:13:08 +0100 Subject: added boss fight, did not work --- game/GameScene.cpp | 5 ++--- game/scheduler/ObjectsScheduler.cpp | 13 +++++++++++-- game/scheduler/ObjectsScheduler.h | 8 +++++--- 3 files changed, 18 insertions(+), 8 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/GameScene.cpp b/game/GameScene.cpp index a255e17..07275ab 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -8,6 +8,7 @@ #include "background/BackgroundSubScene.h" #include "enemy/BattleScript.h" #include "enemy/EnemyBulletPool.h" +#include "enemy/EnemyBulletSubScene.h" #include "enemy/EnemyPool.h" #include "enemy/EnemySubScene.h" #include "hud/HudScript.h" @@ -62,8 +63,8 @@ void GameScene::load_scene() { camera.add_component().set_script(); camera.add_component().set_script(); camera.add_component().set_script(); - camera.add_component().set_script(); + camera.add_component(Rigidbody::Data {}); AI & enemy_path_1 = camera.add_component(400); enemy_path_1.make_oval_path(100, 100, camera.transform.position, 1.5708, true); @@ -73,9 +74,7 @@ void GameScene::load_scene() { enemy_path_3.make_oval_path(100, 100, {0, 0}, 1.5708, true); // camer.add_component PlayerSubScene player(*this); - MissilePool missile_pool(*this); - WorkersSubScene workers(*this); GameObject floor = new_object("floor", "game_world", vec2(0, 325)); diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 21465e3..416a8da 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -5,6 +5,7 @@ #include "../Random.h" #include "../missile/SpawnEvent.h" #include "api/Transform.h" +#include "enemy/BattleScript.h" #include "prefab/ZapperPoolSubScene.h" #include @@ -14,7 +15,12 @@ void ObjectsScheduler::preset_1() { trigger_event(MissileSpaw void ObjectsScheduler::preset_2() { trigger_event(CreateZapperEvent {}); } void ObjectsScheduler::preset_3() {} void ObjectsScheduler::preset_4() {} -void ObjectsScheduler::boss_fight_1() { std::cout << "Boss fight" << std::endl; } +void ObjectsScheduler::boss_fight_1() { trigger_event(BattleStartEvent {}); } + +bool ObjectsScheduler::boss_fight_1_event() { + std::cout << "BATTLE WON" << std::endl; + return false; +} void ObjectsScheduler::init() { this->obstacles.push_back([this]() { preset_0(); }); @@ -24,6 +30,9 @@ void ObjectsScheduler::init() { this->obstacles.push_back([this]() { boss_fight_1(); }); // subscribe to battlewonevent + this->subscribe([this](const BattleWonEvent & ev) -> bool { + return this->boss_fight_1_event(); + }); } void ObjectsScheduler::fixed_update(duration_t dt) { @@ -32,7 +41,7 @@ void ObjectsScheduler::fixed_update(duration_t dt) { int boss_check = (pos_x - this->start_offset) / this->boss_fight_interval; if (boss_check > this->last_boss_check) { - this->obstacles[2](); + this->obstacles.back()(); this->last_boss_check = boss_check; } int obstacle_check = (pos_x - this->start_offset) / this->obstacle_interval; diff --git a/game/scheduler/ObjectsScheduler.h b/game/scheduler/ObjectsScheduler.h index 7bc9337..1bd0940 100644 --- a/game/scheduler/ObjectsScheduler.h +++ b/game/scheduler/ObjectsScheduler.h @@ -15,11 +15,11 @@ private: int last_boss_check = 0; int last_obstacle_check = 0; - int boss_fight_interval = 2500; - int obstacle_interval = 300; + int boss_fight_interval = 1000; + int obstacle_interval = 3000; int start_offset = 1300; - +private: void preset_0(); void preset_1(); void preset_2(); @@ -27,6 +27,8 @@ private: void preset_4(); void boss_fight_1(); + bool boss_fight_1_event(); + public: void init(); void fixed_update(crepe::duration_t dt); -- cgit v1.2.3 From 698628cf1fb1b8a1f68bf6a5672d984bd64be58f Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 8 Jan 2025 15:26:35 +0100 Subject: added camera stop boss fight --- game/scheduler/ObjectsScheduler.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 416a8da..11bb111 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -3,7 +3,9 @@ #include "ObjectsScheduler.h" #include "../Random.h" +#include "../Config.h" #include "../missile/SpawnEvent.h" +#include "api/Rigidbody.h" #include "api/Transform.h" #include "enemy/BattleScript.h" #include "prefab/ZapperPoolSubScene.h" @@ -15,10 +17,16 @@ void ObjectsScheduler::preset_1() { trigger_event(MissileSpaw void ObjectsScheduler::preset_2() { trigger_event(CreateZapperEvent {}); } void ObjectsScheduler::preset_3() {} void ObjectsScheduler::preset_4() {} -void ObjectsScheduler::boss_fight_1() { trigger_event(BattleStartEvent {}); } +void ObjectsScheduler::boss_fight_1() { + this->get_components_by_name("camera").front().get().data.linear_velocity.x = 0; + this->get_components_by_name("player").front().get().data.linear_velocity.x = 0; + + this->trigger_event(BattleStartEvent{.num_enemies = 5}); +} bool ObjectsScheduler::boss_fight_1_event() { - std::cout << "BATTLE WON" << std::endl; + this->get_components_by_name("camera").front().get().data.linear_velocity.x = PLAYER_SPEED; + this->get_components_by_name("player").front().get().data.linear_velocity.x = PLAYER_SPEED; return false; } -- cgit v1.2.3 From 1ec7e724fcace1274473dfcae91022cc1c930baa Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 8 Jan 2025 15:57:05 +0100 Subject: working scheduler and enemies and rest --- game/Config.h | 1 + game/GameScene.cpp | 4 ++-- game/enemy/BattleScript.cpp | 2 +- game/enemy/EnemyScript.cpp | 3 +-- game/scheduler/ObjectsScheduler.cpp | 8 +++----- game/scheduler/ObjectsScheduler.h | 4 ++-- 6 files changed, 10 insertions(+), 12 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/Config.h b/game/Config.h index 58a51f2..e4f617a 100644 --- a/game/Config.h +++ b/game/Config.h @@ -63,3 +63,4 @@ static constexpr int PLAYER_GRAVITY_SCALE = 60; // In game units // Jetpack particles static constexpr const char * JETPACK_PARTICLES = "jetpack_particles"; +static constexpr const char * CAMERA_NAME = "camera"; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 07275ab..4cb3671 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -61,9 +61,9 @@ void GameScene::load_scene() { camera.add_component().set_script(); camera.add_component().set_script(); camera.add_component().set_script(); - camera.add_component().set_script(); - camera.add_component().set_script(); camera.add_component().set_script(); + camera.add_component().set_script(); + camera.add_component().set_script(); camera.add_component(Rigidbody::Data {}); AI & enemy_path_1 = camera.add_component(400); diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp index dde8da1..4260c42 100644 --- a/game/enemy/BattleScript.cpp +++ b/game/enemy/BattleScript.cpp @@ -39,7 +39,7 @@ bool BattleScript::create_battle(const BattleStartEvent & e) { for (int i = 0; i < e.num_enemies; i++) { BehaviorScript & script = enemy_scripts[i]; script.active = true; - this->trigger_event( + this->queue_event( SpawnEnemyEvent { .speed = dist(engine), .column = i, diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 8e475a8..07ed9e8 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -84,8 +84,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { bool EnemyScript::on_collide(const CollisionEvent & e) { if (e.info.other.metadata.tag == "player_bullet") { - //this->despawn_enemy(); - + this->despawn_enemy(); } Animator& body_animator = this->get_components().front(); body_animator.data.col = 2; diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 11bb111..02d84c1 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -9,7 +9,6 @@ #include "api/Transform.h" #include "enemy/BattleScript.h" #include "prefab/ZapperPoolSubScene.h" -#include using namespace crepe; void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); } @@ -20,13 +19,12 @@ void ObjectsScheduler::preset_4() {} void ObjectsScheduler::boss_fight_1() { this->get_components_by_name("camera").front().get().data.linear_velocity.x = 0; this->get_components_by_name("player").front().get().data.linear_velocity.x = 0; - - this->trigger_event(BattleStartEvent{.num_enemies = 5}); + this->trigger_event(BattleStartEvent{.num_enemies = 2}); } bool ObjectsScheduler::boss_fight_1_event() { - this->get_components_by_name("camera").front().get().data.linear_velocity.x = PLAYER_SPEED; - this->get_components_by_name("player").front().get().data.linear_velocity.x = PLAYER_SPEED; + this->get_components_by_name("camera").front().get().data.linear_velocity.x = PLAYER_SPEED * 0.02; + this->get_components_by_name("player").front().get().data.linear_velocity.x = PLAYER_SPEED * 0.02; return false; } diff --git a/game/scheduler/ObjectsScheduler.h b/game/scheduler/ObjectsScheduler.h index 1bd0940..56d72cb 100644 --- a/game/scheduler/ObjectsScheduler.h +++ b/game/scheduler/ObjectsScheduler.h @@ -15,8 +15,8 @@ private: int last_boss_check = 0; int last_obstacle_check = 0; - int boss_fight_interval = 1000; - int obstacle_interval = 3000; + int boss_fight_interval = 5000; + int obstacle_interval = 350; int start_offset = 1300; private: -- cgit v1.2.3 From eb3d9ec9baa0b95b95d741a0615adaf4c8c1d3c0 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 8 Jan 2025 16:32:03 +0100 Subject: added preset with nothing --- game/missile/MissileSubScene.cpp | 4 +++- game/missile/SpawnEvent.h | 2 +- game/scheduler/ObjectsScheduler.cpp | 21 ++++++++++++++------- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/missile/MissileSubScene.cpp b/game/missile/MissileSubScene.cpp index db49f88..59d8221 100644 --- a/game/missile/MissileSubScene.cpp +++ b/game/missile/MissileSubScene.cpp @@ -65,6 +65,7 @@ void MissileSubScene::create(crepe::Scene & scn) { missle.add_component( missle_sprite, ivec2 {32, 32}, uvec2 {4, 1}, Animator::Data { + .fps = 15, .looping = true, } ); @@ -72,6 +73,7 @@ void MissileSubScene::create(crepe::Scene & scn) { missle.add_component( missle_thruster_sprite, ivec2 {64, 64}, uvec2 {4, 2}, Animator::Data { + .fps = 15, .looping = true, } ); @@ -86,7 +88,7 @@ void MissileSubScene::create(crepe::Scene & scn) { missile_explosion_sprite.active = false; explosion_anim.active = false; - std::uniform_int_distribution<> dist(140, 200); + std::uniform_int_distribution<> dist(200, 250); missle.add_component(Rigidbody::Data { .body_type = Rigidbody::BodyType::KINEMATIC, .max_linear_velocity = static_cast(dist(gen)), diff --git a/game/missile/SpawnEvent.h b/game/missile/SpawnEvent.h index ce301fd..58293d7 100644 --- a/game/missile/SpawnEvent.h +++ b/game/missile/SpawnEvent.h @@ -9,7 +9,7 @@ struct MissileSpawnEvent : public crepe::Event {}; class MissileSpawnEventHandler : public crepe::Script { private: - static constexpr int MISSILE_OFFSET = VIEWPORT_X / 1.8; + static constexpr int MISSILE_OFFSET = VIEWPORT_X; static constexpr int RANGE = GAME_HEIGHT / 4; static constexpr int MIN_RANGE = -RANGE; static constexpr int MAX_RANGE = RANGE; diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 02d84c1..60e3f47 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -2,8 +2,8 @@ #include "ObjectsScheduler.h" -#include "../Random.h" #include "../Config.h" +#include "../Random.h" #include "../missile/SpawnEvent.h" #include "api/Rigidbody.h" #include "api/Transform.h" @@ -11,20 +11,25 @@ #include "prefab/ZapperPoolSubScene.h" using namespace crepe; -void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); } +void ObjectsScheduler::preset_0() { + trigger_event(MissileSpawnEvent {}); + trigger_event(MissileSpawnEvent {}); +} void ObjectsScheduler::preset_1() { trigger_event(MissileSpawnEvent {}); } void ObjectsScheduler::preset_2() { trigger_event(CreateZapperEvent {}); } -void ObjectsScheduler::preset_3() {} +void ObjectsScheduler::preset_3() { trigger_event(CreateZapperEvent {}); } void ObjectsScheduler::preset_4() {} -void ObjectsScheduler::boss_fight_1() { +void ObjectsScheduler::boss_fight_1() { this->get_components_by_name("camera").front().get().data.linear_velocity.x = 0; this->get_components_by_name("player").front().get().data.linear_velocity.x = 0; - this->trigger_event(BattleStartEvent{.num_enemies = 2}); + this->trigger_event(BattleStartEvent {.num_enemies = 2}); } bool ObjectsScheduler::boss_fight_1_event() { - this->get_components_by_name("camera").front().get().data.linear_velocity.x = PLAYER_SPEED * 0.02; - this->get_components_by_name("player").front().get().data.linear_velocity.x = PLAYER_SPEED * 0.02; + this->get_components_by_name("camera").front().get().data.linear_velocity.x + = PLAYER_SPEED * 0.02; + this->get_components_by_name("player").front().get().data.linear_velocity.x + = PLAYER_SPEED * 0.02; return false; } @@ -32,6 +37,8 @@ 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(); }); -- cgit v1.2.3 From 4eb68c5f5672ed9b5746cc09249dddc804ebd37d Mon Sep 17 00:00:00 2001 From: Max-001 Date: Wed, 8 Jan 2025 18:50:22 +0100 Subject: Background paralax fix at boss fight --- game/scheduler/ObjectsScheduler.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 60e3f47..3ce2018 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -23,6 +23,12 @@ void ObjectsScheduler::boss_fight_1() { this->get_components_by_name("camera").front().get().data.linear_velocity.x = 0; this->get_components_by_name("player").front().get().data.linear_velocity.x = 0; this->trigger_event(BattleStartEvent {.num_enemies = 2}); + + RefVector rb_back_forest + = this->get_components_by_tag("forest_background"); + for (Rigidbody & rb : rb_back_forest) { + rb.data.linear_velocity.x = 0; + } } bool ObjectsScheduler::boss_fight_1_event() { @@ -30,6 +36,12 @@ bool ObjectsScheduler::boss_fight_1_event() { = PLAYER_SPEED * 0.02; this->get_components_by_name("player").front().get().data.linear_velocity.x = PLAYER_SPEED * 0.02; + + RefVector rb_back_forest + = this->get_components_by_tag("forest_background"); + rb_back_forest.front().get().data.linear_velocity.x = 30; + rb_back_forest.back().get().data.linear_velocity.x = 40; + return false; } -- cgit v1.2.3 From 7739a80176cea889ce240d18d354c5174825b25a Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 14:46:30 +0100 Subject: workers during normal sequence working --- game/Config.h | 1 + game/enemy/BattleScript.cpp | 15 ++++++--- game/enemy/BattleScript.h | 2 ++ game/enemy/EnemyBulletScript.cpp | 2 +- game/enemy/EnemyBulletSubScene.cpp | 7 ++--- game/enemy/EnemyScript.cpp | 61 +++++++++++++++++++++++++++++++------ game/enemy/EnemyScript.h | 15 ++++++--- game/enemy/EnemySubScene.cpp | 41 +++++++++++++++++++++++++ game/main.cpp | 1 + game/player/PlayerScript.cpp | 6 ++++ game/player/PlayerScript.h | 5 ++- game/player/PlayerSubScene.cpp | 7 +++-- game/scheduler/ObjectsScheduler.cpp | 26 ++++++++++++++-- 13 files changed, 159 insertions(+), 30 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/Config.h b/game/Config.h index 8fa41ba..3242a03 100644 --- a/game/Config.h +++ b/game/Config.h @@ -34,6 +34,7 @@ static constexpr int COLL_LAY_MISSILE = 8; // Only for GameScene static constexpr int COLL_LAY_BULLET = 9; // Only for GameScene static constexpr int COLL_LAY_ENEMY = 10; // Only for GameScene static constexpr int COLL_LAY_PLAYER_BULLET = 11; // Only for GameScene +static constexpr int COLL_LAY_PLAYER_SHIELD = 12; // Only for GameScene static constexpr float GAME_HEIGHT = 800; // In game units static constexpr float HALLWAY_HEIGHT = 475; // In game units diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp index 6d96ef6..3eda89e 100644 --- a/game/enemy/BattleScript.cpp +++ b/game/enemy/BattleScript.cpp @@ -1,6 +1,7 @@ #include "BattleScript.h" #include "EnemyScript.h" #include +#include #include #include using namespace std; @@ -28,16 +29,23 @@ void BattleScript::fixed_update(duration_t dt) { } if (!enemies_alive) { this->battle_active = false; + cout << "battle won" << endl; this->trigger_event(); } } bool BattleScript::create_battle(const BattleStartEvent & e) { - this->battle_active = true; + this->battle_active = e.battle; + this->spawn_enemies(e.num_enemies); + return false; +} +void BattleScript::spawn_enemies(int amount) { RefVector enemy_scripts = this->get_components_by_tag("enemy"); - std::uniform_real_distribution dist(10, 30); - for (int i = 0; i < e.num_enemies; i++) { + std::uniform_real_distribution dist(70, 150); + + for (int i = 0; i < amount; i++) { BehaviorScript & script = enemy_scripts[i]; + if(script.active == true) continue; script.active = true; this->queue_event( SpawnEnemyEvent { @@ -47,5 +55,4 @@ bool BattleScript::create_battle(const BattleStartEvent & e) { script.game_object_id ); } - return false; } diff --git a/game/enemy/BattleScript.h b/game/enemy/BattleScript.h index ddd0be1..57aa16c 100644 --- a/game/enemy/BattleScript.h +++ b/game/enemy/BattleScript.h @@ -9,6 +9,7 @@ struct BattleWonEvent : public crepe::Event {}; struct BattleStartEvent : public crepe::Event { public: int num_enemies = 0; + bool battle = false; }; class BattleScript : public crepe::Script { public: @@ -20,5 +21,6 @@ private: bool battle_active = false; std::random_device rd; std::default_random_engine engine; + void spawn_enemies(int amount); bool create_battle(const BattleStartEvent & e); }; diff --git a/game/enemy/EnemyBulletScript.cpp b/game/enemy/EnemyBulletScript.cpp index 65c0c23..d208a88 100644 --- a/game/enemy/EnemyBulletScript.cpp +++ b/game/enemy/EnemyBulletScript.cpp @@ -18,7 +18,7 @@ void EnemyBulletScript::fixed_update(crepe::duration_t dt) { Transform & cam_transform = this->get_components_by_name("camera").front(); Rigidbody & bullet_body = this->get_component(); //move - transform.position.x += bullet_body.data.linear_velocity.x * dt.count(); + transform.position += bullet_body.data.linear_velocity * dt.count(); vec2 half_screen = camera.viewport_size / 2; float despawn_location = cam_transform.position.x - half_screen.x - 50; if (transform.position.x < despawn_location) { diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index ad2ca9d..eb43f0a 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -27,14 +27,13 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { Rigidbody & bullet_body = bullet.add_component(Rigidbody::Data { .gravity_scale = 0, .body_type = Rigidbody::BodyType::KINEMATIC, - - .linear_velocity = vec2 {-250, 0}, + .linear_velocity = vec2 {-400, 0}, .kinematic_collision = false, - .collision_layers = {COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, + .collision_layers = {COLL_LAY_BOT_TOP,COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, .collision_layer = COLL_LAY_BULLET }); bullet_body.active = false; - BoxCollider & bullet_collider = bullet.add_component(vec2(60, 30)); + BoxCollider & bullet_collider = bullet.add_component(vec2(40, 10)); //bullet_collider.active = false; Asset bullet_asset {"asset/other_effects/effect_smgbullet_x2.png"}; Sprite & bullet_sprite = bullet.add_component( diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 5c03539..04d577a 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -2,6 +2,7 @@ #include "../Config.h" #include "../Random.h" #include "EnemyConfig.h" +#include #include #include #include @@ -9,7 +10,11 @@ #include #include #include +#include #include +#include "../Random.h" +#include "api/Color.h" +#include "api/Sprite.h" #include using namespace crepe; using namespace std; @@ -40,23 +45,33 @@ void EnemyScript::fixed_update(duration_t dt) { //transform.position += enemy_body.data.linear_velocity * dt.count(); float direction_to_player_y = player_transform.position.y - transform.position.y; float distance_to_player_y = std::abs(direction_to_player_y); + float adjustment_speed = speed * (distance_to_player_y / MAX_DISTANCE); - + //cout << "before clamp speed: " << adjustment_speed << endl; adjustment_speed = std::clamp(adjustment_speed, MIN_SPEED, MAX_SPEED); // Move the path nodes on the Y-axis + //cout << "adjusted_speed: " << adjustment_speed << endl; + Rigidbody& player_body = this->get_components_by_tag("player").front(); for (vec2 & path_node : ai_component.path) { path_node.y += (direction_to_player_y > 0 ? 1 : -1) * adjustment_speed * dt.count(); + path_node.x += player_body.data.linear_velocity.x * dt.count(); } //bullet fire logic: auto now = std::chrono::steady_clock::now(); std::chrono::duration elapsed = now - last_fired; if (elapsed > shot_delay) { - this->shoot(transform.position, 0); + this->shoot(transform.position); last_fired = now; this->shot_delay = std::chrono::duration(Random::f(4, 1)); } + std::chrono::duration elapsed_hit = now - last_hit; + //hit blink timer + if(elapsed_hit > blink_time){ + set_hit_blink(false); + } } + bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { this->speed = e.speed; AI & ai_component = this->get_component(); @@ -65,7 +80,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { Transform & cam_transform = this->get_components_by_name("camera").front(); vec2 half_screen = camera.viewport_size / 2; - float x_value = cam_transform.position.x + half_screen.x - 50 * (1 + e.column); + float x_value = cam_transform.position.x + half_screen.x - 70 * (1 + e.column); uniform_real_distribution dist( cam_transform.position.y - half_screen.y + 100, cam_transform.position.y + half_screen.y - 100 @@ -75,31 +90,52 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { = {cam_transform.position.x + camera.viewport_size.x / 2 + 100, random_height}; transform.position = spawn_location; ai_component.path.clear(); - ai_component.make_oval_path(10, 10, vec2 {x_value, random_height}, 1.5708, true); + ai_component.make_oval_path(10, 30, vec2 {x_value, random_height}, 1.5708, true); ai_component.active = true; this->last_fired = std::chrono::steady_clock::now(); return false; } +void EnemyScript::set_hit_blink(bool status){ + RefVector sprites = this->get_components(); + for(Sprite& sprite : sprites){ + if(status){ + sprite.data.color = Color::RED; + continue; + } + sprite.data.color = Color::WHITE; + } +} + bool EnemyScript::on_collide(const CollisionEvent & e) { if (e.info.other.metadata.tag == "player_bullet") { + this->health--; + last_hit = std::chrono::steady_clock::now(); + //Sprite& sprite; + set_hit_blink(true); + + } + if(health <= 0){ this->despawn_enemy(); } - Animator & body_animator = this->get_components().front(); - body_animator.data.col = 2; //body_animator.play(); - BehaviorScript & enemy_script = this->get_component(); - enemy_script.active = false; + return false; } + void EnemyScript::despawn_enemy() { Transform & transform = this->get_component(); + BehaviorScript & enemy_script = this->get_component(); + enemy_script.active = false; + Animator & body_animator = this->get_components().front(); + body_animator.data.col = 2; transform.position = ENEMY_POOL_LOCATION; AI & ai_component = this->get_component(); // Rigidbody& enemy_body ai_component.active = false; } -void EnemyScript::shoot(const vec2 & location, float angle) { + +void EnemyScript::shoot(const vec2 & location) { RefVector bullet_transforms = this->get_components_by_tag("enemy_bullet"); @@ -120,3 +156,10 @@ void EnemyScript::shoot(const vec2 & location, float angle) { } } } + +void EnemyScript::create_tank(){ + RefVector sprites = this->get_components(); + Sprite& tank_body = sprites[2]; + tank_body.active = true; + +} diff --git a/game/enemy/EnemyScript.h b/game/enemy/EnemyScript.h index 42ecac4..24799a5 100644 --- a/game/enemy/EnemyScript.h +++ b/game/enemy/EnemyScript.h @@ -13,19 +13,24 @@ public: EnemyScript(); void init() override; void fixed_update(crepe::duration_t dt) override; - void shoot(const crepe::vec2 & position, float angle); + void shoot(const crepe::vec2 & position); bool on_collide(const crepe::CollisionEvent & collisionData); void despawn_enemy(); bool spawn_enemy(const SpawnEnemyEvent & e); - + void create_tank(); + void create_soldier(); + void set_hit_blink(bool status); private: std::random_device rd; std::default_random_engine engine; bool alive = false; float speed = 50; - const float MIN_SPEED = 10; - const float MAX_SPEED = 130; - const float MAX_DISTANCE = 100; + int health = 2; + const float MIN_SPEED = 20; + const float MAX_SPEED = 150; + const float MAX_DISTANCE = 200; std::chrono::time_point last_fired; + std::chrono::time_point last_hit; std::chrono::duration shot_delay = std::chrono::duration(0); + std::chrono::duration blink_time = std::chrono::duration(0.1); }; diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index 607b9a9..edc537f 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -31,6 +31,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .collision_layer = COLL_LAY_ENEMY, }); + // normal body Asset enemy_body_asset {"asset/workers/worker2Body.png"}; enemy.add_component(vec2(50, 50)); Sprite & enemy_body_sprite = enemy.add_component( @@ -51,7 +52,9 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = false, } ); + enemy_body_sprite.active = false; body_animator.pause(); + body_animator.active = true; enemy.add_component(vec2(40, 60), vec2(-20, 0)); Asset enemy_head_asset {"asset/workers/worker2Head.png"}; Sprite & enemy_head_sprite = enemy.add_component( @@ -71,6 +74,32 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = true, } ); + // tanky body + Asset tank_body_asset {"asset/workers/workerFatBody.png"}; + enemy.add_component(vec2(50, 50)); + Sprite & tank_body_sprite = enemy.add_component( + tank_body_asset, + Sprite::Data { + .flip = {true, false}, + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 0, + .size = vec2(0, 50), + } + ); + tank_body_sprite.active = true; + Animator & tank_animator = enemy.add_component( + tank_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .col = 1, + .row = 0, + .looping = false, + } + ); + tank_animator.pause(); + tank_animator.active = true; + + //jetpack enemy.add_component(25, vec2(0, -20)); Asset enemy_jetpack_asset {"asset/barry/jetpackDefault.png"}; Sprite & enemy_jetpack_sprite = enemy.add_component( @@ -91,6 +120,18 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = true, } ); + //gun + Asset enemy_pistol_asset{"asset/workers/gun.png"}; + Sprite & enemy_pistol_sprite = enemy.add_component( + enemy_pistol_asset, + Sprite::Data { + .flip = {false, false}, + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 2, + .size = vec2(0, 20), + .position_offset = vec2(-20, 0), + } + ); enemy.add_component(Asset("asset/sfx/bike_gun_2.ogg")).volume = 0.1; AI & ai_component = enemy.add_component(3000); ai_component.path_follow_on(); diff --git a/game/main.cpp b/game/main.cpp index 14eec99..a34121e 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -17,6 +17,7 @@ int main() { Config::get_instance() = ENGINE_CONFIG; Engine gameloop; + gameloop.add_scene(); gameloop.add_scene(); gameloop.add_scene(); diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index fadca9c..c072e06 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -104,6 +104,12 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { last_fired = now; } } + if (this->get_key_state(Keycode::P)) { + this->trigger_event(BattleStartEvent{ + .num_enemies = 4, + .battle = true, + }); + } if (this->get_key_state(Keycode::SPACE)) { rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 2.5) * dt.count() / 0.02); if (prev_anim != 1) { diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h index e7d860a..0fe21d1 100644 --- a/game/player/PlayerScript.h +++ b/game/player/PlayerScript.h @@ -15,8 +15,11 @@ private: private: int prev_anim = 0; + bool gravity_mode = true; + bool fall_direction = false; std::chrono::time_point last_fired; + std::chrono::time_point last_switched; std::chrono::duration shot_delay = std::chrono::duration(0.5); - + std::chrono::duration switch_delay = std::chrono::duration(0.01); int current_jetpack_sound = 0; }; diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index c4d689a..245f19c 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -22,7 +22,7 @@ using namespace crepe; using namespace std; PlayerSubScene::PlayerSubScene(Scene & scn) { - GameObject player = scn.new_object("player", "player", vec2(-100, 200)); + GameObject player = scn.new_object("player", "player", vec2(200, 200)); Asset player_bullet {"asset/other_effects/effect_smgbullet.png"}; Sprite & player_bullet_sprite = player.add_component( @@ -106,7 +106,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .looping = true, } ); - player.add_component(vec2(50, 50)); + player.add_component(vec2(35, 35)); Asset player_head_asset {"asset/barry/defaultHead.png"}; Sprite & player_head_sprite = player.add_component( player_head_asset, @@ -143,7 +143,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .looping = true, } ); - player.add_component(vec2(40, 60), vec2(-20, 0)); + player.add_component(vec2(40, 50), vec2(-20, 0)); player.add_component(Rigidbody::Data { .gravity_scale = PLAYER_GRAVITY_SCALE, .body_type = Rigidbody::BodyType::DYNAMIC, @@ -153,6 +153,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { }, .collision_layer = COLL_LAY_PLAYER, }); + player.add_component().set_script().active = false; player.add_component().set_script(); player.add_component().set_script().active = false; diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 3ce2018..a802806 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -5,6 +5,7 @@ #include "../Config.h" #include "../Random.h" #include "../missile/SpawnEvent.h" +#include "../enemy/EnemyScript.h" #include "api/Rigidbody.h" #include "api/Transform.h" #include "enemy/BattleScript.h" @@ -14,15 +15,34 @@ using namespace crepe; void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); trigger_event(MissileSpawnEvent {}); + this->trigger_event(BattleStartEvent { + .num_enemies = Random::i(3,1), + .battle = false, + }); +} +void ObjectsScheduler::preset_1() { + trigger_event(MissileSpawnEvent {}); + this->trigger_event(BattleStartEvent { + .num_enemies = Random::i(4,1), + .battle = false, + }); +} +void ObjectsScheduler::preset_2() { + trigger_event(CreateZapperEvent {}); + this->trigger_event(BattleStartEvent { + .num_enemies = Random::i(2,1), + .battle = false, + }); } -void ObjectsScheduler::preset_1() { trigger_event(MissileSpawnEvent {}); } -void ObjectsScheduler::preset_2() { trigger_event(CreateZapperEvent {}); } void ObjectsScheduler::preset_3() { trigger_event(CreateZapperEvent {}); } void ObjectsScheduler::preset_4() {} void ObjectsScheduler::boss_fight_1() { this->get_components_by_name("camera").front().get().data.linear_velocity.x = 0; this->get_components_by_name("player").front().get().data.linear_velocity.x = 0; - this->trigger_event(BattleStartEvent {.num_enemies = 2}); + this->trigger_event(BattleStartEvent { + .num_enemies = 7, + .battle = true, + }); RefVector rb_back_forest = this->get_components_by_tag("forest_background"); -- cgit v1.2.3 From b091cb7910fa82e9fb00abdb163d277ba574f804 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 14:54:51 +0100 Subject: make format --- game/enemy/BattleScript.cpp | 4 ++-- game/enemy/EnemyBulletSubScene.cpp | 2 +- game/enemy/EnemyScript.cpp | 28 ++++++++++++---------------- game/enemy/EnemyScript.h | 1 + game/enemy/EnemySubScene.cpp | 4 ++-- game/main.cpp | 2 +- game/scheduler/ObjectsScheduler.cpp | 20 ++++++++++---------- 7 files changed, 29 insertions(+), 32 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp index 2d1e143..cfffcb3 100644 --- a/game/enemy/BattleScript.cpp +++ b/game/enemy/BattleScript.cpp @@ -40,10 +40,10 @@ void BattleScript::spawn_enemies(int amount) { RefVector enemy_scripts = this->get_components_by_tag("enemy"); std::uniform_real_distribution dist(70, 150); - + for (int i = 0; i < amount; i++) { BehaviorScript & script = enemy_scripts[i]; - if(script.active == true) continue; + if (script.active == true) continue; script.active = true; this->queue_event( SpawnEnemyEvent { diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index eb43f0a..c0e94e0 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -29,7 +29,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { .body_type = Rigidbody::BodyType::KINEMATIC, .linear_velocity = vec2 {-400, 0}, .kinematic_collision = false, - .collision_layers = {COLL_LAY_BOT_TOP,COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, + .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, .collision_layer = COLL_LAY_BULLET }); bullet_body.active = false; diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 2382847..8804f50 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -2,18 +2,17 @@ #include "../Config.h" #include "../Random.h" #include "EnemyConfig.h" +#include "api/Color.h" +#include "api/Sprite.h" #include #include #include #include #include #include -#include #include +#include #include -#include "../Random.h" -#include "api/Color.h" -#include "api/Sprite.h" #include using namespace crepe; using namespace std; @@ -43,11 +42,10 @@ void EnemyScript::fixed_update(duration_t dt) { float direction_to_player_y = player_transform.position.y - transform.position.y; float distance_to_player_y = std::abs(direction_to_player_y); - float adjustment_speed = speed * (distance_to_player_y / MAX_DISTANCE); adjustment_speed = std::clamp(adjustment_speed, MIN_SPEED, MAX_SPEED); - Rigidbody& player_body = this->get_components_by_tag("player").front(); + Rigidbody & player_body = this->get_components_by_tag("player").front(); // move path nodes for (vec2 & path_node : ai_component.path) { path_node.y += (direction_to_player_y > 0 ? 1 : -1) * adjustment_speed * dt.count(); @@ -63,7 +61,7 @@ void EnemyScript::fixed_update(duration_t dt) { } std::chrono::duration elapsed_hit = now - last_hit; //hit blink timer - if(elapsed_hit > blink_time){ + if (elapsed_hit > blink_time) { set_hit_blink(false); } } @@ -92,10 +90,10 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { return false; } -void EnemyScript::set_hit_blink(bool status){ +void EnemyScript::set_hit_blink(bool status) { RefVector sprites = this->get_components(); - for(Sprite& sprite : sprites){ - if(status){ + for (Sprite & sprite : sprites) { + if (status) { sprite.data.color = Color::RED; continue; } @@ -109,13 +107,12 @@ bool EnemyScript::on_collide(const CollisionEvent & e) { last_hit = std::chrono::steady_clock::now(); //Sprite& sprite; set_hit_blink(true); - } - if(health <= 0){ + if (health <= 0) { this->despawn_enemy(); } //body_animator.play(); - + return false; } @@ -153,9 +150,8 @@ void EnemyScript::shoot(const vec2 & location) { } } -void EnemyScript::create_tank(){ +void EnemyScript::create_tank() { RefVector sprites = this->get_components(); - Sprite& tank_body = sprites[2]; + Sprite & tank_body = sprites[2]; tank_body.active = true; - } diff --git a/game/enemy/EnemyScript.h b/game/enemy/EnemyScript.h index 24799a5..2bd9742 100644 --- a/game/enemy/EnemyScript.h +++ b/game/enemy/EnemyScript.h @@ -20,6 +20,7 @@ public: void create_tank(); void create_soldier(); void set_hit_blink(bool status); + private: std::random_device rd; std::default_random_engine engine; diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index edc537f..fe9fd63 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -74,7 +74,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = true, } ); - // tanky body + // tanky body Asset tank_body_asset {"asset/workers/workerFatBody.png"}; enemy.add_component(vec2(50, 50)); Sprite & tank_body_sprite = enemy.add_component( @@ -121,7 +121,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { } ); //gun - Asset enemy_pistol_asset{"asset/workers/gun.png"}; + Asset enemy_pistol_asset {"asset/workers/gun.png"}; Sprite & enemy_pistol_sprite = enemy.add_component( enemy_pistol_asset, Sprite::Data { diff --git a/game/main.cpp b/game/main.cpp index a34121e..751cbe5 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -17,7 +17,7 @@ int main() { Config::get_instance() = ENGINE_CONFIG; Engine gameloop; - + gameloop.add_scene(); gameloop.add_scene(); gameloop.add_scene(); diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index a802806..8415ef8 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -4,8 +4,8 @@ #include "../Config.h" #include "../Random.h" -#include "../missile/SpawnEvent.h" #include "../enemy/EnemyScript.h" +#include "../missile/SpawnEvent.h" #include "api/Rigidbody.h" #include "api/Transform.h" #include "enemy/BattleScript.h" @@ -16,23 +16,23 @@ void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(3,1), + .num_enemies = Random::i(3, 1), .battle = false, }); } -void ObjectsScheduler::preset_1() { - trigger_event(MissileSpawnEvent {}); +void ObjectsScheduler::preset_1() { + trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(4,1), + .num_enemies = Random::i(4, 1), .battle = false, - }); + }); } -void ObjectsScheduler::preset_2() { +void ObjectsScheduler::preset_2() { trigger_event(CreateZapperEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(2,1), + .num_enemies = Random::i(2, 1), .battle = false, - }); + }); } void ObjectsScheduler::preset_3() { trigger_event(CreateZapperEvent {}); } void ObjectsScheduler::preset_4() {} @@ -42,7 +42,7 @@ void ObjectsScheduler::boss_fight_1() { this->trigger_event(BattleStartEvent { .num_enemies = 7, .battle = true, - }); + }); RefVector rb_back_forest = this->get_components_by_tag("forest_background"); -- cgit v1.2.3 From c1325d3e979e294fced8f80ce43dd1eb86d7f5df Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 10 Jan 2025 10:12:41 +0100 Subject: balance changes --- game/enemy/EnemyBulletSubScene.cpp | 2 +- game/enemy/EnemyScript.cpp | 11 +++++++---- game/player/PlayerBulletSubScene.cpp | 2 +- game/scheduler/ObjectsScheduler.cpp | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index fb3a4cd..1406660 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -28,7 +28,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { Rigidbody & bullet_body = bullet.add_component(Rigidbody::Data { .gravity_scale = 0, .body_type = Rigidbody::BodyType::KINEMATIC, - .linear_velocity = vec2 {-350, 0}, + .linear_velocity = vec2 {-300, 0}, .kinematic_collision = false, .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, .collision_layer = COLL_LAY_BULLET diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index c677dac..e3c8e9f 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -14,6 +14,7 @@ #include #include #include +#include using namespace crepe; using namespace std; EnemyScript::EnemyScript() { @@ -72,7 +73,7 @@ void EnemyScript::fixed_update(duration_t dt) { if (elapsed > shot_delay) { this->shoot(transform.position); last_fired = now; - this->shot_delay = std::chrono::duration(Random::f(4, 1)); + this->shot_delay = std::chrono::duration(Random::f(4, 1.5)); } } @@ -100,7 +101,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { Transform & cam_transform = this->get_components_by_name("camera").front(); vec2 half_screen = camera.viewport_size / 2; - float x_value = cam_transform.position.x + half_screen.x - 60 * (1 + e.column); + float x_value = cam_transform.position.x + half_screen.x - 40 * (1 + e.column); uniform_real_distribution dist( cam_transform.position.y - half_screen.y + 100, cam_transform.position.y + half_screen.y - 100 @@ -131,14 +132,16 @@ void EnemyScript::set_hit_blink(bool status) { bool EnemyScript::on_collide(const CollisionEvent & e) { if (!this->alive) return false; if (e.info.other.metadata.tag == "player_bullet") { + cout << "health: " << health << endl; this->health--; last_hit = std::chrono::steady_clock::now(); //Sprite& sprite; set_hit_blink(true); - } - if (health <= 0) { + if (health <= 0) { this->death(); } + } + //body_animator.play(); return false; diff --git a/game/player/PlayerBulletSubScene.cpp b/game/player/PlayerBulletSubScene.cpp index 5e1c66e..82ce4a9 100644 --- a/game/player/PlayerBulletSubScene.cpp +++ b/game/player/PlayerBulletSubScene.cpp @@ -24,7 +24,7 @@ int PlayerBulletSubScene::create(Scene & scn, int counter) { Rigidbody & player_bullet_body = player_bullet.add_component(Rigidbody::Data { .gravity_scale = 0, .body_type = Rigidbody::BodyType::KINEMATIC, - .linear_velocity = vec2 {400, 0}, + .linear_velocity = vec2 {450, 0}, .angular_velocity = 300, .kinematic_collision = false, .collision_layers = {COLL_LAY_ENEMY, COLL_LAY_ZAPPER}, diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 8415ef8..816e1ee 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -16,14 +16,14 @@ void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(3, 1), + .num_enemies = Random::i(2, 1), .battle = false, }); } void ObjectsScheduler::preset_1() { trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(4, 1), + .num_enemies = Random::i(2, 1), .battle = false, }); } -- cgit v1.2.3 From d7c8cc30e1d37526cf142f950038500b96760514 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 10 Jan 2025 14:07:30 +0100 Subject: balance changes --- game/enemy/EnemyScript.cpp | 4 ++-- game/scheduler/ObjectsScheduler.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 24583c0..0822c29 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -19,7 +19,7 @@ using namespace std; EnemyScript::EnemyScript() { engine.seed(rd()); this->last_fired = std::chrono::steady_clock::now(); - this->shot_delay = std::chrono::duration(3 + Random::f(1, 0)); + this->shot_delay = std::chrono::duration(1.5 + Random::f(2, 0)); } void EnemyScript::init() { Metadata & meta = this->get_component(); @@ -72,7 +72,7 @@ void EnemyScript::fixed_update(duration_t dt) { if (elapsed > shot_delay) { this->shoot(transform.position); last_fired = now; - this->shot_delay = std::chrono::duration(Random::f(4, 1.5)); + this->shot_delay = std::chrono::duration(Random::f(3, 1.5)); } } diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 816e1ee..c33c707 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -16,7 +16,7 @@ void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(2, 1), + .num_enemies = Random::i(2, 0), .battle = false, }); } @@ -40,7 +40,7 @@ void ObjectsScheduler::boss_fight_1() { this->get_components_by_name("camera").front().get().data.linear_velocity.x = 0; this->get_components_by_name("player").front().get().data.linear_velocity.x = 0; this->trigger_event(BattleStartEvent { - .num_enemies = 7, + .num_enemies = 5, .battle = true, }); -- cgit v1.2.3 From 8dcd74c0672014c34175e237120209c15345fbad Mon Sep 17 00:00:00 2001 From: Max-001 Date: Fri, 10 Jan 2025 15:19:28 +0100 Subject: Fixed Paralax --- game/scheduler/ObjectsScheduler.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 3ce2018..36bf901 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -37,10 +37,18 @@ bool ObjectsScheduler::boss_fight_1_event() { this->get_components_by_name("player").front().get().data.linear_velocity.x = PLAYER_SPEED * 0.02; + bool first = true; RefVector rb_back_forest = this->get_components_by_tag("forest_background"); - rb_back_forest.front().get().data.linear_velocity.x = 30; - rb_back_forest.back().get().data.linear_velocity.x = 40; + for (Rigidbody & rb : rb_back_forest) { + if (first == true) { + rb.data.linear_velocity.x = 30; + first = false; + } else { + rb.data.linear_velocity.x = 40; + first = true; + } + } return false; } -- cgit v1.2.3 From 842ed3c20d923a84b5a267169b15c2170f97f099 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Fri, 10 Jan 2025 17:37:36 +0100 Subject: Spawn more enemies when game is further --- game/scheduler/ObjectsScheduler.cpp | 45 ++++++++++++++++++++++++------------- game/scheduler/ObjectsScheduler.h | 2 ++ 2 files changed, 32 insertions(+), 15 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.cpp') diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 0839fe5..7f58c79 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -12,35 +12,50 @@ #include "prefab/ZapperPoolSubScene.h" using namespace crepe; + void ObjectsScheduler::preset_0() { - trigger_event(MissileSpawnEvent {}); - trigger_event(MissileSpawnEvent {}); - this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(2, 0), - .battle = false, - }); + for (int i = 0; i < this->amount_of_boss_fights; i++) { + this->trigger_event(MissileSpawnEvent {}); + } + if (this->amount_of_boss_fights >= 1) { + this->trigger_event(BattleStartEvent { + .num_enemies = Random::i(this->amount_of_boss_fights, 0), + .battle = false, + }); + } } + void ObjectsScheduler::preset_1() { trigger_event(MissileSpawnEvent {}); - this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(2, 1), - .battle = false, - }); + if (this->amount_of_boss_fights >= 3) { + this->trigger_event(BattleStartEvent { + .num_enemies = Random::i(1, 0), + .battle = false, + }); + } } + void ObjectsScheduler::preset_2() { trigger_event(CreateZapperEvent {}); - this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(2, 1), - .battle = false, - }); + if (this->amount_of_boss_fights >= 2) { + this->trigger_event(BattleStartEvent { + .num_enemies = Random::i(2, 1), + .battle = false, + }); + } } + void ObjectsScheduler::preset_3() { trigger_event(CreateZapperEvent {}); } + void ObjectsScheduler::preset_4() {} + void ObjectsScheduler::boss_fight_1() { this->get_components_by_name("camera").front().get().data.linear_velocity.x = 0; this->get_components_by_name("player").front().get().data.linear_velocity.x = 0; + + this->amount_of_boss_fights++; this->trigger_event(BattleStartEvent { - .num_enemies = 5, + .num_enemies = amount_of_boss_fights, .battle = true, }); diff --git a/game/scheduler/ObjectsScheduler.h b/game/scheduler/ObjectsScheduler.h index bd0701b..7ada8e1 100644 --- a/game/scheduler/ObjectsScheduler.h +++ b/game/scheduler/ObjectsScheduler.h @@ -16,6 +16,8 @@ private: int obstacle_interval = 350; int start_offset = 1300; + int amount_of_boss_fights = 0; + private: void preset_0(); void preset_1(); -- cgit v1.2.3