4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include "gameconfig.hpp"
36 #include "video/drawing_context.hpp"
37 #include "audio/sound_manager.hpp"
38 #include "math/vector.hpp"
40 static const float LOOP_DELAY = 20.0;
42 void fillrect(float x, float y, float w, float h, const Color& col)
53 glColor4f(col.red, col.green, col.blue, col.alpha);
55 glDisable(GL_TEXTURE_2D);
62 glEnable(GL_TEXTURE_2D);
64 glColor4f(0, 0, 0, 1);
67 void fadeout(float fade_time)
69 float alpha_inc = LOOP_DELAY / fade_time;
70 Color c(0, 0, 0, alpha_inc);
75 fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, c);
79 sound_manager->update();
81 SDL_Delay(int(LOOP_DELAY));
85 fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Color());
88 void shrink_fade(const Vector& point, float fade_time)
90 float left_inc = point.x / (fade_time / LOOP_DELAY);
91 float right_inc = (SCREEN_WIDTH - point.x) / (fade_time / LOOP_DELAY);
92 float up_inc = point.y / (fade_time / LOOP_DELAY);
93 float down_inc = (SCREEN_HEIGHT - point.y) / (fade_time / LOOP_DELAY);
95 float left_cor = 0, right_cor = 0, up_cor = 0, down_cor = 0;
98 while(left_cor < point.x && right_cor < SCREEN_WIDTH - point.x &&
99 up_cor < point.y && down_cor < SCREEN_HEIGHT - point.y) {
100 left_cor += left_inc;
101 right_cor += right_inc;
103 down_cor += down_inc;
105 fillrect(0, 0, left_cor, SCREEN_HEIGHT, c); // left side
106 fillrect(SCREEN_WIDTH - right_cor, 0, right_cor, SCREEN_HEIGHT, c); // right side
107 fillrect(0, 0, SCREEN_WIDTH, up_cor, c); // up side
108 fillrect(0, SCREEN_HEIGHT - down_cor, SCREEN_WIDTH, down_cor+1, c); // down side
110 SDL_GL_SwapBuffers();
112 sound_manager->update();
113 SDL_Delay(int(LOOP_DELAY));