diff options
-rw-r--r-- | game/CMakeLists.txt | 3 | ||||
-rw-r--r-- | game/PreviewScene.cpp | 74 | ||||
-rw-r--r-- | game/menus/ButtonSubScene.cpp | 15 | ||||
-rw-r--r-- | game/menus/ButtonSubScene.h | 3 | ||||
-rw-r--r-- | game/preview/PreviewReplaySubScript.cpp | 51 | ||||
-rw-r--r-- | game/preview/PreviewReplaySubScript.h | 23 | ||||
-rw-r--r-- | game/preview/PreviewStartRecSubScript.cpp | 21 | ||||
-rw-r--r-- | game/preview/PreviewStartRecSubScript.h | 11 | ||||
-rw-r--r-- | game/preview/PreviewStopRecSubScript.cpp | 21 | ||||
-rw-r--r-- | game/preview/PreviewStopRecSubScript.h | 11 |
10 files changed, 233 insertions, 0 deletions
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>(Rigidbody::Data {}); camera.add_component<BehaviorScript>().set_script<MissileSpawnEventHandler>(); + camera.add_component<BehaviorScript>().set_script<HudScript>(); + camera.add_component<BehaviorScript>().set_script<SpeedScript>(); GameObject floor = new_object("floor", "game_world", vec2(0, 325)); floor.add_component<Rigidbody>(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<BehaviorScript>() .set_script<ButtonShowCreditsSubScript>(); break; + case ScriptSelect::PREVIEW_REPLAY: + button_object.add_component<BehaviorScript>() + .set_script<PreviewReplaySubScript>(); + break; + case ScriptSelect::PREVIEW_START: + button_object.add_component<BehaviorScript>() + .set_script<PreviewStartRecSubScript>(); + break; + case ScriptSelect::PREVIEW_STOP: + button_object.add_component<BehaviorScript>() + .set_script<PreviewStopRecSubScript>(); + break; case ScriptSelect::NONE: button_object.add_component<BehaviorScript>().set_script<IButtonScript>(); 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 <crepe/api/AudioSource.h> +#include <crepe/types.h> + +using namespace crepe; +using namespace std; + +void PreviewReplaySubScript::init() { + IButtonScript::init(); + this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + this->subscribe<StopPreviewRecording>([this](const StopPreviewRecording & e) { + return this->stop_recording(); + }); + this->subscribe<DeleteRecordingEvent>([this](const DeleteRecordingEvent & e) { + return this->delete_recording(); + }); + this->subscribe<StartPreviewRecording>([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 <crepe/api/Script.h> + +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 <crepe/api/AudioSource.h> +#include <crepe/types.h> + +using namespace crepe; +using namespace std; + +void PreviewStartRecSubScript::init() { + IButtonScript::init(); + this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + +} + +bool PreviewStartRecSubScript::on_button_press(const ButtonPressEvent & e) { + this->trigger_event<StartPreviewRecording>(); + 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 <crepe/api/Script.h> + +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 <crepe/api/AudioSource.h> +#include <crepe/types.h> + +using namespace crepe; +using namespace std; + +void PreviewStopRecSubScript::init() { + IButtonScript::init(); + this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + +} + +bool PreviewStopRecSubScript::on_button_press(const ButtonPressEvent & e) { + this->trigger_event<StopPreviewRecording>(); + 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 <crepe/api/Script.h> + +class PreviewStopRecSubScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); +}; |