aboutsummaryrefslogtreecommitdiff
path: root/game/player
diff options
context:
space:
mode:
Diffstat (limited to 'game/player')
-rw-r--r--game/player/PlayerScript.cpp53
-rw-r--r--game/player/PlayerScript.h5
-rw-r--r--game/player/PlayerSubScene.cpp3
3 files changed, 60 insertions, 1 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
diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h
index dfd02eb..d8eb098 100644
--- a/game/player/PlayerScript.h
+++ b/game/player/PlayerScript.h
@@ -1,11 +1,16 @@
#pragma once
+#include <crepe/api/Event.h>
#include <crepe/api/Script.h>
class PlayerScript : public crepe::Script {
public:
+ void init();
void fixed_update(crepe::duration_t dt);
private:
+ bool on_collision(const crepe::CollisionEvent & ev);
+
+private:
int prev_anim = 0;
};
diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp
index ccf3d42..812d99a 100644
--- a/game/player/PlayerSubScene.cpp
+++ b/game/player/PlayerSubScene.cpp
@@ -143,7 +143,8 @@ PlayerSubScene::PlayerSubScene(Scene & scn) {
.gravity_scale = 20,
.body_type = Rigidbody::BodyType::DYNAMIC,
.linear_velocity = vec2(100, 0),
- .collision_layers = {COLL_LAY_BOT_TOP},
+ .collision_layers
+ = {COLL_LAY_BOT_TOP, COLL_LAY_ZAPPER, COLL_LAY_LASER, COLL_LAY_MISSILE},
.collision_layer = COLL_LAY_PLAYER,
});
player.add_component<BehaviorScript>().set_script<PlayerScript>().active = false;