From b445a1716a46dc875e0b2180c1a1b6022ec7a6d3 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 8 Jan 2025 14:10:27 +0100 Subject: missile/preview/schedular/PreviewScene --- game/preview/PrevPlayerScript.cpp | 132 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 game/preview/PrevPlayerScript.cpp (limited to 'game/preview/PrevPlayerScript.cpp') diff --git a/game/preview/PrevPlayerScript.cpp b/game/preview/PrevPlayerScript.cpp new file mode 100644 index 0000000..2657b8d --- /dev/null +++ b/game/preview/PrevPlayerScript.cpp @@ -0,0 +1,132 @@ +#include "PrevPlayerScript.h" + +#include "../missile/SpawnEvent.h" +#include "api/Transform.h" +#include +#include +#include +#include +#include + +using namespace crepe; + +bool PrevPlayerScript::key_pressed(const KeyPressEvent & ev) { + switch (ev.key) { + case Keycode::A: + this->get_component().data.linear_velocity.x = -move_speed; + this->body->data.flip = {true, false}; + this->head->data.flip = {true, false}; + break; + case Keycode::D: + this->get_component().data.linear_velocity.x = move_speed; + this->body->data.flip = {false, false}; + this->head->data.flip = {false, false}; + break; + + case Keycode::SPACE: + this->get_component().data.linear_velocity.y = -move_speed; + break; + case Keycode::D0: + this->body_anim->set_anim(0); + this->head_anim->set_anim(0); + break; + case Keycode::D1: + this->body_anim->set_anim(1); + this->head_anim->set_anim(1); + break; + case Keycode::D2: + this->body_anim->set_anim(2); + this->head_anim->set_anim(2); + break; + case Keycode::D3: + this->body_anim->set_anim(3); + this->head_anim->set_anim(3); + break; + case Keycode::D4: + this->body_anim->set_anim(4); + this->head_anim->set_anim(4); + break; + case Keycode::D5: + this->body_anim->set_anim(5); + this->head_anim->set_anim(5); + break; + case Keycode::D6: + this->body_anim->set_anim(6); + this->head_anim->set_anim(6); + break; + case Keycode::D7: + this->body_anim->set_anim(7); + this->head_anim->set_anim(7); + break; + case Keycode::LEFT: + this->head->data.angle_offset -= 1; + break; + case Keycode::RIGHT: + this->head->data.angle_offset += 1; + break; + case Keycode::UP: + this->head->data.scale_offset += 0.1; + break; + case Keycode::DOWN: + this->head->data.scale_offset -= 0.1; + break; + case Keycode::P: + this->get_component().play(); + break; + case Keycode::Q: + this->get_components_by_name("camera").front().get().data.zoom -= 0.01; + break; + case Keycode::E: + this->get_components_by_name("camera").front().get().data.zoom += 0.01; + break; + case Keycode::J: + this->get_components_by_name("camera").front().get().position.x + -= move_speed; + break; + case Keycode::K: + this->get_components_by_name("camera").front().get().position.y + -= move_speed; + break; + case Keycode::L: + this->get_components_by_name("camera").front().get().position.x + += move_speed; + break; + case Keycode::I: + this->get_components_by_name("camera").front().get().position.y + += move_speed; + break; + case Keycode::M: + trigger_event(MissileSpawnEvent {}); + break; + //todo + case Keycode::PAGE_UP: + case Keycode::PAGE_DOWN: + case Keycode::HOME: + break; + default: + break; + } + return false; +} + +void PrevPlayerScript::init() { + auto animations = this->get_components(); + body_anim = animations[0]; + head_anim = animations[1]; + + auto sprites = this->get_components(); + body = sprites[0]; + head = sprites[1]; + + subscribe([this](const KeyPressEvent & ev) -> bool { + return this->key_pressed(ev); + }); +}; + +void PrevPlayerScript::fixed_update(crepe::duration_t dt) { + auto & savemgr = this->get_save_manager(); + const auto & pos = this->get_component().position; + + savemgr.set("player_x", pos.x); + savemgr.set("player_y", pos.y); +}; -- cgit v1.2.3 From c17a1ac94186a2de6ad30e9228a031fb08434e52 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 10 Jan 2025 19:32:25 +0100 Subject: tiny adjustments for preview scene --- game/PreviewScene.cpp | 2 +- game/preview/NpcSubScene.cpp | 2 +- game/preview/PrevPlayerScript.cpp | 18 ++++++------------ game/preview/PrevPlayerSubScene.cpp | 4 ++-- 4 files changed, 10 insertions(+), 16 deletions(-) (limited to 'game/preview/PrevPlayerScript.cpp') diff --git a/game/PreviewScene.cpp b/game/PreviewScene.cpp index ae43225..1179ffc 100644 --- a/game/PreviewScene.cpp +++ b/game/PreviewScene.cpp @@ -81,7 +81,7 @@ void PreviewScene::load_scene() { GameObject world = this->new_object("world", "TAG", vec2 {0, 0}, 0, 1); world.add_component(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, - .collision_layer = COLL_LAY_BOT_TOP, + .collision_layer = 100, }); world.add_component(vec2(100,INFINITY), vec2(VIEWPORT_X,VIEWPORT_Y)); diff --git a/game/preview/NpcSubScene.cpp b/game/preview/NpcSubScene.cpp index a3781af..c9ab5b6 100644 --- a/game/preview/NpcSubScene.cpp +++ b/game/preview/NpcSubScene.cpp @@ -57,7 +57,7 @@ NpcSubScene::NpcSubScene(Scene & scn) { .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = {-50, 0}, //.max_linear_velocity = 40, - .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_PLAYER}, + .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_PLAYER, 100}, .collision_layer = COLL_LAY_PLAYER, }); diff --git a/game/preview/PrevPlayerScript.cpp b/game/preview/PrevPlayerScript.cpp index 2657b8d..3e6eed4 100644 --- a/game/preview/PrevPlayerScript.cpp +++ b/game/preview/PrevPlayerScript.cpp @@ -1,12 +1,11 @@ #include "PrevPlayerScript.h" #include "../missile/SpawnEvent.h" -#include "api/Transform.h" + +#include #include #include #include -#include -#include using namespace crepe; @@ -59,16 +58,16 @@ bool PrevPlayerScript::key_pressed(const KeyPressEvent & ev) { this->head_anim->set_anim(7); break; case Keycode::LEFT: - this->head->data.angle_offset -= 1; + this->get_component().rotation += 10; break; case Keycode::RIGHT: - this->head->data.angle_offset += 1; + this->get_component().rotation -= 10; break; case Keycode::UP: - this->head->data.scale_offset += 0.1; + this->head->data.position_offset += 10; break; case Keycode::DOWN: - this->head->data.scale_offset -= 0.1; + this->head->data.position_offset -= 10; break; case Keycode::P: this->get_component().play(); @@ -98,11 +97,6 @@ bool PrevPlayerScript::key_pressed(const KeyPressEvent & ev) { case Keycode::M: trigger_event(MissileSpawnEvent {}); break; - //todo - case Keycode::PAGE_UP: - case Keycode::PAGE_DOWN: - case Keycode::HOME: - break; default: break; } diff --git a/game/preview/PrevPlayerSubScene.cpp b/game/preview/PrevPlayerSubScene.cpp index 4351deb..3f5a5d5 100644 --- a/game/preview/PrevPlayerSubScene.cpp +++ b/game/preview/PrevPlayerSubScene.cpp @@ -71,10 +71,10 @@ PrevPlayerSubScene::PrevPlayerSubScene(Scene & scn) { } ); player.add_component(Rigidbody::Data { - .gravity_scale = 20, + .gravity_scale = 1, .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = vec2(100, 0), - .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layers = {COLL_LAY_BOT_TOP, 100}, .collision_layer = COLL_LAY_PLAYER, }); player.add_component(vec2(50, 50)); -- cgit v1.2.3 From 0b19fe5a9168368d4be0993407dd3fc3bdfa0611 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 10 Jan 2025 19:32:49 +0100 Subject: make format --- game/PreviewScene.cpp | 6 +++--- game/preview/PrevPlayerScript.cpp | 2 +- game/preview/PrevPlayerSubScene.cpp | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'game/preview/PrevPlayerScript.cpp') diff --git a/game/PreviewScene.cpp b/game/PreviewScene.cpp index 1179ffc..14a5560 100644 --- a/game/PreviewScene.cpp +++ b/game/PreviewScene.cpp @@ -77,15 +77,15 @@ void PreviewScene::load_scene() { .collision_layer = COLL_LAY_BOT_TOP, }); ceiling.add_component(vec2(INFINITY, 200)); - + GameObject world = this->new_object("world", "TAG", vec2 {0, 0}, 0, 1); world.add_component(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, .collision_layer = 100, }); - world.add_component(vec2(100,INFINITY), vec2(VIEWPORT_X,VIEWPORT_Y)); - world.add_component(vec2(100,INFINITY), vec2(100,VIEWPORT_Y)); + world.add_component(vec2(100, INFINITY), vec2(VIEWPORT_X, VIEWPORT_Y)); + world.add_component(vec2(100, INFINITY), vec2(100, VIEWPORT_Y)); PrevPlayerSubScene player(*this); NpcSubScene npc(*this); diff --git a/game/preview/PrevPlayerScript.cpp b/game/preview/PrevPlayerScript.cpp index 3e6eed4..fce5c5a 100644 --- a/game/preview/PrevPlayerScript.cpp +++ b/game/preview/PrevPlayerScript.cpp @@ -2,9 +2,9 @@ #include "../missile/SpawnEvent.h" -#include #include #include +#include #include using namespace crepe; diff --git a/game/preview/PrevPlayerSubScene.cpp b/game/preview/PrevPlayerSubScene.cpp index 3f5a5d5..9ff111c 100644 --- a/game/preview/PrevPlayerSubScene.cpp +++ b/game/preview/PrevPlayerSubScene.cpp @@ -17,8 +17,7 @@ using namespace crepe; PrevPlayerSubScene::PrevPlayerSubScene(Scene & scn) { - GameObject player - = scn.new_object("player", "player", vec2 {800 , -100}, 0, 1); + GameObject player = scn.new_object("player", "player", vec2 {800, -100}, 0, 1); Asset player_body_asset {"asset/barry/defaultBody.png"}; Sprite & player_body_sprite = player.add_component( player_body_asset, -- cgit v1.2.3