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.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 game/scheduler/ObjectsScheduler.h (limited to 'game/scheduler/ObjectsScheduler.h') 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 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.h') 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.h') 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 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.h') 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 bb976ed881a989b8b2cec90c905d906d9b652a9d Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 8 Jan 2025 16:20:10 +0100 Subject: `make format` --- game/GameScene.cpp | 2 +- game/enemy/EnemyBulletSubScene.cpp | 2 +- game/enemy/EnemyScript.cpp | 7 +++---- game/enemy/EnemySubScene.cpp | 5 ++--- game/menus/shop/ShopMenuScene.cpp | 1 - game/player/PlayerBulletSubScene.cpp | 2 +- game/scheduler/ObjectsScheduler.cpp | 12 +++++++----- game/scheduler/ObjectsScheduler.h | 6 +----- game/workers/CollisionScript.cpp | 3 ++- 9 files changed, 18 insertions(+), 22 deletions(-) (limited to 'game/scheduler/ObjectsScheduler.h') diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 34b0fcb..3ae64fb 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -20,8 +20,8 @@ #include "player/PlayerBulletPool.h" #include "player/PlayerBulletSubScene.h" #include "player/PlayerSubScene.h" -#include "scheduler/ObjectsScheduler.h" #include "prefab/ZapperPoolSubScene.h" +#include "scheduler/ObjectsScheduler.h" #include "workers/WorkersSubScene.h" #include diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index 5c31f1d..ad2ca9d 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -30,7 +30,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { .linear_velocity = vec2 {-250, 0}, .kinematic_collision = false, - .collision_layers = {COLL_LAY_MISSILE,COLL_LAY_ZAPPER}, + .collision_layers = {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 8cf8b80..5c03539 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -4,12 +4,11 @@ #include "EnemyConfig.h" #include #include +#include #include #include #include #include -#include -#include #include #include using namespace crepe; @@ -86,7 +85,7 @@ bool EnemyScript::on_collide(const CollisionEvent & e) { if (e.info.other.metadata.tag == "player_bullet") { this->despawn_enemy(); } - Animator& body_animator = this->get_components().front(); + Animator & body_animator = this->get_components().front(); body_animator.data.col = 2; //body_animator.play(); BehaviorScript & enemy_script = this->get_component(); @@ -115,7 +114,7 @@ void EnemyScript::shoot(const vec2 & location, float angle) { = this->get_components_by_id(bullet_pos.game_object_id).front(); bullet_collider.active = true; bullet_body.active = true; - AudioSource& audio = this->get_component(); + AudioSource & audio = this->get_component(); audio.play(); return; } diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index 8316db9..607b9a9 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -2,13 +2,13 @@ #include #include +#include #include #include #include #include #include #include -#include #include #include "../Config.h" @@ -91,8 +91,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = true, } ); - enemy.add_component(Asset("asset/sfx/bike_gun_2.ogg")).volume - = 0.1; + 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(); BehaviorScript & enemy_script diff --git a/game/menus/shop/ShopMenuScene.cpp b/game/menus/shop/ShopMenuScene.cpp index 5ada0d3..d1ea81d 100644 --- a/game/menus/shop/ShopMenuScene.cpp +++ b/game/menus/shop/ShopMenuScene.cpp @@ -6,7 +6,6 @@ #include "../ButtonSubScene.h" #include "../MenusConfig.h" #include "types.h" -#include "../../Config.h" #include #include diff --git a/game/player/PlayerBulletSubScene.cpp b/game/player/PlayerBulletSubScene.cpp index 2d237de..795747b 100644 --- a/game/player/PlayerBulletSubScene.cpp +++ b/game/player/PlayerBulletSubScene.cpp @@ -27,7 +27,7 @@ int PlayerBulletSubScene::create(Scene & scn, int counter) { .linear_velocity = vec2 {400, 0}, .angular_velocity = 10, .kinematic_collision = false, - .collision_layers = {COLL_LAY_ENEMY,COLL_LAY_ZAPPER}, + .collision_layers = {COLL_LAY_ENEMY, COLL_LAY_ZAPPER}, .collision_layer = COLL_LAY_PLAYER_BULLET, diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 02d84c1..fca8fa2 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" @@ -16,15 +16,17 @@ 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() { +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; } diff --git a/game/scheduler/ObjectsScheduler.h b/game/scheduler/ObjectsScheduler.h index 56d72cb..bd0701b 100644 --- a/game/scheduler/ObjectsScheduler.h +++ b/game/scheduler/ObjectsScheduler.h @@ -1,17 +1,14 @@ #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; @@ -32,5 +29,4 @@ private: public: void init(); void fixed_update(crepe::duration_t dt); - }; diff --git a/game/workers/CollisionScript.cpp b/game/workers/CollisionScript.cpp index 625044d..372bfec 100644 --- a/game/workers/CollisionScript.cpp +++ b/game/workers/CollisionScript.cpp @@ -49,7 +49,8 @@ bool CollisionScript::on_collision(const CollisionEvent & ev) { bs_panic.active = false; return false; - } else if (ev.info.other.metadata.tag == "missile" || ev.info.other.metadata.tag == "enemy_bullet") { + } else if (ev.info.other.metadata.tag == "missile" + || ev.info.other.metadata.tag == "enemy_bullet") { for (Animator & anim : animators) { anim.active = false; anim.set_anim(3); -- cgit v1.2.3