diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 1 | ||||
-rw-r--r-- | src/player.cpp | 23 | ||||
-rw-r--r-- | src/world.cpp | 33 |
3 files changed, 39 insertions, 18 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index f81312b..54181c8 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -38,6 +38,7 @@ void Engine::render(entityx::TimeDelta dt) systems.update<RenderSystem>(dt); systems.update<WindowSystem>(dt); + ui::fadeUpdate(); } void Engine::update(entityx::TimeDelta dt) diff --git a/src/player.cpp b/src/player.cpp index 95a9c08..82de470 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -4,8 +4,8 @@ #include <engine.hpp> #include <ui.hpp> #include <gametime.hpp> - -constexpr const float PLAYER_SPEED_CONSTANT = 0.15f; +#include <world.hpp> +#include <components.hpp> void PlayerSystem::configure(entityx::EventManager &ev) { @@ -62,6 +62,7 @@ void PlayerSystem::receive(const KeyUpEvent &kue) void PlayerSystem::receive(const KeyDownEvent &kde) { auto kc = kde.keycode; + auto& loc = *game::entities.get(pid).component<Position>().get(); auto& faceLeft = game::entities.get(pid).component<Sprite>().get()->faceLeft; /*auto worldSwitch = [&](const WorldSwitchInfo& wsi){ @@ -102,27 +103,15 @@ void PlayerSystem::receive(const KeyDownEvent &kde) moveLeft = faceLeft = true; moveRight = false; - /*if (currentWorldToLeft) { - std::thread([&](void){ - auto thing = currentWorld->goWorldLeft(p); - if (thing.first != currentWorld) - worldSwitch(thing); - }).detach(); - }*/ + game::engine.getSystem<WorldSystem>()->goWorldLeft(loc); } } else if (kc == getControl(2)) { if (!ui::fadeEnable) { moveLeft = faceLeft = false; moveRight = true; - /*if (currentWorldToRight) { - std::thread([&](void){ - auto thing = currentWorld->goWorldRight(p); - if (thing.first != currentWorld) - worldSwitch(thing); - }).detach(); - }*/ - } + game::engine.getSystem<WorldSystem>()->goWorldRight(loc); + } } else if (kc == getControl(3)) { if (game::canSprint) speed = 2.0f; diff --git a/src/world.cpp b/src/world.cpp index 5f696b5..508e2ac 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -18,6 +18,7 @@ #include <render.hpp> #include <engine.hpp> #include <components.hpp> +#include <player.hpp> // local library headers #include <tinyxml2.h> @@ -236,6 +237,8 @@ void WorldSystem::load(const std::string& file) } } + world.toLeft = world.toRight = ""; + // iterate through tags while (wxml) { std::string tagName = wxml->Name(); @@ -312,8 +315,12 @@ void WorldSystem::load(const std::string& file) if (loc != nullptr) { auto locVec = str2coord(loc); float locDat[2] = {locVec.x, locVec.y}; - entity.assign<Position>(locVec.x, locVec.y); + entity.assign<Position>(locDat[0], locDat[1]); } + + unsigned int health; + if (wxml->QueryUnsignedAttribute("health", &health) != XML_NO_ERROR) + entity.assign<Health>(health, health); } // hill creation @@ -989,3 +996,27 @@ void WorldSystem::detect(entityx::TimeDelta dt) } }); } + +void WorldSystem::goWorldRight(Position& p) +{ + if (!(world.toRight.empty()) && (p.x > world.startX * -1 - HLINES(10))) { + ui::toggleBlack(); + ui::waitForCover(); + auto file = world.toRight; + load(file); + p.x = world.startX + HLINES(15); + ui::toggleBlack(); + } +} + +void WorldSystem::goWorldLeft(Position& p) +{ + if (!(world.toLeft.empty()) && (p.x < world.startX + HLINES(10))) { + ui::toggleBlack(); + ui::waitForCover(); + auto file = world.toLeft; + load(file); + p.x = world.startX * -1 - HLINES(15); + ui::toggleBlack(); + } +} |