diff options
-rw-r--r-- | Changelog | 5 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/ui.h | 2 | ||||
-rw-r--r-- | src/entities.cpp | 2 | ||||
-rw-r--r-- | src/gameplay.cpp | 8 | ||||
-rw-r--r-- | src/main.cpp | 24 | ||||
-rw-r--r-- | src/ui.cpp | 26 |
7 files changed, 42 insertions, 27 deletions
@@ -57,3 +57,8 @@ - added displaying of entity names on mouse hover - found more fonts + +10/1/2015: +========== + + - player can now complete assigned requests @@ -1,4 +1,4 @@ -FLAGS_LINUX = -lGL -lSDL2_image
+FLAGS_LINUX = -lGL -lSDL2_image -lSDL2_mixer
FLAGS_WIN32 = -lopengl32 -lmingw32 -lSDL2_Image
FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lSDL2main -lSDL2 -lfreetype
diff --git a/include/ui.h b/include/ui.h index dbcee35..b94b284 100644 --- a/include/ui.h +++ b/include/ui.h @@ -21,7 +21,7 @@ namespace ui { // Functions are kept in a namespace simply // are determined by what's currently set by setFontSize() void putText(const float x,const float y,const char *str,...); // Draws the formatted string 'str' using putString() - void dialogBox(const char *text); // Prepares a dialog box to be drawn (its drawn as a black background at the top of the + void dialogBox(const char *name,const char *text,...); // Prepares a dialog box to be drawn (its drawn as a black background at the top of the // screen and then 'text' is putString()'d void draw(void); // Draws things like dialogBox's if necessary 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;i<tempN;i++){ entity.push_back(new NPC()); //create a new entity of NPC type npc.push_back(NPC()); //create new NPC diff --git a/src/gameplay.cpp b/src/gameplay.cpp index b32c75a..ad44eb2 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -10,18 +10,18 @@ extern std::vector<Structures *>build; 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; @@ -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){ |