]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
documentation part 4
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 22 Oct 2015 13:25:33 +0000 (09:25 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 22 Oct 2015 13:25:33 +0000 (09:25 -0400)
.gitignore
Changelog
Makefile
include/entities.h
main.cpp
src/Makefile
src/entities.cpp
src/ui.cpp
src/world.cpp

index 0193326932b72c8ca4dcad108951b0e8d7a46352..4304556917d08735cc82448ae4595deb132b3607 100644 (file)
@@ -1,3 +1,5 @@
 main.exe\r
 main\r
-game.odt\r
+\r
+.kdev4\r
+gamedev.kdev4\r
index f21582b473a959a6848cc919099c810ee0b01db5..43e8d5d7b475d8de78db2b7fcedb1586bfa89fe0 100644 (file)
--- a/Changelog
+++ b/Changelog
        - began documenting entities.h/.cpp and world.h/.cpp
        - fixed structure physics
        - improved include locations
+
+10/22/2015:
+===========
+
+       - 1 month Changelog anniversary :)
+       - successfully built and ran game on 64-bit linux
+       - successfully build game on 32-bit Windows (game crashes on execution)
+       - removed npc array; NPCs are now created in the entity array
+       - created a basic texture handling library
+       
+       
\ No newline at end of file
index da4e36ab6151995f96134aeef117aba0151f9164..a362803df2d19bb32747a505496d8f4da6f27e83 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 LIBS = -lGL\r
 WIN_LIBS = -lopengl32 -lmingw32\r
 \r
-FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
+FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2 -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
 \r
 all:\r
        @rm -f out/*.o\r
index fab2ca50fe95885c572e0d723d111e3dfbc7c92e..30a0b0c20ee9c18306e2ad2bb5632b33ec166df0 100644 (file)
@@ -7,7 +7,9 @@
 
 #define DEBUG
 
-#define NPCp(n) ((NPC *)n)
+#define NPCp(n)                        ((NPC *)n)
+#define Structurep(n)  ((Structures *)n)
+#define Mobp(n)                        ((Mob *)n)
 
 #define PLAYER_INV_SIZE        30      // The size of the player's inventory
 #define NPC_INV_SIZE   3       // Size of an NPC's inventory
index 17f34b5d4f6bf8a26b9034d395ce9da8f2bddb33..9fc2c01ed79a6e37848d2c4885e5ab598c5fb07a 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -65,44 +65,43 @@ static GLuint  bgImage;
 bool gameRunning = true;
 
 /*
- *     currentWorld -  This is a pointer to the current world that the player
- *                                     is in. Most drawing/entity handling is done through this
- *                                     variable. This should only be changed when layer switch
- *                                     buttons are pressed (see src/ui.cpp), or when the player
- *                                     enters a Structure/Indoor World (see src/ui.cpp again).
+ *     currentWorld    -       This is a pointer to the current world that the player
+ *                             is in. Most drawing/entity handling is done through this
+ *                             variable. This should only be changed when layer switch
+ *                             buttons are pressed (see src/ui.cpp), or when the player
+ *                             enters a Structure/Indoor World (see src/ui.cpp again).
  * 
- *     player           -      This points to a Player object, containing everything for
- *                                     the player. Most calls made with currentWorld require a
- *                                     Player object as an argument, and glOrtho is set based
- *                                     off of the player's coordinates. This is probably the one
- *                                     Entity-derived object that is not pointed to in the entity
- *                                     array.
+ *     player                This points to a Player object, containing everything for
+ *                             the player. Most calls made with currentWorld require a
+ *                             Player object as an argument, and glOrtho is set based
+ *                             off of the player's coordinates. This is probably the one
+ *                             Entity-derived object that is not pointed to in the entity
+ *                             array.
  * 
  *     entity           -      Contains pointers to 'all' entities that have been created in
- *                                     the game, including NPCs, Structures, and Mobs. World draws
- *                                     and entity handling done by the world cycle through entities
- *                                     using this array. Entities made that aren't added to this
- *                                     array probably won't be noticable by the game.
+ *                             the game, including NPCs, Structures, and Mobs. World draws
+ *                             and entity handling done by the world cycle through entities
+ *                             using this array. Entities made that aren't added to this
+ *                             array probably won't be noticable by the game.
  * 
- *     npc                      -      An array of all NPCs in the game. It's not exactly clear how
- *                                     NPC initing is done, their constructed in this array, then set
- *                                     to be pointed to by entity, then maybe spawned with Entity->spawn().
- *                                     See src/entities.cpp for more.
- *                                     This variable might be referenced as an extern in other files.
+ *     npc              -      An array of all NPCs in the game. It's not exactly clear how
+ *                             NPC initing is done, their constructed in this array, then set
+ *                             to be pointed to by entity, then maybe spawned with Entity->spawn().
+ *                             See src/entities.cpp for more.
+ *                             This variable might be referenced as an extern in other files.
  * 
  *     build            -      An array of all Structures in the game. Entries in entity point to
- *                                     these, allowing worlds to handle the drawing and stuff of these.
- *                                     See src/entities.cpp for more.
+ *                             these, allowing worlds to handle the drawing and stuff of these.
+ *                             See src/entities.cpp for more.
  * 
- *     mob                      -      An array of all Mobs in the game, entity entries should point to these
- *                                     so the world can take care of them. See src/entities.cpp for more.
+ *     mob              -      An array of all Mobs in the game, entity entries should point to these
+ *                             so the world can take care of them. See src/entities.cpp for more.
  * 
 */
 
 World                                                  *currentWorld=NULL;
 Player                                                 *player;
 std::vector<Entity *   >        entity;
-std::vector<NPC                        >        npc;
 std::vector<Structures *>       build;
 std::vector<Mob                        >        mob;
 
index b88dc5314620e430b4583fa94618d7da23c7187c..8021f42c48fd63422c968dd09b92f3fc689a0719 100644 (file)
@@ -1,6 +1,6 @@
 LIBS = -lGL -lSDL2_image -lSDL2_mixer
 
-FLAGS = -m32 -std=c++11 -I../include -I../include/freetype2 -lSDL2main -lSDL2 -lfreetype
+FLAGS = -std=c++11 -I../include -I../include/freetype2 -lSDL2main -lSDL2 -lfreetype
 
 OUT = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out\//g'`
 
index 9b8715093cb837d329baf2a7f39cf2e2dbce69ef..ce983e89d81862a55179431dd35eb4e1a6dde9ba 100644 (file)
@@ -2,7 +2,7 @@
 #include <ui.h>
 
 extern std::vector<Entity*>entity;
-extern std::vector<NPC>npc;
+//extern std::vector<NPC>npc;
 extern std::vector<Structures>build;
 
 extern FILE* names;
@@ -13,14 +13,14 @@ void Entity::spawn(float x, float y){       //spawns the entity you pass to it based o
        loc.y = y;
        vel.x = 0;
        vel.y = 0;
-       right = false;
-       left = false;
-       near = false;
-       ticksToUse = 0;
-       canMove = true;
-       ground = false;
        alive = true;
-       if(!maxHealth)health = maxHealth = 50;
+       right = true;
+       left  = false;
+       near  = false;
+       canMove = true;
+       ground  = false;
+       ticksToUse = 0;
+       if(!maxHealth)health = maxHealth = 1;
        name = (char*)malloc(16);
        getName();
 }
@@ -33,9 +33,6 @@ Player::Player(){ //sets all of the player specific traits on object creation
        subtype = 0;
        maxHealth = 100;
        health = maxHealth;
-       alive = true;
-       ground = false;
-       near = true;
        texture[0] = loadTexture("assets/player.png");
        texture[1] = loadTexture("assets/player1.png");
        texture[2] = loadTexture("assets/player2.png");
@@ -48,9 +45,6 @@ NPC::NPC(){   //sets all of the NPC specific traits on object creation
        speed = 1;
        type = NPCT; //sets type to npc
        subtype = 0;
-       alive = true;
-       canMove = true;
-       near = false;
        texture[0] = loadTexture("assets/NPC.png");
        texture[1] = 0;
        texture[2] = 0;
@@ -60,8 +54,6 @@ NPC::NPC(){   //sets all of the NPC specific traits on object creation
 Structures::Structures(){ //sets the structure type
        type = STRUCTURET;
        speed = 0;
-       alive = true;
-       near = false;
        texture[0] = loadTexture("assets/house1.png");
        texture[1] = 0;
        texture[2] = 0;
@@ -73,9 +65,6 @@ Mob::Mob(){
        speed = 1;
        type = MOBT; //sets type to MOB
        subtype = 1; //SKIRL
-       alive = true;
-       canMove = true;
-       near = false;
        texture[0] = loadTexture("assets/rabbit.png");
        texture[1] = loadTexture("assets/rabbit1.png");
        texture[2] = 0;
@@ -261,9 +250,7 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure
                int tempN = (getRand() % 5 + 2); //amount of villagers that will spawn
                for(int i=0;i<tempN;i++){
                        entity.push_back(new NPC()); //create a new entity of NPC type
-                       npc.push_back(NPC()); //create new NPC
-                       entity[entity.size()] = &npc[npc.size()-1]; //set the new entity to have the same traits as an NPC
-                       entity[entity.size()-1]->spawn(loc.x + (float)(i - 5),100); //sets the position of the villager around the village
+                       NPCp(entity[entity.size()-1])->spawn(loc.x + (float)(i - 5),100); //sets the position of the villager around the village
                }
                return entity.size();
        }
index 256f5d7267670cf29d921d101a7d45340aad167c..f36edebfbfece1ed616d6c368430cd5879c196c1 100644 (file)
@@ -21,9 +21,11 @@ namespace ui {
        bool debug=false;
        bool dialogBoxExists=false;
        unsigned int fontSize;
+
        /*
         * initFonts(), setFontFace(), and setFontSize() are pretty self-explanatory
        */
+
        void initFonts(void){
                if(FT_Init_FreeType(&ftl)){
                        std::cout<<"Error! Couldn't initialize freetype."<<std::endl;
index bd585731d3c8b036e5b6f124951cad3bc47b91c3..98b9aa7a498741d8e5bf4890eba3c2321868831c 100644 (file)
@@ -3,10 +3,11 @@
 #define getWidth(w) ((w->lineCount-GEN_INC)*HLINE)     // Calculates the width of world 'w'
 
 #define GEN_INC 10             // Defines at what interval y values should be calculated for the array 'line'.
-                                               // As explained in World(), the last few lines in the array 'line' are incorrectly calculated
-                                               // or not calculated at all, so GEN_INC is also used to decrease 'lineCount' in functions like draw()
-                                               // and detect().
-#define GRASS_HEIGHT 4 // Defines how long the grass layer of a line should be in multiples of HLINE.
+                               // As explained in World(), the last few lines in the array 'line' are incorrectly calculated
+                               // or not calculated at all, so GEN_INC is also used to decrease 'lineCount' in functions like draw()
+                               // and detect().
+
+#define GRASS_HEIGHT 4         // Defines how long the grass layer of a line should be in multiples of HLINE.
 
 
 #define DRAW_Y_OFFSET 50       // Defines how many pixels each layer should be offset from each other on the y axis when drawn.
@@ -30,8 +31,8 @@ World::World(void){
 }
 
 void World::generate(unsigned int width){      // Generates the world and sets all variables contained in the World class.
-       unsigned int i;                                         // Used for 'for' loops 
-       float inc;                                                      // See line 40
+       unsigned int i;                         // Used for 'for' loops 
+       float inc;                              // See line 40
        
        /*
         *      Calculate the world's real width. The current form of generation fails to generate
@@ -228,47 +229,121 @@ LOOP2:                                                                                                   // Draw each world
 
 void World::singleDetect(Entity *e){
        unsigned int i;
+       
+       /*
+        *      Kill any dead entities.
+       */
+       
        if(e->health<=0){
+         
                e->alive=false;
-       }else if(e->alive){
-               i=(e->loc.x+e->width/2-x_start)/HLINE;  // Calculate what line the player is currently on
-               if(e->loc.y<line[i].y){
-                       e->vel.y=0;
+               
+       }
+       
+       /*
+        *      Handle only living entities.
+       */
+       
+       if(e->alive){
+         
+               /*
+                *      Calculate the line that this entity is currently standing on.
+               */
+               
+               i=(e->loc.x + e->width / 2 - x_start) / HLINE;
+               
+               /*
+                *      If the entity is under the world/line, pop it back to the surface.
+               */
+               
+               if(e->loc.y < line[i].y){
+                 
                        e->ground=true;
-                       e->loc.y=line[i].y-.001*deltaTime;      
-               }else if(e->loc.y>line[i].y-.002*deltaTime){
+                       
+                       e->vel.y=0;
+                       e->loc.y=line[i].y - .001 * deltaTime;
+               
+               /*
+                *      Otherwise, if the entity is above the line... 
+               */
+               
+               }else if(e->loc.y > line[i].y - .002 * deltaTime){
+                 
+                       /*
+                        *      Check for any potential platform collision (i.e. landing on a platform) 
+                       */
+                 
                        for(i=0;i<platform.size();i++){
-                               if(((e->loc.x+e->width>platform[i].p1.x)&(e->loc.x+e->width<platform[i].p2.x))||
-                                  ((e->loc.x<platform[i].p2.x)&(e->loc.x>platform[i].p1.x))){
-                                       if(e->loc.y>platform[i].p1.y&&e->loc.y<platform[i].p2.y){
-                                               if(e->vel.y<0){
+                         
+                               if(((e->loc.x + e->width > platform[i].p1.x) & (e->loc.x + e->width < platform[i].p2.x)) ||     // Check X left bounds
+                                  ((e->loc.x < platform[i].p2.x) & (e->loc.x>platform[i].p1.x))){                                                      // Check X right bounds
+                                       if(e->loc.y > platform[i].p1.y && e->loc.y < platform[i].p2.y){                                                 // Check Y bounds
+                                         
+                                               /*
+                                                *      Check if the entity is falling onto the platform so
+                                                *      that it doesn't snap to it when attempting to jump
+                                                *      through it.
+                                                * 
+                                               */
+                                         
+                                               if(e->vel.y<=0){
+                                                 
+                                                       e->ground=2;
+                                                 
                                                        e->vel.y=0;
                                                        e->loc.y=platform[i].p2.y;
-                                                       e->ground=2;
-                                                       return;
+                                                       
+                                                       //return;       // May not be necessary
                                                }
                                        }
                                }
                        }
-                       e->vel.y-=.001*deltaTime;
+                       
+                       /*
+                        *      Handle gravity.
+                       */
+                       
+                       e->vel.y-=.001 * deltaTime;
+                       
                }
-               if(e->loc.x<x_start){                           // Keep the player inside world bounds (ui.cpp handles world jumping)
+               
+               /*
+                *      Insure that the entity doesn't fall off either edge of the world.
+               */
+               
+               if(e->loc.x<x_start){                                                                                           // Left bound
+                       
                        e->vel.x=0;
-                       e->loc.x=x_start+HLINE/2;
-               }else if(e->loc.x+e->width+HLINE>x_start+getWidth(this)){
+                       e->loc.x=x_start + HLINE / 2;
+                       
+               }else if(e->loc.x + e->width + HLINE > x_start + getWidth(this)){       // Right bound
+                       
                        e->vel.x=0;
-                       e->loc.x=x_start+getWidth(this)-e->width-HLINE;
+                       e->loc.x=x_start + getWidth(this) - e->width - HLINE;
+                       
                }
        }
 }
 
-extern unsigned int newEntityCount;
 void World::detect(Player *p){
        unsigned int i;
+       
+       /*
+        *      Handle the player. 
+       */
+       
        singleDetect(p);
-       for(i=0;i<entity.size()+1;i++){
+       
+       /*
+        *      Handle all remaining entities in this world. 
+       */
+       
+       for(i=0;i<entity.size();i++){
+               
                if(entity[i]->inWorld==this){
+                       
                        singleDetect(entity[i]);
+                       
                }
        }
 }