aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-10-01 08:53:49 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-10-01 08:53:49 -0400
commit68ec0bf510fd16cf4e6d7aabd7998fe656c25444 (patch)
treefc269ebdb6f7c9c76037058e8b1b95caefc6ee59 /src
parent9757c1c7e8704080c4e20cde442baf06960e98e7 (diff)
quest completion
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp2
-rw-r--r--src/gameplay.cpp8
-rw-r--r--src/main.cpp24
-rw-r--r--src/ui.cpp26
4 files changed, 35 insertions, 25 deletions
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;
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){