aboutsummaryrefslogtreecommitdiff
path: root/game/workers/CollisionScript.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 12:17:36 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 12:17:36 +0100
commitdc5d46426b30303843e8746d514db6f55ce1495b (patch)
tree2b01a358b3daa4f55e54ca2c87f58becf83edeb8 /game/workers/CollisionScript.cpp
parent1a5744a3285a5ba5132fb4f6f031c27df1b64d33 (diff)
parentc9c9702edc58ff8f40b13dc6b86b216421f79e9b (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/enemyAI
Diffstat (limited to 'game/workers/CollisionScript.cpp')
-rw-r--r--game/workers/CollisionScript.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/game/workers/CollisionScript.cpp b/game/workers/CollisionScript.cpp
new file mode 100644
index 0000000..deaf0ee
--- /dev/null
+++ b/game/workers/CollisionScript.cpp
@@ -0,0 +1,68 @@
+#include "CollisionScript.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+#include <crepe/types.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<Animator>();
+ RefVector<Sprite> sprites = this->get_components<Sprite>();
+ Rigidbody & rb = this->get_component<Rigidbody>();
+ Transform & tr = this->get_component<Transform>();
+ BehaviorScript & bs_panic = this->get_components<BehaviorScript>().front();
+
+ if (ev.info.other.metadata.tag == "zapper") {
+ for (Animator & anim : animators) {
+ anim.active = false;
+ anim.set_anim(3);
+ }
+ for (Sprite & sprite : sprites) {
+ sprite.data.position_offset.x = 15;
+ }
+ rb.data.linear_velocity_coefficient = {0.5, 0.5};
+ tr.rotation = 90;
+ bs_panic.active = false;
+
+ return false;
+ } else if (ev.info.other.metadata.tag == "laser") {
+ for (Animator & anim : animators) {
+ anim.active = false;
+ anim.set_anim(3);
+ }
+ for (Sprite & sprite : sprites) {
+ sprite.data.position_offset.x = 15;
+ }
+ rb.data.linear_velocity_coefficient = {0.5, 0.5};
+ tr.rotation = 90;
+ bs_panic.active = false;
+
+ return false;
+ } else if (ev.info.other.metadata.tag == "missile") {
+ for (Animator & anim : animators) {
+ anim.active = false;
+ anim.set_anim(3);
+ }
+ for (Sprite & sprite : sprites) {
+ sprite.data.position_offset.x = 15;
+ }
+ rb.data.linear_velocity_coefficient = {0.5, 0.5};
+ tr.rotation = 90;
+ bs_panic.active = false;
+
+ return false;
+ }
+
+ return false;
+}