From a0a3e7e2d12d3acb7bf4073cb5a10c08047cd08e Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 12:14:51 +0100 Subject: Added EndGameScript --- game/CMakeLists.txt | 1 + game/EndGameScript.cpp | 6 ++++++ game/EndGameScript.h | 8 ++++++++ game/GameScene.cpp | 3 +++ game/player/PlayerScript.cpp | 6 ++++++ 5 files changed, 24 insertions(+) create mode 100644 game/EndGameScript.cpp create mode 100644 game/EndGameScript.h (limited to 'game') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index c3a2d52..33ceaf4 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -19,6 +19,7 @@ add_executable(main player/PlayerScript.cpp player/PlayerSubScene.cpp StartGameScript.cpp + EndGameScript.cpp background/StartSubScene.cpp main.cpp ) diff --git a/game/EndGameScript.cpp b/game/EndGameScript.cpp new file mode 100644 index 0000000..4d7b5fd --- /dev/null +++ b/game/EndGameScript.cpp @@ -0,0 +1,6 @@ +#include "EndGameScript.h" + +void EndGameScript::fixed_update(crepe::duration_t dt) { + logf("EndGameScript::fixed_update"); + // ... +} diff --git a/game/EndGameScript.h b/game/EndGameScript.h new file mode 100644 index 0000000..b63ac9d --- /dev/null +++ b/game/EndGameScript.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +class EndGameScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 821191d..b471484 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,5 +1,6 @@ #include "GameScene.h" #include "Config.h" +#include "EndGameScript.h" #include "MoveCameraManualyScript.h" #include "StartGameScript.h" @@ -66,6 +67,8 @@ void GameScene::load_scene() { GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); start_game_script.add_component().set_script(); + GameObject end_game_script = new_object("end_game_script", "script", vec2(0, 0)); + end_game_script.add_component().set_script().active = false; // zapper, laser and missile (below) for testing purpose only!!! GameObject zapper = new_object("zapper", "zapper", vec2(1000, 0)); diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 1a5d497..de53fc7 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -1,4 +1,5 @@ #include "PlayerScript.h" +#include "api/BehaviorScript.h" #include #include @@ -17,6 +18,8 @@ void PlayerScript::init() { bool PlayerScript::on_collision(const CollisionEvent & ev) { BehaviorScript & play_scr = this->get_components_by_name("player").front(); + BehaviorScript & end_scr + = this->get_components_by_name("end_game_script").front(); RefVector animators = this->get_components_by_name("player"); RefVector emitters = this->get_components_by_name("player"); @@ -32,6 +35,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { emitter.data.emission_rate = 0; } play_scr.active = false; + end_scr.active = true; return true; } else if (ev.info.other.metadata.tag == "laser") { for (Animator & anim : animators) { @@ -44,6 +48,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { emitter.data.emission_rate = 0; } play_scr.active = false; + end_scr.active = true; return true; } else if (ev.info.other.metadata.tag == "missile") { for (Animator & anim : animators) { @@ -56,6 +61,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { emitter.data.emission_rate = 0; } play_scr.active = false; + end_scr.active = true; return true; } -- cgit v1.2.3