]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added object class, and added quest listing
authordrumsetmonkey <abelleisle@roadrunner.com>
Fri, 13 Nov 2015 13:26:31 +0000 (08:26 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Fri, 13 Nov 2015 13:26:31 +0000 (08:26 -0500)
Makefile
include/common.h
include/entities.h
include/world.h
main.cpp
src/Makefile
src/entities.cpp
src/gameplay.cpp
src/ui.cpp
src/world.cpp

index bbeff1eef73ef30286d5f2cb17134c82ffbd1b15..7a7a868ac273b0b1541dc144f286dba1c3b265cf 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
-LIBS = -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
+LIBS = -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
 \r
 WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype\r
 \r
-FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2\r
+FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2\r
 \r
 all:\r
        @rm -f out/*.o\r
index 93735fae523a9457785f3e69b686e5fbbe0d2810..bfd9db66d6df0118af96e9c64b9915b5fd793da7 100644 (file)
@@ -36,7 +36,7 @@ typedef unsigned int uint;
  *     This flag lets the compiler know that we are using shaders
 */
 
-#define SHADERSd
+#define SHADERSs
 
 /*
  *     Create a basic 2-point structure for coordinate saving
index 53efc639968bf91d0720257edf1882f281b50841..b590c8d1d7472bd2718322ca23681d2de2d601c7 100644 (file)
@@ -15,6 +15,7 @@
 #define NPC_INV_SIZE   3       // Size of an NPC's inventory
 
 enum _TYPE { //these are the main types of entities
+       OBJECTT = -2,
        STRUCTURET = -1,
        PLAYERT,
        NPCT,
@@ -106,6 +107,13 @@ public:
        void wander(int);
 };
 
+class Object : public Entity{
+public:
+       Object(int);
+       void interact();
+private:
+       int ID;
+};
 #endif // ENTITIES_H
 
 /**
index cb40ef63b39ed5466fdcb9b73231fcfe0596ca0b..6b14f7ef4d7f32ea4e653672735238046fd07d2a 100644 (file)
@@ -76,10 +76,17 @@ public:
        std::vector<Structures  *>      build;
        std::vector<Mob                 *>      mob;
        std::vector<Entity              *>      entity;
+       std::vector<Object              *>      object;
        
+       //template<class T>
+       //void getEntityLocation(std::vector<T*>&, unsigned int);
+
        void addStructure(_TYPE t,float x,float y,World *outside,World *inside);
        void addMob(int t,float x,float y);
        void addNPC(float x,float y);
+       void addObject(int, float, float);
+
+       //void removeObjet(Object);
        
        void update(Player *p,unsigned int delta);
        
index 292cde6d9c63f35c5ade03cb57bd528d53e4b98f..aa77fc2e8ecb39e602d8e116f08a1e52511864a7 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -85,7 +85,6 @@ float handAngle;
 
 World                                                          *currentWorld=NULL;
 Player                                                         *player;
-
 /*
  *     Tells if player is currently inside a structure.
 */
@@ -215,7 +214,7 @@ typedef enum {
        RAIN
 } WEATHER;
 
-#define DAY_CYCLE 3000
+#define DAY_CYCLE 300
 
 static WEATHER weather = SUNNY;
 static vec2 star[100];
@@ -530,6 +529,7 @@ void mainLoop(void){
                logic();
                prevPrevTime = currentTime;
        }
+       //ui::handleMouse();
        
        /*
         *      Update player and entity coordinates.
@@ -548,8 +548,7 @@ void mainLoop(void){
                
        }else if(!(debugDiv%10)){
                debugY = player->loc.y;
-       }
-       
+       }       
        render();       // Call the render loop
 }
 
@@ -674,12 +673,15 @@ void render(){
         *      Draws stars if it is an appropriate time of day for them.
        */
 
+       int base = 40 - (int)worldGetYBase(currentWorld);
+       int shade = worldShade*2;
+
        if(((weather==DARK )&(tickCount%DAY_CYCLE)<DAY_CYCLE/2)   ||
           ((weather==SUNNY)&(tickCount%DAY_CYCLE)>DAY_CYCLE*.75) ){
                   
                if(tickCount%DAY_CYCLE){        // The above if statement doesn't check for exact midnight.
                                
-                       glColor4ub(255,255,255,255);
+                       safeSetColorA(255,255,255,shade);
                        for(unsigned int i=0;i<100;i++){
                                glRectf(star[i].x+offset.x*.9,star[i].y,star[i].x+offset.x*.9+HLINE,star[i].y+HLINE);
                        }
@@ -692,9 +694,6 @@ void render(){
         *      background elements should be. 
        */
 
-       int base = 40 - (int)worldGetYBase(currentWorld);
-       int shade = worldShade*2;
-
        glEnable(GL_TEXTURE_2D);
 
        /*
@@ -882,7 +881,7 @@ void render(){
                
                ui::putText(offset.x-SCREEN_WIDTH/2,
                                        (offset.y+SCREEN_HEIGHT/2)-ui::fontSize,
-                                       "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n     (y)%+.2f\nTc: %u\nQc: %u\n HA: %+.2f",
+                                       "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n     (y)%+.2f\nTc: %u\nHA: %+.2f",
                                        fps,
                                        player->ground,
                                        SCREEN_WIDTH,                           // Window dimensions
@@ -891,7 +890,6 @@ void render(){
                                        player->loc.x,                          // The player's x coordinate
                                        debugY,                                         // The player's y coordinate
                                        tickCount,
-                                       player->qh.current.size(),      // Active quest count
                                        handAngle
                                        );
                if(ui::posFlag){
@@ -1073,6 +1071,28 @@ void logic(){
                }
        }
 
+       unsigned int i = 0;
+       for(auto &o : currentWorld->object){
+               if(o->alive){
+                       if(pow((o->loc.x - player->loc.x),2) + pow((o->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
+
+                                       /*
+                                        *      Check for a right click, and allow the Object to interact with the
+                                        *      player if one was made.
+                                       */
+
+                                       if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
+                                               std::cout << "Picking up!\n";
+                                               o->interact();
+                                       }
+                               }
+               }
+               if(!(o->alive)){
+                       currentWorld->object.erase(currentWorld->object.begin()+i);
+               }
+               i++;
+       }
+
        /*
         *      Switch between day and night (SUNNY and DARK) if necessary.
        */
index a243846937aa25fecec9f36a614d74e0dbd303ec..aacef575c2349860915b6724aaef5fba0becdca7 100644 (file)
@@ -1,6 +1,6 @@
-LIBS = -lGL -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
+LIBS = -lGL -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
 
-FLAGS = -m32 -std=c++11 -I../include -I../include/freetype2
+FLAGS = -std=c++11 -I../include -I../include/freetype2
 
 OUT = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out\//g'`
 
index b076684b2cfacf960c2b960da638cfdb14dd1f54..a0005c33cd620537905fc81ce164dc657ee422ee 100644 (file)
@@ -6,6 +6,8 @@ extern unsigned int loops;
 
 extern World *currentWorld;
 
+extern Player *player;
+
 void Entity::spawn(float x, float y){  //spawns the entity you pass to it based off of coords and global entity settings
        loc.x = x;
        loc.y = y;
@@ -89,6 +91,18 @@ Mob::Mob(int sub){
        inv = new Inventory(NPC_INV_SIZE);
 }
 
+Object::Object(int id):ID(id){
+       type = OBJECTT;
+       alive = true;
+       near = false;
+       width  = HLINE * 8;
+       height = HLINE * 8;
+
+       maxHealth = health = 1;
+       tex = new Texturec(1, "assets/items/ITEM_SWORD.png");   
+}
+
+
 void Entity::draw(void){               //draws the entities
        glPushMatrix();
        if(type==NPCT){
@@ -161,6 +175,8 @@ void Entity::draw(void){            //draws the entities
                        default:
                        break;
                }
+       }else if(type == OBJECTT){
+               tex->bind(0);
        }else{
                tex->bind(0);
        }
@@ -279,6 +295,11 @@ void NPC::interact(){ //have the npc's interact back to the player
        }
 }
 
+void Object::interact(){
+       this->alive = false;
+       player->inv->addItem((ITEM_ID)(ID), (char)1);
+}
+
 /*
  *     This spawns the structures
  *
@@ -359,4 +380,4 @@ void Mob::wander(int timeRun){
        default:
                break;
        }
-}
+}
\ No newline at end of file
index c1705119b213eb4b6d9fb132fa5a9d1a14578978..bfc2bdb843b3bfb09ec04b735577367cb05ec244 100644 (file)
@@ -5,7 +5,6 @@
 
 extern World   *currentWorld;
 extern Player  *player;
-
 extern void mainLoop(void);
 
 int compTestQuest(NPC *speaker){
@@ -32,7 +31,6 @@ void initEverything(void){
        /*
         *      World creation:
        */
-       
        World *test=new World();
        World *playerSpawnHill=new World();
        
@@ -89,8 +87,10 @@ void initEverything(void){
         *      Spawn a mob. 
        */
        
-       currentWorld->addMob(MS_RABBIT,200,100);
-       currentWorld->addMob(MS_BIRD,-500,500);
+       test->addMob(MS_RABBIT,200,100);
+       test->addMob(MS_BIRD,-500,500);
+
+       currentWorld->addObject(2, 500,200);
        
        /*
         *      Link all the entities that were just created to the initial world, and setup a test AI function. 
index 237d09aeb840612e5aa5a09c1f7ebacd9824fa6e..edfa7865dfb38be40f0efe34969768beaa72d068 100644 (file)
@@ -108,6 +108,7 @@ namespace ui {
                case 'y':
                case 'p':
                case 'j':y-=fontSize/4;break;
+               case 'Q':y-=fontSize/5;break;
                default:break;
                }
                glBegin(GL_QUADS);
@@ -217,6 +218,7 @@ namespace ui {
                }
                setFontSize(14);
                putText(((SCREEN_WIDTH/2)+offset.x)-125,(offset.y+SCREEN_HEIGHT/2)-fontSize,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
+                                                               
                                                                                                                                                                                        (unsigned)player->maxHealth);
                if(player->alive){
                        glColor3ub(255,0,0);
@@ -225,6 +227,16 @@ namespace ui {
                                        ((SCREEN_WIDTH/2+offset.x)-125)+((player->health/player->maxHealth)*100),
                                        (offset.y+SCREEN_HEIGHT/2)-32+12);
                }
+
+               /*
+                * Lists all of the quests the player has
+               */
+               putText(((SCREEN_WIDTH/2)+offset.x)-125,(offset.y+SCREEN_HEIGHT/2)-fontSize*4, "Current Quests:",NULL);
+
+               for(auto &c : player->qh.current){
+                       putText(((SCREEN_WIDTH/2)+offset.x)-125,(offset.y+SCREEN_HEIGHT/2)-fontSize*5, "%s",c->title);
+               }
+
        }
        void handleEvents(void){
                static bool left=false,right=false;
index 049e49877d49774ea6d7f7170874a9151d795e38..51f75793333fa6f4df88ce9814292d800f5e4aaf 100644 (file)
@@ -286,7 +286,9 @@ LOOP2:
        /*
         *      Draw the layer up until the grass portion, which is done later.
        */
-       
+       /*
+        * TODO: CLYNE CHANGE THE NAME OF THIS
+       */
        bool hey=false;
        glBegin(GL_QUADS);
                for(i=is;i<ie-GEN_INC;i++){
@@ -372,6 +374,13 @@ LOOP2:
                m->draw();
                m->loc.y-=(yoff-DRAW_Y_OFFSET);
        }
+       for(auto &o : current->object){
+               if(o->alive){
+                       o->loc.y+=(yoff-DRAW_Y_OFFSET);
+                       o->draw();
+                       o->loc.y-=(yoff-DRAW_Y_OFFSET);
+               }
+       }
        
        /*
         *      If we're drawing the closest/last world, handle and draw the player.
@@ -549,6 +558,18 @@ void World::addStructure(_TYPE t,float x,float y,World *outside,World *inside){
        entity.push_back(build.back());
 }
 
+/*template<class T>
+void World::getEntityLocation(std::vector<T*>&vecBuf, unsigned int n){
+       T bufVar = vecBuf.at(n);
+       unsigned int i = 0;
+       for(auto &e : entity){
+               if(entity.at(i) == bufVar){
+                       entity.erase(entity.begin()+i);
+               }
+               i++;
+       }
+}*/
+
 void World::addMob(int t,float x,float y){
        mob.push_back(new Mob(t));
        mob.back()->spawn(x,y);
@@ -563,6 +584,17 @@ void World::addNPC(float x,float y){
        entity.push_back(npc.back());
 }
 
+void World::addObject(int i, float x, float y){
+       object.push_back(new Object(i));
+       object.back()->spawn(x,y);
+
+       entity.push_back(object.back());
+}
+
+/*void World::removeObject(Object i){
+       object.delete(i);
+}*/
+
 /*
  *     The rest of these functions are explained well enough in world.h ;)
 */