diff options
author | heavydemon21 <48092678+heavydemon21@users.noreply.github.com> | 2025-01-10 20:08:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-10 20:08:37 +0100 |
commit | ba0db2e49ff1b5c3e952c00bbc3f31176397f6b6 (patch) | |
tree | eefa561b81c48549277950692fdad714a2f501f2 /game/preview | |
parent | b9d00961a8894356c7cff7597de424a12d2841a6 (diff) | |
parent | 16917357837916d1ef88b6122218fa0d567d1ddc (diff) |
Merge pull request #131 from lonkaars/niels/game
Niels/game
Diffstat (limited to 'game/preview')
-rw-r--r-- | game/preview/NpcScript.cpp | 9 | ||||
-rw-r--r-- | game/preview/NpcScript.h | 5 | ||||
-rw-r--r-- | game/preview/NpcSubScene.cpp | 8 | ||||
-rw-r--r-- | game/preview/PrevPlayerScript.cpp | 18 | ||||
-rw-r--r-- | game/preview/PrevPlayerSubScene.cpp | 11 |
5 files changed, 14 insertions, 37 deletions
diff --git a/game/preview/NpcScript.cpp b/game/preview/NpcScript.cpp index c4148f2..5a93c2b 100644 --- a/game/preview/NpcScript.cpp +++ b/game/preview/NpcScript.cpp @@ -7,16 +7,15 @@ using namespace std; using namespace crepe; -void NpcScript::init() {} void NpcScript::fixed_update(duration_t dt) { auto & rb = this->get_component<Rigidbody>(); auto & npc = this->get_component<Sprite>(); auto & transform = this->get_component<Transform>(); - if (transform.position.x < -990) { + if (transform.position.x < 200) { rb.data.linear_velocity.x *= -1; } - if (transform.position.x > 990) { + if (transform.position.x > 700) { rb.data.linear_velocity.x *= -1; } @@ -25,8 +24,4 @@ void NpcScript::fixed_update(duration_t dt) { } else { npc.data.flip = {false, false}; } - - auto & savemgr = this->get_save_manager(); - savemgr.set("npc_x", transform.position.x); - savemgr.set("npc_y", transform.position.y); } diff --git a/game/preview/NpcScript.h b/game/preview/NpcScript.h index 8d856fd..d278f83 100644 --- a/game/preview/NpcScript.h +++ b/game/preview/NpcScript.h @@ -1,11 +1,8 @@ +#pragma once #include <crepe/api/Script.h> class NpcScript : public crepe::Script { - -private: - public: - void init(); void fixed_update(crepe::duration_t dt); }; diff --git a/game/preview/NpcSubScene.cpp b/game/preview/NpcSubScene.cpp index bd6cfb2..c9ab5b6 100644 --- a/game/preview/NpcSubScene.cpp +++ b/game/preview/NpcSubScene.cpp @@ -15,11 +15,7 @@ using namespace crepe; NpcSubScene::NpcSubScene(Scene & scn) { - auto & savemgr = scn.get_save_manager(); - ValueBroker npc_x = savemgr.get<float>("npc_x", 500); - ValueBroker npc_y = savemgr.get<float>("npc_y", 0); - - GameObject npc = scn.new_object("npc", "npc_tag", vec2 {npc_x.get(), npc_y.get()}, 0, 1); + GameObject npc = scn.new_object("npc", "npc_tag", vec2 {500, 0}, 0, 1); Asset npc_body {"asset/workers/worker1Body.png"}; Asset npc_head {"asset/workers/worker1Head.png"}; @@ -61,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..fce5c5a 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 <crepe/api/AudioSource.h> #include <crepe/api/Camera.h> +#include <crepe/api/Transform.h> #include <crepe/manager/SaveManager.h> -#include <iostream> -#include <ostream> 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<Transform>().rotation += 10; break; case Keycode::RIGHT: - this->head->data.angle_offset += 1; + this->get_component<Transform>().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<AudioSource>().play(); @@ -98,11 +97,6 @@ bool PrevPlayerScript::key_pressed(const KeyPressEvent & ev) { case Keycode::M: trigger_event<MissileSpawnEvent>(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 b59a0af..9ff111c 100644 --- a/game/preview/PrevPlayerSubScene.cpp +++ b/game/preview/PrevPlayerSubScene.cpp @@ -16,13 +16,8 @@ using namespace crepe; PrevPlayerSubScene::PrevPlayerSubScene(Scene & scn) { - auto & savemgr = scn.get_save_manager(); - ValueBroker player_x = savemgr.get<float>("player_x", 500); - ValueBroker player_y = savemgr.get<float>("player_y", -100); - - GameObject player - = scn.new_object("player", "TAG", vec2 {player_x.get(), player_y.get()}, 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<Sprite>( player_body_asset, @@ -75,10 +70,10 @@ PrevPlayerSubScene::PrevPlayerSubScene(Scene & scn) { } ); player.add_component<Rigidbody>(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<BoxCollider>(vec2(50, 50)); |