]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
working linking, left/right
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 22 Oct 2016 22:40:40 +0000 (18:40 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 22 Oct 2016 22:40:40 +0000 (18:40 -0400)
include/player.hpp
include/world.hpp
src/engine.cpp
src/player.cpp
src/world.cpp
xml/!town.xml
xml/!town2.xml [new file with mode: 0644]

index 430173fe10fdee6d323e496ffa8692cc2d59083e..1caccc8e3ed574c94f27dacc6e282d50de2b1fce 100644 (file)
@@ -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;
index 36ccdfa05130f349384b3e327d5a972d9e70b6e1..1f54292253bfbc4759dbc89eb0f6887027e7d202 100644 (file)
@@ -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;
 
 /**
@@ -64,11 +64,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
@@ -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;
index f81312b5de54ca3c559f17d61b327c2717839636..54181c87dcd4ea0b231d32dd15bdf08867fada2a 100644 (file)
@@ -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)
index 912027ff434aa2ab2922161e8f0e82361cc9ad9f..fcbff1cda1792fcc6fdb4ec6f8cf81af55ab2c35 100644 (file)
@@ -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;
index 4b5bb2dad53f8602d2ffdc405ce4e89629242661..508e2acdf565f2c8349bbeca974c510153a0b86e 100644 (file)
@@ -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();
+       }
+}
index 0530762ff5662017d34e748ed664e2a0873e7895..69441f3a47f89b6359a81f00782b1744727ced57 100644 (file)
@@ -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 (file)
index 0000000..1282e4c
--- /dev/null
@@ -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>