]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fade improvements
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 9 Dec 2015 13:14:12 +0000 (08:14 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 9 Dec 2015 13:14:12 +0000 (08:14 -0500)
include/ui.h
main.cpp
src/ui.cpp
src/world.cpp

index f2c01148ead938b05a4b4590d3b309df4b077e80..a5a2ec05af59c376617edd09bb0d352963823d17 100644 (file)
@@ -85,6 +85,9 @@ namespace ui {
        */
        
        void toggleBlack(void);
+       void toggleBlackFast(void);
+       void toggleWhite(void);
+       void waitForCover(void);
        
 }
 
index d1fd85e96d173a0fd3c241231361c89404cabd2c..4cafc249fecb6f8f8621a6e369aa736e48ec6d43 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -208,6 +208,8 @@ unsigned int millis(void){
 extern WEATHER weather;
 
 extern bool fadeEnable;
+extern bool fadeWhite;
+extern bool fadeFast;
 extern unsigned int fadeIntensity;
 
 /*******************************************************************************
@@ -709,7 +711,10 @@ void render(){
        */
        
        if(fadeIntensity){
-               glColor4ub(0,0,0,fadeIntensity);
+               if(fadeWhite)
+                       glColor4ub(255,255,255,fadeIntensity);
+               else
+                       glColor4ub(0,0,0,fadeIntensity);
                glRectf(offset.x-SCREEN_WIDTH /2,
                                offset.y-SCREEN_HEIGHT/2,
                                offset.x+SCREEN_WIDTH /2,
@@ -965,11 +970,11 @@ void logic(){
         *      Transition to and from black if necessary.
        */
        if(fadeEnable){
-                        if(fadeIntensity < 160)fadeIntensity+=10;
-               else if(fadeIntensity < 255)fadeIntensity+=5;
+                        if(fadeIntensity < 150)fadeIntensity+=fadeFast?30:10;
+               else if(fadeIntensity < 255)fadeIntensity+=fadeFast?15:5;
        }else{
-                        if(fadeIntensity > 150)fadeIntensity-=5;
-               else if(fadeIntensity > 0)      fadeIntensity-=10;
+                        if(fadeIntensity > 150)fadeIntensity-=fadeFast?15:5;
+               else if(fadeIntensity > 0)      fadeIntensity-=fadeFast?30:10;
        }
 
        /*
index f843e7dfb2124d8844150978d6840946717f949e..d72bf2cff0e3fc6dabf49f813860856f3dce1383 100644 (file)
@@ -61,6 +61,8 @@ extern void mainLoop(void);
 */
 
 bool fadeEnable = false;
+bool fadeWhite = false;
+bool fadeFast = false;
 unsigned int fadeIntensity = 0;
 
 bool inBattle = false;
@@ -452,6 +454,11 @@ namespace ui {
                        mainLoop();
                }while(ui::dialogBoxExists);
        }
+       void waitForCover(void){
+               do{
+                       mainLoop();
+               }while(fadeIntensity != 255);
+       }
        void importantText(const char *text,...){
                va_list textArgs;
                
@@ -525,7 +532,7 @@ namespace ui {
                                Mix_PlayChannel(1,dialogClick,0);
                        }
                        
-               }else if(!dialogImportant){
+               }else if(!dialogImportant && !fadeIntensity){
                
                        vec2 hub = {
                                (SCREEN_WIDTH/2+offset.x)-fontSize*10,
@@ -560,11 +567,34 @@ namespace ui {
                        }
                }
        }
+       void dialogAdvance(void){
+               unsigned char i;
+               if(!typeOutDone){
+                       typeOutDone = true;
+                       return;
+               }
+
+               for(i=0;i<dialogOptCount;i++){
+                       if(mouse.x > dialogOptLoc[i][0] &&
+                          mouse.x < dialogOptLoc[i][2] &&
+                          mouse.y > dialogOptLoc[i][1] &&
+                          mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
+                               dialogOptChosen = i + 1;
+                               goto DONE;
+                       }
+               }
+DONE:
+               if(dialogImportant){
+                       dialogImportant = false;
+                       setFontSize(16);
+                       toggleBlack();
+               }
+               dialogBoxExists = false;
+       }
        void handleEvents(void){
                static bool left=true,right=false;
                static vec2 premouse={0,0};
                static int heyOhLetsGo = 0;
-               unsigned char i;
                World *tmp;
                SDL_Event e;
                
@@ -582,28 +612,7 @@ namespace ui {
                                break;
                        case SDL_MOUSEBUTTONDOWN:
                                if((e.button.button&SDL_BUTTON_RIGHT)&&dialogBoxExists){
-                               
-                                       if(!typeOutDone){
-                                               typeOutDone = true;
-                                               break;
-                                       }
-                               
-                                       for(i=0;i<dialogOptCount;i++){
-                                               if(mouse.x > dialogOptLoc[i][0] &&
-                                                  mouse.x < dialogOptLoc[i][2] &&
-                                                  mouse.y > dialogOptLoc[i][1] &&
-                                                  mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
-                                                       dialogOptChosen = i + 1;
-                                                       goto DONE;
-                                               }
-                                       }
-DONE:
-                                       if(dialogImportant){
-                                               dialogImportant = false;
-                                               setFontSize(16);
-                                               toggleBlack();
-                                       }
-                                       dialogBoxExists = false;
+                                       dialogAdvance();
                                }
                                break;
                        /*
@@ -612,12 +621,18 @@ DONE:
                        case SDL_KEYDOWN:
                                if(SDL_KEY == SDLK_ESCAPE){
                                        gameRunning = false;
+                                       return;
+                               }else if(SDL_KEY == SDLK_SPACE){
+                                       if(dialogBoxExists)
+                                               dialogAdvance();
+                                       else if(player->ground){
+                                               player->vel.y=.4;
+                                               player->loc.y+=HLINE*2;
+                                               player->ground=false;
+                                       }
                                        break;
                                }else if(!dialogBoxExists){//&&!fadeEnable){
                                        switch(SDL_KEY){
-                                       case SDLK_ESCAPE:
-                                               gameRunning=false;
-                                               break;
                                        case SDLK_a:
                                                player->vel.x=-.15;
                                                player->left = true;
@@ -645,13 +660,6 @@ DONE:
                                                         currentWorld=((Arena *)currentWorld)->exitArena(player);
                                                else currentWorld=currentWorld->goInsideStructure(player);
                                                break;
-                                       case SDLK_SPACE:
-                                               if(player->ground){
-                                                       player->vel.y=.4;
-                                                       player->loc.y+=HLINE*2;
-                                                       player->ground=false;
-                                               }
-                                               break;
                                        case SDLK_i:
                                                tmp=currentWorld;
                                                currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible  
@@ -757,5 +765,17 @@ DONE:
        
        void toggleBlack(void){
                fadeEnable ^= true;
+               fadeWhite = false;
+               fadeFast = false;
+       }
+       void toggleBlackFast(void){
+               fadeEnable ^= true;
+               fadeWhite = false;
+               fadeFast = true;
+       }
+       void toggleWhite(void){
+               fadeEnable ^= true;
+               fadeWhite = true;
+               fadeFast = false;
        }
 }
index f751287f97079b41afef56a7affc418e363adbe4..cb5f3ecedc16b7e7798bc9237ba235011da20d2b 100644 (file)
@@ -1,4 +1,5 @@
 #include <world.h>
+#include <ui.h>
 
 #define getWidth(w) ((w->lineCount-GEN_INC)*HLINE)     // Calculates the width of world 'w'
 
@@ -923,6 +924,9 @@ World *World::goInsideStructure(Player *p){
                        if(p->loc.x            > b->loc.x            &&
                           p->loc.x + p->width < b->loc.x + b->width ){
                                thing.push_back(this);
+                               ui::toggleBlackFast();
+                               ui::waitForCover();
+                               ui::toggleBlackFast();
                                return (World *)b->inside;
                        }
                }
@@ -932,6 +936,9 @@ World *World::goInsideStructure(Player *p){
                                World *tmp = (World *)thing.back();
                                p->loc.x = b->loc.x + (b->width / 2) - (p->width / 2);
                                thing.erase(thing.end()-1);
+                               ui::toggleBlackFast();
+                               ui::waitForCover();
+                               ui::toggleBlackFast();
                                return tmp;
                        }
                }