]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
ortho snapping, reset option
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 3 May 2016 12:49:01 +0000 (08:49 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 3 May 2016 12:49:01 +0000 (08:49 -0400)
Changelog
include/inventory.hpp
include/texture.hpp
include/world.hpp
main.cpp
src/entities.cpp
src/mob.cpp
src/ui_action.cpp
src/world.cpp

index 711829083ffbb4e3ff477d027bbe15d59d099332..a604032288d5d55844c8a28221fa6e2eb7c2834e 100644 (file)
--- a/Changelog
+++ b/Changelog
        - render is now separated from the main loop
 
        ~8,100 lines of code
+
+5/3/2016:
+=========
+
+       - smoothed out ortho snapping
+       - improved arenas, fixed door texture
+       - fixed mob riding / ortho snaps
+       - added command line option handling, with -r option to clear .dat files
+       - found segfault when exiting game
+       - made string tokenizer for tokenizing strings
+       - messed with HLINE scaling, it's bad
index bee2fbdfffe828beb389b345d57ae35446aae698..c34eadbbcb2ce1cb04788cc2a79a4cc4f60d48de 100644 (file)
@@ -17,9 +17,10 @@ class Entity;
 class Item {
 private:
        bool beingUsed;
-
+protected:
        std::vector<Entity*> interact;
 public:
+
        // what we want to call each item
        std::string name;
 
index 22a245960ba4c1b8faeff28d60ce94f313c06d85..ecf85e49facc243caa8bf9275529b1c97ad5ad66 100644 (file)
@@ -86,69 +86,22 @@ public:
 
 class Texturec{
 private:
-
-       /**
-        * Contains the index in the image array of the currently loaded texture.
-        */
-
        unsigned int texState;
 
 public:
 
-       /**
-        * Contains an array of the GLuints returned from Texture::loadTexture().
-        */
-
        std::vector<GLuint> image;
-
-       /**
-        * Contains the dimensions of each texture in the vector
-        */
-        //TODO
-       //std::vector<vec2> imageDim;
-
-       /**
-        * Stores the location of all the images
-        */
        std::vector<std::string> texLoc;
 
-       /**
-        * Populates the image array from a list of strings, with each string as a
-        * separate argument.
-        */
-
        Texturec(uint amt, ...);
-
-       /**
-        * Populates the image array from an array of strings.
-        */
-
        Texturec(uint amt,const char **paths);
        Texturec(std::vector<std::string>vec);
        Texturec(std::initializer_list<std::string> l);
 
-       /**
-        * Frees memory taken by the image array.
-        */
-
        ~Texturec();
 
-       /**
-        * Binds the next texture in the array, incrementing texState.
-        */
-
        void bindNext();
-
-       /**
-        * Binds the previous texture in the array, decrementing texState.
-        */
-
        void bindPrev();
-
-       /**
-        * Binds the texture with the provided index.
-        */
-
        void bind(unsigned int);
 };
 
index 5d301615c8d21d8658fcafdeb6757c38efb25e85..2dd166a8caff6e9a8abeb0ebc45d87646fccfde6 100644 (file)
@@ -320,11 +320,14 @@ private:
 public:
 
        // creates the arena with the world being left for it
-       Arena(World *leave, Player *p, Mob *m);
+       Arena(void);
 
        // frees memory
        ~Arena(void);
 
+       // starts a new fight??
+       void fight(World *leave, const Player *p, Mob *m);
+
        // attempts to exit the arena, returning what world the player should be in
        WorldSwitchInfo exitArena(Player *p);
 };
index ac9eb5d5312feb633848b15c058372a3ab00dc19..cc6d5eb6a2817e7a516485273e977f01e4871941 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -39,6 +39,9 @@ World *currentWorld        = NULL,
          *currentWorldToLeft  = NULL,
          *currentWorldToRight = NULL;
 
+// an arena for fightin'
+Arena *arena = nullptr;
+
 // the currently used folder to grab XML files
 std::string xmlFolder;
 
@@ -80,6 +83,18 @@ int main(int argc, char *argv[]){
 
        static SDL_GLContext mainGLContext = NULL;
 
+       // handle command line arguments
+       if (argc > 1) {
+               std::vector<std::string> args (argc, "");
+               for (int i = 1; i < argc; i++)
+                       args[i] = argv[i];
+
+               for (const auto &s : args) {
+                       if (s == "--reset" || s == "-r")
+                               system("rm -f xml/*.dat");
+               }
+       }
+
        // attempt to initialize SDL
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
                UserError(std::string("SDL was not able to initialize! Error: ") + SDL_GetError());
@@ -218,9 +233,10 @@ int main(int argc, char *argv[]){
        if (currentWorld == NULL)
                UserError("Plot twist: The world never existed...?");
 
-       /**************************
-       ****     GAMELOOP      ****
-       **************************/
+       arena = new Arena();
+       arena->setStyle("");
+       arena->setBackground(WorldBGType::Forest);
+       arena->setBGM("assets/music/embark.wav");
 
        // the main loop, in all of its gloriousness..
        gameRunning = true;
@@ -244,6 +260,7 @@ int main(int argc, char *argv[]){
 
        // close up the game stuff
        currentWorld->save();
+       delete arena;
        //delete currentWorld;
        //delete[] currentXML;
        //aipreload.clear();
@@ -290,32 +307,27 @@ void mainLoop(void){
                        fps = 1000 / game::time::getDeltaTime();
                        debugY = player->loc.y;
                }
-               SDL_Delay(1);
        }
 
        SDL_Delay(1);
 }
 
 void render() {
-       auto SCREEN_WIDTH = game::SCREEN_WIDTH;
-       auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+       const auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+       const auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
 
-       // offset should contain the coordinates of the center of the player's view
-       offset.x = player->loc.x + player->width/2;
-       offset.y = SCREEN_HEIGHT/2;
+       offset.x = player->loc.x + player->width / 2;
 
-       // snap the player's view if we're at a world edge
-       if (currentWorld->getTheWidth() < (int)SCREEN_WIDTH) {
+       // ortho x snapping
+       if (currentWorld->getTheWidth() < (int)SCREEN_WIDTH)
                offset.x = 0;
-       } else {
-               if (player->loc.x - SCREEN_WIDTH/2 < currentWorld->getTheWidth() * -0.5f)
-                       offset.x = ((currentWorld->getTheWidth() * -0.5f) + SCREEN_WIDTH / 2) + player->width / 2;
-               if (player->loc.x + player->width + SCREEN_WIDTH/2 > currentWorld->getTheWidth() *  0.5f)
-                       offset.x = ((currentWorld->getTheWidth() *  0.5f) - SCREEN_WIDTH / 2) - player->width / 2;
-       }
+       else if (offset.x - SCREEN_WIDTH / 2 < currentWorld->getTheWidth() * -0.5f)
+               offset.x = ((currentWorld->getTheWidth() * -0.5f) + SCREEN_WIDTH / 2);
+       else if (offset.x + SCREEN_WIDTH / 2 > currentWorld->getTheWidth() *  0.5f)
+               offset.x = ((currentWorld->getTheWidth() *  0.5f) - SCREEN_WIDTH / 2);
 
-       if(player->loc.y > SCREEN_HEIGHT/2)
-               offset.y = player->loc.y + player->height;
+       // ortho y snapping
+       offset.y = std::max(player->loc.y + player->height / 2, SCREEN_HEIGHT / 2.0f);
 
        // "setup"
        glMatrixMode(GL_PROJECTION);
index 58c1651be6803f0b44d81b717df5db9c5569ed22..216d9efb71171149e94f7bd8194721581dd83c4e 100644 (file)
@@ -64,15 +64,8 @@ void randGetomName(Entity *e)
 
        names.close();
 
-       switch(bufs[0]) {
-       default :
-       case 'm':
-               e->gender = MALE;
-               break;
-       case 'f':
-               e->gender = FEMALE;
-               break;
-       }
+       // gender is a binary construct
+       e->gender = (bufs[0] == 'm') ? MALE : FEMALE;
 
        strcpy(e->name, bufs + 1);
 
@@ -343,7 +336,7 @@ void Entity::draw(void)
                        glColor3ub(255, 105, 180);
        } else if (type == MOBT) {
                if (Mobp(this)->rider != nullptr) {
-               Mobp(this)->rider->loc.x = loc.x + width / 2;
+                       Mobp(this)->rider->loc.x = loc.x + width * 0.25f;
                Mobp(this)->rider->loc.y = loc.y + height - game::HLINE;
                Mobp(this)->rider->vel.y = .12;
            }
index 18292408892a5ed713554a26383e9017c09e3d45..6ce46ab9738a39e65ce355b410fc4ce71fddf439 100644 (file)
@@ -310,6 +310,8 @@ Mob::~Mob()
 }
 
 extern World *currentWorld;
+extern Arena *arena;
+
 void Mob::wander(void)
 {
        static bool YAYA = false;
@@ -320,16 +322,12 @@ void Mob::wander(void)
     if (aggressive && !YAYA && isInside(vec2 {player->loc.x + width / 2, player->loc.y + height / 4})) {
                if (!ui::dialogBoxExists) {
             std::thread([&](void){
-                           auto *a = new Arena(currentWorld, player, this);
-                           a->setStyle("");
-                           a->setBackground(WorldBGType::Forest);
-                           a->setBGM("assets/music/embark.wav");
-
+                           arena->fight(currentWorld, player, this);
                            ui::toggleWhiteFast();
                            YAYA = true;
                            ui::waitForCover();
                            YAYA = false;
-                           currentWorld = a;
+                           currentWorld = arena;
                            ui::toggleWhiteFast();
             }).detach();
                }
index 960b2225f989d2eb09976389c0f2637f54f7c4aa..ebdc7054edbea65bc201dddcc300011826b99dbe 100644 (file)
@@ -5,6 +5,7 @@
 #define ACTION_EPILOUGE { actioning = false; actionHover = 0; }
 
 extern World *currentWorld;
+extern Arena *arena;
 extern Player *player;
 extern bool inBattle;
 
@@ -115,14 +116,11 @@ void actionAttack(void)
 
     if (m->type == MOBT) {
         if (!inBattle && m != nullptr) {
-            Arena *a = new Arena(currentWorld, player, Mobp(m));
-            a->setStyle("");
-            a->setBackground(WorldBGType::Forest);
-            a->setBGM("assets/music/embark.wav");
+            arena->fight(currentWorld, player, Mobp(m));
 
             ui::toggleWhiteFast();
             ui::waitForCover();
-            currentWorld = a;
+            currentWorld = arena;
             ui::toggleWhiteFast();
         }
     } else {
index 223a8bca364c3a6b2305bed62a887efd65f346e0..80fc3229a4b0e5b8c4291063dc491d044a1588e4 100644 (file)
@@ -1488,26 +1488,31 @@ draw(Player *p)
        p->draw();
 }
 
-Arena::Arena(World *leave, Player *p, Mob *m)
+Arena::Arena(void)
 {
        generate(800);
        addMob(new Door(), vec2 {100, 100});
+}
+
+Arena::~Arena(void)
+{
+    mmob->die();
+       deleteEntities();
+}
 
-       inBattle = true;
+void Arena::fight(World *leave, const Player *p, Mob *m)
+{
+    inBattle = true;
 
-       mob.push_back((mmob = m));
+    mob.push_back((mmob = m));
     entity.push_back(mmob);
        mmob->aggressive = false;
 
     arenaNest.emplace_back(leave, p->loc);
 }
 
-Arena::~Arena(void) {
-    mmob->die();
-       deleteEntities();
-}
-
-WorldSwitchInfo Arena::exitArena(Player *p) {
+WorldSwitchInfo Arena::exitArena(Player *p)
+{
        if (!mmob->isAlive() &&
         p->loc.x + p->width / 2 > mob[0]->loc.x &&
            p->loc.x + p->width / 2 < mob[0]->loc.x + HLINES(12)) {