#include "CollisionScript.h" #include #include #include #include #include #include using namespace crepe; using namespace std; void CollisionScript::init() { subscribe([this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); }); } bool CollisionScript::on_collision(const CollisionEvent & ev) { RefVector animators = this->get_components(); RefVector sprites = this->get_components(); Rigidbody & rb = this->get_component(); Transform & tr = this->get_component(); BehaviorScript & bs_panic = this->get_components().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; }