From 8deee144293102d4498424c38161d13c877250b2 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 30 Sep 2015 08:51:10 -0400 Subject: quest stuff --- Changelog | 3 +++ include/Quest.h | 13 +++++-------- include/common.h | 1 + include/entities.h | 1 + src/Quest.cpp | 52 +++++++++++++++++++++++++--------------------------- src/entities.cpp | 3 +-- src/main.cpp | 4 +++- 7 files changed, 39 insertions(+), 38 deletions(-) diff --git a/Changelog b/Changelog index c1d3ed9..a699b0d 100644 --- 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 diff --git a/include/Quest.h b/include/Quest.h index c73bf79..076b800 100644 --- a/include/Quest.h +++ b/include/Quest.h @@ -1,26 +1,23 @@ #ifndef QUEST_H #define QUEST_H -#include +#include +#include #include -#define QUEST_LIMIT 5 #define TOTAL_QUESTS 1 class Quest { public: char *title,*desc; - unsigned int xp; - Quest(const char *t,const char *d,unsigned int x); + unsigned int reward; + Quest(const char *t,const char *d,unsigned int r); ~Quest(); }; class QuestHandler { -private: - unsigned char ccnt; - const Quest *current[QUEST_LIMIT]; public: - QuestHandler(); + std::vectorcurrent; int assign(const char *t); int drop(const char *t); int finish(const char *t); diff --git a/include/common.h b/include/common.h index 8410f58..5dfbb78 100644 --- a/include/common.h +++ b/include/common.h @@ -20,6 +20,7 @@ enum _TYPE { //these are the main types of entities NPCT = 1 }; +#include #include #define SCREEN_WIDTH 1280 diff --git a/include/entities.h b/include/entities.h index 9e0257f..aa7eff9 100644 --- a/include/entities.h +++ b/include/entities.h @@ -37,6 +37,7 @@ private: class Player : public Entity{ public: + QuestHandler qh; Player(); void interact(); }; diff --git a/src/Quest.cpp b/src/Quest.cpp index a42e42c..c9175b1 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -4,58 +4,56 @@ const Quest QuestList[TOTAL_QUESTS]={ Quest("Test","A test quest",0) }; -Quest::Quest(const char *t,const char *d,unsigned int x){ +Quest::Quest(const char *t,const char *d,unsigned int r){ size_t len; title=(char *)malloc((len=strlen(t))); strncpy(title,t,len); desc=(char *)malloc((len=strlen(d))); strncpy(desc,d,len); - xp=x; + reward=r; } + Quest::~Quest(){ free(title); free(desc); - xp=0; + reward=0; } -QuestHandler::QuestHandler(){ - ccnt=0; -} int QuestHandler::assign(const char *t){ - unsigned int i=0; - if(ccnt==QUEST_LIMIT) - return -1; - for(;ititle,t)){ + return -2; + } + } + for(i=0;ititle,t)){ - for(i++;ititle,t)){ - j=current[i]->xp; - for(i++;ireward; + current.erase(current.begin()+i); + return r; } } return -1; diff --git a/src/entities.cpp b/src/entities.cpp index cff971f..8689b00 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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;ispawn(loc.x + (float)(i - 5),100); //sets the position of the villager around the village } - entity.pop_back(); return entity.size(); } } diff --git a/src/main.cpp b/src/main.cpp index 77d22bc..afc34b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 } -- cgit v1.2.3