diff options
-rw-r--r-- | assets/names_en-us | 0 | ||||
-rw-r--r-- | include/Quest.h | 29 | ||||
-rw-r--r-- | include/common.h | 3 | ||||
-rw-r--r-- | src/Quest.cpp | 62 | ||||
-rw-r--r-- | src/main.cpp | 7 |
5 files changed, 99 insertions, 2 deletions
diff --git a/assets/names_en-us b/assets/names_en-us new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/assets/names_en-us diff --git a/include/Quest.h b/include/Quest.h new file mode 100644 index 0000000..c73bf79 --- /dev/null +++ b/include/Quest.h @@ -0,0 +1,29 @@ +#ifndef QUEST_H
+#define QUEST_H
+
+#include <common.h>
+#include <cstring>
+
+#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);
+ ~Quest();
+};
+
+class QuestHandler {
+private:
+ unsigned char ccnt;
+ const Quest *current[QUEST_LIMIT];
+public:
+ QuestHandler();
+ int assign(const char *t);
+ int drop(const char *t);
+ int finish(const char *t);
+};
+
+#endif // QUEST_H
diff --git a/include/common.h b/include/common.h index 0c35604..8410f58 100644 --- a/include/common.h +++ b/include/common.h @@ -11,7 +11,8 @@ #include <SDL2/SDL_image.h> #include <SDL2/SDL_opengl.h> -typedef struct { float x; float y; } vec2; +typedef struct { float x; float y; }vec2; +typedef struct { char* first; char* last; }_name; enum _TYPE { //these are the main types of entities STRUCTURET = -1, diff --git a/src/Quest.cpp b/src/Quest.cpp new file mode 100644 index 0000000..a42e42c --- /dev/null +++ b/src/Quest.cpp @@ -0,0 +1,62 @@ +#include <Quest.h>
+
+const Quest QuestList[TOTAL_QUESTS]={
+ Quest("Test","A test quest",0)
+};
+
+Quest::Quest(const char *t,const char *d,unsigned int x){
+ 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;
+}
+Quest::~Quest(){
+ free(title);
+ free(desc);
+ xp=0;
+}
+
+QuestHandler::QuestHandler(){
+ ccnt=0;
+}
+int QuestHandler::assign(const char *t){
+ unsigned int i=0;
+ if(ccnt==QUEST_LIMIT)
+ return -1;
+ for(;i<TOTAL_QUESTS;i++){
+ if(!strcmp(QuestList[i].title,t)){
+ current[ccnt++]=&QuestList[i];
+ return ccnt;
+ }
+ }
+ return -1;
+}
+int QuestHandler::drop(const char *t){
+ unsigned char i=0;
+ for(;i<ccnt;i++){
+ if(!strcmp(current[i]->title,t)){
+ for(i++;i<ccnt;i++){
+ current[i-1]=current[i];
+ }
+ return (--ccnt);
+ }
+ }
+ return -1;
+}
+int QuestHandler::finish(const char *t){
+ unsigned char i=0;
+ unsigned int j;
+ for(;i<ccnt;i++){
+ if(!strcmp(current[i]->title,t)){
+ j=current[i]->xp;
+ for(i++;i<ccnt;i++){
+ current[i-1]=current[i];
+ }
+ ccnt--;
+ return j;
+ }
+ }
+ return -1;
+}
diff --git a/src/main.cpp b/src/main.cpp index 7980cf7..1e3bc10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,9 @@ std::vector<Structures>build; int mx, my; +FILE* config; +FILE* names; + void logic(); void render(); @@ -151,6 +154,7 @@ void render(){ glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on glPushMatrix(); //push the matrix to the top of the matrix stack glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode +typedef struct { char* first; char glOrtho(player->loc.x-SCREEN_WIDTH/2,player->loc.x+SCREEN_WIDTH/2,0,SCREEN_HEIGHT,-1,1); glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects glPushMatrix(); //push the matrix to the top of the matrix stack @@ -214,7 +218,8 @@ void logic(){ if(entity[i]->alive&&entity[i]->type == NPCT){ entity[i]->wander((rand()%120 + 30), &entity[i]->vel); if( pow((entity[i]->loc.x - player->loc.x),2) + pow((entity[i]->loc.y - player->loc.y),2) <= pow(35*HLINE,2)){ - if(mx >= entity[i]->loc.x && mx <= entity[i]->loc.x + entity[i]->width && my >= entity[i]->loc.y && my <= entity[i]->loc.y + entity[i]->width && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT))) + if(mx >= entity[i]->loc.x && mx <= entity[i]->loc.x + entity[i]->width && my >= entity[i]->loc.y && my <= entity[i]->loc.y + entity[i]->width + && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT))) entity[i]->interact(); } } |