aboutsummaryrefslogtreecommitdiff
path: root/game/workers/CollisionScript.cpp
diff options
context:
space:
mode:
authorMax-001 <maxsmits21@kpnmail.nl>2025-01-08 09:51:06 +0100
committerMax-001 <maxsmits21@kpnmail.nl>2025-01-08 09:51:06 +0100
commite9082de7d114ce024a884cac38c545c99de4026a (patch)
treead10395021fed08e8143ea40b42bc9784ed4dc4e /game/workers/CollisionScript.cpp
parentb8ff1dcd4e531c3c858ee09f705cf553e86ed7ff (diff)
Finnished collision
Diffstat (limited to 'game/workers/CollisionScript.cpp')
-rw-r--r--game/workers/CollisionScript.cpp48
1 files changed, 36 insertions, 12 deletions
diff --git a/game/workers/CollisionScript.cpp b/game/workers/CollisionScript.cpp
index baa058b..deaf0ee 100644
--- a/game/workers/CollisionScript.cpp
+++ b/game/workers/CollisionScript.cpp
@@ -1,6 +1,11 @@
#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;
@@ -13,31 +18,50 @@ void CollisionScript::init() {
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 = true;
- anim.set_anim(4);
- anim.data.looping = true;
+ 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 true;
+ return false;
} else if (ev.info.other.metadata.tag == "laser") {
for (Animator & anim : animators) {
- anim.active = true;
- anim.set_anim(4);
- anim.data.looping = true;
+ 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 true;
+ return false;
} else if (ev.info.other.metadata.tag == "missile") {
for (Animator & anim : animators) {
- anim.active = true;
- anim.set_anim(5);
- anim.data.looping = true;
+ 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 true;
+ return false;
}
return false;