From abbfe5d06697b93de485dcfe975812befc018a00 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 16:31:58 +0100 Subject: Moved EndGameScript to Player --- game/player/PlayerEndScript.cpp | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 game/player/PlayerEndScript.cpp (limited to 'game/player/PlayerEndScript.cpp') diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp new file mode 100644 index 0000000..c0b4e74 --- /dev/null +++ b/game/player/PlayerEndScript.cpp @@ -0,0 +1,60 @@ +#include "PlayerEndScript.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +void PlayerEndScript::init() { + BoxCollider jetpack_coll = this->get_components_by_name("player").back(); + CircleCollider head_coll = this->get_components_by_name("player").back(); + jetpack_coll.active = false; + head_coll.active = false; +} + +void PlayerEndScript::fixed_update(crepe::duration_t dt) { + Transform & transform_player = this->get_components_by_name("player").front(); + RefVector anim_player = this->get_components_by_name("player"); + Rigidbody & rb_player = this->get_components_by_name("player").front(); + Rigidbody & rb_camera = this->get_components_by_name("camera").front(); + + if (transform_player.position.y >= 194) { + if (jump == 0 || jump == 1) { + int random_number = rand() % 4; + for (Animator & anim : anim_player) { + anim.active = false; + anim.set_anim(6); + for (int i = 0; i < random_number; i++) { + anim.next_anim(); + } + } + } else if (jump == 2) { + for (Animator & anim : anim_player) { + anim.active = false; + anim.set_anim(7); + } + rb_player.data.angular_velocity = 0; + transform_player.rotation = 90; + } + if (jump == 0) { + rb_player.data.linear_velocity = vec2(100, -150); + rb_player.data.angular_velocity = 320; + rb_player.data.angular_velocity_coefficient = 0.8; + jump++; + } else if (jump == 1) { + rb_player.data.linear_velocity = vec2(100, -125); + rb_player.data.angular_velocity = 300; + rb_player.data.angular_velocity_coefficient = 0.8; + jump++; + } else if (jump == 2) { + rb_player.data.linear_velocity = vec2(100, 0); + rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); + rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); + jump++; + } + } +} -- cgit v1.2.3 From 493f7bd2f8f74a418fb06ddbd419e5d010ec5808 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 17:28:10 +0100 Subject: Re-implemented player end --- game/player/PlayerEndScript.cpp | 52 +++++++++++++++++++++-------------------- game/player/PlayerEndScript.h | 4 +++- 2 files changed, 30 insertions(+), 26 deletions(-) (limited to 'game/player/PlayerEndScript.cpp') diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index c0b4e74..37b870c 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -10,19 +10,22 @@ using namespace crepe; using namespace std; void PlayerEndScript::init() { - BoxCollider jetpack_coll = this->get_components_by_name("player").back(); - CircleCollider head_coll = this->get_components_by_name("player").back(); - jetpack_coll.active = false; - head_coll.active = false; + Rigidbody & rb_player = this->get_components_by_name("player").front(); + rb_player.data.elasticity_coefficient = 0.7; + + subscribe([this](const CollisionEvent & ev) -> bool { + return this->on_collision(ev); + }); } -void PlayerEndScript::fixed_update(crepe::duration_t dt) { - Transform & transform_player = this->get_components_by_name("player").front(); - RefVector anim_player = this->get_components_by_name("player"); - Rigidbody & rb_player = this->get_components_by_name("player").front(); - Rigidbody & rb_camera = this->get_components_by_name("camera").front(); +bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { + if (ev.info.other.metadata.name == "floor") { + Transform & transform_player + = this->get_components_by_name("player").front(); + RefVector anim_player = this->get_components_by_name("player"); + Rigidbody & rb_player = this->get_components_by_name("player").front(); + Rigidbody & rb_camera = this->get_components_by_name("camera").front(); - if (transform_player.position.y >= 194) { if (jump == 0 || jump == 1) { int random_number = rand() % 4; for (Animator & anim : anim_player) { @@ -32,29 +35,28 @@ void PlayerEndScript::fixed_update(crepe::duration_t dt) { anim.next_anim(); } } - } else if (jump == 2) { - for (Animator & anim : anim_player) { - anim.active = false; - anim.set_anim(7); - } - rb_player.data.angular_velocity = 0; - transform_player.rotation = 90; } + if (jump == 0) { - rb_player.data.linear_velocity = vec2(100, -150); rb_player.data.angular_velocity = 320; - rb_player.data.angular_velocity_coefficient = 0.8; + rb_player.data.angular_velocity_coefficient = 0.7; jump++; - } else if (jump == 1) { - rb_player.data.linear_velocity = vec2(100, -125); - rb_player.data.angular_velocity = 300; - rb_player.data.angular_velocity_coefficient = 0.8; - jump++; - } else if (jump == 2) { + } else if (jump == 1 && transform_player.rotation > 65 + && transform_player.rotation < 115) { + rb_player.data.angular_velocity = 0; + rb_player.data.elasticity_coefficient = 0; rb_player.data.linear_velocity = vec2(100, 0); rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); + for (Animator & anim : anim_player) { + anim.active = false; + anim.set_anim(7); + } jump++; } + + return true; } + + return false; } diff --git a/game/player/PlayerEndScript.h b/game/player/PlayerEndScript.h index 240ab7c..03ea8a9 100644 --- a/game/player/PlayerEndScript.h +++ b/game/player/PlayerEndScript.h @@ -5,7 +5,9 @@ class PlayerEndScript : public crepe::Script { public: void init(); - void fixed_update(crepe::duration_t dt); + +private: + bool on_collision(const crepe::CollisionEvent & ev); private: int jump = 0; -- cgit v1.2.3 From bc66ba7754dec9d6f907bc69730f211ae2215906 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sun, 29 Dec 2024 12:15:10 +0100 Subject: Improved stop sprite --- game/player/PlayerEndScript.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'game/player/PlayerEndScript.cpp') diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index 37b870c..80d3011 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -26,7 +26,7 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { Rigidbody & rb_player = this->get_components_by_name("player").front(); Rigidbody & rb_camera = this->get_components_by_name("camera").front(); - if (jump == 0 || jump == 1) { + if (jump == 0) { int random_number = rand() % 4; for (Animator & anim : anim_player) { anim.active = false; @@ -35,14 +35,19 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { anim.next_anim(); } } + } else if (jump == 1) { + for (Animator & anim : anim_player) { + anim.next_anim(); + } } if (jump == 0) { rb_player.data.angular_velocity = 320; rb_player.data.angular_velocity_coefficient = 0.7; jump++; - } else if (jump == 1 && transform_player.rotation > 65 - && transform_player.rotation < 115) { + } else if (jump == 1) { + jump++; + } else if (jump == 2) { rb_player.data.angular_velocity = 0; rb_player.data.elasticity_coefficient = 0; rb_player.data.linear_velocity = vec2(100, 0); @@ -52,6 +57,24 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { anim.active = false; anim.set_anim(7); } + if (transform_player.rotation > 0 && transform_player.rotation < 90) { + // Do not call next_anim() + } else if (transform_player.rotation > 90 && transform_player.rotation < 180) { + for (Animator & anim : anim_player) { + anim.next_anim(); + } + } else if (transform_player.rotation > 180 && transform_player.rotation < 270) { + for (Animator & anim : anim_player) { + anim.next_anim(); + anim.next_anim(); + } + } else { + for (Animator & anim : anim_player) { + anim.next_anim(); + anim.next_anim(); + anim.next_anim(); + } + } jump++; } -- cgit v1.2.3 From e7cebc43f567b0fa1701d953a9f25d5f527e89bb Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sun, 29 Dec 2024 12:29:40 +0100 Subject: Added Player params to Config --- game/Config.h | 3 +++ game/StartGameScript.cpp | 3 ++- game/player/PlayerEndScript.cpp | 4 +++- game/player/PlayerScript.cpp | 5 +++-- game/player/PlayerSubScene.cpp | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) (limited to 'game/player/PlayerEndScript.cpp') diff --git a/game/Config.h b/game/Config.h index 796ad6c..973944e 100644 --- a/game/Config.h +++ b/game/Config.h @@ -22,3 +22,6 @@ static constexpr int GAME_HEIGHT = 800; // In game units static constexpr int VIEWPORT_X = 1100; // In game units // 'GAME_HEIGHT' (below) should be replaced by '500' when game development is finished static constexpr int VIEWPORT_Y = GAME_HEIGHT; // In game units + +static constexpr int PLAYER_SPEED = 100; // In game units +static constexpr int PLAYER_GRAVITY_SCALE = 40; // In game units diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp index 50ba86c..72bdcd5 100644 --- a/game/StartGameScript.cpp +++ b/game/StartGameScript.cpp @@ -1,4 +1,5 @@ #include "StartGameScript.h" +#include "Config.h" #include #include @@ -50,7 +51,7 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { // Start camera movement, enable player jumping and disable this script if (player_transform.position.x > 500) { Rigidbody & rb = this->get_components_by_name("camera").front(); - rb.data.linear_velocity = vec2(100, 0); + rb.data.linear_velocity = vec2(PLAYER_SPEED, 0); BehaviorScript & player_script = this->get_components_by_name("player").front(); player_script.active = true; diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index 80d3011..8833c28 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -1,5 +1,7 @@ #include "PlayerEndScript.h" +#include "../Config.h" + #include #include #include @@ -50,7 +52,7 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { } else if (jump == 2) { rb_player.data.angular_velocity = 0; rb_player.data.elasticity_coefficient = 0; - rb_player.data.linear_velocity = vec2(100, 0); + rb_player.data.linear_velocity = vec2(PLAYER_SPEED, 0); rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); for (Animator & anim : anim_player) { diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 7f5d0c4..3b4cc5e 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -1,5 +1,6 @@ #include "PlayerScript.h" -#include "api/BehaviorScript.h" + +#include "../Config.h" #include #include @@ -79,7 +80,7 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { Rigidbody & rb = this->get_components_by_name("player").front(); if (this->get_key_state(Keycode::SPACE)) { - rb.add_force_linear(vec2(0, -10)); + rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 3)); if (prev_anim != 1) { for (Animator & anim : animators) { anim.active = true; diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 91ae882..7e78e82 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -141,9 +141,9 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { ); player.add_component(vec2(40, 60), vec2(-20, 0)); player.add_component(Rigidbody::Data { - .gravity_scale = 20, + .gravity_scale = PLAYER_GRAVITY_SCALE, .body_type = Rigidbody::BodyType::DYNAMIC, - .linear_velocity = vec2(100, 0), + .linear_velocity = vec2(PLAYER_SPEED, 0), .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_ZAPPER, COLL_LAY_LASER, COLL_LAY_MISSILE}, .collision_layer = COLL_LAY_PLAYER, -- cgit v1.2.3 From b31934cc6867be10e986a4bd4d0ab81dc91d56ec Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 10:14:58 +0100 Subject: Paralax stops when player stops --- game/GameScene.cpp | 2 +- game/player/PlayerEndScript.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'game/player/PlayerEndScript.cpp') diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 821191d..a8fcb47 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -100,7 +100,7 @@ void GameScene::load_scene() { .collision_layer = COLL_LAY_LASER, }); laser.add_component(vec2(100, 100)); - GameObject missile = new_object("missile", "missile", vec2(3000, 0)); + GameObject missile = new_object("missile", "missile", vec2(4000, 0)); Asset missile_asset {"asset/obstacles/missile/missile.png"}; Sprite & missile_sprite = missile.add_component( missile_asset, diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index 8833c28..4cd2cd0 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -50,6 +50,12 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { } else if (jump == 1) { jump++; } else if (jump == 2) { + RefVector rb_back_forest + = this->get_components_by_tag("forest_background"); + for (Rigidbody & rb : rb_back_forest) { + rb.data.linear_velocity_coefficient = vec2(0.5, 0.5); + } + rb_player.data.angular_velocity = 0; rb_player.data.elasticity_coefficient = 0; rb_player.data.linear_velocity = vec2(PLAYER_SPEED, 0); -- cgit v1.2.3 From 20ae1e9dc2043ef3c190f77dd5f9de74bcd533de Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 11:11:25 +0100 Subject: Added dt --- game/Config.h | 2 +- game/StartGameScript.cpp | 2 +- game/player/PlayerEndScript.cpp | 7 +++++-- game/player/PlayerSubScene.cpp | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) (limited to 'game/player/PlayerEndScript.cpp') diff --git a/game/Config.h b/game/Config.h index 1e51141..d6f8349 100644 --- a/game/Config.h +++ b/game/Config.h @@ -23,5 +23,5 @@ static constexpr int VIEWPORT_X = 1100; // In game units // 'GAME_HEIGHT' (below) should be replaced by '500' when game development is finished static constexpr int VIEWPORT_Y = GAME_HEIGHT; // In game units -static constexpr int PLAYER_SPEED = 150; // In game units +static constexpr int PLAYER_SPEED = 7500; // In game units static constexpr int PLAYER_GRAVITY_SCALE = 60; // In game units diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp index 72bdcd5..c786eb4 100644 --- a/game/StartGameScript.cpp +++ b/game/StartGameScript.cpp @@ -51,7 +51,7 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { // Start camera movement, enable player jumping and disable this script if (player_transform.position.x > 500) { Rigidbody & rb = this->get_components_by_name("camera").front(); - rb.data.linear_velocity = vec2(PLAYER_SPEED, 0); + rb.data.linear_velocity = vec2(PLAYER_SPEED * dt.count(), 0); BehaviorScript & player_script = this->get_components_by_name("player").front(); player_script.active = true; diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index 4cd2cd0..e04fb9d 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -1,6 +1,7 @@ #include "PlayerEndScript.h" #include "../Config.h" +#include "manager/LoopTimerManager.h" #include #include @@ -28,6 +29,8 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { Rigidbody & rb_player = this->get_components_by_name("player").front(); Rigidbody & rb_camera = this->get_components_by_name("camera").front(); + float dt = this->get_loop_timer().get_fixed_delta_time().count(); + if (jump == 0) { int random_number = rand() % 4; for (Animator & anim : anim_player) { @@ -44,7 +47,7 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { } if (jump == 0) { - rb_player.data.angular_velocity = 320; + rb_player.data.angular_velocity = 16000 * dt; rb_player.data.angular_velocity_coefficient = 0.7; jump++; } else if (jump == 1) { @@ -58,7 +61,7 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { rb_player.data.angular_velocity = 0; rb_player.data.elasticity_coefficient = 0; - rb_player.data.linear_velocity = vec2(PLAYER_SPEED, 0); + rb_player.data.linear_velocity = vec2(PLAYER_SPEED * dt, 0); rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); for (Animator & anim : anim_player) { diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 7e78e82..c1e5e2f 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -143,7 +143,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { player.add_component(Rigidbody::Data { .gravity_scale = PLAYER_GRAVITY_SCALE, .body_type = Rigidbody::BodyType::DYNAMIC, - .linear_velocity = vec2(PLAYER_SPEED, 0), + .linear_velocity = vec2(PLAYER_SPEED * 0.02, 0), .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_ZAPPER, COLL_LAY_LASER, COLL_LAY_MISSILE}, .collision_layer = COLL_LAY_PLAYER, -- cgit v1.2.3 From fcae8934916c9f429e58c8e178ab14fcf65a2bbc Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Tue, 7 Jan 2025 11:20:58 +0100 Subject: added end game --- game/CMakeLists.txt | 2 ++ game/Events.h | 5 ++++ game/GameScene.cpp | 6 ++-- game/menus/IFloatingWindowScript.cpp | 23 +++++++++++++++ game/menus/IFloatingWindowScript.h | 15 ++++++++++ game/menus/endgame/EndGameSubScene.cpp | 14 +++++++-- game/menus/endgame/EndGameSubScript.cpp | 51 +++++++++++++++++++++++++++++++++ game/menus/endgame/EndGameSubScript.h | 16 +++++++++++ game/menus/mainmenu/MainMenuScene.cpp | 3 -- game/player/PlayerEndScript.cpp | 5 ++++ 10 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 game/Events.h create mode 100644 game/menus/IFloatingWindowScript.cpp create mode 100644 game/menus/IFloatingWindowScript.h create mode 100644 game/menus/endgame/EndGameSubScript.cpp create mode 100644 game/menus/endgame/EndGameSubScript.h (limited to 'game/player/PlayerEndScript.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 9886973..fffe6d3 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -28,12 +28,14 @@ add_executable(main menus/ButtonSetShopScript.cpp menus/ButtonSetMainMenuScript.cpp menus/FloatingWindowSubScene.cpp + menus/IFloatingWindowScript.cpp menus/shop/ShopMenuScene.cpp menus/mainmenu/ButtonTransitionPreviewScript.cpp menus/mainmenu/ITransitionScript.cpp menus/mainmenu/MainMenuScene.cpp menus/mainmenu/TransitionStartScript.cpp menus/endgame/EndGameSubScene.cpp + menus/endgame/EndGameSubScript.cpp coins/CoinSubScene.cpp coins/CoinPool.cpp coins/CoinSystemScript.cpp diff --git a/game/Events.h b/game/Events.h new file mode 100644 index 0000000..cf0be68 --- /dev/null +++ b/game/Events.h @@ -0,0 +1,5 @@ +#pragma once + +#include "api/Event.h" + +struct EndGameEvent : public crepe::Event {}; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 24b4287..a1f3fa6 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -11,6 +11,7 @@ #include "hud/HudSubScene.h" #include "hud/SpeedScript.h" #include "menus/endgame/EndGameSubScene.h" +#include "menus/endgame/EndGameSubScript.h" #include "player/PlayerSubScene.h" #include @@ -135,9 +136,8 @@ void GameScene::load_scene() { }); missile.add_component(vec2(100, 100)); - - EndGameSubScene test; - test.create(*this); + EndGameSubScene endgamewindow; + endgamewindow.create(*this); } string GameScene::get_name() const { return "scene1"; } diff --git a/game/menus/IFloatingWindowScript.cpp b/game/menus/IFloatingWindowScript.cpp new file mode 100644 index 0000000..ce84de7 --- /dev/null +++ b/game/menus/IFloatingWindowScript.cpp @@ -0,0 +1,23 @@ +#include "IFloatingWindowScript.h" +#include "api/Sprite.h" +#include "types.h" + +using namespace crepe; + +void IFloatingWindowScript::init(){ + this->disable_all_sprites(); +} + +void IFloatingWindowScript::disable_all_sprites(){ + RefVector sprites = this->get_components_by_tag(this->tag); + for(Sprite & sprite : sprites){ + sprite.active = false; + } +} + +void IFloatingWindowScript::enable_all_sprites(){ + RefVector sprites = this->get_components_by_tag(this->tag); + for(Sprite & sprite : sprites){ + sprite.active = true; + } +} diff --git a/game/menus/IFloatingWindowScript.h b/game/menus/IFloatingWindowScript.h new file mode 100644 index 0000000..9775726 --- /dev/null +++ b/game/menus/IFloatingWindowScript.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +class IFloatingWindowScript : public virtual crepe::Script { +public: + virtual void init(); + void disable_all_sprites(); + void enable_all_sprites(); +protected: + std::string tag = ""; +}; + + diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp index 8d785ed..41556af 100644 --- a/game/menus/endgame/EndGameSubScene.cpp +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include "EndGameSubScript.h" #include "types.h" #include "../../Config.h" @@ -13,10 +15,14 @@ using namespace std; void EndGameSubScene::create(Scene & scn){ + const std::string TAG = "end_game_tag"; + GameObject script = scn.new_object("script"); + script.add_component().set_script(TAG); + // Window FloatingWindowSubScene window; window.create(scn, FloatingWindowSubScene::Data{ - .group_tag = "end_game_window", + .group_tag = TAG, .width = 500, .offset = {0,-50}, .width_middle_offset = -2, @@ -24,7 +30,7 @@ void EndGameSubScene::create(Scene & scn){ // Titel const string TITEL_STRING = "GAME OVER"; - GameObject titel = scn.new_object("titel"); + GameObject titel = scn.new_object("titel",TAG); crepe::vec2 size = {200,(200.0f/TITEL_STRING.size())*2}; titel.add_component(size, FONT,Text::Data{ .world_space = false, @@ -43,6 +49,7 @@ void EndGameSubScene::create(Scene & scn){ .button_type = ButtonSubScene::ButtonSelect::NEXT, .scale = 0.6, .worldspace = false, + .tag = TAG, .sorting_layer_offset = 20, }); @@ -50,10 +57,11 @@ void EndGameSubScene::create(Scene & scn){ .text = "REPLAY", .text_width = 150, .position = {-button_position.x,button_position.y}, - .script_type = ButtonSubScene::ScriptSelect::MAINMENU, + // .script_type = ButtonSubScene::ScriptSelect::MAINMENU, .button_type = ButtonSubScene::ButtonSelect::BACK, .scale = 0.6, .worldspace = false, + .tag = TAG, .sorting_layer_offset = 20, }); diff --git a/game/menus/endgame/EndGameSubScript.cpp b/game/menus/endgame/EndGameSubScript.cpp new file mode 100644 index 0000000..2be6931 --- /dev/null +++ b/game/menus/endgame/EndGameSubScript.cpp @@ -0,0 +1,51 @@ +#include "EndGameSubScript.h" +#include "../IFloatingWindowScript.h" +#include "api/Button.h" +#include "api/Sprite.h" +#include "api/Text.h" +#include "types.h" +#include "../../Events.h" +#include + +using namespace crepe; + +EndGameSubScript::EndGameSubScript(const std::string & tag){ + this->tag = tag; +} + +void EndGameSubScript::init(){ + this->disable_all(); + this->subscribe([this](const EndGameEvent e) { return this->enable_all(); }); + this->subscribe([this](const EndGameEvent e) { return this->reset_timescale(); }); +} + +bool EndGameSubScript::disable_all(){ + IFloatingWindowScript::disable_all_sprites(); + RefVector