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/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 +++++++++++++--------- 8 files changed, 129 insertions(+), 24 deletions(-) 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/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