]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
quest stuff
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 30 Sep 2015 12:51:10 +0000 (08:51 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 30 Sep 2015 12:51:10 +0000 (08:51 -0400)
Changelog
include/Quest.h
include/common.h
include/entities.h
src/Quest.cpp
src/entities.cpp
src/main.cpp

index c1d3ed99ae628251a2eab3ecfc3fb5e8d5fa57da..a699b0d1b904cda22beabc2c4a38a495a114d62f 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -50,3 +50,6 @@
 
        - improved left/right movement
        - added framework work NPC dialog n' stuff
+       - added quest stuff between NPCs and player
+       - began work on giving names to NPCs
+       - began working on config file
index c73bf79711ebe9c9b994a5d57592298a1fcd85a8..076b8005f371676cac8a7fd1b7cfcde9b7f4fda9 100644 (file)
@@ -1,26 +1,23 @@
 #ifndef QUEST_H\r
 #define QUEST_H\r
 \r
-#include <common.h>\r
+#include <vector>\r
+#include <cstdlib>\r
 #include <cstring>\r
 \r
-#define QUEST_LIMIT 5\r
 #define TOTAL_QUESTS 1\r
 \r
 class Quest {\r
 public:\r
        char *title,*desc;\r
-       unsigned int xp;\r
-       Quest(const char *t,const char *d,unsigned int x);\r
+       unsigned int reward;\r
+       Quest(const char *t,const char *d,unsigned int r);\r
        ~Quest();\r
 };\r
 \r
 class QuestHandler {\r
-private:\r
-       unsigned char ccnt;\r
-       const Quest *current[QUEST_LIMIT];\r
 public:\r
-       QuestHandler();\r
+       std::vector<const Quest *>current;\r
        int assign(const char *t);\r
        int drop(const char *t);\r
        int finish(const char *t);\r
index 8410f58608ff300106af517019f749247c8eeec3..5dfbb78411e831c7b8c90e89d492a3d48dc6105f 100644 (file)
@@ -20,6 +20,7 @@ enum _TYPE { //these are the main types of entities
        NPCT       = 1
 };
 
+#include <Quest.h>
 #include <entities.h>
 
 #define SCREEN_WIDTH  1280
index 9e0257ff16c9ffd71897f14b6825d9741615f6d8..aa7eff9345a3829af17ee1e4e154be2f239aa4b3 100644 (file)
@@ -37,6 +37,7 @@ private:
 
 class Player : public Entity{
 public:
+       QuestHandler qh;
        Player();
        void interact();
 };
index a42e42c96795e97062d1d569e9d4b3ae2f1c305f..c9175b1cd93045f854a511ece58f87cd49f7125a 100644 (file)
@@ -4,58 +4,56 @@ const Quest QuestList[TOTAL_QUESTS]={
        Quest("Test","A test quest",0)\r
 };\r
 \r
-Quest::Quest(const char *t,const char *d,unsigned int x){\r
+Quest::Quest(const char *t,const char *d,unsigned int r){\r
        size_t len;\r
        title=(char *)malloc((len=strlen(t)));\r
        strncpy(title,t,len);\r
        desc=(char *)malloc((len=strlen(d)));\r
        strncpy(desc,d,len);\r
-       xp=x;\r
+       reward=r;\r
 }\r
+\r
 Quest::~Quest(){\r
        free(title);\r
        free(desc);\r
-       xp=0;\r
+       reward=0;\r
 }\r
 \r
-QuestHandler::QuestHandler(){\r
-       ccnt=0;\r
-}\r
 int QuestHandler::assign(const char *t){\r
-       unsigned int i=0;\r
-       if(ccnt==QUEST_LIMIT)\r
-               return -1;\r
-       for(;i<TOTAL_QUESTS;i++){\r
+       unsigned char i;\r
+       for(i=0;i<current.size();i++){\r
+               if(!strcmp(current[i]->title,t)){\r
+                       return -2;\r
+               }\r
+       }\r
+       for(i=0;i<TOTAL_QUESTS;i++){\r
                if(!strcmp(QuestList[i].title,t)){\r
-                       current[ccnt++]=&QuestList[i];\r
-                       return ccnt;\r
+                       current.push_back(&QuestList[i]);\r
+                       return current.size();\r
                }\r
        }\r
        return -1;\r
 }\r
+\r
 int QuestHandler::drop(const char *t){\r
-       unsigned char i=0;\r
-       for(;i<ccnt;i++){\r
+       unsigned char i;\r
+       for(i=0;i<current.size();i++){\r
                if(!strcmp(current[i]->title,t)){\r
-                       for(i++;i<ccnt;i++){\r
-                               current[i-1]=current[i];\r
-                       }\r
-                       return (--ccnt);\r
+                       current.erase(current.begin()+i);\r
+                       return current.size();\r
                }\r
        }\r
        return -1;\r
 }\r
+\r
 int QuestHandler::finish(const char *t){\r
-       unsigned char i=0;\r
-       unsigned int j;\r
-       for(;i<ccnt;i++){\r
+       unsigned char i;\r
+       unsigned int r;\r
+       for(;i<current.size();i++){\r
                if(!strcmp(current[i]->title,t)){\r
-                       j=current[i]->xp;\r
-                       for(i++;i<ccnt;i++){\r
-                               current[i-1]=current[i];\r
-                       }\r
-                       ccnt--;\r
-                       return j;\r
+                       r=current[i]->reward;\r
+                       current.erase(current.begin()+i);\r
+                       return r;\r
                }\r
        }\r
        return -1;\r
index cff971f5d3e429d9311646b21d13b1b1281b9c77..8689b005333a1b3096b561e53ef62cf1929be41e 100644 (file)
@@ -94,14 +94,13 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure
                width =  20 * HLINE;
                height = 16 * HLINE;
 
-               int tempN = (getRand() % 5 + 1); //amount of villagers that will spawn
+               int tempN = 2;//(getRand() % 5 + 1); //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
                }
-               entity.pop_back();
                return entity.size();
        }
 }
index 77d22bc1f3857aee93cf05d8e9d285762b2fe442..afc34b633978e99da0e78d7b391735809ab6f346 100644 (file)
@@ -34,7 +34,7 @@ void logic();
 void render();
 
 int entityInteractTest(NPC *speaker){
-       ui::dialogBox("NPC: Hello there!");
+       player->qh.assign("Test");
        return 1;
 }
 
@@ -213,6 +213,8 @@ void render(){
                glVertex2i(mx,my-HLINE*3.5);
        glEnd();
 
+       ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT/2,"Quest count: %d",player->qh.current.size());
+
        glPopMatrix();                                                                  //take the matrix(s) off the stack to pass them to the renderer
        SDL_GL_SwapWindow(window);                                              //give the stack to SDL to render it
 }