aboutsummaryrefslogtreecommitdiff
path: root/src/example/StartGameScript.cpp
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-19 11:21:37 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-19 11:21:37 +0100
commitea970a901d169824a99a336eacd06ebc032e5f66 (patch)
tree6f939f3a3a9593c0c4cceacd202665f83b7073f6 /src/example/StartGameScript.cpp
parentedd5fd83f4a5337ba06955bd59a136f7eb699234 (diff)
Moved scripts to seperate files
Diffstat (limited to 'src/example/StartGameScript.cpp')
-rw-r--r--src/example/StartGameScript.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/example/StartGameScript.cpp b/src/example/StartGameScript.cpp
new file mode 100644
index 0000000..00f419d
--- /dev/null
+++ b/src/example/StartGameScript.cpp
@@ -0,0 +1,61 @@
+#include "StartGameScript.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/ParticleEmitter.h>
+#include <crepe/api/Sprite.h>
+
+using namespace crepe;
+using namespace std;
+
+void StartGameScript::update() {
+ Transform & player_transform = this->get_components_by_name<Transform>("player").front();
+
+ // Create hole in wall and activate panic lamp
+ if (player_transform.position.x > 75 && !this->created_hole) {
+ Sprite & lamp_sprite = this->get_components_by_name<Sprite>("start_end").back();
+ lamp_sprite.active = true;
+ Sprite & hole_sprite = this->get_components_by_name<Sprite>("start_hole").front();
+ hole_sprite.active = true;
+
+ RefVector<Rigidbody> frags_rg
+ = this->get_components_by_tag<Rigidbody>("wall_fragment");
+ RefVector<Sprite> frags_sprite = this->get_components_by_tag<Sprite>("wall_fragment");
+ for (Rigidbody & frag_rg : frags_rg) {
+ frag_rg.active = true;
+ }
+ for (Sprite & frag_sprite : frags_sprite) {
+ frag_sprite.active = true;
+ }
+
+ RefVector<ParticleEmitter> smoke_emitters
+ = this->get_components_by_name<ParticleEmitter>("smoke_particles");
+ for (ParticleEmitter & emitter : smoke_emitters) {
+ emitter.active = true;
+ }
+
+ this->created_hole = true;
+ }
+
+ // Take jetpack from jetpack stand
+ if (player_transform.position.x > 275 && !this->took_jetpack) {
+ Animator & jetpack_stand_anim
+ = this->get_components_by_name<Animator>("start_begin").back();
+ jetpack_stand_anim.next_anim();
+ Sprite & jetpack_sprite = this->get_components_by_name<Sprite>("player").back();
+ jetpack_sprite.active = true;
+
+ this->took_jetpack = true;
+ }
+
+ // Start camera movement, enable player jumping and disable this script
+ if (player_transform.position.x > 500) {
+ Rigidbody & rb = this->get_components_by_name<Rigidbody>("camera").front();
+ rb.data.linear_velocity = vec2(100, 0);
+ BehaviorScript & player_script
+ = this->get_components_by_name<BehaviorScript>("player").front();
+ player_script.active = true;
+ BehaviorScript & this_script
+ = this->get_components_by_name<BehaviorScript>("start_game_script").front();
+ this_script.active = false;
+ }
+}