]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world draw fixes
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 9 May 2016 11:42:18 +0000 (07:42 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 9 May 2016 11:42:18 +0000 (07:42 -0400)
13 files changed:
Changelog
include/inventory.hpp
include/world.hpp
main.cpp
src/brice.cpp
src/common.cpp
src/entities.cpp
src/inventory.cpp
src/mob.cpp
src/shader_utils.cpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp

index 458634d66679e6d790fe9fd6f2fbea5dd57b40a3..a37470a4925c398cdb81ad619c0545b92c0c2619 100644 (file)
--- a/Changelog
+++ b/Changelog
        - re-added click to speed up dialogs
        - almost ready to add new draw stuff
 
+
+5/5/2016:
+=========
+
+       - pushing new drawing to master, it's okay...
+       - changed how swords function, only hits nearest entity
index 552b30c4f7599661523c69f56d5f8705734a66b7..1431f42a903a8e60b7b55995b106013873c1b1ee 100644 (file)
@@ -204,10 +204,6 @@ public:
        ~NewCurrency(){}
 };
 
-/***********************************************************************************
- *                                                     OLD STUFF THAT NEEDS TO BURN                                               *
- **********************************************************************************/
-
 /***********************************************************************************
  *                                             OLD STUFF THAT NEEDS TO GET UPDATED                                                *
  **********************************************************************************/
index 5bfd9f22595c2a66a916cbeb9922935e6dac7604..ac17580c4903885a3c587ae65d3991839d403fc0 100644 (file)
@@ -112,7 +112,7 @@ protected:
        unsigned int lineCount;
 
        // the left-most (negative) coordinate of the worldStart
-       int worldStart;
+       float worldStart;
 
        // holds / handles textures for background elements
        TextureIterator bgTex;
@@ -192,8 +192,6 @@ public:
        // gets a pointer to the most recently added mob
        Mob *getLastMob(void);
 
-       std::vector<Entity*> getMobs(void);
-
        // gets the nearest interactable entity to the given one
        Entity *getNearInteractable(Entity &e);
 
index 8c3b631f110d540b314dbf96c0cbec29a2da3e49..570f12f5ce7316d315a87899f195e395f023d070 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -99,9 +99,6 @@ void mainLoop(void);
 ********************************************************************************/
 
 int main(int argc, char *argv[]){
-       (void)argc;
-       (void)argv;
-
        static SDL_GLContext mainGLContext = NULL;
 
        // handle command line arguments
@@ -275,6 +272,7 @@ int main(int argc, char *argv[]){
        if (currentWorld == NULL)
                UserError("Plot twist: The world never existed...?");
 
+       // spawn the arena
        arena = new Arena();
        arena->setStyle("");
        arena->setBackground(WorldBGType::Forest);
@@ -307,9 +305,7 @@ int main(int argc, char *argv[]){
        // close up the game stuff
        currentWorld->save();
        delete arena;
-       //delete currentWorld;
-       //delete[] currentXML;
-       //aipreload.clear();
+       delete currentWorld;
 
     return 0; // Calls everything passed to atexit
 }
index fef336efa12b98ee33a27110875cc0a75acc8e23..6b64d88c24b226207cf36298d3dbd7f611c73fef 100644 (file)
@@ -50,11 +50,13 @@ namespace game {
        }
 
        void briceLoad(void) {
-               const std::string data = readFile("brice.dat");
+               const char *data = readFile("brice.dat");
                auto datas = StringTokenizer(data, ',');
 
                for (const auto& d : datas)
                        std::cout << d << '\n';
+
+               delete[] data;
        }
 
        void briceUpdate(void) {
index 14fad9c4472ce2d7acd4e8fc9b7f7765c460d2a0..77be09819c79f3a9b6b278a20021609f0e7b4b7f 100644 (file)
@@ -13,6 +13,8 @@
 #include <errno.h>
 #include <vector>
 
+#include <texture.hpp>
+
 unsigned int millis(void) {
        std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
        return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
index c4e418681e2ca060a12e7f5ce38ad2bc98497cb6..a8f5e484cec5dca85584734f17410fddb0182623 100644 (file)
@@ -435,38 +435,38 @@ if (health != maxHealth) {
        };
 
        GLfloat coord_front[] = {
-               loc.x,                  loc.y + height,                         1.0,
-               loc.x + width,  loc.y + height,                         1.0,
-               loc.x + width,  loc.y + height + game::HLINE * 2, 1.0,
+               loc.x,                                      loc.y + height,                   1.0,
+               loc.x + health / maxHealth * width, loc.y + height,                   1.0,
+               loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, 1.0,
 
-               loc.x + width,  loc.y + height + game::HLINE * 2, 1.0,
-               loc.x,                  loc.y + height + game::HLINE * 2,       1.0,
-               loc.x,                  loc.y + height,                         1.0,
+               loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, 1.0,
+               loc.x,                              loc.y + height + game::HLINE * 2, 1.0,
+               loc.x,                              loc.y + height,                   1.0,
        };
 
-       vec2 index = Texture::getIndex(Color(150,0,0));
+       static const vec2 index1 = Texture::getIndex(Color(0,0,0));
        GLfloat back_tex[] = {
-               float(.25*index.x), float(.125*index.y),
-               float(.25*index.x), float(.125*index.y),
-               float(.25*index.x), float(.125*index.y),
+               float(.25*index1.x), float(.125*index1.y),
+               float(.25*index1.x), float(.125*index1.y),
+               float(.25*index1.x), float(.125*index1.y),
 
-               float(.25*index.x), float(.125*index.y),
-               float(.25*index.x), float(.125*index.y),
-               float(.25*index.x), float(.125*index.y),
+               float(.25*index1.x), float(.125*index1.y),
+               float(.25*index1.x), float(.125*index1.y),
+               float(.25*index1.x), float(.125*index1.y),
        };
        glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coord_back);
        glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, back_tex);
        glDrawArrays(GL_TRIANGLES, 0, 6);
 
-       index = Texture::getIndex(Color(255,0,0));
+       static const vec2 index2 = Texture::getIndex(Color(255,0,0));
        GLfloat front_tex[] = {
-               float(.25*index.x), float(.125*index.y),
-               float(.25*index.x), float(.125*index.y),
-               float(.25*index.x), float(.125*index.y),
+               float(.25*index2.x), float(.125*index2.y),
+               float(.25*index2.x), float(.125*index2.y),
+               float(.25*index2.x), float(.125*index2.y),
 
-               float(.25*index.x), float(.125*index.y),
-               float(.25*index.x), float(.125*index.y),
-               float(.25*index.x), float(.125*index.y),
+               float(.25*index2.x), float(.125*index2.y),
+               float(.25*index2.x), float(.125*index2.y),
+               float(.25*index2.x), float(.125*index2.y),
        };
        glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coord_front);
        glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, front_tex);
index b363b860d8445c2a2b8ffa1e3d04fe60368efc8b..a1181e282f6861cdbeebc94e1d98019cb5b3b5c6 100644 (file)
@@ -63,6 +63,7 @@ void items(void)
                        Sword *tmpSword = new Sword();
                        tmpSword->setDamage(exml->FloatAttribute("damage"));
                        ItemMap.push_back(tmpSword->clone());
+                       delete tmpSword;
 
                // if the type is a bow
                } else if (strCaseCmp(name, "bow")) {
@@ -70,6 +71,7 @@ void items(void)
                        Bow *tmpBow = new Bow();
                        tmpBow->setDamage(exml->FloatAttribute("damage"));
                        ItemMap.push_back(tmpBow->clone());
+                       delete tmpBow;
 
                // arrow
                } else if (strCaseCmp(name, "arrow")) {
@@ -77,6 +79,7 @@ void items(void)
                        Arrow *tmpArrow = new Arrow();
                        tmpArrow->setDamage(exml->FloatAttribute("damage"));
                        ItemMap.push_back(tmpArrow->clone());
+                       delete tmpArrow;
 
                // uncooked / raw food
                }else if (strCaseCmp(name, "raw food")) {
@@ -214,8 +217,8 @@ void destroyInventory(void) {
 
        // NEWEWEWEWEWEWEWEW
        while (!ItemMap.empty()) {
-               delete ItemMap.front();
-               ItemMap.erase(std::begin(ItemMap));
+               delete ItemMap.back();
+               ItemMap.pop_back();
        }
 
        Mix_FreeChunk(swordSwing);
index d5243977169a4482183a08264e35474e7af2c385..ec8b8497602712c590c61eb03166642e1de1bd9c 100644 (file)
@@ -149,28 +149,23 @@ Rabbit::Rabbit(void) : Mob()
     actCounter = 1;
 }
 
-extern bool inBattle;
 void Rabbit::act(void)
 {
     static int direction = 0;
 
-    if (inBattle) {
-        die();
-    } else {
-        if (!--actCounter) {
-            actCounter = actCounterInitial;
-            direction = (randGet() % 3 - 1);   //sets the direction to either -1, 0, 1
-            if (direction == 0)
-                ticksToUse /= 2;
-            vel.x *= direction;
-        }
+    if (!--actCounter) {
+        actCounter = actCounterInitial;
+        direction = (randGet() % 3 - 1);       //sets the direction to either -1, 0, 1
+        if (direction == 0)
+            ticksToUse /= 2;
+        vel.x *= direction;
+    }
 
-        if (ground && direction) {
-            ground = false;
-            vel.y = .15;
-            loc.y += HLINES(0.25f);
-            vel.x = 0.05f * direction;
-        }
+    if (ground && direction) {
+        ground = false;
+        vel.y = .15;
+        loc.y += HLINES(0.25f);
+        vel.x = 0.05f * direction;
     }
 }
 
index 13b2f746f1f28314504606960736c602d903d163..bc9375c7d7f4425c0dd48b94ed6139b65be8a098 100644 (file)
@@ -1,9 +1,3 @@
-/**
- * From the OpenGL Programming wikibook: http://en.wikibooks.org/wiki/OpenGL_Programming
- * This file is in the public domain.
- * Contributors: Sylvain Beucler, Guus Sliepen
- */
-
 #include <iostream>
 #include <vector>
 using namespace std;
@@ -76,21 +70,8 @@ GLuint create_shader(const char* filename, GLenum type) {
                return 0;
        }
        GLuint res = glCreateShader(type);
-       const GLchar* sources[] = {
-               // Define GLSL version
-               "#version 130\n"  // OpenGL 2.0
-               ,
-               // Define default float precision for fragment shaders:
-               (type == GL_FRAGMENT_SHADER) ?
-               "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
-               "precision highp float;           \n"
-               "#else                            \n"
-               "precision mediump float;         \n"
-               "#endif                           \n"
-               : ""
-               ,
-               source };
-       glShaderSource(res, 3, sources, NULL);
+       const GLchar* sources[2] = { "#version 120\n", source };
+       glShaderSource(res, 2, sources,NULL);
        delete[] source;
 
        glCompileShader(res);
index 8d15bcd10e8d8608fb14cc0f7b32bff707094399..6a68cc0a1fe427471fba2716491bd983f0323137 100644 (file)
@@ -1035,8 +1035,10 @@ EXIT:
                                } else {
                                        // left click uses item
                                        if (e.button.button & SDL_BUTTON_LEFT) {
-                                               player->inv->currentAddInteract(currentWorld->getMobs());
-                                               player->inv->useCurrent();
+                                               if ((m = currentWorld->getNearMob(*player)) != nullptr) {
+                                                       player->inv->currentAddInteract(m);
+                                                       player->inv->useCurrent();
+                                               }
                                        }
 
                                }
index 09b09c814a00f0683d52d00eba91f7229db61ed6..c9510c2d664ba75868b93a61354d76c2870f8f13 100644 (file)
@@ -135,7 +135,7 @@ namespace ui {
 
             //draw the dark transparent background
             glColor4f(0.0f, 0.0f, 0.0f, .8f);
-            glRectf(offset.x-SCREEN_WIDTH/2,0,offset.x+SCREEN_WIDTH/2,SCREEN_HEIGHT);
+            glRectf(offset.x-SCREEN_WIDTH/2,-SCREEN_HEIGHT/2,offset.x+SCREEN_WIDTH/2,SCREEN_HEIGHT/2);
 
             //loop through all elements of the menu
             for (auto &m : currentMenu->items) {
index c2cdbc5e7d71500c88bc5fe0f20f86fb04126703..362cc8b89eb32c2cde37428289e2ac905d07cdac 100644 (file)
@@ -206,7 +206,7 @@ generate(int width)
     // create empty star array, should be filled here as well...
        star = std::vector<vec2> (100, vec2 { 0, 400 });
        for (auto &s : star) {
-               s.x = (randGet() % (-worldStart * 2)) + worldStart;
+               s.x = (randGet() % (static_cast<int>(-worldStart) * 2)) + worldStart;
                s.y = (randGet() % game::SCREEN_HEIGHT) + 100;
        }
 
@@ -269,8 +269,6 @@ draw(Player *p)
     glUniform1i(worldShader_uniform_texture, 0);
 
     // draw background images.
-    //glEnable(GL_TEXTURE_2D);
-
     GLfloat tex_coord[] = { 0.0f, 1.0f,
                             1.0f, 1.0f,
                             1.0f, 0.0f,
@@ -581,13 +579,13 @@ draw(Player *p)
         // glTexCoord2i(1, ty); glVertex2i(worldStart + i * HLINE + HLINE, 0);
         // glTexCoord2i(0, ty); glVertex2i(worldStart + i * HLINE            , 0);
 
-        c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + i * HLINE,         worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
-        c.push_back(std::make_pair(vec2(1, 0), vec3(worldStart + i * HLINE + HLINE, worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
-        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + i * HLINE + HLINE, 0,                                        1.0f)));
+               c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i),         worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
+        c.push_back(std::make_pair(vec2(1, 0), vec3(worldStart + HLINES(i) + HLINE, worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
+        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0,                                        1.0f)));
 
-        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + i * HLINE + HLINE, 0,                                        1.0f)));
-        c.push_back(std::make_pair(vec2(0, ty),vec3(worldStart + i * HLINE,         0,                                        1.0f)));
-        c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + i * HLINE,         worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
+        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0,                                        1.0f)));
+        c.push_back(std::make_pair(vec2(0, ty),vec3(worldStart + HLINES(i),         0,                                        1.0f)));
+        c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i),         worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
 
         if (worldData[i].groundHeight == GROUND_HEIGHT_MINIMUM - 1)
             worldData[i].groundHeight = 0;
@@ -659,22 +657,22 @@ draw(Player *p)
                        glTexCoord2i(1, 1); glVertex2i(worldStart + i * HLINE + HLINE    , wd.groundHeight - GRASS_HEIGHT);
                        glTexCoord2i(0, 1); glVertex2i(worldStart + i * HLINE + HLINE / 2, wd.groundHeight - GRASS_HEIGHT);*/
 
-                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + i * HLINE            , wd.groundHeight + gh[0])));
-                c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight + gh[0])));
-                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
+                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0])));
+                c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[0])));
+                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
 
-                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
-                c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + i * HLINE                   , wd.groundHeight - GRASS_HEIGHT)));
-                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + i * HLINE            , wd.groundHeight + gh[0])));
+                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
+                c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i)                   , wd.groundHeight - GRASS_HEIGHT)));
+                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0])));
 
 
-                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight + gh[1])));
-                c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + i * HLINE + HLINE    , wd.groundHeight + gh[1])));
-                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + i * HLINE + HLINE    , wd.groundHeight - GRASS_HEIGHT)));
+                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1])));
+                c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight + gh[1])));
+                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT)));
 
-                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + i * HLINE + HLINE    , wd.groundHeight - GRASS_HEIGHT)));
-                c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
-                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight + gh[1])));
+                c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT)));
+                c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
+                c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1])));
 
             //glEnd();
         }
@@ -1051,16 +1049,6 @@ getLastMob(void)
     return mob.back();
 }
 
-std::vector<Entity*> World::
-getMobs(void)
-{
-    std::vector<Entity*> meme;
-    for (auto &m : mob) {
-        meme.push_back(m);
-    }
-    return meme;
-}
-
 /**
  * Get the interactable entity that is closest to the entity provided.
  */