From 380137ca06c2c74806c1838cb10ef3a17dda8406 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 9 Dec 2015 08:14:12 -0500 Subject: fade improvements --- include/ui.h | 3 ++ main.cpp | 15 ++++++---- src/ui.cpp | 88 ++++++++++++++++++++++++++++++++++++----------------------- src/world.cpp | 7 +++++ 4 files changed, 74 insertions(+), 39 deletions(-) diff --git a/include/ui.h b/include/ui.h index f2c0114..a5a2ec0 100644 --- a/include/ui.h +++ b/include/ui.h @@ -85,6 +85,9 @@ namespace ui { */ void toggleBlack(void); + void toggleBlackFast(void); + void toggleWhite(void); + void waitForCover(void); } diff --git a/main.cpp b/main.cpp index d1fd85e..4cafc24 100644 --- 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; } /* diff --git a/src/ui.cpp b/src/ui.cpp index f843e7d..d72bf2c 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -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 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 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; } } diff --git a/src/world.cpp b/src/world.cpp index f751287..cb5f3ec 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1,4 +1,5 @@ #include +#include #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; } } -- cgit v1.2.3