diff options
-rw-r--r-- | include/player.hpp | 2 | ||||
-rw-r--r-- | include/world.hpp | 11 | ||||
-rw-r--r-- | src/engine.cpp | 1 | ||||
-rw-r--r-- | src/player.cpp | 23 | ||||
-rw-r--r-- | src/world.cpp | 57 | ||||
-rw-r--r-- | xml/!town.xml | 1 | ||||
-rw-r--r-- | xml/!town2.xml | 7 |
7 files changed, 72 insertions, 30 deletions
diff --git a/include/player.hpp b/include/player.hpp index 430173f..1caccc8 100644 --- a/include/player.hpp +++ b/include/player.hpp @@ -5,6 +5,8 @@ #include <events.hpp> +constexpr const float PLAYER_SPEED_CONSTANT = 0.15f; + class PlayerSystem : public entityx::System<PlayerSystem>, public entityx::Receiver<PlayerSystem> { private: entityx::Entity::Id pid; diff --git a/include/world.hpp b/include/world.hpp index 36ccdfa..1f54292 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -9,10 +9,10 @@ // local game includes #include <common.hpp> #include <coolarray.hpp> - #include <events.hpp> #include <texture.hpp> #include <tinyxml2.h> +#include <components.hpp> using namespace tinyxml2; /** @@ -65,11 +65,6 @@ extern std::string currentXML; constexpr const unsigned int DAY_CYCLE = 10000; /** - * Defines the velocity of player when moved by the keyboard - */ -constexpr const float PLAYER_SPEED_CONSTANT = 0.15f; - -/** * Defines the strongest pull gravity can have on an entity. * This is the most that can be subtracted from an entity's velocity in one * game tick. @@ -165,8 +160,8 @@ public: void detect(entityx::TimeDelta dt); - void goWorldLeft(void) {} - void goWorldRight(void) {} + void goWorldLeft(Position& p); + void goWorldRight(Position& p); // worlddata2 stuff WorldData2 worldData; 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 912027f..fcbff1c 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 worldSwitch = [&](const WorldSwitchInfo& wsi){ player->canMove = false; @@ -101,27 +102,15 @@ void PlayerSystem::receive(const KeyDownEvent &kde) moveLeft = 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 = 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 4b5bb2d..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(); @@ -299,6 +302,27 @@ void WorldSystem::load(const std::string& file) game::time::setTickCount(std::stoi(wxml->GetText())); } + else if (tagName == "entity") { + auto str2coord = [](std::string s) -> vec2 { + auto cpos = s.find(','); + s[cpos] = '\0'; + return vec2 (std::stof(s), std::stof(s.substr(cpos + 1))); + }; + + auto entity = game::entities.create(); + + auto loc = wxml->Attribute("loc"); + if (loc != nullptr) { + auto locVec = str2coord(loc); + float locDat[2] = {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 /*else if (tagName == "hill") { addHill(ivec2 { wxml->IntAttribute("peakx"), wxml->IntAttribute("peaky") }, wxml->UnsignedAttribute("width")); @@ -930,13 +954,12 @@ void WorldSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, void WorldSystem::detect(entityx::TimeDelta dt) { - game::entities.each<Position, Direction, Health, Solid>( - [&](entityx::Entity e, Position &loc, Direction &vel, Health &health, Solid &dim) { - + game::entities.each<Position, Direction, Solid>( + [&](entityx::Entity e, Position &loc, Direction &vel, Solid &dim) { (void)e; - if (health.health <= 0) - UserError("die mofo"); + //if (health.health <= 0) + // UserError("die mofo"); // get the line the entity is on int line = std::clamp(static_cast<int>((loc.x + dim.width / 2 - world.startX) / game::HLINE), @@ -973,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(); + } +} diff --git a/xml/!town.xml b/xml/!town.xml index 0530762..69441f3 100644 --- a/xml/!town.xml +++ b/xml/!town.xml @@ -3,6 +3,7 @@ <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/> <generation width="1600"/> <time>6000</time> + <link right="!town2.xml" /> <spawnx>-300</spawnx> <npc name="Sanc" hasDialog="true"/> <npc name="Bob" hasDialog="true" spawnx="30"/> diff --git a/xml/!town2.xml b/xml/!town2.xml new file mode 100644 index 0000000..1282e4c --- /dev/null +++ b/xml/!town2.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<World> + <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/> + <generation width="600"/> + <time>6000</time> + <link left="!town.xml" /> +</World> |