]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
quest completion
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 1 Oct 2015 12:53:49 +0000 (08:53 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 1 Oct 2015 12:53:49 +0000 (08:53 -0400)
Changelog
Makefile
include/ui.h
src/entities.cpp
src/gameplay.cpp
src/main.cpp
src/ui.cpp

index fa7b5dea5332e76954a0064b1b4ccbf12fd09a60..0ecb80c865d026d15ae6324f62975256c768ebc8 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -57,3 +57,8 @@
        
        - added displaying of entity names on mouse hover
        - found more fonts
+       
+10/1/2015:
+==========
+
+       - player can now complete assigned requests
index a78377ab2e930672cad49ebefefdba9cfa19bdd1..8cec40d35e55bcca62fd1bc79b1b8ab358ddf704 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-FLAGS_LINUX = -lGL                 -lSDL2_image\r
+FLAGS_LINUX = -lGL                 -lSDL2_image -lSDL2_mixer\r
 FLAGS_WIN32 = -lopengl32 -lmingw32 -lSDL2_Image\r
 FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lSDL2main -lSDL2 -lfreetype\r
 \r
index dbcee3570ebcdeaac50bc7493f9f364ed0e7347d..b94b28468d8282e861e937f6fd7566b02a46a59f 100644 (file)
@@ -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
index 9f5d776dba05f723e8397ba22a0929b7fc4fdb68..e7ba599eb0bed0091103726b56d3b74f527b3256 100644 (file)
@@ -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
index b32c75a029691f62b07eb180f1a8e78341e3337e..ad44eb20d606b6919e964c0ba3ee6b16ac927fdf 100644 (file)
@@ -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;
        }
 }
index d454f0bbb75cb8d2d77b02280adf2fb558965fa0..ea579981e2f272c63ce61b5fc5e2f257c37bcbf0 100644 (file)
@@ -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;
index de875b9281d423c88d7bcbcb242dfa3ec1c429e5..8b62aab86bab15a3170276ca48f18d99e49b6d3e 100644 (file)
@@ -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){