diff options
Diffstat (limited to 'game/workers')
-rw-r--r-- | game/workers/CollisionScript.cpp | 69 | ||||
-rw-r--r-- | game/workers/CollisionScript.h | 12 | ||||
-rw-r--r-- | game/workers/PanicFromPlayerScript.cpp | 55 | ||||
-rw-r--r-- | game/workers/PanicFromPlayerScript.h | 8 | ||||
-rw-r--r-- | game/workers/WorkerScript.cpp | 145 | ||||
-rw-r--r-- | game/workers/WorkerScript.h | 8 | ||||
-rw-r--r-- | game/workers/WorkersSubScene.cpp | 423 | ||||
-rw-r--r-- | game/workers/WorkersSubScene.h | 20 |
8 files changed, 740 insertions, 0 deletions
diff --git a/game/workers/CollisionScript.cpp b/game/workers/CollisionScript.cpp new file mode 100644 index 0000000..372bfec --- /dev/null +++ b/game/workers/CollisionScript.cpp @@ -0,0 +1,69 @@ +#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" + || ev.info.other.metadata.tag == "enemy_bullet") { + 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; +} diff --git a/game/workers/CollisionScript.h b/game/workers/CollisionScript.h new file mode 100644 index 0000000..70c5fe1 --- /dev/null +++ b/game/workers/CollisionScript.h @@ -0,0 +1,12 @@ +#pragma once + +#include <crepe/api/Event.h> +#include <crepe/api/Script.h> + +class CollisionScript : public crepe::Script { +public: + void init(); + +private: + bool on_collision(const crepe::CollisionEvent & ev); +}; diff --git a/game/workers/PanicFromPlayerScript.cpp b/game/workers/PanicFromPlayerScript.cpp new file mode 100644 index 0000000..baa48df --- /dev/null +++ b/game/workers/PanicFromPlayerScript.cpp @@ -0,0 +1,55 @@ +#include "PanicFromPlayerScript.h" + +#include <crepe/api/Animator.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 PanicFromPlayerScript::fixed_update(duration_t dt) { + Animator & anim_player = this->get_components_by_name<Animator>("player").front(); + + if (anim_player.data.col == 1) { + Transform & trans_player = this->get_components_by_name<Transform>("player").back(); + Transform & trans_worker = this->get_components<Transform>().back(); + + float result_x = trans_player.position.x - trans_worker.position.x; + + if (result_x < 100 && result_x > -20) { + RefVector<Animator> anim_worker = this->get_components<Animator>(); + RefVector<Sprite> sprite_worker = this->get_components<Sprite>(); + Rigidbody & rb_worker = this->get_components<Rigidbody>().back(); + + if (anim_worker.front().get().data.col != 1) { + anim_worker.front().get().set_anim(1); + anim_worker.back().get().set_anim(1); + + anim_worker.front().get().data.fps = 10; + anim_worker.back().get().data.fps = 10; + } + + if (result_x < 0) { + float min_value = 8000; + float max_value = 10000; + float value = min_value + + static_cast<float>(rand()) + / (static_cast<float>(RAND_MAX / (max_value - min_value))); + rb_worker.data.linear_velocity.x = value * dt.count(); + sprite_worker.front().get().data.flip.flip_x = false; + sprite_worker.back().get().data.flip.flip_x = false; + } else { + float min_value = -4000; + float max_value = -5000; + float value = min_value + + static_cast<float>(rand()) + / (static_cast<float>(RAND_MAX / (max_value - min_value))); + rb_worker.data.linear_velocity.x = value * dt.count(); + sprite_worker.front().get().data.flip.flip_x = true; + sprite_worker.back().get().data.flip.flip_x = true; + } + } + } +}; diff --git a/game/workers/PanicFromPlayerScript.h b/game/workers/PanicFromPlayerScript.h new file mode 100644 index 0000000..d173e89 --- /dev/null +++ b/game/workers/PanicFromPlayerScript.h @@ -0,0 +1,8 @@ +#pragma once + +#include <crepe/api/Script.h> + +class PanicFromPlayerScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/workers/WorkerScript.cpp b/game/workers/WorkerScript.cpp new file mode 100644 index 0000000..b0bfc4e --- /dev/null +++ b/game/workers/WorkerScript.cpp @@ -0,0 +1,145 @@ +#include "WorkerScript.h" + +#include "../Config.h" +#include "api/BehaviorScript.h" + +#include <crepe/api/Animator.h> +#include <crepe/api/Rigidbody.h> +#include <crepe/api/Sprite.h> +#include <crepe/api/Transform.h> +#include <crepe/types.h> +#include <cstdlib> + +using namespace crepe; +using namespace std; + +void WorkerScript::fixed_update(duration_t dt) { + RefVector<Rigidbody> rb_workers = this->get_components_by_tag<Rigidbody>("worker"); + RefVector<Transform> trans_workers = this->get_components_by_tag<Transform>("worker"); + + Rigidbody & rb_cam = this->get_components_by_name<Rigidbody>("camera").back(); + Transform & trans_cam = this->get_components_by_name<Transform>("camera").back(); + + int counter = 0; + for (Rigidbody & rb_worker : rb_workers) { + Transform & trans_worker = trans_workers.at(counter); + + float result_x = rb_cam.data.linear_velocity.x - rb_worker.data.linear_velocity.x; + + if (result_x > 0) { + float left_cam_pos_x = trans_cam.position.x - VIEWPORT_X / 2; + if (trans_worker.position.x < left_cam_pos_x - 1000) { + trans_worker.position.x = left_cam_pos_x + VIEWPORT_X + 1000; + + do { + float min_value = -2500 * dt.count(); + float max_value = 2500 * dt.count(); + rb_worker.data.linear_velocity.x + = min_value + + static_cast<float>(rand()) + / (static_cast<float>(RAND_MAX / (max_value - min_value))); + } while (rb_worker.data.linear_velocity.x < 500 * dt.count() + && rb_worker.data.linear_velocity.x > -500 * dt.count()); + + RefVector<Sprite> sprite_worker + = this->get_components_by_id<Sprite>(trans_worker.game_object_id); + RefVector<Animator> animator_worker + = this->get_components_by_id<Animator>(trans_worker.game_object_id); + BehaviorScript & bs_panic + = this->get_components_by_id<BehaviorScript>(trans_worker.game_object_id) + .front(); + + if (rb_worker.data.linear_velocity.x < 0) { + sprite_worker.front().get().data.flip.flip_x = true; + sprite_worker.back().get().data.flip.flip_x = true; + + animator_worker.front().get().data.fps + = -rb_worker.data.linear_velocity.x / 5; + animator_worker.back().get().data.fps + = -rb_worker.data.linear_velocity.x / 5; + animator_worker.front().get().set_anim(0); + animator_worker.back().get().set_anim(0); + animator_worker.front().get().active = true; + animator_worker.back().get().active = true; + } else { + sprite_worker.front().get().data.flip.flip_x = false; + sprite_worker.back().get().data.flip.flip_x = false; + + animator_worker.front().get().data.fps + = rb_worker.data.linear_velocity.x / 5; + animator_worker.back().get().data.fps + = rb_worker.data.linear_velocity.x / 5; + animator_worker.front().get().set_anim(0); + animator_worker.back().get().set_anim(0); + animator_worker.front().get().active = true; + animator_worker.back().get().active = true; + } + + trans_worker.rotation = 0; + bs_panic.active = true; + rb_worker.data.linear_velocity_coefficient = {1, 1}; + for (Sprite & sprite : sprite_worker) { + sprite.data.position_offset.x = 0; + } + } + } else { + float right_cam_pos_x = trans_cam.position.x + VIEWPORT_X / 2; + if (trans_worker.position.x > right_cam_pos_x + 1000) { + do { + float min_value = -2500 * dt.count(); + float max_value = 2500 * dt.count(); + rb_worker.data.linear_velocity.x + = min_value + + static_cast<float>(rand()) + / (static_cast<float>(RAND_MAX / (max_value - min_value))); + } while (rb_worker.data.linear_velocity.x < 500 * dt.count() + && rb_worker.data.linear_velocity.x > -500 * dt.count()); + + RefVector<Sprite> sprite_worker + = this->get_components_by_id<Sprite>(trans_worker.game_object_id); + RefVector<Animator> animator_worker + = this->get_components_by_id<Animator>(trans_worker.game_object_id); + BehaviorScript & bs_panic + = this->get_components_by_id<BehaviorScript>(trans_worker.game_object_id) + .front(); + + if (rb_worker.data.linear_velocity.x < 0) { + sprite_worker.front().get().data.flip.flip_x = true; + sprite_worker.back().get().data.flip.flip_x = true; + + animator_worker.front().get().data.fps + = -rb_worker.data.linear_velocity.x / 5; + animator_worker.back().get().data.fps + = -rb_worker.data.linear_velocity.x / 5; + + animator_worker.front().get().set_anim(0); + animator_worker.back().get().set_anim(0); + animator_worker.front().get().active = true; + animator_worker.back().get().active = true; + } else { + sprite_worker.front().get().data.flip.flip_x = false; + sprite_worker.back().get().data.flip.flip_x = false; + + animator_worker.front().get().data.fps + = rb_worker.data.linear_velocity.x / 5; + animator_worker.back().get().data.fps + = rb_worker.data.linear_velocity.x / 5; + + animator_worker.front().get().set_anim(0); + animator_worker.back().get().set_anim(0); + animator_worker.front().get().active = true; + animator_worker.back().get().active = true; + } + + trans_worker.rotation = 0; + bs_panic.active = true; + rb_worker.data.linear_velocity_coefficient = {1, 1}; + for (Sprite & sprite : sprite_worker) { + sprite.data.position_offset.x = 0; + } + } + } + + counter++; + } +} diff --git a/game/workers/WorkerScript.h b/game/workers/WorkerScript.h new file mode 100644 index 0000000..ae4a6c7 --- /dev/null +++ b/game/workers/WorkerScript.h @@ -0,0 +1,8 @@ +#pragma once + +#include <crepe/api/Script.h> + +class WorkerScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/workers/WorkersSubScene.cpp b/game/workers/WorkersSubScene.cpp new file mode 100644 index 0000000..54996d1 --- /dev/null +++ b/game/workers/WorkersSubScene.cpp @@ -0,0 +1,423 @@ +#include "WorkersSubScene.h" +#include "CollisionScript.h" +#include "PanicFromPlayerScript.h" +#include "WorkerScript.h" + +#include "../Config.h" +#include "api/GameObject.h" + +#include <crepe/api/Animator.h> +#include <crepe/api/BehaviorScript.h> +#include <crepe/api/BoxCollider.h> +#include <crepe/api/Rigidbody.h> +#include <crepe/api/Scene.h> +#include <crepe/api/Sprite.h> + +using namespace crepe; +using namespace std; + +WorkersSubScene::WorkersSubScene(Scene & scn) { + this->worker1(scn, 1200, -50); + this->worker2(scn, 1300, 20); + this->worker3(scn, 1400, -40); + this->worker4(scn, 7250, 50); + this->worker5(scn, 3400, -20); + this->worker6(scn, 2000, 30); + this->worker7(scn, 3725, 35); + this->worker8(scn, 2200, -15); + + GameObject script = scn.new_object("workers_script"); + script.add_component<BehaviorScript>().set_script<WorkerScript>(); +} + +void WorkersSubScene::worker1(crepe::Scene & scn, float start_x, float init_speed) { + GameObject worker_1 = scn.new_object("worker_1", "worker", vec2(start_x, 200)); + Sprite & worker_1_body_sprite = worker_1.add_component<Sprite>( + Asset {"asset/workers/worker1Body.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_BACK, + .order_in_layer = 0, + .size = vec2(0, 50), + } + ); + worker_1.add_component<Animator>( + worker_1_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_1_head_sprite = worker_1.add_component<Sprite>( + Asset {"asset/workers/worker1Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_BACK, + .order_in_layer = 1, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_1.add_component<Animator>( + worker_1_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + worker_1.add_component<BoxCollider>(vec2(50, 50)); + worker_1.add_component<Rigidbody>(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_TOP}, + }); + worker_1.add_component<BehaviorScript>().set_script<PanicFromPlayerScript>(); + worker_1.add_component<BehaviorScript>().set_script<CollisionScript>(); + + if (init_speed < 0) { + worker_1_body_sprite.data.flip = Sprite::FlipSettings {true, false}; + worker_1_head_sprite.data.flip = Sprite::FlipSettings {true, false}; + } +} + +void WorkersSubScene::worker2(crepe::Scene & scn, float start_x, float init_speed) { + GameObject worker_2 = scn.new_object("worker_2", "worker", vec2(start_x, 200)); + Sprite & worker_2_body_sprite = worker_2.add_component<Sprite>( + Asset {"asset/workers/worker2Body.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 2, + .size = vec2(0, 50), + } + ); + worker_2.add_component<Animator>( + worker_2_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_2_head_sprite = worker_2.add_component<Sprite>( + Asset {"asset/workers/worker1Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 3, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_2.add_component<Animator>( + worker_2_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + worker_2.add_component<BoxCollider>(vec2(50, 50)); + worker_2.add_component<Rigidbody>(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_TOP}, + }); + worker_2.add_component<BehaviorScript>().set_script<PanicFromPlayerScript>(); + worker_2.add_component<BehaviorScript>().set_script<CollisionScript>(); + + if (init_speed < 0) { + worker_2_body_sprite.data.flip = Sprite::FlipSettings {true, false}; + worker_2_head_sprite.data.flip = Sprite::FlipSettings {true, false}; + } +} + +void WorkersSubScene::worker3(crepe::Scene & scn, float start_x, float init_speed) { + GameObject worker_3 = scn.new_object("worker_3", "worker", vec2(start_x, 200)); + Sprite & worker_3_body_sprite = worker_3.add_component<Sprite>( + Asset {"asset/workers/worker1Body.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_BACK, + .order_in_layer = 4, + .size = vec2(0, 50), + } + ); + worker_3.add_component<Animator>( + worker_3_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_3_head_sprite = worker_3.add_component<Sprite>( + Asset {"asset/workers/worker2Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_BACK, + .order_in_layer = 5, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_3.add_component<Animator>( + worker_3_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + worker_3.add_component<BoxCollider>(vec2(50, 50)); + worker_3.add_component<Rigidbody>(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_TOP}, + }); + worker_3.add_component<BehaviorScript>().set_script<PanicFromPlayerScript>(); + worker_3.add_component<BehaviorScript>().set_script<CollisionScript>(); + + if (init_speed < 0) { + worker_3_body_sprite.data.flip = Sprite::FlipSettings {true, false}; + worker_3_head_sprite.data.flip = Sprite::FlipSettings {true, false}; + } +} + +void WorkersSubScene::worker4(crepe::Scene & scn, float start_x, float init_speed) { + GameObject worker_4 = scn.new_object("worker_4", "worker", vec2(start_x, 200)); + Sprite & worker_4_body_sprite = worker_4.add_component<Sprite>( + Asset {"asset/workers/worker2Body.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 6, + .size = vec2(0, 50), + } + ); + worker_4.add_component<Animator>( + worker_4_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_4_head_sprite = worker_4.add_component<Sprite>( + Asset {"asset/workers/worker2Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 7, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_4.add_component<Animator>( + worker_4_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + worker_4.add_component<BoxCollider>(vec2(50, 50)); + worker_4.add_component<Rigidbody>(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_HIGH}, + }); + worker_4.add_component<BehaviorScript>().set_script<PanicFromPlayerScript>(); + worker_4.add_component<BehaviorScript>().set_script<CollisionScript>(); + + if (init_speed < 0) { + worker_4_body_sprite.data.flip = Sprite::FlipSettings {true, false}; + worker_4_head_sprite.data.flip = Sprite::FlipSettings {true, false}; + } +} + +void WorkersSubScene::worker5(crepe::Scene & scn, float start_x, float init_speed) { + GameObject worker_5 = scn.new_object("worker_5", "worker", vec2(start_x, 200)); + Sprite & worker_5_body_sprite = worker_5.add_component<Sprite>( + Asset {"asset/workers/workerFatBody.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_BACK, + .order_in_layer = 8, + .size = vec2(0, 50), + } + ); + worker_5.add_component<Animator>( + worker_5_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_5_head_sprite = worker_5.add_component<Sprite>( + Asset {"asset/workers/worker1Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_BACK, + .order_in_layer = 9, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_5.add_component<Animator>( + worker_5_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + worker_5.add_component<BoxCollider>(vec2(50, 50)); + worker_5.add_component<Rigidbody>(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_HIGH}, + }); + worker_5.add_component<BehaviorScript>().set_script<PanicFromPlayerScript>(); + worker_5.add_component<BehaviorScript>().set_script<CollisionScript>(); + + if (init_speed < 0) { + worker_5_body_sprite.data.flip = Sprite::FlipSettings {true, false}; + worker_5_head_sprite.data.flip = Sprite::FlipSettings {true, false}; + } +} + +void WorkersSubScene::worker6(crepe::Scene & scn, float start_x, float init_speed) { + GameObject worker_6 = scn.new_object("worker_6", "worker", vec2(start_x, 200)); + Sprite & worker_6_body_sprite = worker_6.add_component<Sprite>( + Asset {"asset/workers/workerFatBody.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 10, + .size = vec2(0, 50), + } + ); + worker_6.add_component<Animator>( + worker_6_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_6_head_sprite = worker_6.add_component<Sprite>( + Asset {"asset/workers/worker2Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 11, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_6.add_component<Animator>( + worker_6_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + worker_6.add_component<BoxCollider>(vec2(50, 50)); + worker_6.add_component<Rigidbody>(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_LOW}, + }); + worker_6.add_component<BehaviorScript>().set_script<PanicFromPlayerScript>(); + worker_6.add_component<BehaviorScript>().set_script<CollisionScript>(); + + if (init_speed < 0) { + worker_6_body_sprite.data.flip = Sprite::FlipSettings {true, false}; + worker_6_head_sprite.data.flip = Sprite::FlipSettings {true, false}; + } +} + +void WorkersSubScene::worker7(crepe::Scene & scn, float start_x, float init_speed) { + GameObject worker_7 = scn.new_object("worker_7", "worker", vec2(start_x, 200)); + Sprite & worker_7_body_sprite = worker_7.add_component<Sprite>( + Asset {"asset/workers/workerTallBody.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_BACK, + .order_in_layer = 12, + .size = vec2(0, 50), + } + ); + worker_7.add_component<Animator>( + worker_7_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_7_head_sprite = worker_7.add_component<Sprite>( + Asset {"asset/workers/worker1Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_BACK, + .order_in_layer = 13, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_7.add_component<Animator>( + worker_7_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + worker_7.add_component<BoxCollider>(vec2(50, 50)); + worker_7.add_component<Rigidbody>(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_LOW}, + }); + worker_7.add_component<BehaviorScript>().set_script<PanicFromPlayerScript>(); + worker_7.add_component<BehaviorScript>().set_script<CollisionScript>(); + + if (init_speed < 0) { + worker_7_body_sprite.data.flip = Sprite::FlipSettings {true, false}; + worker_7_head_sprite.data.flip = Sprite::FlipSettings {true, false}; + } +} + +void WorkersSubScene::worker8(crepe::Scene & scn, float start_x, float init_speed) { + GameObject worker_8 = scn.new_object("worker_8", "worker", vec2(start_x, 200)); + Sprite & worker_8_body_sprite = worker_8.add_component<Sprite>( + Asset {"asset/workers/workerTallBody.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 14, + .size = vec2(0, 50), + } + ); + worker_8.add_component<Animator>( + worker_8_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_8_head_sprite = worker_8.add_component<Sprite>( + Asset {"asset/workers/worker2Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, + .order_in_layer = 15, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_8.add_component<Animator>( + worker_8_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast<unsigned int>(abs(init_speed) / 5), + .looping = true, + } + ); + worker_8.add_component<BoxCollider>(vec2(50, 50)); + worker_8.add_component<Rigidbody>(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_LOW}, + }); + worker_8.add_component<BehaviorScript>().set_script<PanicFromPlayerScript>(); + worker_8.add_component<BehaviorScript>().set_script<CollisionScript>(); + + if (init_speed < 0) { + worker_8_body_sprite.data.flip = Sprite::FlipSettings {true, false}; + worker_8_head_sprite.data.flip = Sprite::FlipSettings {true, false}; + } +} diff --git a/game/workers/WorkersSubScene.h b/game/workers/WorkersSubScene.h new file mode 100644 index 0000000..6692d87 --- /dev/null +++ b/game/workers/WorkersSubScene.h @@ -0,0 +1,20 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class WorkersSubScene { +public: + WorkersSubScene(crepe::Scene & scn); + +private: + void worker1(crepe::Scene & scn, float start_x, float init_speed); + void worker2(crepe::Scene & scn, float start_x, float init_speed); + void worker3(crepe::Scene & scn, float start_x, float init_speed); + void worker4(crepe::Scene & scn, float start_x, float init_speed); + void worker5(crepe::Scene & scn, float start_x, float init_speed); + void worker6(crepe::Scene & scn, float start_x, float init_speed); + void worker7(crepe::Scene & scn, float start_x, float init_speed); + void worker8(crepe::Scene & scn, float start_x, float init_speed); +}; |