aboutsummaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorMax-001 <maxsmits21@kpnmail.nl>2024-12-24 12:14:51 +0100
committerMax-001 <maxsmits21@kpnmail.nl>2024-12-24 12:14:51 +0100
commita0a3e7e2d12d3acb7bf4073cb5a10c08047cd08e (patch)
tree063137e04def88c0b3bb7404cf7630881a9c2f3e /game
parent192aea3112af0b36f6f26670e66c7e24926c579a (diff)
Added EndGameScript
Diffstat (limited to 'game')
-rw-r--r--game/CMakeLists.txt1
-rw-r--r--game/EndGameScript.cpp6
-rw-r--r--game/EndGameScript.h8
-rw-r--r--game/GameScene.cpp3
-rw-r--r--game/player/PlayerScript.cpp6
5 files changed, 24 insertions, 0 deletions
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 <crepe/api/Script.h>
+
+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<BehaviorScript>().set_script<StartGameScript>();
+ GameObject end_game_script = new_object("end_game_script", "script", vec2(0, 0));
+ end_game_script.add_component<BehaviorScript>().set_script<EndGameScript>().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 <crepe/api/Animator.h>
#include <crepe/api/ParticleEmitter.h>
@@ -17,6 +18,8 @@ void PlayerScript::init() {
bool PlayerScript::on_collision(const CollisionEvent & ev) {
BehaviorScript & play_scr = this->get_components_by_name<BehaviorScript>("player").front();
+ BehaviorScript & end_scr
+ = this->get_components_by_name<BehaviorScript>("end_game_script").front();
RefVector<Animator> animators = this->get_components_by_name<Animator>("player");
RefVector<ParticleEmitter> emitters
= this->get_components_by_name<ParticleEmitter>("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;
}