]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
names, jumping
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 28 Oct 2016 00:50:29 +0000 (20:50 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 28 Oct 2016 00:50:29 +0000 (20:50 -0400)
include/common.hpp
include/components.hpp
include/events.hpp
include/player.hpp
include/world.hpp
src/components.cpp
src/player.cpp
src/ui.cpp
src/world.cpp
xml/entities.xml

index d152bb7f1c84babeb0d839dc106747a72bcd9dd9..d13e397c446bcafbaa6a727238eda99341e925d6 100644 (file)
@@ -58,6 +58,12 @@ typedef unsigned int uint;
 
 #define BREAKPOINT __asm__("int $3")
 
+template<typename T>
+inline const T * const& coalesce(const T * const &p1, const T * const &p2)
+{
+       return ((p1 == nullptr) ? p2 : p1);
+}
+
 /**
  * Creates a coordinate of integers.
  */
index c0b711098153c4af204e1c88198b27ee87dc4a40..11953372e3236d4dd40293b10bfb4da2afa0e7c7 100644 (file)
@@ -81,6 +81,12 @@ struct Portal {
        std::string toFile;
 };
 
+struct Name {
+       Name(std::string n = "") : name(n) {}
+
+       std::string name;
+};
+
 /**
  * @struct Solid
  * @brief Allows an entity to collide with other objects.
index d98d52ae2b021765e6cc9b44316bd8f426eb8105..6a9bd8caf83e953bdc57a04a40e86421cd33907f 100644 (file)
@@ -16,7 +16,7 @@ struct MouseScrollEvent {
                : scrollDistance(sd) {}
 
        int scrollDistance;
- };
+};
 
 struct KeyDownEvent {
     KeyDownEvent(SDL_Keycode kc = 0)
index e196fa4feb8abe61116a2ac054ee3df23004f7ff..187e77e1296986dc933a31c29258e76f01617c54 100644 (file)
@@ -4,6 +4,7 @@
 #include <entityx/entityx.h>
 
 #include <events.hpp>
+#include <components.hpp>
 #include <common.hpp>
 
 constexpr const float PLAYER_SPEED_CONSTANT = 0.15f;
@@ -31,6 +32,8 @@ public:
     void receive(const KeyDownEvent&);
 
     vec2 getPosition(void) const;
+       inline void setX(const float& x)
+       { player.component<Position>().get()->x = x; }
 };
 
 #endif // PLAYER_HPP_
index fb0a5fac7ea8799100f88d689a23225288b8f771..421031c5619d1264e2ebe75d786acf2c172ab6a4 100644 (file)
@@ -166,7 +166,7 @@ public:
        void detect(entityx::TimeDelta dt);
 
        void goWorldLeft(Position& p);
-       void goWorldRight(Position& p);
+       void goWorldRight(Position& p, Solid &d);
        void goWorldPortal(Position& p);
 
        // worlddata2 stuff
index 45a931544bb724278fc3ffb9a7167126c1019a67..e00d474ad1f76eb42b87d683f35ac644cdff2f9a 100644 (file)
@@ -4,6 +4,7 @@
 #include <events.hpp>
 
 #include <render.hpp>
+#include <ui.hpp>
 #include <engine.hpp>
 
 void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
@@ -88,6 +89,12 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
 
        Render::worldShader.disable();
        Render::worldShader.unuse();
+
+       en.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) {
+               (void)e;
+               (void)v;
+               ui::putStringCentered(pos.x + dim.width / 2, pos.y - ui::fontSize - HLINES(0.5), name.name);
+       });
 }
 
 /*
index 37a958da1bbc7d0808cc4ede26d4241586014979..1bbfaeaab9ead5479b0b2dca0f726bf3024b2fc8 100644 (file)
@@ -5,7 +5,6 @@
 #include <ui.hpp>
 #include <gametime.hpp>
 #include <world.hpp>
-#include <components.hpp>
 
 void PlayerSystem::create(void)
 {
@@ -85,30 +84,14 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
 
        auto kc = kde.keycode;
        auto& loc = *player.component<Position>().get();
+       auto& vel = *player.component<Direction>().get();
     auto& faceLeft = player.component<Sprite>().get()->faceLeft;
 
-       /*if ((kc == SDLK_SPACE) && (game::canJump & p->ground)) {
-               p->loc.y += HLINES(2);
-               p->vel.y = .4;
-               p->ground = false;
-       }*/
-
-       if (!ui::dialogBoxExists || ui::dialogPassive) {
+       if ((kc == SDLK_SPACE) && game::canJump && ((vel.y > -0.01) & (vel.y < 0.01))) {
+               loc.y += HLINES(2);
+               vel.y = .4;
+       } else if (!ui::dialogBoxExists || ui::dialogPassive) {
                if (kc == getControl(0)) {
-                       /*if (inBattle) {
-                               std::thread([&](void){
-                                       auto thing = dynamic_cast<Arena *>(currentWorld)->exitArena(p);
-                                       if (thing.first != currentWorld)
-                                               worldSwitch(thing);
-                               }).detach();
-                       } else if (!ui::fadeIntensity) {
-                               std::thread([&](void){
-                                       auto thing = currentWorld->goInsideStructure(p);
-                                       if (thing.first != currentWorld)
-                                               worldSwitch(thing);
-                               }).detach();
-                       }*/
-                       
                        if (!ui::fadeIntensity)
                                worldSystem.goWorldPortal(loc);
 
@@ -124,7 +107,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                                moveLeft = faceLeft = false;
                 moveRight = true;
 
-                               worldSystem.goWorldRight(loc);
+                               worldSystem.goWorldRight(loc, *player.component<Solid>().get());
                        }
                } else if (kc == getControl(3)) {
                        if (game::canSprint)
index 473126192062b6580d82ecc98554c55365887ebe..3c568d1d86530118881b2ec724a9b8547c2f35d7 100644 (file)
@@ -237,7 +237,8 @@ namespace ui {
        */
 
        void setFontSize(unsigned int size) {
-               if (size == 16) {
+               (void)size;
+               /*if (size == 16) {
                        if (!ft16loaded) {
                                loadFontSize(fontSize = size, ftex16, ftdat16);
                                ft16loaded = true;
@@ -253,7 +254,7 @@ namespace ui {
                        ftex = &ftex24;
                        ftdat = &ftdat24;
                        fontSize = 24;
-               }
+               }*/
        }
 
        /*
@@ -572,11 +573,13 @@ namespace ui {
        }
 
        void waitForCover(void) {
+               fadeIntensity = 0;
                while (fadeIntensity < 255);
                fadeIntensity = 255;
        }
 
        void waitForUncover(void) {
+               fadeIntensity = 255;
                while (fadeIntensity > 0);
                fadeIntensity = 0;
        }
@@ -1075,10 +1078,9 @@ EXIT:
                        return;
                }
 
-               if (fadeWhite)
-                       glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255, 255, 255, fadeIntensity)));
-               else
-                       glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0, 0, 0, fadeIntensity)));
+               auto fadeTex = Texture::genColor( (fadeWhite ? Color(255, 255, 255, fadeIntensity) :
+                                                              Color(0, 0, 0, fadeIntensity)) );
+
 
         GLfloat tex[] = {0.0, 0.0,
                         1.0, 0.0,
@@ -1096,6 +1098,7 @@ EXIT:
                Render::textShader.use();
                Render::textShader.enable();
 
+               glBindTexture(GL_TEXTURE_2D, fadeTex);
         glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, backdrop);
         glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -1105,21 +1108,22 @@ EXIT:
 
                setFontZ(-8.0);
 
+               glDeleteTextures(1, &fadeTex);
     }
 
        void fadeUpdate(void) {
                if (fadeEnable) {
                        if (fadeIntensity < 150)
-                               fadeIntensity += fadeFast ? 40 : 10;
-                       else if (fadeIntensity < 255)
                                fadeIntensity += fadeFast ? 20 : 5;
+                       else if (fadeIntensity < 255)
+                               fadeIntensity += fadeFast ? 10 : 5;
                        else
                                fadeIntensity = 255;
                } else {
                        if (fadeIntensity > 150)
-                               fadeIntensity -= fadeFast ? 20 : 5;
+                               fadeIntensity -= fadeFast ? 10 : 5;
                        else if (fadeIntensity > 0)
-                               fadeIntensity -= fadeFast ? 40 : 10;
+                               fadeIntensity -= fadeFast ? 20 : 5;
                        else
                                fadeIntensity = 0;
                }
index 8e2d60b8f61e3c2290e57a649930ba3e14d7af02..3ff819b838e2d0b382794d806aba1393fdb35c5e 100644 (file)
@@ -260,8 +260,11 @@ void WorldSystem::load(const std::string& file)
 
        world.toLeft = world.toRight = "";
        currentXMLFile = file;
+       std::cout << "ka" << std::endl;
        game::entities.reset();
+       std::cout << "CHOW!!!" << std::endl;
        game::engine.getSystem<PlayerSystem>()->create();
+       std::cout << "chow cow" << std::endl;
 
        // iterate through tags
        while (wxml) {
@@ -395,6 +398,8 @@ void WorldSystem::load(const std::string& file)
                                                }
                                                
                                                entity.assign<Physics>(g);
+                                       } else if (tname == "Name") {
+                                               entity.assign<Name>(coalesce(wxml->Attribute("name"), abcd->Attribute("value"))); 
                                        }
 
                                        abcd = abcd->NextSiblingElement();
@@ -1085,14 +1090,14 @@ void WorldSystem::detect(entityx::TimeDelta dt)
        });
 }
 
-void WorldSystem::goWorldRight(Position& p)
+void WorldSystem::goWorldRight(Position& p, Solid &d)
 {
-       if (!(world.toRight.empty()) && (p.x > world.startX * -1 - HLINES(10))) {
+       if (!(world.toRight.empty()) && (p.x + d.width > world.startX * -1 - HLINES(15))) {
                ui::toggleBlack();
                ui::waitForCover();
                auto file = world.toRight;
                load(file);
-               p.x = world.startX + HLINES(15);
+               game::engine.getSystem<PlayerSystem>()->setX(world.startX + HLINES(15));
                ui::toggleBlack();
        }
 }
@@ -1103,7 +1108,7 @@ void WorldSystem::goWorldLeft(Position& p)
                ui::toggleBlack();
                ui::waitForCover();
                load(world.toLeft);
-               p.x = world.startX * -1 - HLINES(15);
+               game::engine.getSystem<PlayerSystem>()->setX(world.startX * -1 - HLINES(15));
                ui::toggleBlack();
        }
 }
@@ -1119,7 +1124,6 @@ void WorldSystem::goWorldPortal(Position& p)
                                ui::toggleBlack();
                                ui::waitForCover();
                                load(portal.toFile);
-                               p.x = 0;
                                ui::toggleBlack();
                                return;
                        }
index cf6dbf3554cb0eab131690a51771edbe55c90e54..431c0678cd308b0b704f6bdce55447fc653901f4 100644 (file)
@@ -7,6 +7,7 @@
        <Direction />
        <Solid />
        <Physics />
+       <Name value="Daddy" />
 </npc>
 
 <structure>