diff options
author | Max-001 <maxsmits21@kpnmail.nl> | 2025-01-08 08:57:19 +0100 |
---|---|---|
committer | Max-001 <maxsmits21@kpnmail.nl> | 2025-01-08 08:57:19 +0100 |
commit | 231d33954dab62e2452eb88e509d2741a8437498 (patch) | |
tree | e6cfea2dabc3d576894b4b413e93947a28cc917c /game | |
parent | 1a4dcd898138e6f1de5a8fbb6f0388f39b338189 (diff) |
Init
Diffstat (limited to 'game')
-rw-r--r-- | game/workers/CollisionScript.cpp | 62 | ||||
-rw-r--r-- | game/workers/CollisionScript.h | 12 |
2 files changed, 74 insertions, 0 deletions
diff --git a/game/workers/CollisionScript.cpp b/game/workers/CollisionScript.cpp new file mode 100644 index 0000000..9e9b981 --- /dev/null +++ b/game/workers/CollisionScript.cpp @@ -0,0 +1,62 @@ +#include "CollisionScript.h" + +#include <crepe/api/Animator.h> +#include <crepe/api/AudioSource.h> +#include <crepe/api/ParticleEmitter.h> + + +using namespace crepe; +using namespace std; + +void CollisionScript::init() { + subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool { + return this->on_collision(ev); + }); +} + +bool CollisionScript::on_collision(const CollisionEvent & ev) { + RefVector<Animator> animators = this->get_components_by_name<Animator>("player"); + RefVector<ParticleEmitter> emitters + = this->get_components_by_name<ParticleEmitter>("player"); + + if (ev.info.other.metadata.tag == "zapper") { + for (Animator & anim : animators) { + anim.active = true; + anim.set_anim(4); + anim.data.looping = true; + } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } + + return true; + } else if (ev.info.other.metadata.tag == "laser") { + for (Animator & anim : animators) { + anim.active = true; + anim.set_anim(4); + anim.data.looping = true; + } + for (ParticleEmitter & emitter : emitters) { + 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) { + anim.active = true; + anim.set_anim(5); + anim.data.looping = true; + } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } + play_scr.active = false; + end_scr.active = true; + + return true; + } + + return false; +} diff --git a/game/workers/CollisionScript.h b/game/workers/CollisionScript.h new file mode 100644 index 0000000..70c5fe1 --- /dev/null +++ b/game/workers/CollisionScript.h @@ -0,0 +1,12 @@ +#pragma once + +#include <crepe/api/Event.h> +#include <crepe/api/Script.h> + +class CollisionScript : public crepe::Script { +public: + void init(); + +private: + bool on_collision(const crepe::CollisionEvent & ev); +}; |