]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world improvements, quest preloads
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 29 Oct 2015 13:17:32 +0000 (09:17 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 29 Oct 2015 13:17:32 +0000 (09:17 -0400)
Changelog
Goals.txt
include/common.h
include/world.h
main.cpp
src/ui.cpp
src/world.cpp

index 4af9d0cc99e11f5183df475dc6ba9c3cf0738900..a5b5df97e820ced91bd55c3c24b99bb87d32feaf 100644 (file)
--- a/Changelog
+++ b/Changelog
        - found bug with npc quest preloading
        - documented more of world.cpp
        - improved background textures/parallax stuff
-       - 
+
+10/29/2015:
+===========
+
+       - re-added NPC quests
+       - fixed issue with player standing on grass
+       - made game exit when player falls in hole
+       - documented world.h
+       - fixed camera ortho
+       - began working on layer-switching animation
index 9b259183210671f3d782ba5f018832302480d264..46a35b712f25179e4bca94a2fce6e56fb258e85f 100644 (file)
--- a/Goals.txt
+++ b/Goals.txt
@@ -3,9 +3,9 @@ Goals:
 End of October:
 ===============
 
-       - have textures for the world and entities (png's and stuff)
-       - have basic quest handling/player can interact with NPCs to take quests
-       - have basic mobs/animals
+       - have textures for the world and entities (png's and stuff)                            check!
+       - have basic quest handling/player can interact with NPCs to take quests        check!
+       - have basic mobs/animals                                                                                                       check?
 
 End of November:
 ================
index f278020fd1c41ac652e85560f961913bf11aff1b..c3b1aed5e3b367713894370c4c567aa54df1d7dd 100644 (file)
@@ -47,7 +47,7 @@ typedef struct {
  *     and whether or not we want the window to be fullscreen.
 */
 
-#define GAME_NAME              "Independent Study v.0.2 alpha"
+#define GAME_NAME              "Independent Study v.0.3 alpha"
 
 #define SCREEN_WIDTH   1280
 #define SCREEN_HEIGHT  720
index ab161c05df54aed8e2bacbed524b54d1036fe0eb..5ec01aec873248397b7f3983c33928bca2167a77 100644 (file)
@@ -13,6 +13,7 @@ typedef struct {
 */
 class World {
 protected:
+       
        /*
         *      struct line_t
         * 
@@ -24,61 +25,126 @@ protected:
         * line no. 123456789...
         * 
         */
+        
        struct line_t {
                bool gs;
                float y,gh[2];
                unsigned char color;
        } __attribute__ ((packed)) *line;
-       std::vector<Platform> platform; // An array (vector thing) of platforms
-       int x_start;                    // Worlds are centered on the x axis (0,n), this contains
-                                                       // where to start drawing the world to have it centered properly.
-       World *behind;                  // Pointers to other areas of land that are behind or in front of this one, respectively.
-       void singleDetect(Entity *e);   // Handles an individual entity (gravity n' stuff)
+       
+       /*
+        *      Keeps a dynamically allocated array of platforms in the world.
+       */
+       
+       std::vector<Platform> platform;
+       
+       /*
+        *      Contains the starting x-coordinate to draw the world at. This should be equal to
+        *      - getWidth() (see world.cpp) / 2
+       */
+       
+       int x_start;
+       
+       /*
+        *      Runs world detection for a single entity. This function is used in World->detect()
+        *      to detect the player and all entities in the world.
+       */
+       
+       void singleDetect(Entity *e);
+       
+       /*
+        *      The size of the line array. This is set once by World->generate().
+       */
+       
+       unsigned int lineCount;
+       
 public:
-       unsigned int lineCount;         // Size of the array 'line' (aka the width of the world)
-       World *toLeft,*toRight;         // Pointers to areas to the left and right of this world. These are made public
-                                                               // so that they can easily be set without a function.
-       World *infront;
-                                                               
+
+       /*
+        *      These pointers keep track of worlds that are adjacent to this one. Used in ui.cpp
+        *      for world jumping.
+       */
+
+       World *toLeft,
+                 *toRight,
+                 *behind,
+                 *infront;
+       
+       /*
+        *      Constructor and deconstructor, these do what you would expect.
+       */
+                                               
        World(void);
        ~World(void);                           // Frees the 'line' array.
        
-       virtual void generate(unsigned int width);                      // Generate the world
+       /*
+        *      Generate a world of width `width`. This function is virtual so that other world
+        *      classes that are based on this one can generate themselves their own way.
+       */
        
-       void addLayer(unsigned int width);                                      // Generates a new world and makes 'behind' point to it. If 'behind'
-                                                                                                               // already points to a world, the new world will be set to be behind 'behind'.
-                                                                                                               
-       virtual void draw(Player *p);                                           // Draws the world around the coordinates 'vec'
+       virtual void generate(unsigned int width);
        
+       /*
+        *      Looks for the furthest back layer in this world and adds a new layer of width `width` behind it.
+       */
        
-       void detect(Player *p);                                                         // Insures objects/entities stored in an Entity class stay outside of the
-                                                                                                               // ground (defined by array 'line'), and handles gravity for the object/entity
-                                                                                                               // by modifying it's velocity
+       void addLayer(unsigned int width);
        
-       World *goWorldLeft(Player *p);                                          // Returns the world to the left of this one if it exists and the player at
-                                                                                                               // location 'loc' with width 'width' is at the left edge of this world.
-       World *goWorldRight(Player *p);                                         // Functions the same as goWorldLeft(), but checks/returns the world to the right
-                                                                                                               // of the player.
+       /*
+        *      Draw the world and entities based on the player's coordinates. Virtual for the same
+        *      reason generate() is.
+       */
                                                                                                                
-       World *goWorldBack(Player *p);                                          // Returns the address of the world behind this one if it exists and the player
-                                                                                                               // at location 'loc' with width 'width' is within the area of it (i.e., when this
-                                                                                                               // world is drawn the world has to appear directly behind the player)
-       World *goWorldFront(Player *p);                                         // Functions the same as goWorldBack(), but checks/returns the world in front of
-                                                                                                               // this one.
-       World *goInsideStructure(Player *p);                            // Returns the world contained in a structure if the player is requesting to enter
-                                                                                                               // it and is standing in front of it.
-       void addPlatform(float x,float y,float w,float h);      // Dynamically adds a platform to the platform array. These will be automatically
-                                                                                                               // drawn and handled by the world.
-       void addHole(unsigned int start,unsigned int end);      // Create a hole in the world
-       
-       int getStart(void);
+       virtual void draw(Player *p);
+       
+       
+       /*
+        *      Detect the player and any entities in the current world.
+       */
+       
+       void detect(Player *p);
+       
+       /*
+        *      These functions return the pointer to the world in the direction that is requested if it
+        *      exists and the player is in a condition that it can make the switch, otherwise they
+        *      return the current world.
+       */
+       
+       World *goWorldLeft(Player *p);
+       World *goWorldRight(Player *p);                                 
+       World *goWorldBack(Player *p);
+       World *goWorldFront(Player *p);
+       
+       /*
+        *      Called to enter/exit a structure.
+       */
+       
+       World *goInsideStructure(Player *p);
+       
+       /*
+        *      These functions add features to the world.
+       */
+       
+       void addPlatform(float x,float y,float w,float h);
+       void addHole(unsigned int start,unsigned int end);
+       
+       /*
+        *      Get's the world's width.
+       */
+       
+       int getTheWidth(void);
 };
 
+/*
+ *     Gets a good base y value for background rendering.
+*/
+
 float worldGetYBase(World *w);
 
 /*
  *     IndoorWorld - Indoor settings stored in a World class ;)
  */
 class IndoorWorld : public World {
 public:
        IndoorWorld(void);
index faa2be4fa5a564c464619cd7c576825282ad4b9c..3af8baf25f9dd38a6227953b1eff867ff67cbedc 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -181,6 +181,7 @@ unsigned int millis(void){
 /*******************************************************************************
  * MAIN ************************************************************************
  *******************************************************************************/
 int main(int argc, char *argv[]){
        gameRunning=false;
        
@@ -740,6 +741,7 @@ void logic(){
        */
        
        currentWorld->detect(player);
+       if(player->loc.y<.02)gameRunning=false;
        
        /*
         *      Entity logic: This loop finds every entity that is alive and in the current world. It then
index e5a2f44982ee3b6b7c72969086085c79779296a2..5d6c2abdf1f79c030617b55d184fd802d365b055 100644 (file)
@@ -122,15 +122,18 @@ namespace ui {
        }
        float putString(const float x,const float y,const char *s){
                unsigned int i=0,j;
-               float xo=x,yo=y;
+               float xo=x,yo=y,pw=0;
                do{
                        if(s[i]=='\n'){
                                yo-=fontSize*1.05;
                                xo=x;
                        }else if(s[i]==' '){
                                xo+=fontSize/2;
+                       }else if(s[i]=='\b'){
+                               xo-=pw;
                        }else{
-                               xo+=putChar(xo,yo,s[i])+fontSize*.1;
+                               pw=putChar(xo,yo,s[i])+fontSize*.1;
+                               xo+=pw;
                        }
                }while(s[i++]);
                return xo;
@@ -237,17 +240,29 @@ namespace ui {
                                                player->ground=false;
                                        }
                                }
+                               World *tmp;
                                if(SDL_KEY==SDLK_i){
-                                       player->vel.y=.2;
-                                       player->loc.y+=HLINE*7;
-                                       player->ground=false;
+                                       tmp=currentWorld;
                                        currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible  
+                                       if(tmp!=currentWorld){
+                                               currentWorld->detect(player);
+                                               player->vel.y=.2;
+                                               player->loc.y+=HLINE*5;
+                                               player->ground=false;
+                                       }
                                }
                                if(SDL_KEY==SDLK_k){
-                                       player->vel.y=.2;
-                                       player->loc.y+=HLINE*10;
-                                       player->ground=false;
+                                       tmp=currentWorld;
                                        currentWorld=currentWorld->goWorldFront(player);        // Go forward a layer if possible
+                                       if(tmp!=currentWorld){
+                                               player->loc.y=0;
+                                               currentWorld->behind->detect(player);
+                                               player->vel.y=.2;
+                                               player->ground=false;
+                                       }
+                               }
+                               if(SDL_KEY==SDLK_c){
+                                       dialogBox("","You pressed `c`, but nothing happened.");
                                }
                                if(SDL_KEY==SDLK_LSHIFT)player->speed = 3;                                                      // Sprint
                                if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
@@ -271,12 +286,12 @@ namespace ui {
                }
                
                unsigned int i;
-               //if(!dialogBoxExists&&AIpreaddr.size()){       // Flush preloaded AI functions if necessary
-                       //for(i=0;i<AIpreaddr.size();i++){
-                               //AIpreaddr.front()->addAIFunc(AIpreload.front(),false);
-                               //AIpreaddr.erase(AIpreaddr.begin());
-                               //AIpreload.erase(AIpreload.begin());
-                       //}
-               //}
+               if(!dialogBoxExists&&AIpreaddr.size()){ // Flush preloaded AI functions if necessary
+                       for(i=0;i<AIpreaddr.size();i++){
+                               AIpreaddr.front()->addAIFunc(AIpreload.front(),false);
+                               AIpreaddr.erase(AIpreaddr.begin());
+                               AIpreload.erase(AIpreload.begin());
+                       }
+               }
        }
 }
index 97ec5accf2f06573deab8fdb1dc3273ebd7803b4..599b1ef8b49e2796c3dd9c5cd9565f79dde33ff1 100644 (file)
@@ -240,15 +240,26 @@ LOOP2:
         *      Draw the layer up until the grass portion, which is done later.
        */
        
+       bool hey=false;
        glBegin(GL_QUADS);
                for(i=is;i<ie-GEN_INC;i++){
-                       cline[i].y+=(yoff-DRAW_Y_OFFSET);                                                                                                               // Add the y offset
-                       safeSetColor(cline[i].color+shade,cline[i].color-50+shade,cline[i].color-100+shade);    // Set the shaded dirt color
+                       cline[i].y+=(yoff-DRAW_Y_OFFSET);                                                                                                                       // Add the y offset
+                       if(!cline[i].y){
+                               cline[i].y+=50;
+                               hey=true;
+                               safeSetColor(cline[i].color-100+shade,cline[i].color-150+shade,cline[i].color-200+shade);
+                       }else{
+                               safeSetColor(cline[i].color+shade,cline[i].color-50+shade,cline[i].color-100+shade);    // Set the shaded dirt color
+                       }
                        glVertex2i(cx_start+i*HLINE      ,cline[i].y-GRASS_HEIGHT);
                        glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT);
                        glVertex2i(cx_start+i*HLINE+HLINE,0);
                        glVertex2i(cx_start+i*HLINE              ,0);
-                       cline[i].y-=(yoff-DRAW_Y_OFFSET);                                                                                                               // Restore the line's y value
+                       cline[i].y-=(yoff-DRAW_Y_OFFSET);                                                                                                                       // Restore the line's y value
+                       if(hey){
+                               hey=false;
+                               cline[i].y=0;
+                       }
                }
        glEnd();
        
@@ -277,6 +288,10 @@ LOOP2:
                                        cline[i].gs=false;
                                else cline[i].gs=true;
                        }
+               }else{
+                       for(i=0;i<lineCount-GEN_INC;i++){
+                               cline[i].gs=true;
+                       }
                }
                
                /*
@@ -289,12 +304,17 @@ LOOP2:
                 *      Draw non-structure entities.
                */
                
-               if(current==this){
-                       for(i=0;i<entity.size();i++){
-                               if(entity[i]->inWorld==this && entity[i]->type != STRUCTURET)
-                                       entity[i]->draw();
-                       }
+               for(i=0;i<entity.size();i++){
+                       if(entity[i]->inWorld==this && entity[i]->type != STRUCTURET)
+                               entity[i]->draw();
                }
+               
+       }else{
+               
+               /*for(i=0;i<lineCount-GEN_INC;i++){
+                       cline[i].gs=true;
+               }*/
+       
        }
        
        /*
@@ -581,8 +601,8 @@ void World::addHole(unsigned int start,unsigned int end){
        }
 }
 
-int World::getStart(void){
-       return -x_start;
+int World::getTheWidth(void){
+       return x_start*2;
 }
 
 IndoorWorld::IndoorWorld(void){