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/preview/NpcScript.cpp | 32 +++++++++ game/preview/NpcScript.h | 11 +++ game/preview/NpcSubScene.cpp | 69 +++++++++++++++++++ game/preview/NpcSubScene.h | 10 +++ game/preview/PrevPlayerScript.cpp | 132 ++++++++++++++++++++++++++++++++++++ game/preview/PrevPlayerScript.h | 23 +++++++ game/preview/PrevPlayerSubScene.cpp | 86 +++++++++++++++++++++++ game/preview/PrevPlayerSubScene.h | 10 +++ game/preview/SmokeSubScene.cpp | 37 ++++++++++ game/preview/SmokeSubScene.h | 10 +++ 10 files changed, 420 insertions(+) create mode 100644 game/preview/NpcScript.cpp create mode 100644 game/preview/NpcScript.h create mode 100644 game/preview/NpcSubScene.cpp create mode 100644 game/preview/NpcSubScene.h create mode 100644 game/preview/PrevPlayerScript.cpp create mode 100644 game/preview/PrevPlayerScript.h create mode 100644 game/preview/PrevPlayerSubScene.cpp create mode 100644 game/preview/PrevPlayerSubScene.h create mode 100644 game/preview/SmokeSubScene.cpp create mode 100644 game/preview/SmokeSubScene.h (limited to 'game/preview') diff --git a/game/preview/NpcScript.cpp b/game/preview/NpcScript.cpp new file mode 100644 index 0000000..c4148f2 --- /dev/null +++ b/game/preview/NpcScript.cpp @@ -0,0 +1,32 @@ +#include "NpcScript.h" + +#include +#include +#include + +using namespace std; +using namespace crepe; + +void NpcScript::init() {} +void NpcScript::fixed_update(duration_t dt) { + auto & rb = this->get_component(); + auto & npc = this->get_component(); + auto & transform = this->get_component(); + + if (transform.position.x < -990) { + rb.data.linear_velocity.x *= -1; + } + if (transform.position.x > 990) { + rb.data.linear_velocity.x *= -1; + } + + if (rb.data.linear_velocity.x < 0) { + npc.data.flip = {true, false}; + } else { + npc.data.flip = {false, false}; + } + + auto & savemgr = this->get_save_manager(); + savemgr.set("npc_x", transform.position.x); + savemgr.set("npc_y", transform.position.y); +} diff --git a/game/preview/NpcScript.h b/game/preview/NpcScript.h new file mode 100644 index 0000000..8d856fd --- /dev/null +++ b/game/preview/NpcScript.h @@ -0,0 +1,11 @@ + +#include + +class NpcScript : public crepe::Script { + +private: + +public: + void init(); + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/preview/NpcSubScene.cpp b/game/preview/NpcSubScene.cpp new file mode 100644 index 0000000..bd6cfb2 --- /dev/null +++ b/game/preview/NpcSubScene.cpp @@ -0,0 +1,69 @@ + + +#include "NpcSubScene.h" + +#include "../Config.h" +#include "NpcScript.h" + +#include +#include +#include +#include +#include +#include + +using namespace crepe; + +NpcSubScene::NpcSubScene(Scene & scn) { + auto & savemgr = scn.get_save_manager(); + ValueBroker npc_x = savemgr.get("npc_x", 500); + ValueBroker npc_y = savemgr.get("npc_y", 0); + + GameObject npc = scn.new_object("npc", "npc_tag", vec2 {npc_x.get(), npc_y.get()}, 0, 1); + Asset npc_body {"asset/workers/worker1Body.png"}; + Asset npc_head {"asset/workers/worker1Head.png"}; + + auto & npc_body_sprite = npc.add_component( + npc_body, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .size = {0, 50}, + } + ); + auto & npc_head_sprite = npc.add_component( + npc_head, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .size = {0, 50}, + .position_offset = {0, -20}, + } + ); + + npc.add_component( + npc_body_sprite, ivec2 {32, 32}, uvec2 {4, 8}, + Animator::Data { + .fps = 5, + .looping = true, + } + ); + npc.add_component( + npc_head_sprite, ivec2 {32, 32}, uvec2 {4, 8}, + Animator::Data { + .fps = 5, + .looping = true, + } + ); + npc.add_component(vec2 {50, 50}); + + npc.add_component(Rigidbody::Data { + .mass = 10, + .gravity_scale = 1, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = {-50, 0}, + //.max_linear_velocity = 40, + .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_PLAYER}, + .collision_layer = COLL_LAY_PLAYER, + }); + + npc.add_component().set_script(); +} diff --git a/game/preview/NpcSubScene.h b/game/preview/NpcSubScene.h new file mode 100644 index 0000000..a226195 --- /dev/null +++ b/game/preview/NpcSubScene.h @@ -0,0 +1,10 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class NpcSubScene { +public: + NpcSubScene(crepe::Scene & scn); +}; diff --git a/game/preview/PrevPlayerScript.cpp b/game/preview/PrevPlayerScript.cpp new file mode 100644 index 0000000..2657b8d --- /dev/null +++ b/game/preview/PrevPlayerScript.cpp @@ -0,0 +1,132 @@ +#include "PrevPlayerScript.h" + +#include "../missile/SpawnEvent.h" +#include "api/Transform.h" +#include +#include +#include +#include +#include + +using namespace crepe; + +bool PrevPlayerScript::key_pressed(const KeyPressEvent & ev) { + switch (ev.key) { + case Keycode::A: + this->get_component().data.linear_velocity.x = -move_speed; + this->body->data.flip = {true, false}; + this->head->data.flip = {true, false}; + break; + case Keycode::D: + this->get_component().data.linear_velocity.x = move_speed; + this->body->data.flip = {false, false}; + this->head->data.flip = {false, false}; + break; + + case Keycode::SPACE: + this->get_component().data.linear_velocity.y = -move_speed; + break; + case Keycode::D0: + this->body_anim->set_anim(0); + this->head_anim->set_anim(0); + break; + case Keycode::D1: + this->body_anim->set_anim(1); + this->head_anim->set_anim(1); + break; + case Keycode::D2: + this->body_anim->set_anim(2); + this->head_anim->set_anim(2); + break; + case Keycode::D3: + this->body_anim->set_anim(3); + this->head_anim->set_anim(3); + break; + case Keycode::D4: + this->body_anim->set_anim(4); + this->head_anim->set_anim(4); + break; + case Keycode::D5: + this->body_anim->set_anim(5); + this->head_anim->set_anim(5); + break; + case Keycode::D6: + this->body_anim->set_anim(6); + this->head_anim->set_anim(6); + break; + case Keycode::D7: + this->body_anim->set_anim(7); + this->head_anim->set_anim(7); + break; + case Keycode::LEFT: + this->head->data.angle_offset -= 1; + break; + case Keycode::RIGHT: + this->head->data.angle_offset += 1; + break; + case Keycode::UP: + this->head->data.scale_offset += 0.1; + break; + case Keycode::DOWN: + this->head->data.scale_offset -= 0.1; + break; + case Keycode::P: + this->get_component().play(); + break; + case Keycode::Q: + this->get_components_by_name("camera").front().get().data.zoom -= 0.01; + break; + case Keycode::E: + this->get_components_by_name("camera").front().get().data.zoom += 0.01; + break; + case Keycode::J: + this->get_components_by_name("camera").front().get().position.x + -= move_speed; + break; + case Keycode::K: + this->get_components_by_name("camera").front().get().position.y + -= move_speed; + break; + case Keycode::L: + this->get_components_by_name("camera").front().get().position.x + += move_speed; + break; + case Keycode::I: + this->get_components_by_name("camera").front().get().position.y + += move_speed; + break; + case Keycode::M: + trigger_event(MissileSpawnEvent {}); + break; + //todo + case Keycode::PAGE_UP: + case Keycode::PAGE_DOWN: + case Keycode::HOME: + break; + default: + break; + } + return false; +} + +void PrevPlayerScript::init() { + auto animations = this->get_components(); + body_anim = animations[0]; + head_anim = animations[1]; + + auto sprites = this->get_components(); + body = sprites[0]; + head = sprites[1]; + + subscribe([this](const KeyPressEvent & ev) -> bool { + return this->key_pressed(ev); + }); +}; + +void PrevPlayerScript::fixed_update(crepe::duration_t dt) { + auto & savemgr = this->get_save_manager(); + const auto & pos = this->get_component().position; + + savemgr.set("player_x", pos.x); + savemgr.set("player_y", pos.y); +}; diff --git a/game/preview/PrevPlayerScript.h b/game/preview/PrevPlayerScript.h new file mode 100644 index 0000000..cc3184e --- /dev/null +++ b/game/preview/PrevPlayerScript.h @@ -0,0 +1,23 @@ + +#include +#include +#include + +#include +#include + +class PrevPlayerScript : public crepe::Script { +private: + crepe::OptionalRef head_anim; + crepe::OptionalRef body_anim; + crepe::OptionalRef head; + crepe::OptionalRef body; + +private: + float move_speed = 100; + +private: + void init(); + void fixed_update(crepe::duration_t dt); + bool key_pressed(const crepe::KeyPressEvent & ev); +}; diff --git a/game/preview/PrevPlayerSubScene.cpp b/game/preview/PrevPlayerSubScene.cpp new file mode 100644 index 0000000..b59a0af --- /dev/null +++ b/game/preview/PrevPlayerSubScene.cpp @@ -0,0 +1,86 @@ + +#include "PrevPlayerSubScene.h" + +#include "../Config.h" +#include "PrevPlayerScript.h" + +#include +#include +#include +#include +#include + +#include +#include + +using namespace crepe; + +PrevPlayerSubScene::PrevPlayerSubScene(Scene & scn) { + auto & savemgr = scn.get_save_manager(); + + ValueBroker player_x = savemgr.get("player_x", 500); + ValueBroker player_y = savemgr.get("player_y", -100); + + GameObject player + = scn.new_object("player", "TAG", vec2 {player_x.get(), player_y.get()}, 0, 1); + Asset player_body_asset {"asset/barry/defaultBody.png"}; + Sprite & player_body_sprite = player.add_component( + player_body_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 0, + .size = vec2(0, 50), + } + ); + player.add_component( + player_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + Asset player_head_asset {"asset/barry/defaultHead.png"}; + Sprite & player_head_sprite = player.add_component( + player_head_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 1, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + player.add_component( + player_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + Asset player_jetpack_asset {"asset/barry/jetpackDefault.png"}; + Sprite & player_jetpack_sprite = player.add_component( + player_jetpack_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 2, + .size = vec2(0, 60), + .position_offset = vec2(-20, 0), + } + ); + player_jetpack_sprite.active = false; + player.add_component( + player_jetpack_sprite, ivec2(32, 44), uvec2(4, 4), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + player.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(100, 0), + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_PLAYER, + }); + player.add_component(vec2(50, 50)); + player.add_component().set_script(); +} diff --git a/game/preview/PrevPlayerSubScene.h b/game/preview/PrevPlayerSubScene.h new file mode 100644 index 0000000..a61f341 --- /dev/null +++ b/game/preview/PrevPlayerSubScene.h @@ -0,0 +1,10 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class PrevPlayerSubScene { +public: + PrevPlayerSubScene(crepe::Scene & scn); +}; diff --git a/game/preview/SmokeSubScene.cpp b/game/preview/SmokeSubScene.cpp new file mode 100644 index 0000000..e363f95 --- /dev/null +++ b/game/preview/SmokeSubScene.cpp @@ -0,0 +1,37 @@ + +#include "SmokeSubScene.h" + +#include "../Config.h" + +#include +#include +#include + +using namespace crepe; + +SmokeSubScene::SmokeSubScene(Scene & scn) { + GameObject smoke = scn.new_object("smoke_particle", "TAG", vec2 {500, -210}, 0, 1); + + Asset smoke_ss {"asset/particles/smoke.png"}; + + auto & smoke_sprite = smoke.add_component( + smoke_ss, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, + .size = {0, 30}, + } + ); + + smoke.add_component( + smoke_sprite, + ParticleEmitter::Data { + .offset = {0, -60}, + .max_particles = 10, + .emission_rate = 25, + .min_angle = 60, + .max_angle = 120, + .begin_lifespan = 1, + .end_lifespan = 2, + } + ); +} diff --git a/game/preview/SmokeSubScene.h b/game/preview/SmokeSubScene.h new file mode 100644 index 0000000..93d8a2d --- /dev/null +++ b/game/preview/SmokeSubScene.h @@ -0,0 +1,10 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class SmokeSubScene { +public: + SmokeSubScene(crepe::Scene & scn); +}; -- cgit v1.2.3 From 30974f588816aa03652002111c6a946b138e3bc5 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 19:47:31 +0100 Subject: replay in preview scene --- game/CMakeLists.txt | 3 ++ game/PreviewScene.cpp | 74 +++++++++++++++++++++++++++++++ game/menus/ButtonSubScene.cpp | 15 +++++++ game/menus/ButtonSubScene.h | 3 ++ game/preview/PreviewReplaySubScript.cpp | 51 +++++++++++++++++++++ game/preview/PreviewReplaySubScript.h | 23 ++++++++++ game/preview/PreviewStartRecSubScript.cpp | 21 +++++++++ game/preview/PreviewStartRecSubScript.h | 11 +++++ game/preview/PreviewStopRecSubScript.cpp | 21 +++++++++ game/preview/PreviewStopRecSubScript.h | 11 +++++ 10 files changed, 233 insertions(+) create mode 100644 game/preview/PreviewReplaySubScript.cpp create mode 100644 game/preview/PreviewReplaySubScript.h create mode 100644 game/preview/PreviewStartRecSubScript.cpp create mode 100644 game/preview/PreviewStartRecSubScript.h create mode 100644 game/preview/PreviewStopRecSubScript.cpp create mode 100644 game/preview/PreviewStopRecSubScript.h (limited to 'game/preview') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index e1168eb..9dfd2b4 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -52,6 +52,9 @@ target_sources(main PUBLIC preview/NpcScript.cpp preview/PrevPlayerSubScene.cpp preview/PrevPlayerScript.cpp + preview/PreviewStopRecSubScript.cpp + preview/PreviewStartRecSubScript.cpp + preview/PreviewReplaySubScript.cpp # scripts GameScene.cpp diff --git a/game/PreviewScene.cpp b/game/PreviewScene.cpp index 6cd9e78..0812c0d 100644 --- a/game/PreviewScene.cpp +++ b/game/PreviewScene.cpp @@ -2,6 +2,10 @@ #include "Config.h" #include "background/BackgroundSubScene.h" +#include "hud/HudScript.h" +#include "hud/HudSubScene.h" +#include "hud/SpeedScript.h" +#include "menus/ButtonSubScene.h" #include "missile/MissilePool.h" #include "missile/SpawnEvent.h" #include "preview/NpcSubScene.h" @@ -47,6 +51,8 @@ void PreviewScene::load_scene() { ); camera.add_component(Rigidbody::Data {}); camera.add_component().set_script(); + camera.add_component().set_script(); + camera.add_component().set_script(); GameObject floor = new_object("floor", "game_world", vec2(0, 325)); floor.add_component(Rigidbody::Data { @@ -83,6 +89,74 @@ void PreviewScene::load_scene() { SmokeSubScene smoke(*this); MissilePool mpool(*this); + HudSubScene hud; + hud.create(*this); + + + const float Y_POS_BUTTONS = -220; + const float X_POS_BUTTONS = -150; + const float X_POS_BUTTONS_SPACING = 145; + ButtonSubScene button; + button.create( + *this, + ButtonSubScene::Data { + .text = "BACK", + .text_width = 60, + .position = {X_POS_BUTTONS,Y_POS_BUTTONS}, + .script_type = ButtonSubScene::ScriptSelect::NEXT, + .button_type = ButtonSubScene::ButtonSelect::BACK, + .scale = 0.6, + .worldspace = false, + .tag = "Next button", + .sorting_layer_offset = 20, + } + ); + + button.create( + *this, + ButtonSubScene::Data { + .text = "START REC", + .text_width = 130, + .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, + .worldspace = false, + .tag = "Next button", + .sorting_layer_offset = 20, + } + ); + + button.create( + *this, + ButtonSubScene::Data { + .text = "STOP REC", + .text_width = 120, + .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, + .worldspace = false, + .tag = "Next button", + .sorting_layer_offset = 20, + } + ); + + button.create( + *this, + ButtonSubScene::Data { + .text = "REPLAY", + .text_width = 90, + .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, + .worldspace = false, + .tag = "Next button", + .sorting_layer_offset = 20, + } + ); + /* for (int i = 0; i < 200; ++i) { diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 30646f1..2c912b7 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -7,6 +7,9 @@ #include "IButtonScript.h" #include "MenusConfig.h" +#include "../preview/PreviewReplaySubScript.h" +#include "../preview/PreviewStartRecSubScript.h" +#include "../preview/PreviewStopRecSubScript.h" #include "mainmenu/ButtonTransitionPreviewSubScript.h" #include "../Config.h" @@ -72,6 +75,18 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object, const Data & button_object.add_component() .set_script(); break; + case ScriptSelect::PREVIEW_REPLAY: + button_object.add_component() + .set_script(); + break; + case ScriptSelect::PREVIEW_START: + button_object.add_component() + .set_script(); + break; + case ScriptSelect::PREVIEW_STOP: + button_object.add_component() + .set_script(); + break; case ScriptSelect::NONE: button_object.add_component().set_script(); break; diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index 74f9464..29287b6 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -19,6 +19,9 @@ public: REPLAY, CREDITS_SHOW, CREDITS_BACK, + PREVIEW_START, + PREVIEW_STOP, + PREVIEW_REPLAY, NONE, }; //icon enum diff --git a/game/preview/PreviewReplaySubScript.cpp b/game/preview/PreviewReplaySubScript.cpp new file mode 100644 index 0000000..9725ba2 --- /dev/null +++ b/game/preview/PreviewReplaySubScript.cpp @@ -0,0 +1,51 @@ +#include "PreviewReplaySubScript.h" +#include "menus/ButtonReplaySubScript.h" +#include +#include + +using namespace crepe; +using namespace std; + +void PreviewReplaySubScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + this->subscribe([this](const StopPreviewRecording & e) { + return this->stop_recording(); + }); + this->subscribe([this](const DeleteRecordingEvent & e) { + return this->delete_recording(); + }); + this->subscribe([this](const StartPreviewRecording & e) { + return this->start_recording(); + }); + +} + +bool PreviewReplaySubScript::on_button_press(const ButtonPressEvent & e) { + replay.play(this->recording); + return false; +} +bool PreviewReplaySubScript::start_recording(){ + if(record_saved){ + this->stop_recording(); + this->delete_recording(); + } + replay.record_start(); + this->record_started = true; + return false; +} + +bool PreviewReplaySubScript::stop_recording() { + if(this->record_started)this->recording = replay.record_end(); + this->record_saved = true; + return false; +} + +bool PreviewReplaySubScript::delete_recording() { + if(this->record_started) this->stop_recording(); + if(this->record_saved)replay.release(this->recording); + this->record_saved = false; + return false; +} diff --git a/game/preview/PreviewReplaySubScript.h b/game/preview/PreviewReplaySubScript.h new file mode 100644 index 0000000..ca5bd08 --- /dev/null +++ b/game/preview/PreviewReplaySubScript.h @@ -0,0 +1,23 @@ +#pragma once + +#include "menus/IButtonScript.h" + +#include + +struct StartPreviewRecording : public crepe::Event {}; +struct StopPreviewRecording : public crepe::Event {}; + +class PreviewReplaySubScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); + +private: + crepe::recording_t recording = 0; + bool start_recording(); + bool stop_recording(); + bool delete_recording(); +private: + bool record_saved = false; + bool record_started = false; +}; diff --git a/game/preview/PreviewStartRecSubScript.cpp b/game/preview/PreviewStartRecSubScript.cpp new file mode 100644 index 0000000..194f849 --- /dev/null +++ b/game/preview/PreviewStartRecSubScript.cpp @@ -0,0 +1,21 @@ +#include "PreviewStartRecSubScript.h" +#include "PreviewReplaySubScript.h" + +#include +#include + +using namespace crepe; +using namespace std; + +void PreviewStartRecSubScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + +} + +bool PreviewStartRecSubScript::on_button_press(const ButtonPressEvent & e) { + this->trigger_event(); + return false; +} diff --git a/game/preview/PreviewStartRecSubScript.h b/game/preview/PreviewStartRecSubScript.h new file mode 100644 index 0000000..a54a085 --- /dev/null +++ b/game/preview/PreviewStartRecSubScript.h @@ -0,0 +1,11 @@ +#pragma once + +#include "menus/IButtonScript.h" + +#include + +class PreviewStartRecSubScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); +}; diff --git a/game/preview/PreviewStopRecSubScript.cpp b/game/preview/PreviewStopRecSubScript.cpp new file mode 100644 index 0000000..c674a8b --- /dev/null +++ b/game/preview/PreviewStopRecSubScript.cpp @@ -0,0 +1,21 @@ +#include "PreviewStopRecSubScript.h" +#include "PreviewReplaySubScript.h" + +#include +#include + +using namespace crepe; +using namespace std; + +void PreviewStopRecSubScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + +} + +bool PreviewStopRecSubScript::on_button_press(const ButtonPressEvent & e) { + this->trigger_event(); + return false; +} diff --git a/game/preview/PreviewStopRecSubScript.h b/game/preview/PreviewStopRecSubScript.h new file mode 100644 index 0000000..b2dd73b --- /dev/null +++ b/game/preview/PreviewStopRecSubScript.h @@ -0,0 +1,11 @@ +#pragma once + +#include "menus/IButtonScript.h" + +#include + +class PreviewStopRecSubScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); +}; -- cgit v1.2.3 From 64a0cf67d6c299a099b48ce083b1f3a688787cb3 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 10 Jan 2025 11:04:44 +0100 Subject: added optional replay and added black background --- game/Config.h | 2 ++ game/menus/ButtonReplaySubScript.cpp | 5 +++++ game/menus/mainmenu/MainMenuScene.cpp | 2 +- game/preview/PreviewReplaySubScript.cpp | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) (limited to 'game/preview') diff --git a/game/Config.h b/game/Config.h index 8fa41ba..391fd76 100644 --- a/game/Config.h +++ b/game/Config.h @@ -64,3 +64,5 @@ static constexpr int PLAYER_GRAVITY_SCALE = 60; // In game units static constexpr const char * CAMERA_NAME = "camera"; // Jetpack particles static constexpr const char * JETPACK_PARTICLES = "jetpack_particles"; + +static constexpr bool DISABLE_REPLAY = false; diff --git a/game/menus/ButtonReplaySubScript.cpp b/game/menus/ButtonReplaySubScript.cpp index ddd9fa4..55e718d 100644 --- a/game/menus/ButtonReplaySubScript.cpp +++ b/game/menus/ButtonReplaySubScript.cpp @@ -1,4 +1,5 @@ #include "ButtonReplaySubScript.h" +#include "Config.h" #include "MenusConfig.h" #include "../Events.h" @@ -19,20 +20,24 @@ void ButtonReplaySubScript::init() { this->subscribe([this](const DeleteRecordingEvent & e) { return this->delete_recording(); }); + if(DISABLE_REPLAY)return; replay.record_start(); } bool ButtonReplaySubScript::on_button_press(const ButtonPressEvent & e) { + if(DISABLE_REPLAY)return false; replay.play(this->recording); return false; } bool ButtonReplaySubScript::set_recording() { + if(DISABLE_REPLAY)return false; this->recording = replay.record_end(); return false; } bool ButtonReplaySubScript::delete_recording() { + if(DISABLE_REPLAY)return false; replay.release(this->recording); return false; } diff --git a/game/menus/mainmenu/MainMenuScene.cpp b/game/menus/mainmenu/MainMenuScene.cpp index ff94e74..baeca39 100644 --- a/game/menus/mainmenu/MainMenuScene.cpp +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -29,7 +29,7 @@ void MainMenuScene::load_scene() { camera_object.add_component( ivec2(990, 720), vec2(1100, 800), Camera::Data { - .bg_color = Color::RED, + .bg_color = Color::BLACK, } ); camera_object.add_component().set_script(); diff --git a/game/preview/PreviewReplaySubScript.cpp b/game/preview/PreviewReplaySubScript.cpp index 9725ba2..51c27aa 100644 --- a/game/preview/PreviewReplaySubScript.cpp +++ b/game/preview/PreviewReplaySubScript.cpp @@ -1,4 +1,5 @@ #include "PreviewReplaySubScript.h" +#include "Config.h" #include "menus/ButtonReplaySubScript.h" #include #include @@ -24,10 +25,12 @@ void PreviewReplaySubScript::init() { } bool PreviewReplaySubScript::on_button_press(const ButtonPressEvent & e) { + if(DISABLE_REPLAY)return false; replay.play(this->recording); return false; } bool PreviewReplaySubScript::start_recording(){ + if(DISABLE_REPLAY)return false; if(record_saved){ this->stop_recording(); this->delete_recording(); @@ -38,12 +41,14 @@ bool PreviewReplaySubScript::start_recording(){ } bool PreviewReplaySubScript::stop_recording() { + if(DISABLE_REPLAY)return false; if(this->record_started)this->recording = replay.record_end(); this->record_saved = true; return false; } bool PreviewReplaySubScript::delete_recording() { + if(DISABLE_REPLAY)return false; if(this->record_started) this->stop_recording(); if(this->record_saved)replay.release(this->recording); this->record_saved = false; -- 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/preview') 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