]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
importantText revised
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 7 Dec 2015 13:23:50 +0000 (08:23 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 7 Dec 2015 13:23:50 +0000 (08:23 -0500)
main.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp

index 1fb5cb1388b4bea6a81addc318ffc25d749ed5cd..dbea56462258d2b83b456265567691fe0d7cfe12 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -206,7 +206,9 @@ unsigned int millis(void){
 #endif
 
 extern WEATHER weather;
-static unsigned int fadeIntensity = 0;
+
+extern bool fadeEnable;
+extern unsigned int fadeIntensity;
 
 /*******************************************************************************
  * MAIN ************************************************************************
@@ -514,8 +516,6 @@ void mainLoop(void){
        render();       // Call the render loop;
 }
 
-extern bool fadeEnable;
-
 void render(){
        
         /*
@@ -703,11 +703,23 @@ void render(){
                glUseProgramObjectARB(0);
        }
        player->inv->draw();
-
+       
        /*
-        *      Draw UI elements. This includes the player's health bar and the dialog box.
+        *      Here we draw a black overlay if it's been requested.
        */
        
+       if(fadeIntensity){
+               glColor4ub(0,0,0,fadeIntensity);
+               glRectf(offset.x-SCREEN_WIDTH /2,
+                               offset.y-SCREEN_HEIGHT/2,
+                               offset.x+SCREEN_WIDTH /2,
+                               offset.y+SCREEN_HEIGHT/2);
+       }else if(ui::fontSize != 16) ui::setFontSize(16);
+       
+       /*
+        *      Draw UI elements. This includes the player's health bar and the dialog box.
+       */      
+       
        ui::draw();
 
        /*
@@ -758,20 +770,7 @@ void render(){
                glVertex2i(ui::mouse.x+HLINE*3.5,ui::mouse.y              );
                glVertex2i(ui::mouse.x                  ,ui::mouse.y-HLINE*3.5);
        glEnd();
-
-       /*
-        *      Here we draw a black overlay if it's been requested.
-       */
-       if(fadeIntensity){
-               glColor4ub(0,0,0,fadeIntensity);
-               glRectf(offset.x-SCREEN_WIDTH /2,
-                               offset.y-SCREEN_HEIGHT/2,
-                               offset.x+SCREEN_WIDTH /2,
-                               offset.y+SCREEN_HEIGHT/2);
-               if(fadeIntensity == 255){
-                       ui::importantText("The screen is black.");
-               }
-       }else if(ui::fontSize != 16) ui::setFontSize(16);
+       
        /**************************
        ****  END RENDERING   ****
        **************************/
index 26eb09ae31a30f65486c873a6cbb8b13303f1af9..05b79b559244a0022a31073461f781ad08251654 100644 (file)
@@ -36,8 +36,10 @@ void getRandomName(Entity *e){
        }
        
        if((fgets(bufs,16,(FILE*)names)) != NULL){
-               bufs[strlen(bufs)-1] = '\0';
+               bufs[strlen(bufs)] = '\0';
                strcpy(e->name,bufs);
+               if(e->name[strlen(e->name)-1] == '\n')
+                       e->name[strlen(e->name)-1] = '\0';
        }
        
        delete[] bufs;
index 8e7d961326c2459b6f499c917bdfaa5a097eafae..856b39701900883973a301d85396a85d9bdd3e97 100644 (file)
@@ -29,21 +29,15 @@ int giveTestQuest(NPC *speaker){
        return 0;
 }
 
-//static World *a;
-
 void CUTSCENEEE(Mob *callee){
        player->vel.x = 0;
        
        ui::dialogBox(player->name,":K then","No way I\'m gettin\' up this hill.");
        ui::waitForDialog();
 
-       //a = new World();//Arena(currentWorld,player);
-       //a->generate(300);
-       currentWorld = currentWorld->toRight;
-
-       /*player->right = true;
+       player->right = true;
        player->left  = false;
-       player->loc.x += HLINE * 5;*/
+       player->loc.x += HLINE * 5;
        
        callee->alive = false;
 }
@@ -56,6 +50,13 @@ void CUTSCENEEE2(Mob *callee){
        callee->alive = false;
 }
 
+void story(Mob *callee){
+       player->vel.x = 0;
+       ui::importantText("It was a dark and stormy night...");
+       ui::waitForDialog();
+       callee->alive = false;
+}
+
 float playerSpawnHillFunc(float x){
        return (float)(pow(2,(-x+200)/5) + 80);
 }
@@ -122,6 +123,8 @@ void initEverything(void){
         *      Spawn some entities.
        */
 
+       playerSpawnHill->addMob(MS_TRIGGER,player->loc.x,0,story);
+
        playerSpawnHill->addStructure(STRUCTURET,(rand()%120*HLINE),100,test,iw);
        playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);
        
@@ -129,17 +132,9 @@ void initEverything(void){
        playerSpawnHill->addObject(FLASHLIGHT, false, "", 500,200);
        playerSpawnHill->addObject(PLAYER_BAG, false, "", 520,200);
        playerSpawnHill->addObject(TEST_ITEM, false, "", 540,200);
-       //playerSpawnHill->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200);
        
        test->addMob(MS_RABBIT,200,100);
        test->addMob(MS_BIRD,-500,500);
-
-       /*currentWorld->addObject(DEBUG_ITEM, 500,200);
-       currentWorld->addObject(TEST_ITEM,  550,200);
-       currentWorld->addObject(PLAYER_BAG, 600,200);
-       currentWorld->addObject(SWORD_WOOD, 650,200);
-       currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",700,200);
-       */
        
        playerSpawnHill->npc[0]->addAIFunc(giveTestQuest,false);
        
@@ -169,30 +164,3 @@ void destroyEverything(void){
        
        //delete iw;    // segfaults
 }
-
-/*void story(void){
-       for(int i=0;i<600;i++){
-               glMatrixMode(GL_PROJECTION);
-               glPushMatrix();
-               glLoadIdentity();
-               glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
-               glMatrixMode(GL_MODELVIEW);
-               glPushMatrix();
-               glLoadIdentity();
-               glEnable(GL_STENCIL_TEST);
-               glPushMatrix();
-
-               glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT );
-               glClear(GL_COLOR_BUFFER_BIT);
-
-               glColor4f(0.0f,0.0f,0.0f,0.0f);
-               glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT);
-               glColor4f(1.0f,1.0f,1.0f,1.0f);
-               ui::importantText("Oh hello, where are you?");
-               //ui::setFontSize(16);
-               //ui::putText(54,540,"BITC.");
-
-               glPopMatrix();
-               SDL_GL_SwapWindow(window);
-       }
-}*/
index c0b50044c366633187ef787bf03898faddc39f78..9b96254dc558be2fe6db2026ac739e7cba6215ee 100644 (file)
@@ -44,12 +44,14 @@ static unsigned char fontColor[3] = {255,255,255};
  *     Variables for dialog boxes / options.
 */
 
-static char *dialogBoxText                     = NULL;
+static char dialogBoxText[512];
 static char *dialogOptText[4];
 static float dialogOptLoc[4][3];
 static unsigned char dialogOptCount = 0;
 static bool typeOutDone = true;
 
+static bool dialogImportant = false;
+
 extern void mainLoop(void);
 
 /*
@@ -57,7 +59,7 @@ extern void mainLoop(void);
 */
 
 bool fadeEnable = false;
-
+unsigned int fadeIntensity = 0;
 
 bool inBattle = false;
 
@@ -387,7 +389,6 @@ namespace ui {
                 *      Set up the text buffer.
                */
                
-               if(!dialogBoxText) dialogBoxText = new char[512];       //(char *)malloc(512);
                memset(dialogBoxText,0,512);
                
                /*
@@ -439,6 +440,7 @@ namespace ui {
                */
                
                dialogBoxExists = true;
+               dialogImportant = false;
                
        }
        void waitForDialog(void){
@@ -448,19 +450,18 @@ namespace ui {
        }
        void importantText(const char *text,...){
                va_list textArgs;
-               char *ttext,*rtext;
-               if(!player->ground)return;
+               
+               //if(!player->ground)return;
+               
+               memset(dialogBoxText,0,512);
+                               
                va_start(textArgs,text);
-               ttext = new char[512];  //(char *)calloc(512,sizeof(char));
-               memset(ttext,0,512*sizeof(char));
-               vsnprintf(ttext,512,text,textArgs);
+               vsnprintf(dialogBoxText,512,text,textArgs);
                va_end(textArgs);
-               setFontSize(24);
-               rtext=typeOut(ttext);
-               putString(offset.x-SCREEN_WIDTH/2,
-                                 offset.y+fontSize,
-                                 rtext);
-               delete[] ttext; //free(ttext);
+                                 
+               dialogBoxExists = true;
+               dialogImportant = true;
+               toggleBlack();
        }
        void draw(void){
                unsigned char i;
@@ -469,66 +470,77 @@ namespace ui {
                
                if(dialogBoxExists){
                        
-                       glColor3ub(0,0,0);
-                       x=offset.x-SCREEN_WIDTH/2+HLINE*8;
-                       y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
+                       rtext=typeOut(dialogBoxText);
+                       
+                       if(dialogImportant){
+                               setFontColor(255,255,255);
+                               if(fadeIntensity == 255){
+                                       setFontSize(24);
+                                       putStringCentered(offset.x,offset.y,rtext);
+                               }
+                       }else{
+                       
+                               glColor3ub(0,0,0);
                        
-                       glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4);
+                               x=offset.x-SCREEN_WIDTH/2+HLINE*8;
+                               y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
                        
-                       rtext=typeOut(dialogBoxText);
+                               glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4);
                        
-                       putString(x+HLINE,y-fontSize-HLINE,rtext);
+                               rtext=typeOut(dialogBoxText);
                        
-                       for(i=0;i<dialogOptCount;i++){
-                               setFontColor(255,255,255);
-                               dialogOptLoc[i][1]=y-SCREEN_HEIGHT/4+(fontSize+HLINE)*(i+1);
-                               dialogOptLoc[i][2]=
-                               putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
-                               dialogOptLoc[i][0]=offset.x-dialogOptLoc[i][2]/2;
-                               if(mouse.x > dialogOptLoc[i][0] &&
-                                  mouse.x < dialogOptLoc[i][0] + dialogOptLoc[i][2] &&
-                                  mouse.y > dialogOptLoc[i][1] &&
-                                  mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
-                                         setFontColor(255,255,0);
-                                         putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
+                               putString(x+HLINE,y-fontSize-HLINE,rtext);
+                       
+                               for(i=0;i<dialogOptCount;i++){
+                                       setFontColor(255,255,255);
+                                       dialogOptLoc[i][1]=y-SCREEN_HEIGHT/4+(fontSize+HLINE)*(i+1);
+                                       dialogOptLoc[i][2]=
+                                       putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
+                                       dialogOptLoc[i][0]=offset.x-dialogOptLoc[i][2]/2;
+                                       if(mouse.x > dialogOptLoc[i][0] &&
+                                          mouse.x < dialogOptLoc[i][0] + dialogOptLoc[i][2] &&
+                                          mouse.y > dialogOptLoc[i][1] &&
+                                          mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
+                                                 setFontColor(255,255,0);
+                                                 putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
+                                       }
                                }
+                               setFontColor(255,255,255);
                        }
-                       setFontColor(255,255,255);
-               }
-               
-               vec2 hub = {
-                       (SCREEN_WIDTH/2+offset.x)-fontSize*10,
-                       (offset.y+SCREEN_HEIGHT/2)-fontSize
-               };
-               
-               putText(hub.x,hub.y,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
-                                                                                       (unsigned)player->maxHealth);
-               if(player->alive){
-                       glColor3ub(255,0,0);
-                       hub.y-=fontSize*1.15;
-                       glRectf(hub.x,
-                                       hub.y,
-                                       hub.x+(player->health/player->maxHealth)*130,
-                                       hub.y+12);
-               }
-               
-               /*
-                *      Lists all of the quests the player is currently taking.
-               */
+               }else if(!dialogImportant){
                
-               if(player->inv->invOpen){
-                       hub.y = player->loc.y + fontSize * 8;
-                       hub.x = player->loc.x;
+                       vec2 hub = {
+                               (SCREEN_WIDTH/2+offset.x)-fontSize*10,
+                               (offset.y+SCREEN_HEIGHT/2)-fontSize
+                       };
+                       
+                       putText(hub.x,hub.y,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
+                                                                                               (unsigned)player->maxHealth);
+                       if(player->alive){
+                               glColor3ub(255,0,0);
+                               hub.y-=fontSize*1.15;
+                               glRectf(hub.x,
+                                               hub.y,
+                                               hub.x+(player->health/player->maxHealth)*130,
+                                               hub.y+12);
+                       }
                        
-                       putStringCentered(hub.x,hub.y,"Current Quests:");
+                       /*
+                        *      Lists all of the quests the player is currently taking.
+                       */
                        
-                       for(auto &c : player->qh.current){
-                               hub.y -= fontSize * 1.15;
-                               putString(hub.x,hub.y,c->title);
-                       }       
+                       if(player->inv->invOpen){
+                               hub.y = player->loc.y + fontSize * 8;
+                               hub.x = player->loc.x;
+                               
+                               putStringCentered(hub.x,hub.y,"Current Quests:");
+                               
+                               for(auto &c : player->qh.current){
+                                       hub.y -= fontSize * 1.15;
+                                       putString(hub.x,hub.y,c->title);
+                               }       
+                       }
                }
-
-               
        }
        void handleEvents(void){
                static vec2 premouse={0,0};
@@ -567,15 +579,22 @@ namespace ui {
                                                }
                                        }
 DONE:
-                                       dialogBoxExists=false;
-                                       //dialogBoxText=NULL;
+                                       if(dialogImportant){
+                                               dialogImportant = false;
+                                               setFontSize(16);
+                                               toggleBlack();
+                                       }
+                                       dialogBoxExists = false;
                                }
                                break;
                        /*
                                KEYDOWN
                        */
                        case SDL_KEYDOWN:
-                               if(!dialogBoxExists&&!fadeEnable){
+                               if(SDL_KEY == SDLK_ESCAPE){
+                                       gameRunning = false;
+                                       break;
+                               }else if(!dialogBoxExists){//&&!fadeEnable){
                                        switch(SDL_KEY){
                                        case SDLK_ESCAPE:
                                                gameRunning=false;
@@ -636,9 +655,6 @@ DONE:
                                        case SDLK_LCTRL:
                                                player->speed = .5;
                                                break;
-                                       case SDLK_p:
-                                               toggleBlack();
-                                               break;
                                        case SDLK_F3:
                                                debug ^= true;
                                                break;