]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fixes, dialog box
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 25 Nov 2016 21:51:33 +0000 (16:51 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 25 Nov 2016 21:51:33 +0000 (16:51 -0500)
main.cpp
src/texture.cpp
src/ui.cpp
src/world.cpp

index 4d141903a848cfd64c43493bc3a48cbc13e1208a..ca65dd3eb40869cc7e76d4f87a21cf3ea49ba8c2 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -131,9 +131,6 @@ int main(int argc, char *argv[])
        // load mouse texture, and other inventory textures
        mouseTex = Texture::loadTexture("assets/mouse.png");
 
-       //player = new Player();
-       //player->sspawn(0,100);
-
        // get a world
        if (xmlFolder.empty())
                xmlFolder = "xml/";
@@ -200,7 +197,6 @@ int main(int argc, char *argv[])
        }
 
        ui::menu::init();
-//     game::events.emit<BGMToggleEvent>(currentWorld->bgm);
 
        // the main loop, in all of its gloriousness..
        std::thread([&]{
@@ -265,7 +261,7 @@ void render() {
 
        offset.x = game::engine.getSystem<PlayerSystem>()->getPosition().x;// + player->width / 2;
 
-       auto worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
+       const auto& worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
        if (worldWidth < (int)SCREEN_WIDTH)
                offset.x = 0;
        else if (offset.x - SCREEN_WIDTH / 2 < worldWidth * -0.5f)
@@ -319,12 +315,13 @@ void render() {
        // draw the debug overlay if desired
        if (ui::debug) {
                auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
-               ui::putText(offset.x-SCREEN_WIDTH/2, (offset.y+SCREEN_HEIGHT/2)-ui::fontSize,
-                           "loc: (%+.2f, %+.2f)\noffset: (%+.2f, %+.2f)\nticks: %u\nxml: %s",
+               ui::putText(offset.x - SCREEN_WIDTH / 2, (offset.y + SCREEN_HEIGHT / 2) - ui::fontSize,
+                           "loc: (%+.2f, %+.2f)\noffset: (%+.2f, %+.2f)\nfps: %d\nticks: %d\nxml: %s",
                                        pos.x,
                                        pos.y,
                                        offset.x,
                                        offset.y,
+                                       fps,
                                        game::time::getTickCount(),
                                        game::engine.getSystem<WorldSystem>()->getXMLFile().c_str()
                            );
@@ -342,41 +339,6 @@ void render() {
                                        game::engine.getSystem<WorldSystem>()->getWeatherStr().c_str(),
                                        ""//currentXML.c_str()
                                );*/
-
-               // draw tracer lines if desired
-               //static const GLuint tracerText = Texture::genColor(Color(100,100,255));
-               /*if (ui::posFlag) {
-                       GLfloat *tpoint = new GLfloat[currentWorld->getEntityCount() * 2 * 5];
-                       auto tp = tpoint;
-
-                       for (auto &e : currentWorld->entity) {
-                               *(tp++) = player->loc.x + player->width / 2;
-                               *(tp++) = player->loc.y + player->height / 2;
-                               *(tp++) = -5.0;
-
-                               *(tp++) = 0.0;
-                               *(tp++) = 0.0;
-
-                               *(tp++) = e->loc.x + e->width / 2;
-                               *(tp++) = e->loc.y + e->height / 2;
-                               *(tp++) = -5.0;
-
-                               *(tp++) = 1.0;
-                               *(tp++) = 1.0;
-                       }
-
-                       Render::textShader.use();
-                               glBindTexture(GL_TEXTURE_2D, tracerText);
-                               Render::textShader.enable();
-                               glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &tpoint[0]);
-                               glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &tpoint[3]);
-                               glDrawArrays(GL_LINES, 0, currentWorld->getEntityCount() * 2);
-                               Render::textShader.disable();
-                       Render::textShader.unuse();
-
-                       delete[] tpoint;
-               }*/
-
        }
 
        // draw the menu
index 1f80d38fe58ef6058adce90732e41003deb2950d..3a2f0717acb8abea6ac1b29180f857b766406c76 100644 (file)
@@ -67,7 +67,6 @@ namespace Texture{
 #ifdef DEBUG
                DEBUG_printf("Loaded image file: %s\n", fileName.c_str());
 #endif // DEBUG
-
                /*
                 * Load texture through OpenGL.
                 */
@@ -77,10 +76,8 @@ namespace Texture{
 
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);      // Sets the "min" filter
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);      // The the "max" filter of the stack
-
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Wrap the texture to the matrix
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //
-
                glTexImage2D(GL_TEXTURE_2D,  // Sets the texture to the image file loaded above
                                         0,
                                         GL_RGBA,
@@ -104,7 +101,7 @@ namespace Texture{
     GLuint genColor(Color c)
     {
         std::string out;
-        
+
         // add the red
         out += static_cast<int>(c.red);
 
@@ -140,7 +137,7 @@ namespace Texture{
                                         GL_UNSIGNED_BYTE,  // type
                                         out.data()         // source
                                        );
-        
+
         return object;
     }
 
index 5939368860eaea2882d4594fea265867c8a6a77e..fc7c066ce7dc356da26f0dcca14041c7c0e4a8d9 100644 (file)
@@ -177,7 +177,7 @@ namespace ui {
        bool dialogImportant = false;
        unsigned char dialogOptChosen = 0;
 
-       unsigned int textWrapLimit = 0;
+       unsigned int textWrapLimit = 72;
 
        /*
         *      Current font size. Changing this WILL NOT change the font size, see setFontSize() for
@@ -369,7 +369,7 @@ namespace ui {
                 */
 
                do {
-                       if (dialogBoxExists && o.x > textWrapLimit * nl + x) {
+                       if (dialogBoxExists && i > textWrapLimit * nl) {
 
                                o.y -= fontSize * 1.05f;
                                o.x = x;
@@ -529,7 +529,6 @@ namespace ui {
                va_list dialogArgs;
                std::unique_ptr<char[]> printfbuf (new char[512]);
 
-               textWrapLimit = game::SCREEN_WIDTH - HLINES(20);
                dialogPassive = passive;
 
                // add speaker prefix
@@ -838,10 +837,8 @@ namespace ui {
 
        void draw(void){
                unsigned char i;
-               float x,y,tmp;
                std::string rtext;
 
-               auto SCREEN_WIDTH = static_cast<float>(game::SCREEN_WIDTH);
                auto SCREEN_HEIGHT = static_cast<float>(game::SCREEN_HEIGHT);
 
                // will return if not toggled
@@ -903,16 +900,17 @@ namespace ui {
                                }
                        } else { //normal dialog box
 
-                               x = offset.x - SCREEN_WIDTH / 2  + HLINES(8);
-                               y = offset.y + SCREEN_HEIGHT / 2 - HLINES(8);
+                               float y = offset.y + SCREEN_HEIGHT / 2 - HLINES(8);
+                               float x = offset.x - 300;
 
-                               drawNiceBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH - HLINES(16), y - SCREEN_HEIGHT / 4}, -7.0);
+                               drawNiceBox(vec2 {x, y}, vec2 {x + 600, y - SCREEN_HEIGHT / 4}, -7.0);
 
                                setFontZ(-7.2f);
                                rtext = typeOut(dialogBoxText);
                                putString(x + HLINES(2), y - fontSize - game::HLINE, rtext);
 
-                               for(i=0;i<dialogOptText.size();i++) {
+                               for (i = 0; i < dialogOptText.size(); i++) {
+                                       float tmp;
                                        setFontColor(255,255,255);
                                        tmp = putStringCentered(offset.x,dialogOptText[i].second.y,dialogOptText[i].first);
                                        dialogOptText[i].second.z = offset.x + tmp;
@@ -1253,7 +1251,7 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
                case SDL_QUIT:
                        game::endGame();
                        break;
-               
+
                // window events - used for resizing and stuff
                case SDL_WINDOWEVENT:
                        switch (e.window.event) {
index 4a946d75d5ee728c7883fb57be4e01864ad0e2ea..a50a04d90df646869a036a69f8596bd0899008fe 100644 (file)
@@ -146,7 +146,7 @@ void WorldSystem::generate(unsigned int width)
        }
 
     // define x-coordinate of world's leftmost 'line'
-    world.startX = (width - GROUND_HILLINESS) * game::HLINE / 2 * -1;
+    world.startX = HLINES(width * -0.5);
 }
 
 static Color ambient;
@@ -318,12 +318,11 @@ void WorldSystem::load(const std::string& file)
                                        } else if (tname == "Solid") {
                                                vec2 dim;
 
-                                               if (abcd->Attribute("value") != nullptr) {
+                                               if (abcd->Attribute("value") != nullptr)
                                                        dim = str2coord(abcd->StrAttribute("value"));
-                                               } else {
+                                               else
                                                        dim = entity.component<Sprite>().get()->getSpriteSize() * game::HLINE;
-                                               }
-                                               
+
                                                float cdat[2] = {dim.x, dim.y};
                                                entity.assign<Solid>(cdat[0], cdat[1]);
                                        } else if (tname == "Direction") {
@@ -332,7 +331,7 @@ void WorldSystem::load(const std::string& file)
                                                if (wxml->Attribute("direction") != nullptr) {
                                                        dir = str2coord(wxml->StrAttribute("direction"));
                                                } else if (wxml->Attribute("value") != nullptr) {
-                                                       dir = str2coord(wxml->StrAttribute("value"));   
+                                                       dir = str2coord(wxml->StrAttribute("value"));
                                                } else {
                                                        dir = vec2(0,0);
                                                }
@@ -345,14 +344,14 @@ void WorldSystem::load(const std::string& file)
                                                if (wxml->Attribute("gravity") != nullptr) {
                                                        g = wxml->FloatAttribute("gravity");
                                                } else if (wxml->Attribute("value") != nullptr) {
-                                                       g = wxml->FloatAttribute("value");      
+                                                       g = wxml->FloatAttribute("value");
                                                } else {
                                                        g = 1.0f;
                                                }
-                                               
+
                                                entity.assign<Physics>(g);
                                        } else if (tname == "Name") {
-                                               entity.assign<Name>(coalesce(wxml->Attribute("name"), abcd->Attribute("value"))); 
+                                               entity.assign<Name>(coalesce(wxml->Attribute("name"), abcd->Attribute("value")));
                                        } else if (tname == "Dialog") {
                                                entity.assign<Dialog>((wxml->BoolAttribute("hasDialog") ? 0 : 9999));
                                        } else if (tname == "Grounded") {
@@ -922,7 +921,7 @@ void WorldSystem::render(void)
                        // actually draw the grass.
                if (wd.groundHeight) {
                                const auto& worldStart = world.startX;
-                               
+
                                grasst.push_back(0);
                                grasst.push_back(1);
 
@@ -930,18 +929,18 @@ void WorldSystem::render(void)
                                grassc.push_back(wd.groundHeight + gh[0]);
                                grassc.push_back(-3);
 
-                               
+
                                grasst.push_back(1);
                                grasst.push_back(0);
-                               
+
                                grassc.push_back(worldStart + HLINES(i) + HLINE / 2);
-                               grassc.push_back(wd.groundHeight + gh[0]);      
+                               grassc.push_back(wd.groundHeight + gh[0]);
                                grassc.push_back(-3);
 
 
                    grasst.push_back(1);
                                grasst.push_back(1);
-                               
+
                                grassc.push_back(worldStart + HLINES(i) + HLINE / 2);
                                grassc.push_back(wd.groundHeight - GRASS_HEIGHT);
                                grassc.push_back(-3);
@@ -949,15 +948,15 @@ void WorldSystem::render(void)
 
                grasst.push_back(1);
                                grasst.push_back(1);
-                               
+
                                grassc.push_back(worldStart + HLINES(i) + HLINE / 2);
                                grassc.push_back(wd.groundHeight - GRASS_HEIGHT);
                                grassc.push_back(-3);
-                   
+
 
                                grasst.push_back(0);
                                grasst.push_back(1);
-                               
+
                                grassc.push_back(worldStart + HLINES(i));
                                grassc.push_back(wd.groundHeight - GRASS_HEIGHT);
                                grassc.push_back(-3);
@@ -965,15 +964,15 @@ void WorldSystem::render(void)
 
                                grasst.push_back(0);
                                grasst.push_back(0);
-                               
+
                    grassc.push_back(worldStart + HLINES(i));
-                               grassc.push_back(wd.groundHeight + gh[0]);                      
+                               grassc.push_back(wd.groundHeight + gh[0]);
                                grassc.push_back(-3);
 
 
                                grasst.push_back(0);
                                grasst.push_back(0);
-                   
+
                                grassc.push_back(worldStart + HLINES(i) + HLINE / 2);
                                grassc.push_back(wd.groundHeight + gh[1]);
                                grassc.push_back(-3);
@@ -989,7 +988,7 @@ void WorldSystem::render(void)
 
                                grasst.push_back(1);
                                grasst.push_back(1);
-                   
+
                                grassc.push_back(worldStart + HLINES(i) + HLINE);
                                grassc.push_back(wd.groundHeight - GRASS_HEIGHT);
                                grassc.push_back(-3);
@@ -1005,7 +1004,7 @@ void WorldSystem::render(void)
 
                                grasst.push_back(0);
                                grasst.push_back(1);
-                   
+
                                grassc.push_back(worldStart + HLINES(i) + HLINE / 2);
                                grassc.push_back(wd.groundHeight - GRASS_HEIGHT);
                                grassc.push_back(-3);
@@ -1036,13 +1035,13 @@ void WorldSystem::render(void)
 
                if (offset.x + world.startX > s) {
 
-                       glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0,0,0))); 
+                       glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0,0,0)));
                        glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.0f);
 
-                       GLfloat blackBarLeft[] = {s,                            0.0f,                                                           -3.5f,          0.0f, 0.0f, 
+                       GLfloat blackBarLeft[] = {s,                            0.0f,                                                           -3.5f,          0.0f, 0.0f,
                                                                          world.startX,         0.0f,                                                           -3.5f,          1.0f, 0.0f,
                                                                          world.startX,         static_cast<float>(SCREEN_HEIGHT),      -3.5f,          1.0f, 1.0f,
-                                                                         
+
                                                                          world.startX,         static_cast<float>(SCREEN_HEIGHT),      -3.5f,          1.0f, 1.0f,
                                                                  s,                            static_cast<float>(SCREEN_HEIGHT),      -3.5f,          0.0f, 1.0f,
                                                                          s,                            0.0f,                                                           -3.5f,          0.0f, 0.0f};
@@ -1053,14 +1052,14 @@ void WorldSystem::render(void)
                }
 
                if (offset.x - world.startX < e) {
-                       
-                       glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0,0,0))); 
+
+                       glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0,0,0)));
                        glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.0f);
 
-                       GLfloat blackBarRight[] = {grassc[grassc.size()-3],     0.0f,                                                           -3.5f,          0.0f, 0.0f, 
+                       GLfloat blackBarRight[] = {grassc[grassc.size()-3],     0.0f,                                                           -3.5f,          0.0f, 0.0f,
                                                                           e,                                                   0.0f,                                                           -3.5f,          1.0f, 0.0f,
                                                                           e,                                                   static_cast<float>(SCREEN_HEIGHT),      -3.5f,          1.0f, 1.0f,
-                                                                         
+
                                                                           e,                                                   static_cast<float>(SCREEN_HEIGHT),      -3.5f,          1.0f, 1.0f,
                                                                   grassc[grassc.size()-3],             static_cast<float>(SCREEN_HEIGHT),      -3.5f,          0.0f, 1.0f,
                                                                           grassc[grassc.size()-3],             0.0f,                                                           -3.5f,          0.0f, 0.0f};
@@ -1069,7 +1068,7 @@ void WorldSystem::render(void)
                glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*5, &blackBarRight[3]);
                glDrawArrays(GL_TRIANGLES, 0 , 6);
                }
-               
+
                Render::worldShader.disable();
                Render::worldShader.unuse();
 
@@ -1146,7 +1145,7 @@ void WorldSystem::detect(entityx::TimeDelta dt)
                        }
 
                });
-       
+
        game::entities.each<Direction, Physics>(
                [&](entityx::Entity e, Direction &vel, Physics &phys) {
                        (void)e;
@@ -1181,7 +1180,7 @@ void WorldSystem::detect(entityx::TimeDelta dt)
                                // TODO ground flag
                        }
                }
-        
+
 
                // insure that the entity doesn't fall off either edge of the world.
         if (loc.x < world.startX) {