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/missile/MissilePool.cpp | 16 ++++++ game/missile/MissilePool.h | 11 ++++ game/missile/MissileScript.cpp | 105 +++++++++++++++++++++++++++++++++++++++ game/missile/MissileScript.h | 20 ++++++++ game/missile/MissileSubScene.cpp | 101 +++++++++++++++++++++++++++++++++++++ game/missile/MissileSubScene.h | 12 +++++ game/missile/SpawnEvent.cpp | 47 ++++++++++++++++++ game/missile/SpawnEvent.h | 20 ++++++++ 8 files changed, 332 insertions(+) create mode 100644 game/missile/MissilePool.cpp create mode 100644 game/missile/MissilePool.h create mode 100644 game/missile/MissileScript.cpp create mode 100644 game/missile/MissileScript.h create mode 100644 game/missile/MissileSubScene.cpp create mode 100644 game/missile/MissileSubScene.h create mode 100644 game/missile/SpawnEvent.cpp create mode 100644 game/missile/SpawnEvent.h (limited to 'game/missile') diff --git a/game/missile/MissilePool.cpp b/game/missile/MissilePool.cpp new file mode 100644 index 0000000..e549210 --- /dev/null +++ b/game/missile/MissilePool.cpp @@ -0,0 +1,16 @@ +#include "MissilePool.h" +#include "MissileSubScene.h" + +#include + +using namespace std; +using namespace crepe; + +MissilePool::MissilePool(Scene & scn) { + int amount = 0; + MissileSubScene missile; + while (amount < this->MAX_MISSILE_COUNT) { + missile.create(scn); + amount++; + } +} diff --git a/game/missile/MissilePool.h b/game/missile/MissilePool.h new file mode 100644 index 0000000..296701e --- /dev/null +++ b/game/missile/MissilePool.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +class MissilePool { +public: + MissilePool(crepe::Scene & scn); + +private: + static constexpr unsigned int MAX_MISSILE_COUNT = 5; +}; diff --git a/game/missile/MissileScript.cpp b/game/missile/MissileScript.cpp new file mode 100644 index 0000000..6d0e40e --- /dev/null +++ b/game/missile/MissileScript.cpp @@ -0,0 +1,105 @@ +#include "MissileScript.h" +#include "../Config.h" +#include "api/BehaviorScript.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; +using namespace crepe; + +void MissileScript::init() { + subscribe([this](const CollisionEvent & ev) -> bool { + return this->on_collision(ev); + }); + this->seeking_disabled = false; +} +void MissileScript::kill_missile() { + auto animations = this->get_components(); + auto sprites = this->get_components(); + auto & fly_sound = this->get_components().front().get(); + auto & this_script = this->get_components().back().get(); + + animations[0].get().active = false; + animations[1].get().active = false; + animations[2].get().active = true; + sprites[0].get().active = false; + sprites[1].get().active = false; + sprites[2].get().active = true; + + this_script.active = false; + this->seeking_disabled = false; + + fly_sound.stop(); +} +void MissileScript::activate() { + auto anim = this->get_components(); + auto sprites = this->get_components(); + + anim[0].get().active = true; + anim[1].get().active = true; + anim[2].get().stop(); + sprites[0].get().active = true; + sprites[1].get().active = true; + sprites[2].get().active = false; +} + +bool MissileScript::on_collision(const CollisionEvent & ev) { + auto & explosion_sound = this->get_components().back().get(); + + this->kill_missile(); + explosion_sound.play(); + + return false; +} + +bool MissileScript::is_in_x_range(const Transform & missile, const Transform & player) { + return fabs(missile.position.x - player.position.x) <= this->X_RANGE; +} + +void MissileScript::fixed_update(crepe::duration_t dt) { + auto & explosion_anim = this->get_components().back().get(); + auto & missile = this->get_component(); + auto & m_ai = this->get_component(); + + const auto & player = this->get_components_by_name("player").front().get(); + const auto & cam = this->get_components_by_name("camera").front().get(); + const auto & velocity = this->get_component().data.linear_velocity; + + if (missile.position.x < (cam.position.x - VIEWPORT_X / 1.8)) { + this->kill_missile(); + return; + } + + // check if animation is at the end + if (explosion_anim.data.row == 7) { + this->activate(); + this->seeking_disabled = false; + } + + if (this->seeking_disabled) { + m_ai.seek_off(); + } else { + m_ai.seek_target = player.position; + m_ai.seek_on(); + + if (is_in_x_range(missile, player)) { + this->seeking_disabled = true; + m_ai.seek_off(); + } + } + + vec2 angle_pos = velocity; + float angle = atan2(angle_pos.y, angle_pos.x) * (180 / M_PI); + + missile.rotation = angle; + missile.position += velocity * dt.count(); +} diff --git a/game/missile/MissileScript.h b/game/missile/MissileScript.h new file mode 100644 index 0000000..a492e18 --- /dev/null +++ b/game/missile/MissileScript.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +class MissileScript : public crepe::Script { +private: + bool on_collision(const crepe::CollisionEvent & ev); + + bool seeking_disabled; + + // will be used to calculate when ai will be stopped + static constexpr int X_RANGE = 90; + bool is_in_x_range(const crepe::Transform & missile, const crepe::Transform & player); + void kill_missile(); + void activate(); + +public: + void init(); + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/missile/MissileSubScene.cpp b/game/missile/MissileSubScene.cpp new file mode 100644 index 0000000..db49f88 --- /dev/null +++ b/game/missile/MissileSubScene.cpp @@ -0,0 +1,101 @@ +#include "MissileSubScene.h" +#include "../Config.h" +#include "../missile/MissileScript.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace crepe; + +void MissileSubScene::create(crepe::Scene & scn) { + std::random_device rd; + std::mt19937 gen(rd()); + + GameObject missle = scn.new_object("missile", "missile", {0, 0}, 0, 1); + + Asset missle_ss {"asset/obstacles/missile/missile.png"}; + Asset missle_thruster_ss {"asset/obstacles/missile/missileEffects.png"}; + Asset missile_explosion_ss {"asset/obstacles/missile/missileExplosion.png"}; + Asset explosion_sound {"asset/sfx/rocket_explode_1.ogg"}; + Asset missile_fire {"asset/sfx/missile_launch.ogg"}; + + missle.add_component().set_script().active = false; + + auto & sound = missle.add_component(missile_fire); + sound.volume = 0.1; + auto & sound2 = missle.add_component(explosion_sound); + sound2.volume = 0.1; + + // sprites + auto & missle_sprite = missle.add_component( + missle_ss, + Sprite::Data { + .flip = {true, false}, + .sorting_in_layer = SORT_IN_LAY_OBSTACLES, + .size = {0, 35}, + } + ); + + auto & missle_thruster_sprite = missle.add_component( + missle_thruster_ss, + Sprite::Data { + .flip = {true, false}, + .sorting_in_layer = SORT_IN_LAY_OBSTACLES, + .size = {0, 35}, + .position_offset = {-20, 0}, + } + ); + + auto & missile_explosion_sprite = missle.add_component( + missile_explosion_ss, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_OBSTACLES, + .size = {0, 50}, + } + ); + + // Animations + missle.add_component( + missle_sprite, ivec2 {32, 32}, uvec2 {4, 1}, + Animator::Data { + .looping = true, + } + ); + + missle.add_component( + missle_thruster_sprite, ivec2 {64, 64}, uvec2 {4, 2}, + Animator::Data { + .looping = true, + } + ); + + auto & explosion_anim = missle.add_component( + missile_explosion_sprite, ivec2 {64, 64}, uvec2 {8, 1}, + Animator::Data { + .fps = 10, + } + ); + + missile_explosion_sprite.active = false; + explosion_anim.active = false; + + std::uniform_int_distribution<> dist(140, 200); + missle.add_component(Rigidbody::Data { + .body_type = Rigidbody::BodyType::KINEMATIC, + .max_linear_velocity = static_cast(dist(gen)), + .kinematic_collision = false, + .collision_layers = {COLL_LAY_PLAYER, COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_MISSILE, + }); + + missle.add_component(3); + + auto & missle_ai = missle.add_component(1000); +} diff --git a/game/missile/MissileSubScene.h b/game/missile/MissileSubScene.h new file mode 100644 index 0000000..9ea422a --- /dev/null +++ b/game/missile/MissileSubScene.h @@ -0,0 +1,12 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class MissileSubScene { +public: + MissileSubScene() = default; + + void create(crepe::Scene & scn); +}; diff --git a/game/missile/SpawnEvent.cpp b/game/missile/SpawnEvent.cpp new file mode 100644 index 0000000..03a9b8c --- /dev/null +++ b/game/missile/SpawnEvent.cpp @@ -0,0 +1,47 @@ +#include "SpawnEvent.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace crepe; + +void MissileSpawnEventHandler::init() { + subscribe([this](const MissileSpawnEvent & ev) -> bool { + return this->on_event(ev); + }); +} + +std::random_device rd; +std::mt19937 gen(rd()); + +bool MissileSpawnEventHandler::on_event(const MissileSpawnEvent & event) { + auto missile_sprites = this->get_components_by_name("missile"); + auto missile_transforms = this->get_components_by_name("missile"); + auto missile_behaviorscripts = this->get_components_by_name("missile"); + auto missile_audiosources = this->get_components_by_name("missile"); + auto & camera_transform = this->get_components_by_name("camera").front().get(); + + for (size_t i = 0; i < missile_behaviorscripts.size(); ++i) { + auto & script = missile_behaviorscripts[i].get(); + if (script.active) continue; + script.active = true; + + missile_audiosources[i * 2].get().play(); + + auto & transform = missile_transforms[i].get(); + transform.position.x = camera_transform.position.x + this->MISSILE_OFFSET; + std::uniform_int_distribution<> dist(this->MIN_RANGE, this->MAX_RANGE); + transform.position.y = dist(gen); + + break; + } + + return false; +} diff --git a/game/missile/SpawnEvent.h b/game/missile/SpawnEvent.h new file mode 100644 index 0000000..ce301fd --- /dev/null +++ b/game/missile/SpawnEvent.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +#include "../Config.h" + +struct MissileSpawnEvent : public crepe::Event {}; + +class MissileSpawnEventHandler : public crepe::Script { +private: + static constexpr int MISSILE_OFFSET = VIEWPORT_X / 1.8; + static constexpr int RANGE = GAME_HEIGHT / 4; + static constexpr int MIN_RANGE = -RANGE; + static constexpr int MAX_RANGE = RANGE; + +public: + void init(); + bool on_event(const MissileSpawnEvent & ev); +}; -- 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/missile') 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 4710a16c01c83633a9afab4bf0b78d2640fe2b08 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Wed, 8 Jan 2025 20:17:51 +0100 Subject: Increased missile sound --- game/missile/MissileSubScene.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'game/missile') diff --git a/game/missile/MissileSubScene.cpp b/game/missile/MissileSubScene.cpp index 59d8221..6719c3d 100644 --- a/game/missile/MissileSubScene.cpp +++ b/game/missile/MissileSubScene.cpp @@ -29,9 +29,9 @@ void MissileSubScene::create(crepe::Scene & scn) { missle.add_component().set_script().active = false; auto & sound = missle.add_component(missile_fire); - sound.volume = 0.1; + sound.volume = 0.5; auto & sound2 = missle.add_component(explosion_sound); - sound2.volume = 0.1; + sound2.volume = 3; // sprites auto & missle_sprite = missle.add_component( -- cgit v1.2.3 From 15a958a7f327bb2e81e7d445f1499ec78c7f5839 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 10 Jan 2025 12:05:16 +0100 Subject: alers scripts and quitscript with ESC key --- game/CMakeLists.txt | 3 +++ game/GameScene.cpp | 1 - game/QuitScript.cpp | 23 +++++++++++++++++++++ game/QuitScript.h | 11 ++++++++++ game/menus/mainmenu/MainMenuScene.cpp | 2 ++ game/missile/AlertScript.cpp | 38 +++++++++++++++++++++++++++++++++++ game/missile/AlertScript.h | 10 +++++++++ game/missile/AlertSubScene.cpp | 38 +++++++++++++++++++++++++++++++++++ game/missile/AlertSubScene.h | 7 +++++++ game/missile/MissilePool.cpp | 2 ++ game/missile/MissileScript.cpp | 11 ++++++++-- game/missile/MissileSubScene.cpp | 25 +++++++++++------------ game/missile/SpawnEvent.cpp | 22 +++++++++++--------- 13 files changed, 168 insertions(+), 25 deletions(-) create mode 100644 game/QuitScript.cpp create mode 100644 game/QuitScript.h create mode 100644 game/missile/AlertScript.cpp create mode 100644 game/missile/AlertScript.h create mode 100644 game/missile/AlertSubScene.cpp create mode 100644 game/missile/AlertSubScene.h (limited to 'game/missile') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index e1168eb..70445c9 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -41,6 +41,8 @@ target_sources(main PUBLIC missile/MissilePool.cpp missile/MissileScript.cpp missile/MissileSubScene.cpp + missile/AlertSubScene.cpp + missile/AlertScript.cpp missile/SpawnEvent.cpp #scheduling @@ -57,6 +59,7 @@ target_sources(main PUBLIC GameScene.cpp MoveCameraManualyScript.cpp StartGameScript.cpp + QuitScript.cpp # player player/PlayerScript.cpp diff --git a/game/GameScene.cpp b/game/GameScene.cpp index ea55f7b..7803c9d 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,6 +1,5 @@ #include "GameScene.h" #include "Config.h" -#include "MoveCameraManualyScript.h" #include "StartGameScript.h" #include "coins/CoinPoolSubScene.h" #include "coins/CoinSystemScript.h" diff --git a/game/QuitScript.cpp b/game/QuitScript.cpp new file mode 100644 index 0000000..e48863f --- /dev/null +++ b/game/QuitScript.cpp @@ -0,0 +1,23 @@ + + +#include "QuitScript.h" +#include "api/Event.h" +#include "api/KeyCodes.h" + + +using namespace crepe; + +bool QuitScript::on_event(const KeyPressEvent & ev){ + if (Keycode::ESCAPE == ev.key) { + trigger_event(ShutDownEvent{}); + } + return false; +} + + + +void QuitScript::init(){ + subscribe([this](const KeyPressEvent & ev) -> bool { + return this->on_event(ev); + }); +} diff --git a/game/QuitScript.h b/game/QuitScript.h new file mode 100644 index 0000000..c295183 --- /dev/null +++ b/game/QuitScript.h @@ -0,0 +1,11 @@ +#pragma once + + +#include "api/Script.h" +class QuitScript : public crepe::Script { +private: + bool on_event(const crepe::KeyPressEvent & ev); + +public: + void init(); +}; diff --git a/game/menus/mainmenu/MainMenuScene.cpp b/game/menus/mainmenu/MainMenuScene.cpp index fba90ac..ad2c54d 100644 --- a/game/menus/mainmenu/MainMenuScene.cpp +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -2,6 +2,7 @@ #include "MainMenuScene.h" #include "CreditsSubScene.h" #include "MainMenuConfig.h" +#include "QuitScript.h" #include "TransitionStartSubScript.h" #include "../ButtonSubScene.h" @@ -33,6 +34,7 @@ void MainMenuScene::load_scene() { } ); camera_object.add_component().set_script(); + camera_object.add_component().set_script(); //Button menu GameObject menu_button = this->new_object(MENU_BUTTON_NAME, MENU_BUTTON_NAME, MENU_OFFSET); diff --git a/game/missile/AlertScript.cpp b/game/missile/AlertScript.cpp new file mode 100644 index 0000000..c1124ac --- /dev/null +++ b/game/missile/AlertScript.cpp @@ -0,0 +1,38 @@ +#include "AlertScript.h" +#include "../Config.h" +#include "api/CircleCollider.h" +#include "api/Sprite.h" + +#include + +using namespace crepe; + +void AlertScript::fixed_update(crepe::duration_t dt) { + const auto & cam = this->get_components_by_name("camera").front().get(); + //missile transform + const auto & this_transform = this->get_component(); + auto missile_transforms = this->get_components_by_name("missile"); + const auto & this_collider = this->get_component(); + + auto alert_sprites = this->get_components_by_name("missile_alert"); + auto alert_transforms = this->get_components_by_name("missile_alert"); + + int idx = 0; + for (int i = 0; i < missile_transforms.size(); i++) { + const auto & missile_transform = missile_transforms[i].get(); + if (this_transform.game_object_id == missile_transform.game_object_id) { + idx = i; + break; + } + } + + auto & alert_transform = alert_transforms[idx].get(); + alert_transform.position.x = cam.position.x + (VIEWPORT_X / 2 - 100); + alert_transform.position.y = this_transform.position.y; + + // check if transform is in camera view + if (this_transform.position.x > cam.position.x - (VIEWPORT_X / 2) + && this_transform.position.x < cam.position.x + (VIEWPORT_X / 2)) { + alert_sprites[idx].get().active = false; + } +} diff --git a/game/missile/AlertScript.h b/game/missile/AlertScript.h new file mode 100644 index 0000000..ab29863 --- /dev/null +++ b/game/missile/AlertScript.h @@ -0,0 +1,10 @@ +#pragma once + +#include "api/Script.h" +class AlertScript : public crepe::Script { +private: + bool has_alert = false; + +public: + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/missile/AlertSubScene.cpp b/game/missile/AlertSubScene.cpp new file mode 100644 index 0000000..c3379e8 --- /dev/null +++ b/game/missile/AlertSubScene.cpp @@ -0,0 +1,38 @@ +#include "AlertSubScene.h" +#include "../Config.h" +#include "api/Animator.h" +#include "api/BehaviorScript.h" +#include "api/Scene.h" +#include "api/Sprite.h" +#include "missile/AlertScript.h" + +using namespace crepe; + +MissileAlert::MissileAlert(Scene& scn){ + GameObject alert = scn.new_object("missile_alert", "missile_alert", {0, 0}, 0, 1); + + Asset missile_alert_ss {"asset/obstacles/missile/missileAlert.png"}; + + //alert.add_component().set_script(); + + auto & missile_alert_sprite = alert.add_component( + missile_alert_ss, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_OBSTACLES, + .size = {0, 100}, + } + ); + + auto & missile_alert_anim = alert.add_component( + missile_alert_sprite, ivec2 {64, 64}, uvec2 {4, 2}, + Animator::Data { + .fps = 15, + .looping = true, + } + ); + + missile_alert_anim.set_anim(1); + missile_alert_sprite.active = false; + + +} diff --git a/game/missile/AlertSubScene.h b/game/missile/AlertSubScene.h new file mode 100644 index 0000000..661b3f1 --- /dev/null +++ b/game/missile/AlertSubScene.h @@ -0,0 +1,7 @@ +#pragma once + +#include "api/Scene.h" +class MissileAlert { +public: + MissileAlert(crepe::Scene & scn); +}; diff --git a/game/missile/MissilePool.cpp b/game/missile/MissilePool.cpp index e549210..23f03c9 100644 --- a/game/missile/MissilePool.cpp +++ b/game/missile/MissilePool.cpp @@ -1,5 +1,6 @@ #include "MissilePool.h" #include "MissileSubScene.h" +#include "missile/AlertSubScene.h" #include @@ -10,6 +11,7 @@ MissilePool::MissilePool(Scene & scn) { int amount = 0; MissileSubScene missile; while (amount < this->MAX_MISSILE_COUNT) { + MissileAlert alert(scn); missile.create(scn); amount++; } diff --git a/game/missile/MissileScript.cpp b/game/missile/MissileScript.cpp index 6d0e40e..2d1052e 100644 --- a/game/missile/MissileScript.cpp +++ b/game/missile/MissileScript.cpp @@ -1,6 +1,9 @@ #include "MissileScript.h" #include "../Config.h" +#include "Collider.h" #include "api/BehaviorScript.h" +#include "api/CircleCollider.h" +#include "api/Rigidbody.h" #include #include @@ -25,8 +28,9 @@ void MissileScript::init() { void MissileScript::kill_missile() { auto animations = this->get_components(); auto sprites = this->get_components(); + auto collider = this->get_component(); auto & fly_sound = this->get_components().front().get(); - auto & this_script = this->get_components().back().get(); + auto & this_script = this->get_components().front().get(); animations[0].get().active = false; animations[1].get().active = false; @@ -34,7 +38,7 @@ void MissileScript::kill_missile() { sprites[0].get().active = false; sprites[1].get().active = false; sprites[2].get().active = true; - + collider.active = false; this_script.active = false; this->seeking_disabled = false; @@ -47,9 +51,12 @@ void MissileScript::activate() { anim[0].get().active = true; anim[1].get().active = true; anim[2].get().stop(); + //anim[3].get().active = true; + sprites[0].get().active = true; sprites[1].get().active = true; sprites[2].get().active = false; + //sprites[3].get().active = true; } bool MissileScript::on_collision(const CollisionEvent & ev) { diff --git a/game/missile/MissileSubScene.cpp b/game/missile/MissileSubScene.cpp index 6719c3d..6df6c87 100644 --- a/game/missile/MissileSubScene.cpp +++ b/game/missile/MissileSubScene.cpp @@ -1,6 +1,8 @@ #include "MissileSubScene.h" #include "../Config.h" #include "../missile/MissileScript.h" +#include "Random.h" +#include "missile/AlertScript.h" #include #include @@ -10,14 +12,10 @@ #include #include #include -#include using namespace crepe; void MissileSubScene::create(crepe::Scene & scn) { - std::random_device rd; - std::mt19937 gen(rd()); - GameObject missle = scn.new_object("missile", "missile", {0, 0}, 0, 1); Asset missle_ss {"asset/obstacles/missile/missile.png"}; @@ -27,6 +25,7 @@ void MissileSubScene::create(crepe::Scene & scn) { Asset missile_fire {"asset/sfx/missile_launch.ogg"}; missle.add_component().set_script().active = false; + missle.add_component().set_script(); auto & sound = missle.add_component(missile_fire); sound.volume = 0.5; @@ -88,16 +87,16 @@ void MissileSubScene::create(crepe::Scene & scn) { missile_explosion_sprite.active = false; explosion_anim.active = false; - std::uniform_int_distribution<> dist(200, 250); - missle.add_component(Rigidbody::Data { - .body_type = Rigidbody::BodyType::KINEMATIC, - .max_linear_velocity = static_cast(dist(gen)), - .kinematic_collision = false, - .collision_layers = {COLL_LAY_PLAYER, COLL_LAY_BOT_TOP}, - .collision_layer = COLL_LAY_MISSILE, - }); + missle + .add_component(Rigidbody::Data { + .body_type = Rigidbody::BodyType::KINEMATIC, + .max_linear_velocity = Random::f(250, 200), + .kinematic_collision = false, + .collision_layers = {COLL_LAY_PLAYER, COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_MISSILE, + }); - missle.add_component(3); + missle.add_component(3).active = false; auto & missle_ai = missle.add_component(1000); } diff --git a/game/missile/SpawnEvent.cpp b/game/missile/SpawnEvent.cpp index 03a9b8c..c407832 100644 --- a/game/missile/SpawnEvent.cpp +++ b/game/missile/SpawnEvent.cpp @@ -1,4 +1,7 @@ #include "SpawnEvent.h" +#include "Config.h" +#include "Random.h" +#include "api/CircleCollider.h" #include #include @@ -8,7 +11,6 @@ #include #include -#include using namespace crepe; @@ -18,28 +20,30 @@ void MissileSpawnEventHandler::init() { }); } -std::random_device rd; -std::mt19937 gen(rd()); - bool MissileSpawnEventHandler::on_event(const MissileSpawnEvent & event) { - auto missile_sprites = this->get_components_by_name("missile"); auto missile_transforms = this->get_components_by_name("missile"); + auto alert_sprites = this->get_components_by_name("missile_alert"); + auto alert_transforms = this->get_components_by_name("missile_alert"); + auto colliders = this->get_components_by_name("missile"); auto missile_behaviorscripts = this->get_components_by_name("missile"); auto missile_audiosources = this->get_components_by_name("missile"); auto & camera_transform = this->get_components_by_name("camera").front().get(); for (size_t i = 0; i < missile_behaviorscripts.size(); ++i) { - auto & script = missile_behaviorscripts[i].get(); + auto & script = missile_behaviorscripts[i * 2].get(); if (script.active) continue; script.active = true; - + colliders[i].get().active = true; missile_audiosources[i * 2].get().play(); auto & transform = missile_transforms[i].get(); transform.position.x = camera_transform.position.x + this->MISSILE_OFFSET; - std::uniform_int_distribution<> dist(this->MIN_RANGE, this->MAX_RANGE); - transform.position.y = dist(gen); + transform.position.y = Random::i(this->MAX_RANGE, this->MIN_RANGE); + + auto & alert_transform = alert_transforms[i].get(); + auto & alert_sprite = alert_sprites[i].get(); + alert_sprite.active = true; break; } -- cgit v1.2.3 From 938b6a7bb62459e8308320280d15ccaf1b8af0ac Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 10 Jan 2025 14:43:07 +0100 Subject: adjsuted includes so that it has <> and not --- game/CMakeLists.txt | 2 +- game/QuitScript.cpp | 5 +++-- game/QuitScript.h | 3 ++- game/hud/HudScript.cpp | 3 ++- game/missile/AlertScript.cpp | 4 ++-- game/missile/AlertScript.h | 3 ++- game/missile/AlertSubScene.cpp | 11 ++++------- game/missile/AlertSubScene.h | 3 ++- game/missile/MissileScript.cpp | 10 ++++------ game/missile/SpawnEvent.cpp | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) (limited to 'game/missile') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index b39416b..a94beca 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.28) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 20) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) -set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_BUILD_TYPE Release) project(game C CXX) add_subdirectory(../src crepe) diff --git a/game/QuitScript.cpp b/game/QuitScript.cpp index e48863f..fc33dcf 100644 --- a/game/QuitScript.cpp +++ b/game/QuitScript.cpp @@ -1,8 +1,9 @@ #include "QuitScript.h" -#include "api/Event.h" -#include "api/KeyCodes.h" + +#include +#include using namespace crepe; diff --git a/game/QuitScript.h b/game/QuitScript.h index c295183..af78ccf 100644 --- a/game/QuitScript.h +++ b/game/QuitScript.h @@ -1,7 +1,8 @@ #pragma once -#include "api/Script.h" +#include + class QuitScript : public crepe::Script { private: bool on_event(const crepe::KeyPressEvent & ev); diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index 3fb7a77..e4aeae7 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -3,6 +3,7 @@ #include "../Config.h" #include "../Events.h" +#include "api/KeyCodes.h" #include "menus/endgame/EndGameSubScript.h" #include @@ -37,7 +38,7 @@ void HudScript::init() { } bool HudScript::toggle_fps(crepe::KeyPressEvent ev) { - if (ev.key != Keycode::END) return false; + if (ev.key != Keycode::D1) return false; Text & txt_fps = this->get_components_by_name(HUD_FPS).front(); this->show_fps = !this->show_fps; if (this->show_fps) { diff --git a/game/missile/AlertScript.cpp b/game/missile/AlertScript.cpp index c1124ac..24b4af9 100644 --- a/game/missile/AlertScript.cpp +++ b/game/missile/AlertScript.cpp @@ -1,8 +1,8 @@ #include "AlertScript.h" #include "../Config.h" -#include "api/CircleCollider.h" -#include "api/Sprite.h" +#include +#include #include using namespace crepe; diff --git a/game/missile/AlertScript.h b/game/missile/AlertScript.h index ab29863..5b0b3a1 100644 --- a/game/missile/AlertScript.h +++ b/game/missile/AlertScript.h @@ -1,6 +1,7 @@ #pragma once -#include "api/Script.h" +#include + class AlertScript : public crepe::Script { private: bool has_alert = false; diff --git a/game/missile/AlertSubScene.cpp b/game/missile/AlertSubScene.cpp index c3379e8..8d59f97 100644 --- a/game/missile/AlertSubScene.cpp +++ b/game/missile/AlertSubScene.cpp @@ -1,10 +1,9 @@ #include "AlertSubScene.h" #include "../Config.h" -#include "api/Animator.h" -#include "api/BehaviorScript.h" -#include "api/Scene.h" -#include "api/Sprite.h" -#include "missile/AlertScript.h" + +#include +#include +#include using namespace crepe; @@ -13,8 +12,6 @@ MissileAlert::MissileAlert(Scene& scn){ Asset missile_alert_ss {"asset/obstacles/missile/missileAlert.png"}; - //alert.add_component().set_script(); - auto & missile_alert_sprite = alert.add_component( missile_alert_ss, Sprite::Data { diff --git a/game/missile/AlertSubScene.h b/game/missile/AlertSubScene.h index 661b3f1..8ea288f 100644 --- a/game/missile/AlertSubScene.h +++ b/game/missile/AlertSubScene.h @@ -1,6 +1,7 @@ #pragma once -#include "api/Scene.h" +#include + class MissileAlert { public: MissileAlert(crepe::Scene & scn); diff --git a/game/missile/MissileScript.cpp b/game/missile/MissileScript.cpp index 2d1052e..797e1ac 100644 --- a/game/missile/MissileScript.cpp +++ b/game/missile/MissileScript.cpp @@ -1,17 +1,15 @@ #include "MissileScript.h" #include "../Config.h" -#include "Collider.h" -#include "api/BehaviorScript.h" -#include "api/CircleCollider.h" -#include "api/Rigidbody.h" +#include +#include +#include +#include #include #include #include #include #include - -#include #include #include #include diff --git a/game/missile/SpawnEvent.cpp b/game/missile/SpawnEvent.cpp index c407832..a54d0a5 100644 --- a/game/missile/SpawnEvent.cpp +++ b/game/missile/SpawnEvent.cpp @@ -1,8 +1,8 @@ #include "SpawnEvent.h" -#include "Config.h" #include "Random.h" -#include "api/CircleCollider.h" + +#include #include #include #include -- cgit v1.2.3 From d1cebcca2018ed4ef47ad125e45aafd018a2ab2e Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 10 Jan 2025 14:43:42 +0100 Subject: make format --- game/PreviewScene.cpp | 9 ++- game/QuitScript.cpp | 9 +-- game/QuitScript.h | 1 - game/menus/ButtonNextMainMenuSubScript.cpp | 2 +- game/menus/ButtonReplaySubScript.cpp | 8 +-- game/menus/ButtonSubScene.cpp | 15 +++-- game/menus/endgame/EndGameSubScene.cpp | 21 ++++--- game/menus/endgame/EndGameSubScript.cpp | 26 +++++---- game/menus/shop/ButtonBuySelectBubbleScript.cpp | 18 +++--- game/menus/shop/ButtonBuySelectBulletScript.cpp | 18 +++--- game/menus/shop/ShopLoadScript.cpp | 73 ++++++++++++------------- game/menus/shop/ShopMenuScene.cpp | 21 ++++--- game/menus/shop/Shopconfig.h | 2 - game/missile/AlertSubScene.cpp | 4 +- game/missile/MissileScript.cpp | 12 ++-- game/missile/MissileSubScene.cpp | 15 +++-- game/missile/SpawnEvent.cpp | 4 +- game/preview/PreviewReplaySubScript.cpp | 19 +++---- game/preview/PreviewReplaySubScript.h | 1 + game/preview/PreviewStartRecSubScript.cpp | 1 - game/preview/PreviewStopRecSubScript.cpp | 1 - 21 files changed, 135 insertions(+), 145 deletions(-) (limited to 'game/missile') diff --git a/game/PreviewScene.cpp b/game/PreviewScene.cpp index 6871961..d9801a7 100644 --- a/game/PreviewScene.cpp +++ b/game/PreviewScene.cpp @@ -92,7 +92,6 @@ void PreviewScene::load_scene() { HudSubScene hud; hud.create(*this); - const float Y_POS_BUTTONS = -220; const float X_POS_BUTTONS = -150; const float X_POS_BUTTONS_SPACING = 145; @@ -102,7 +101,7 @@ void PreviewScene::load_scene() { ButtonSubScene::Data { .text = "BACK", .text_width = 60, - .position = {X_POS_BUTTONS,Y_POS_BUTTONS}, + .position = {X_POS_BUTTONS, Y_POS_BUTTONS}, .script_type = ButtonSubScene::ScriptSelect::NEXT, .button_type = ButtonSubScene::ButtonSelect::BACK, .scale = 0.6, @@ -117,7 +116,7 @@ void PreviewScene::load_scene() { ButtonSubScene::Data { .text = "START REC", .text_width = 130, - .position = {X_POS_BUTTONS+X_POS_BUTTONS_SPACING,Y_POS_BUTTONS}, + .position = {X_POS_BUTTONS + X_POS_BUTTONS_SPACING, Y_POS_BUTTONS}, .script_type = ButtonSubScene::ScriptSelect::PREVIEW_START, .button_type = ButtonSubScene::ButtonSelect::LARGE, .scale = 0.6, @@ -133,7 +132,7 @@ void PreviewScene::load_scene() { ButtonSubScene::Data { .text = "STOP REC", .text_width = 120, - .position = {X_POS_BUTTONS+X_POS_BUTTONS_SPACING*2,Y_POS_BUTTONS}, + .position = {X_POS_BUTTONS + X_POS_BUTTONS_SPACING * 2, Y_POS_BUTTONS}, .script_type = ButtonSubScene::ScriptSelect::PREVIEW_STOP, .button_type = ButtonSubScene::ButtonSelect::LARGE, .scale = 0.6, @@ -149,7 +148,7 @@ void PreviewScene::load_scene() { ButtonSubScene::Data { .text = "REPLAY", .text_width = 90, - .position = {X_POS_BUTTONS+X_POS_BUTTONS_SPACING*3,Y_POS_BUTTONS}, + .position = {X_POS_BUTTONS + X_POS_BUTTONS_SPACING * 3, Y_POS_BUTTONS}, .script_type = ButtonSubScene::ScriptSelect::PREVIEW_REPLAY, .button_type = ButtonSubScene::ButtonSelect::LARGE, .scale = 0.6, diff --git a/game/QuitScript.cpp b/game/QuitScript.cpp index fc33dcf..0c9f55a 100644 --- a/game/QuitScript.cpp +++ b/game/QuitScript.cpp @@ -5,19 +5,16 @@ #include #include - using namespace crepe; -bool QuitScript::on_event(const KeyPressEvent & ev){ +bool QuitScript::on_event(const KeyPressEvent & ev) { if (Keycode::ESCAPE == ev.key) { - trigger_event(ShutDownEvent{}); + trigger_event(ShutDownEvent {}); } return false; } - - -void QuitScript::init(){ +void QuitScript::init() { subscribe([this](const KeyPressEvent & ev) -> bool { return this->on_event(ev); }); diff --git a/game/QuitScript.h b/game/QuitScript.h index af78ccf..b79a744 100644 --- a/game/QuitScript.h +++ b/game/QuitScript.h @@ -1,6 +1,5 @@ #pragma once - #include class QuitScript : public crepe::Script { diff --git a/game/menus/ButtonNextMainMenuSubScript.cpp b/game/menus/ButtonNextMainMenuSubScript.cpp index 631b4d3..63a2777 100644 --- a/game/menus/ButtonNextMainMenuSubScript.cpp +++ b/game/menus/ButtonNextMainMenuSubScript.cpp @@ -27,7 +27,7 @@ bool ButtonNextMainMenuSubScript::on_button_press(const ButtonPressEvent & e) { for (AudioSource & audio : audios) { audio.stop(); } - + this->trigger_event(); SaveManager & savemgr = this->get_save_manager(); diff --git a/game/menus/ButtonReplaySubScript.cpp b/game/menus/ButtonReplaySubScript.cpp index 55e718d..01cccbf 100644 --- a/game/menus/ButtonReplaySubScript.cpp +++ b/game/menus/ButtonReplaySubScript.cpp @@ -20,24 +20,24 @@ void ButtonReplaySubScript::init() { this->subscribe([this](const DeleteRecordingEvent & e) { return this->delete_recording(); }); - if(DISABLE_REPLAY)return; + if (DISABLE_REPLAY) return; replay.record_start(); } bool ButtonReplaySubScript::on_button_press(const ButtonPressEvent & e) { - if(DISABLE_REPLAY)return false; + if (DISABLE_REPLAY) return false; replay.play(this->recording); return false; } bool ButtonReplaySubScript::set_recording() { - if(DISABLE_REPLAY)return false; + if (DISABLE_REPLAY) return false; this->recording = replay.record_end(); return false; } bool ButtonReplaySubScript::delete_recording() { - if(DISABLE_REPLAY)return false; + if (DISABLE_REPLAY) return false; replay.release(this->recording); return false; } diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index baf154c..1fe6b03 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -79,23 +79,22 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object, const Data & .set_script(); break; case ScriptSelect::PREVIEW_REPLAY: - button_object.add_component() - .set_script(); + button_object.add_component().set_script(); break; case ScriptSelect::PREVIEW_START: - button_object.add_component() - .set_script(); + button_object.add_component().set_script( + ); break; case ScriptSelect::PREVIEW_STOP: - button_object.add_component() - .set_script(); + button_object.add_component().set_script( + ); break; case ScriptSelect::SHOP_BULLET: - button_object.add_component() + button_object.add_component() .set_script(); break; case ScriptSelect::SHOP_BUBBLE: - button_object.add_component() + button_object.add_component() .set_script(); break; case ScriptSelect::NONE: diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp index 0b72bdc..b33072a 100644 --- a/game/menus/endgame/EndGameSubScene.cpp +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -73,21 +73,24 @@ void EndGameSubScene::create(Scene & scn) { .world_space = false, .text_color = Color::WHITE, }, - vec2 {0, Y_SPACING+Y_OFFSET} + FONTOFFSET, DISTANCE_STRING + vec2 {0, Y_SPACING + Y_OFFSET} + FONTOFFSET, DISTANCE_STRING ); // Highscore const string HIGHSCORE_STRING = "NEW HIGHSCORE"; GameObject highscore = scn.new_object("highscore_endgame", "highscore_tag_end"); crepe::vec2 size_highscore = {200, (200.0f / HIGHSCORE_STRING.size()) * 2}; - highscore.add_component( - size_highscore, FONT, - Text::Data { - .world_space = false, - .text_color = Color::WHITE, - }, - vec2 {0, Y_SPACING*2+Y_OFFSET} + FONTOFFSET, HIGHSCORE_STRING - ).active = false; + highscore + .add_component( + size_highscore, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {0, Y_SPACING * 2 + Y_OFFSET} + FONTOFFSET, HIGHSCORE_STRING + ) + .active + = false; // Buttons vec2 button_position = {190, 190}; diff --git a/game/menus/endgame/EndGameSubScript.cpp b/game/menus/endgame/EndGameSubScript.cpp index e081350..6793f3e 100644 --- a/game/menus/endgame/EndGameSubScript.cpp +++ b/game/menus/endgame/EndGameSubScript.cpp @@ -1,9 +1,9 @@ #include "EndGameSubScript.h" +#include "../../Config.h" #include "../../Events.h" #include "../ButtonReplaySubScript.h" #include "../IFloatingWindowScript.h" -#include "../../Config.h" #include "ValueBroker.h" #include "manager/SaveManager.h" @@ -60,11 +60,13 @@ bool EndGameSubScript::reset_timescale() { return false; } -bool EndGameSubScript::showscore(){ - // Gather text +bool EndGameSubScript::showscore() { + // Gather text Text & coins_text = this->get_components_by_name("gold_endgame").front().get(); - Text & distance_text = this->get_components_by_name("distance_endgame").front().get(); - Text & highscore_text = this->get_components_by_name("highscore_endgame").front().get(); + Text & distance_text + = this->get_components_by_name("distance_endgame").front().get(); + Text & highscore_text + = this->get_components_by_name("highscore_endgame").front().get(); highscore_text.active = false; // Gather saved data @@ -75,20 +77,24 @@ bool EndGameSubScript::showscore(){ int distance_game = savemgr.get(DISTANCE_GAME, 0).get(); // Show highscore - if(distance_run > distance_game) highscore_text.active = true; + if (distance_run > distance_game) highscore_text.active = true; const float CHAR_SIZE_DIS = 20; // Show distance - std::string distance_string = "DISTANCE:" + distance.get(); + std::string distance_string = "DISTANCE:" + distance.get(); distance_text.text = distance_string; - crepe::vec2 size_distance = {CHAR_SIZE_DIS*distance_string.size(), (CHAR_SIZE_DIS*distance_string.size() / distance_string.size()) * 2}; + crepe::vec2 size_distance + = {CHAR_SIZE_DIS * distance_string.size(), + (CHAR_SIZE_DIS * distance_string.size() / distance_string.size()) * 2}; distance_text.dimensions = size_distance; const float CHAR_SIZE_COIN = 16; // Show coins - std::string coins_string = "Coins:" + coins.get(); + std::string coins_string = "Coins:" + coins.get(); coins_text.text = coins_string; - crepe::vec2 size_coins = {CHAR_SIZE_COIN*coins_string.size(), (CHAR_SIZE_COIN*coins_string.size() / coins_string.size()) * 2}; + crepe::vec2 size_coins + = {CHAR_SIZE_COIN * coins_string.size(), + (CHAR_SIZE_COIN * coins_string.size() / coins_string.size()) * 2}; coins_text.dimensions = size_coins; return false; diff --git a/game/menus/shop/ButtonBuySelectBubbleScript.cpp b/game/menus/shop/ButtonBuySelectBubbleScript.cpp index 21dbe1a..741afde 100644 --- a/game/menus/shop/ButtonBuySelectBubbleScript.cpp +++ b/game/menus/shop/ButtonBuySelectBubbleScript.cpp @@ -17,19 +17,17 @@ void ButtonBuySelectBubbleScript::init() { bool ButtonBuySelectBubbleScript::on_button_press(const ButtonPressEvent & e) { SaveManager & save = this->get_save_manager(); - ValueBroker buy_bullet = save.get(BUY_BUBBLE_SAVE,0); - if(!buy_bullet.get()){ - ValueBroker coins = save.get(TOTAL_COINS_GAME,0); - if(coins.get() >= 1000) - { + ValueBroker buy_bullet = save.get(BUY_BUBBLE_SAVE, 0); + if (!buy_bullet.get()) { + ValueBroker coins = save.get(TOTAL_COINS_GAME, 0); + if (coins.get() >= 1000) { int coin = coins.get(); coin -= 1000; - save.set(TOTAL_COINS_GAME,coin); - save.set(BUY_BUBBLE_SAVE,1); + save.set(TOTAL_COINS_GAME, coin); + save.set(BUY_BUBBLE_SAVE, 1); } - } - else { - save.set(JETPACK_PARTICLES,1); + } else { + save.set(JETPACK_PARTICLES, 1); } this->trigger_event(); return false; diff --git a/game/menus/shop/ButtonBuySelectBulletScript.cpp b/game/menus/shop/ButtonBuySelectBulletScript.cpp index 71d8b76..d30849c 100644 --- a/game/menus/shop/ButtonBuySelectBulletScript.cpp +++ b/game/menus/shop/ButtonBuySelectBulletScript.cpp @@ -17,19 +17,17 @@ void ButtonBuySelectBulletScript::init() { bool ButtonBuySelectBulletScript::on_button_press(const ButtonPressEvent & e) { SaveManager & save = this->get_save_manager(); - ValueBroker buy_bullet = save.get(BUY_BULLET_SAVE,0); - if(!buy_bullet.get()){ - ValueBroker coins = save.get(TOTAL_COINS_GAME,0); - if(coins.get() >= 0) - { + ValueBroker buy_bullet = save.get(BUY_BULLET_SAVE, 0); + if (!buy_bullet.get()) { + ValueBroker coins = save.get(TOTAL_COINS_GAME, 0); + if (coins.get() >= 0) { int coin = coins.get(); coin -= 0; - save.set(TOTAL_COINS_GAME,coin); - save.set(BUY_BULLET_SAVE,1); + save.set(TOTAL_COINS_GAME, coin); + save.set(BUY_BULLET_SAVE, 1); } - } - else { - save.set(JETPACK_PARTICLES,0); + } else { + save.set(JETPACK_PARTICLES, 0); } this->trigger_event(); return false; diff --git a/game/menus/shop/ShopLoadScript.cpp b/game/menus/shop/ShopLoadScript.cpp index a9f9bfe..a545fe2 100644 --- a/game/menus/shop/ShopLoadScript.cpp +++ b/game/menus/shop/ShopLoadScript.cpp @@ -1,129 +1,124 @@ #include "ShopLoadScript.h" -#include +#include "Shopconfig.h" #include "api/Button.h" #include "api/Sprite.h" -#include "Shopconfig.h" #include "api/Text.h" #include "manager/SaveManager.h" +#include using namespace crepe; using namespace std; void ShopLoadScript::init() { this->update(); - this->subscribe([this](const ShopUpdate e) { - return this->update(); - }); + this->subscribe([this](const ShopUpdate e) { return this->update(); }); } -bool ShopLoadScript::update(){ +bool ShopLoadScript::update() { SaveManager & save = this->get_save_manager(); - ValueBroker buy_bullet = save.get(BUY_BULLET_SAVE,0); - ValueBroker buy_bubble = save.get(BUY_BUBBLE_SAVE,0); + ValueBroker buy_bullet = save.get(BUY_BULLET_SAVE, 0); + ValueBroker buy_bubble = save.get(BUY_BUBBLE_SAVE, 0); - - if(buy_bullet.get()){ + if (buy_bullet.get()) { auto sprites = this->get_components_by_tag(BUY_BULLET); - for(auto sprite : sprites){ + for (auto sprite : sprites) { sprite.get().active = false; } auto buttons = this->get_components_by_tag