From 80fc064c77bb61d9b329b58532c9cacd99038e0a Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 7 Jan 2025 13:21:09 +0100 Subject: First setup for NPCs --- game/workers/WorkersSubScene.cpp | 405 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 405 insertions(+) create mode 100644 game/workers/WorkersSubScene.cpp (limited to 'game/workers/WorkersSubScene.cpp') diff --git a/game/workers/WorkersSubScene.cpp b/game/workers/WorkersSubScene.cpp new file mode 100644 index 0000000..94d9848 --- /dev/null +++ b/game/workers/WorkersSubScene.cpp @@ -0,0 +1,405 @@ +#include "WorkersSubScene.h" +#include "WorkerScript.h" + +#include "../Config.h" +#include "api/GameObject.h" + +#include +#include +#include +#include +#include +#include + +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().set_script(); +} + +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( + Asset {"asset/workers/worker1Body.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 0, + .size = vec2(0, 50), + } + ); + worker_1.add_component( + worker_1_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_1_head_sprite = worker_1.add_component( + Asset {"asset/workers/worker1Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 1, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_1.add_component( + worker_1_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + worker_1.add_component(vec2(50, 50)); + worker_1.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_TOP}, + }); + + 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( + Asset {"asset/workers/worker2Body.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 2, + .size = vec2(0, 50), + } + ); + worker_2.add_component( + worker_2_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_2_head_sprite = worker_2.add_component( + Asset {"asset/workers/worker1Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 3, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_2.add_component( + worker_2_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + worker_2.add_component(vec2(50, 50)); + worker_2.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_TOP}, + }); + + 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( + Asset {"asset/workers/worker1Body.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 4, + .size = vec2(0, 50), + } + ); + worker_3.add_component( + worker_3_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_3_head_sprite = worker_3.add_component( + Asset {"asset/workers/worker2Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 5, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_3.add_component( + worker_3_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + worker_3.add_component(vec2(50, 50)); + worker_3.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_TOP}, + }); + + 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( + Asset {"asset/workers/worker2Body.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 6, + .size = vec2(0, 50), + } + ); + worker_4.add_component( + worker_4_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_4_head_sprite = worker_4.add_component( + Asset {"asset/workers/worker2Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 7, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_4.add_component( + worker_4_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + worker_4.add_component(vec2(50, 50)); + worker_4.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_HIGH}, + }); + + 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( + Asset {"asset/workers/workerFatBody.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 8, + .size = vec2(0, 50), + } + ); + worker_5.add_component( + worker_5_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_5_head_sprite = worker_5.add_component( + Asset {"asset/workers/worker1Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 9, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_5.add_component( + worker_5_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + worker_5.add_component(vec2(50, 50)); + worker_5.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_HIGH}, + }); + + 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( + Asset {"asset/workers/workerFatBody.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 10, + .size = vec2(0, 50), + } + ); + worker_6.add_component( + worker_6_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_6_head_sprite = worker_6.add_component( + Asset {"asset/workers/worker2Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 11, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_6.add_component( + worker_6_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + worker_6.add_component(vec2(50, 50)); + worker_6.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_LOW}, + }); + + 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( + Asset {"asset/workers/workerTallBody.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 12, + .size = vec2(0, 50), + } + ); + worker_7.add_component( + worker_7_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_7_head_sprite = worker_7.add_component( + Asset {"asset/workers/worker1Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 13, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_7.add_component( + worker_7_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + worker_7.add_component(vec2(50, 50)); + worker_7.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_LOW}, + }); + + 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( + Asset {"asset/workers/workerTallBody.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 14, + .size = vec2(0, 50), + } + ); + worker_8.add_component( + worker_8_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + Sprite & worker_8_head_sprite = worker_8.add_component( + Asset {"asset/workers/worker2Head.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_WORKERS, + .order_in_layer = 15, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + worker_8.add_component( + worker_8_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = static_cast(abs(init_speed) / 5), + .looping = true, + } + ); + worker_8.add_component(vec2(50, 50)); + worker_8.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(init_speed, 0), + .collision_layers = {COLL_LAY_BOT_LOW}, + }); + + if (init_speed < 0) { + worker_8_body_sprite.data.flip = Sprite::FlipSettings {true, false}; + worker_8_head_sprite.data.flip = Sprite::FlipSettings {true, false}; + } +} -- cgit v1.2.3 From 1f0edff951e7580163d8c987d4a021b24d45e9f1 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 7 Jan 2025 14:34:12 +0100 Subject: Added panic from player --- game/CMakeLists.txt | 1 + game/workers/PanicFromPlayer.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ game/workers/PanicFromPlayer.h | 8 +++++++ game/workers/WorkerScript.cpp | 10 +++++++++ game/workers/WorkersSubScene.cpp | 9 ++++++++ 5 files changed, 73 insertions(+) create mode 100644 game/workers/PanicFromPlayer.cpp create mode 100644 game/workers/PanicFromPlayer.h (limited to 'game/workers/WorkersSubScene.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 8a63bd0..dc6a3fd 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -24,6 +24,7 @@ add_executable(main background/StartSubScene.cpp workers/WorkersSubScene.cpp workers/WorkerScript.cpp + workers/PanicFromPlayer.cpp main.cpp ) diff --git a/game/workers/PanicFromPlayer.cpp b/game/workers/PanicFromPlayer.cpp new file mode 100644 index 0000000..fbf4611 --- /dev/null +++ b/game/workers/PanicFromPlayer.cpp @@ -0,0 +1,45 @@ +#include "PanicFromPlayer.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +void PanicFromPlayer::fixed_update(duration_t dt) { + Animator & anim_player = this->get_components_by_name("player").front(); + + if (anim_player.data.col == 1) { + Transform & trans_player = this->get_components_by_name("player").back(); + Transform & trans_worker = this->get_components().back(); + + float result_x = trans_player.position.x - trans_worker.position.x; + + if (result_x < 100 && result_x > -20) { + RefVector anim_worker = this->get_components(); + RefVector sprite_worker = this->get_components(); + Rigidbody & rb_worker = this->get_components().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) { + rb_worker.data.linear_velocity.x = 10000 * dt.count(); + sprite_worker.front().get().data.flip.flip_x = false; + sprite_worker.back().get().data.flip.flip_x = false; + } else { + rb_worker.data.linear_velocity.x = -5000 * 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/PanicFromPlayer.h b/game/workers/PanicFromPlayer.h new file mode 100644 index 0000000..804df5c --- /dev/null +++ b/game/workers/PanicFromPlayer.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +class PanicFromPlayer : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/workers/WorkerScript.cpp b/game/workers/WorkerScript.cpp index d641c6a..1bcf8d5 100644 --- a/game/workers/WorkerScript.cpp +++ b/game/workers/WorkerScript.cpp @@ -53,6 +53,8 @@ void WorkerScript::fixed_update(duration_t dt) { = -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); } else { sprite_worker.front().get().data.flip.flip_x = false; sprite_worker.back().get().data.flip.flip_x = false; @@ -61,6 +63,8 @@ void WorkerScript::fixed_update(duration_t dt) { = 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); } } } else { @@ -89,6 +93,9 @@ void WorkerScript::fixed_update(duration_t dt) { = -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); } else { sprite_worker.front().get().data.flip.flip_x = false; sprite_worker.back().get().data.flip.flip_x = false; @@ -97,6 +104,9 @@ void WorkerScript::fixed_update(duration_t dt) { = 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); } } } diff --git a/game/workers/WorkersSubScene.cpp b/game/workers/WorkersSubScene.cpp index 94d9848..5b070f8 100644 --- a/game/workers/WorkersSubScene.cpp +++ b/game/workers/WorkersSubScene.cpp @@ -1,4 +1,5 @@ #include "WorkersSubScene.h" +#include "PanicFromPlayer.h" #include "WorkerScript.h" #include "../Config.h" @@ -68,6 +69,7 @@ void WorkersSubScene::worker1(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_TOP}, }); + worker_1.add_component().set_script(); if (init_speed < 0) { worker_1_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -115,6 +117,7 @@ void WorkersSubScene::worker2(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_TOP}, }); + worker_2.add_component().set_script(); if (init_speed < 0) { worker_2_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -162,6 +165,7 @@ void WorkersSubScene::worker3(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_TOP}, }); + worker_3.add_component().set_script(); if (init_speed < 0) { worker_3_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -209,6 +213,7 @@ void WorkersSubScene::worker4(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_HIGH}, }); + worker_4.add_component().set_script(); if (init_speed < 0) { worker_4_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -256,6 +261,7 @@ void WorkersSubScene::worker5(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_HIGH}, }); + worker_5.add_component().set_script(); if (init_speed < 0) { worker_5_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -303,6 +309,7 @@ void WorkersSubScene::worker6(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_LOW}, }); + worker_6.add_component().set_script(); if (init_speed < 0) { worker_6_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -350,6 +357,7 @@ void WorkersSubScene::worker7(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_LOW}, }); + worker_7.add_component().set_script(); if (init_speed < 0) { worker_7_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -397,6 +405,7 @@ void WorkersSubScene::worker8(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_LOW}, }); + worker_8.add_component().set_script(); if (init_speed < 0) { worker_8_body_sprite.data.flip = Sprite::FlipSettings {true, false}; -- cgit v1.2.3 From f31bd86ae5d7df21b788a273d4f2e530136ec184 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 7 Jan 2025 14:42:11 +0100 Subject: Added Script suffix --- game/CMakeLists.txt | 2 +- game/workers/PanicFromPlayer.cpp | 45 ---------------------------------- game/workers/PanicFromPlayer.h | 8 ------ game/workers/PanicFromPlayerScript.cpp | 45 ++++++++++++++++++++++++++++++++++ game/workers/PanicFromPlayerScript.h | 8 ++++++ game/workers/WorkersSubScene.cpp | 18 +++++++------- 6 files changed, 63 insertions(+), 63 deletions(-) delete mode 100644 game/workers/PanicFromPlayer.cpp delete mode 100644 game/workers/PanicFromPlayer.h create mode 100644 game/workers/PanicFromPlayerScript.cpp create mode 100644 game/workers/PanicFromPlayerScript.h (limited to 'game/workers/WorkersSubScene.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index dc6a3fd..0fb2424 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -24,7 +24,7 @@ add_executable(main background/StartSubScene.cpp workers/WorkersSubScene.cpp workers/WorkerScript.cpp - workers/PanicFromPlayer.cpp + workers/PanicFromPlayerScript.cpp main.cpp ) diff --git a/game/workers/PanicFromPlayer.cpp b/game/workers/PanicFromPlayer.cpp deleted file mode 100644 index fbf4611..0000000 --- a/game/workers/PanicFromPlayer.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "PanicFromPlayer.h" - -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -void PanicFromPlayer::fixed_update(duration_t dt) { - Animator & anim_player = this->get_components_by_name("player").front(); - - if (anim_player.data.col == 1) { - Transform & trans_player = this->get_components_by_name("player").back(); - Transform & trans_worker = this->get_components().back(); - - float result_x = trans_player.position.x - trans_worker.position.x; - - if (result_x < 100 && result_x > -20) { - RefVector anim_worker = this->get_components(); - RefVector sprite_worker = this->get_components(); - Rigidbody & rb_worker = this->get_components().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) { - rb_worker.data.linear_velocity.x = 10000 * dt.count(); - sprite_worker.front().get().data.flip.flip_x = false; - sprite_worker.back().get().data.flip.flip_x = false; - } else { - rb_worker.data.linear_velocity.x = -5000 * 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/PanicFromPlayer.h b/game/workers/PanicFromPlayer.h deleted file mode 100644 index 804df5c..0000000 --- a/game/workers/PanicFromPlayer.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -class PanicFromPlayer : public crepe::Script { -public: - void fixed_update(crepe::duration_t dt); -}; diff --git a/game/workers/PanicFromPlayerScript.cpp b/game/workers/PanicFromPlayerScript.cpp new file mode 100644 index 0000000..1e49aaa --- /dev/null +++ b/game/workers/PanicFromPlayerScript.cpp @@ -0,0 +1,45 @@ +#include "PanicFromPlayerScript.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +void PanicFromPlayerScript::fixed_update(duration_t dt) { + Animator & anim_player = this->get_components_by_name("player").front(); + + if (anim_player.data.col == 1) { + Transform & trans_player = this->get_components_by_name("player").back(); + Transform & trans_worker = this->get_components().back(); + + float result_x = trans_player.position.x - trans_worker.position.x; + + if (result_x < 100 && result_x > -20) { + RefVector anim_worker = this->get_components(); + RefVector sprite_worker = this->get_components(); + Rigidbody & rb_worker = this->get_components().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) { + rb_worker.data.linear_velocity.x = 10000 * dt.count(); + sprite_worker.front().get().data.flip.flip_x = false; + sprite_worker.back().get().data.flip.flip_x = false; + } else { + rb_worker.data.linear_velocity.x = -5000 * 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 + +class PanicFromPlayerScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/workers/WorkersSubScene.cpp b/game/workers/WorkersSubScene.cpp index 5b070f8..e5b4678 100644 --- a/game/workers/WorkersSubScene.cpp +++ b/game/workers/WorkersSubScene.cpp @@ -1,5 +1,5 @@ #include "WorkersSubScene.h" -#include "PanicFromPlayer.h" +#include "PanicFromPlayerScript.h" #include "WorkerScript.h" #include "../Config.h" @@ -69,7 +69,7 @@ void WorkersSubScene::worker1(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_TOP}, }); - worker_1.add_component().set_script(); + worker_1.add_component().set_script(); if (init_speed < 0) { worker_1_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -117,7 +117,7 @@ void WorkersSubScene::worker2(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_TOP}, }); - worker_2.add_component().set_script(); + worker_2.add_component().set_script(); if (init_speed < 0) { worker_2_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -165,7 +165,7 @@ void WorkersSubScene::worker3(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_TOP}, }); - worker_3.add_component().set_script(); + worker_3.add_component().set_script(); if (init_speed < 0) { worker_3_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -213,7 +213,7 @@ void WorkersSubScene::worker4(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_HIGH}, }); - worker_4.add_component().set_script(); + worker_4.add_component().set_script(); if (init_speed < 0) { worker_4_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -261,7 +261,7 @@ void WorkersSubScene::worker5(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_HIGH}, }); - worker_5.add_component().set_script(); + worker_5.add_component().set_script(); if (init_speed < 0) { worker_5_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -309,7 +309,7 @@ void WorkersSubScene::worker6(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_LOW}, }); - worker_6.add_component().set_script(); + worker_6.add_component().set_script(); if (init_speed < 0) { worker_6_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -357,7 +357,7 @@ void WorkersSubScene::worker7(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_LOW}, }); - worker_7.add_component().set_script(); + worker_7.add_component().set_script(); if (init_speed < 0) { worker_7_body_sprite.data.flip = Sprite::FlipSettings {true, false}; @@ -405,7 +405,7 @@ void WorkersSubScene::worker8(crepe::Scene & scn, float start_x, float init_spee .linear_velocity = vec2(init_speed, 0), .collision_layers = {COLL_LAY_BOT_LOW}, }); - worker_8.add_component().set_script(); + worker_8.add_component().set_script(); if (init_speed < 0) { worker_8_body_sprite.data.flip = Sprite::FlipSettings {true, false}; -- cgit v1.2.3