]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Text is fixed, and objects can be placed on the ground
authorAndy <drumsetmonkey@gmail.com>
Fri, 28 Oct 2016 12:30:14 +0000 (08:30 -0400)
committerAndy <drumsetmonkey@gmail.com>
Fri, 28 Oct 2016 12:30:14 +0000 (08:30 -0400)
include/components.hpp
shaders/new.frag
src/components.cpp
src/engine.cpp
src/ui.cpp
src/world.cpp
xml/entities.xml

index 11953372e3236d4dd40293b10bfb4da2afa0e7c7..507aa336a32e385223e670c174f7cf04840187d3 100644 (file)
@@ -61,6 +61,16 @@ struct Physics {
        float g; /**< The gravity constant, how fast the object falls */
 };
 
+/**
+ * @struct Grounded
+ * @brief Places an entity without physics on the ground.
+ * This is used so we don't have to update the physics of a non-moving object every loop.
+ */
+struct Grounded {
+       //TODO possibly make a way to change this
+       bool grounded = false;
+};
+
 /**
  * @struct Health
  * @brief Gives and entity health and stuff.
@@ -200,7 +210,6 @@ struct Animate {
 };
 
 //TODO
-
 struct Input {
 
 };
index 3537e265045bd024d77e6831dd9dbdea5ec6562d..0e4ed054433553512c89beca6f15598ff7f6e6d7 100644 (file)
@@ -6,7 +6,7 @@ varying vec4 color;
 void main(){
     vec4 pixelColor = texture2D(sampler, vec2(texCoord.x, texCoord.y));
     //TODO
-       if (pixelColor.w != 1.0f)
-               discard;
+       //if (pixelColor.w != 1.0f)
+       //      discard;
        gl_FragColor = pixelColor * color;
 }
index e00d474ad1f76eb42b87d683f35ac644cdff2f9a..609b5f415ad47d4dfe706a0996a2bca02f33246e 100644 (file)
@@ -93,6 +93,7 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
        en.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) {
                (void)e;
                (void)v;
+               ui::setFontZ(-5.0);
                ui::putStringCentered(pos.x + dim.width / 2, pos.y - ui::fontSize - HLINES(0.5), name.name);
        });
 }
index 04ea91272199ec9b35f7ebb879e8c97e6f4e7351..148c4961c4534b7a5d8fdd427a42353c44195ae0 100644 (file)
@@ -46,7 +46,6 @@ void Engine::render(entityx::TimeDelta dt)
 void Engine::update(entityx::TimeDelta dt)
 {
     systems.update<InputSystem>(dt);
-       //systems.update<PhysicsSystem>(dt);
        systems.update<MovementSystem>(dt);
        systems.update<WorldSystem>(dt);
     systems.update<PlayerSystem>(dt);
index 3c568d1d86530118881b2ec724a9b8547c2f35d7..41e818634a7daf1ca9e7dc445714ac450b681adf 100644 (file)
@@ -238,7 +238,7 @@ namespace ui {
 
        void setFontSize(unsigned int size) {
                (void)size;
-               /*if (size == 16) {
+               if (size == 16) {
                        if (!ft16loaded) {
                                loadFontSize(fontSize = size, ftex16, ftdat16);
                                ft16loaded = true;
@@ -254,7 +254,7 @@ namespace ui {
                        ftex = &ftex24;
                        ftdat = &ftdat24;
                        fontSize = 24;
-               }*/
+               }
        }
 
        /*
@@ -303,9 +303,11 @@ namespace ui {
                 *      Draw the character:
                */
 
+
                glActiveTexture(GL_TEXTURE0);
                glBindTexture(GL_TEXTURE_2D,(*ftex)[c-33]);
                glUniform1i(Render::textShader.uniform[WU_texture], 0);
+               glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, 1.0f);
 
                //glDisable(GL_DEPTH_TEST);
 
index 3ff819b838e2d0b382794d806aba1393fdb35c5e..7c53ee45e2de999347254ea70ba7a1490a8b743b 100644 (file)
@@ -400,6 +400,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"))); 
+                                       } else if (tname == "Grounded") {
+                                               entity.assign<Grounded>();
                                        }
 
                                        abcd = abcd->NextSiblingElement();
@@ -1043,6 +1045,25 @@ void WorldSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
 
 void WorldSystem::detect(entityx::TimeDelta dt)
 {
+       game::entities.each<Grounded, Position, Solid>(
+               [&](entityx::Entity e, Grounded &g, Position &loc, Solid &dim) {
+                       (void)e;
+                       if (!g.grounded) {
+                               // get the line the entity is on
+                               int line = std::clamp(static_cast<int>((loc.x + dim.width / 2 - world.startX) / game::HLINE),
+                                                                         0,
+                                                                         static_cast<int>(world.data.size()));
+
+                               // make sure entity is above ground
+                               const auto& data = world.data;
+                               if (loc.y != data[line].groundHeight) {
+                                       loc.y = data[line].groundHeight;
+                                       e.remove<Grounded>();
+                               }
+                       }
+
+               });
+       
        game::entities.each<Direction, Physics>(
                [&](entityx::Entity e, Direction &vel, Physics &phys) {
                        (void)e;
index 431c0678cd308b0b704f6bdce55447fc653901f4..2bcd1bfe389160dc74916f29f9c67d5df02bb571 100644 (file)
@@ -16,6 +16,7 @@
        <Sprite image="assets/style/classic/house1.png" />
        <Portal />
        <Solid />
+       <Grounded />
 </structure>
 
 <chest>
@@ -23,4 +24,5 @@
        <Visible value="0.15" />
        <Sprite image="assets/chest.png" />
        <Solid />
+       <Grounded />
 </chest>