From: Ricardo Cruz Date: Fri, 28 May 2004 18:13:17 +0000 (+0000) Subject: Fade when entering a level. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e20c903338ea152a65f5fcb06589b5821ad3420a;p=supertux.git Fade when entering a level. Sometimes doesn't work, i'll have a look at the fade func later. SVN-Revision: 1349 --- diff --git a/src/intro.cpp b/src/intro.cpp index ea4283a8b..c6e6002d2 100644 --- a/src/intro.cpp +++ b/src/intro.cpp @@ -35,8 +35,7 @@ void draw_intro() { -if(debug_mode) - fade("/images/background/arctis.jpg", 30, false); +shrink_fade(Point((screen->w/2),(screen->h/2)), 2000); display_text_file("intro.txt", "/images/background/arctis.jpg", SCROLL_SPEED_MESSAGE); } diff --git a/src/screen.cpp b/src/screen.cpp index d20543fad..61d51fcf4 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -138,6 +138,36 @@ else } } +/** This fade shrinks to the given point */ + +#define LOOP_DELAY 20 +void shrink_fade(Point point, int fade_time) +{ +float left_inc = (float)point.x / ((float)fade_time / LOOP_DELAY); +float right_inc = ((float)screen->w - point.x) / ((float)fade_time / LOOP_DELAY); +float up_inc = (float)point.y / ((float)fade_time / LOOP_DELAY); +float down_inc = ((float)screen->h - point.y) / ((float)fade_time / LOOP_DELAY); + +float left_cor = 0, right_cor = 0, up_cor = 0, down_cor = 0; + +while(left_cor < screen->w - point.x && right_cor < screen->w - point.x && + up_cor < screen->h - point.y && down_cor < screen->h - point.y) + { + left_cor += left_inc; + right_cor += right_inc; + up_cor += up_inc; + down_cor += down_inc; + + fillrect(0, 0, left_cor, screen->h, 0,0,0); // left side + fillrect(screen->w - right_cor, 0, right_cor, screen->h, 0,0,0); // right side + fillrect(0, 0, screen->w, up_cor, 0,0,0); // up side + fillrect(0, screen->h - down_cor, screen->w, down_cor, 0,0,0); // down side + + flipscreen(); + SDL_Delay(LOOP_DELAY); + } +} + /* 'Stolen' from the SDL documentation. * Set the pixel at (x, y) to the given value * NOTE: The surface must be locked before calling this! diff --git a/src/screen.h b/src/screen.h index 1193cb0d4..a786cc90a 100644 --- a/src/screen.h +++ b/src/screen.h @@ -44,12 +44,32 @@ struct Color int red, green, blue; }; +struct Point +{ + Point() : x(0), y(0) {} + + Point(const Point& pos) + : x(pos.x), y(pos.y) {} + + Point& operator=(const Point& pos) + { x = pos.x; + y = pos.y; + return *this; } + + Point(int x_, int y_) + : x(x_), y(y_) {} + + int x; + int y; +}; + void drawline(int x1, int y1, int x2, int y2, int r, int g, int b, int a); void clearscreen(int r, int g, int b); void drawgradient(Color top_clr, Color bot_clr); -void fillrect(float x, float y, float w, float h, int r, int g, int b, int a); +void fillrect(float x, float y, float w, float h, int r, int g, int b, int a = 255); //void black_fade(Surface* surface, int seconds, bool fade_out); void fade(const std::string& surface, int seconds, bool fade_out); +void shrink_fade(Point point, int fade_time); void updatescreen(void); void flipscreen(void); void update_rect(SDL_Surface *scr, Sint32 x, Sint32 y, Sint32 w, Sint32 h); diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 785edabcb..0de8a82e9 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -640,7 +640,9 @@ WorldMap::update(float delta) { PlayerStatus old_player_status = player_status; - std::cout << "Enter the current level: " << level->name << std::endl;; + std::cout << "Enter the current level: " << level->name << std::endl; + // do a shriking fade to the level + shrink_fade(Point((level->x*32 + 16 + offset.x),(level->y*32 + 16 + offset.y)), 3000); GameSession session(datadir + "/levels/" + level->name, 1, ST_GL_LOAD_LEVEL_FILE); diff --git a/src/worldmap.h b/src/worldmap.h index 48e57d84b..0fb10214d 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -24,28 +24,10 @@ #include #include "musicref.h" +#include "screen.h" namespace WorldMapNS { -struct Point -{ - Point() : x(0), y(0) {} - - Point(const Point& pos) - : x(pos.x), y(pos.y) {} - - Point& operator=(const Point& pos) - { x = pos.x; - y = pos.y; - return *this; } - - Point(int x_, int y_) - : x(x_), y(y_) {} - - int x; - int y; -}; - class Tile { public: