- fixed 'When you jump into the roof or a bonus and fall back down you collide with...
[supertux.git] / src / screen.cpp
index df1b53f..8dfe18b 100644 (file)
@@ -72,21 +72,22 @@ void drawgradient(Color top_clr, Color bot_clr)
       glBegin(GL_QUADS);
       glColor3ub(top_clr.red, top_clr.green, top_clr.blue);
       glVertex2f(0, 0);
-      glVertex2f(640, 0);
+      glVertex2f(screen->w, 0);
       glColor3ub(bot_clr.red, bot_clr.green, bot_clr.blue);
-      glVertex2f(640, 480);
-      glVertex2f(0, 480);
+      glVertex2f(screen->w, screen->h);
+      glVertex2f(0, screen->h);
       glEnd();
     }
   else
   {
 #endif
 
-    for(float y = 0; y < 480; y += 2)
-      fillrect(0, (int)y, 640, 2,
-                     (int)(((float)(top_clr.red-bot_clr.red)/(0-480)) * y + top_clr.red),
-                     (int)(((float)(top_clr.green-bot_clr.green)/(0-480)) * y + top_clr.green),
-                     (int)(((float)(top_clr.blue-bot_clr.blue)/(0-480)) * y + top_clr.blue), 255);
+    for(float y = 0; y < screen->h; y += 2)
+      fillrect(0, (int)y, screen->w, 2,
+       (int)(((float)(top_clr.red-bot_clr.red)/(0-screen->h)) * y + top_clr.red),
+       (int)(((float)(top_clr.green-bot_clr.green)/(0-screen->h)) * y + top_clr.green),
+       (int)(((float)(top_clr.blue-bot_clr.blue)/(0-screen->h)) * y + top_clr.blue),
+       255);
 /* calculates the color for each line, based in the generic equation for functions: y = mx + b */
 
 #ifndef NOOPENGL
@@ -137,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 < point.x && right_cor < screen->w - point.x &&
+      up_cor < 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!