diff options
author | Max-001 <maxsmits21@kpnmail.nl> | 2024-12-24 12:10:28 +0100 |
---|---|---|
committer | Max-001 <maxsmits21@kpnmail.nl> | 2024-12-24 12:10:28 +0100 |
commit | 192aea3112af0b36f6f26670e66c7e24926c579a (patch) | |
tree | ab7cf094850572d4f31e945d884339551cd8b08d /game/player/PlayerScript.cpp | |
parent | 46cc8767338578cbacb5a61bf50bbca71ea8e538 (diff) |
Added collision animations
Diffstat (limited to 'game/player/PlayerScript.cpp')
-rw-r--r-- | game/player/PlayerScript.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 04e7264..1a5d497 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -9,6 +9,59 @@ using namespace crepe; using namespace std; +void PlayerScript::init() { + subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool { + return this->on_collision(ev); + }); +} + +bool PlayerScript::on_collision(const CollisionEvent & ev) { + BehaviorScript & play_scr = this->get_components_by_name<BehaviorScript>("player").front(); + 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; + prev_anim = 0; + } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } + play_scr.active = false; + 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; + prev_anim = 0; + } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } + play_scr.active = false; + 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; + prev_anim = 0; + } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } + play_scr.active = false; + return true; + } + + return false; +} + void PlayerScript::fixed_update(crepe::duration_t dt) { RefVector<Animator> animators = this->get_components_by_name<Animator>("player"); RefVector<ParticleEmitter> emitters |