From 68ec0bf510fd16cf4e6d7aabd7998fe656c25444 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 1 Oct 2015 08:53:49 -0400 Subject: quest completion --- src/entities.cpp | 2 +- src/gameplay.cpp | 8 ++++---- src/main.cpp | 24 ++++++++++-------------- src/ui.cpp | 26 ++++++++++++++++++++------ 4 files changed, 35 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/entities.cpp b/src/entities.cpp index 9f5d776..e7ba599 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -128,7 +128,7 @@ 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 = (getRand() % 5 + 2); //amount of villagers that will spawn for(int i=0;ibuild; extern Player *player; int giveTestQuest(NPC *speaker){ - ui::dialogBox("Here, have a quest!"); + ui::dialogBox(speaker->name,"Here, have a quest!"); player->qh.assign("Test"); return 0; } int compTestQuest(NPC *speaker){ if(player->qh.hasQuest("Test")){ - ui::dialogBox("Ooo, that's a nice quest you got there. Lemme finish that for you ;)."); - player->qh.finish("test"); + ui::dialogBox(speaker->name,"Ooo, that's a nice quest you got there. Lemme finish that for you ;)."); + player->qh.finish("Test"); return 0; }else{ - ui::dialogBox("You need to get a quest from entity[1] first."); + ui::dialogBox(speaker->name,"You need to get a quest from %s first.",entity[1]->name); return 1; } } diff --git a/src/main.cpp b/src/main.cpp index d454f0b..ea57998 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,27 +71,23 @@ int main(int argc, char *argv[]){ return -1; } - ui::initFonts(); + ui::initFonts(); // Initialize text rendering with a font from ttf/ ui::setFontFace("ttf/Perfect DOS VGA 437.ttf"); - initRand(millis()); // fix + initRand(millis()); // Initialize the random number generator with millis() - glViewport(0,0,SCREEN_WIDTH, SCREEN_HEIGHT); - glClearColor(.3,.5,.8,0); - glEnable(GL_BLEND); + glViewport(0,0,SCREEN_WIDTH, SCREEN_HEIGHT); // Switch to pixel-based rendering, not coordinates (the -1 to 1 stuff) + glClearColor(.3,.5,.8,0); // Sky blue + glEnable(GL_BLEND); // Allow transparency glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - SDL_ShowCursor(SDL_DISABLE); + SDL_ShowCursor(SDL_DISABLE); // Hide mouse cursor so we can draw our own //************************************************************************// // WORLD GENERATION STUFF // //************************************************************************// - names = fopen("assets/names_en-us", "r+"); + names = fopen("assets/names_en-us", "r+"); // Open the names file - initEverything(); - - //************************************************************************// - // END WORLD GENERATION STUFF // - //************************************************************************// + initEverything(); // Run world maker thing in src/gameplay.cpp /************************** **** GAMELOOP **** @@ -118,7 +114,7 @@ int main(int argc, char *argv[]){ **************************/ //closes the window and frees resources - //fclose(names); + fclose(names); SDL_GL_DeleteContext(mainGLContext); SDL_DestroyWindow(window); return 0; @@ -149,7 +145,7 @@ void render(){ if(ui::debug){ static unsigned int debugDiv=0; static int fps,d; - static float rndy; //variable to round the player y-coord so it is easier to read + static float rndy; // variable to round the player y-coord so it is easier to read if(++debugDiv==20){ fps=1000/deltaTime; d=deltaTime; diff --git a/src/ui.cpp b/src/ui.cpp index de875b9..8b62aab 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -13,7 +13,7 @@ static FT_Face ftf; static GLuint ftex; static bool dialogBoxExists=false; -static const char *dialogBoxText=NULL; +static char *dialogBoxText; namespace ui { vec2 mouse; @@ -134,17 +134,31 @@ namespace ui { putString(x,y,buf); free(buf); } - void dialogBox(const char *text){ - //while(dialogBoxExists); + void dialogBox(const char *name,const char *text,...){ + unsigned int name_len; + va_list dialogArgs; + va_start(dialogArgs,text); dialogBoxExists=true; - dialogBoxText=text; + if(dialogBoxText){ + free(dialogBoxText); + dialogBoxText=NULL; + } + dialogBoxText=(char *)calloc(512,sizeof(char)); + name_len=strlen(name); + strcpy(dialogBoxText,name); + strcpy(dialogBoxText+strlen(name),": "); + vsnprintf(dialogBoxText+name_len+2,512-name_len-2,text,dialogArgs); + va_end(dialogArgs); } void draw(void){ + float x,y; if(dialogBoxExists){ glColor3ub(0,0,0); - glRectf(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT,player->loc.x+SCREEN_WIDTH/2,SCREEN_HEIGHT-SCREEN_HEIGHT/4); + x=player->loc.x-SCREEN_WIDTH/2+HLINE*8; + y=SCREEN_HEIGHT-HLINE*8; + glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4); setFontSize(16); - putString(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-fontSize,dialogBoxText); + putString(x+HLINE,y-fontSize-HLINE,dialogBoxText); } } void handleEvents(void){ -- cgit v1.2.3