Tux grows faster, stops growing when hit
[supertux.git] / src / object / display_effect.cpp
index 4e6a352..acf52bf 100644 (file)
 
 static const float BORDER_SIZE = 75;
 
-DisplayEffect::DisplayEffect(std::string name) :
-  GameObject(name), screen_fade(NO_FADE), screen_fadetime(0), screen_fading(0),
-  border_fade(NO_FADE), border_fadetime(0), border_size(0), black(false),
-  borders(false)
+DisplayEffect::DisplayEffect(std::string name)
+  : screen_fade(NO_FADE), screen_fadetime(0), screen_fading(0),
+    border_fade(NO_FADE), border_fadetime(0), border_size(0), black(false),
+    borders(false)
 {
+  this->name = name;
 }
 
 DisplayEffect::~DisplayEffect()
@@ -55,115 +56,115 @@ DisplayEffect::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
 void
 DisplayEffect::update(float elapsed_time)
 {
-    switch(screen_fade) {
-        case NO_FADE:
-            break;
-        case FADE_IN:
-            screen_fading -= elapsed_time;
-            if(screen_fading < 0) {
-                screen_fade = NO_FADE;
-            }
-            break;
-        case FADE_OUT:
-            screen_fading -= elapsed_time;
-            if(screen_fading < 0) {
-                screen_fade = NO_FADE;
-                black = true;
-            }
-            break;
-        default:
-            assert(false);
+  switch(screen_fade) {
+  case NO_FADE:
+    break;
+  case FADE_IN:
+    screen_fading -= elapsed_time;
+    if(screen_fading < 0) {
+      screen_fade = NO_FADE;
     }
+    break;
+  case FADE_OUT:
+    screen_fading -= elapsed_time;
+    if(screen_fading < 0) {
+      screen_fade = NO_FADE;
+      black = true;
+    }
+    break;
+  default:
+    assert(false);
+  }
 
-    switch(border_fade) {
-        case NO_FADE:
-            break;
-        case FADE_IN:
-            border_fading -= elapsed_time;
-            if(border_fading < 0) {
-                border_fade = NO_FADE;
-            }
-            border_size = border_fading / border_fading * BORDER_SIZE;
-            break;
-        case FADE_OUT:
-            border_fading -= elapsed_time;
-            if(border_fading < 0) {
-                borders = false;
-                border_fade = NO_FADE;
-            }
-            border_size = (border_fadetime - border_fading)
-                / border_fadetime * BORDER_SIZE;
-            break;
-        default:
-            assert(false);
+  switch(border_fade) {
+  case NO_FADE:
+    break;
+  case FADE_IN:
+    border_fading -= elapsed_time;
+    if(border_fading < 0) {
+      border_fade = NO_FADE;
     }
+    border_size = (border_fadetime - border_fading)
+      / border_fadetime * BORDER_SIZE;
+    break;
+  case FADE_OUT:
+    border_fading -= elapsed_time;
+    if(border_fading < 0) {
+      borders = false;
+      border_fade = NO_FADE;
+    }
+    border_size = border_fading / border_fadetime * BORDER_SIZE;
+    break;
+  default:
+    assert(false);
+  }
 }
 
 void
 DisplayEffect::draw(DrawingContext& context)
 {
-    context.push_transform();
-    context.set_translation(Vector(0, 0));
-
-    if(black || screen_fade != NO_FADE) {
-      float alpha;
-      if(black) {
-          alpha = 1.0f;
-      } else {
-          switch(screen_fade) {
-              case FADE_IN:
-                  alpha = screen_fading / screen_fadetime;
-                  break;
-              case FADE_OUT:
-                  alpha = (screen_fadetime - screen_fading) / screen_fadetime;
-                  break;
-              default:
-                  alpha = 0;
-                  assert(false);
-          }
+  context.push_transform();
+  context.set_translation(Vector(0, 0));
+
+  if(black || screen_fade != NO_FADE) {
+    float alpha;
+    if(black) {
+      alpha = 1.0f;
+    } else {
+      switch(screen_fade) {
+      case FADE_IN:
+        alpha = screen_fading / screen_fadetime;
+        break;
+      case FADE_OUT:
+        alpha = (screen_fadetime - screen_fading) / screen_fadetime;
+        break;
+      default:
+        alpha = 0;
+        assert(false);
       }
-      context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
-              Color(0, 0, 0, alpha), LAYER_GUI-10);
     }
+    context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
+        Color(0, 0, 0, alpha), LAYER_GUI-10);
+  }
 
-    if (borders) {
-      context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, border_size),
-              Color(0, 0, 0, 1.0f), LAYER_GUI-10);
-      context.draw_filled_rect(Vector(0, SCREEN_HEIGHT - border_size), Vector(SCREEN_WIDTH, border_size),
-              Color(0, 0, 0, 1.0f), LAYER_GUI-10);
-    }
+  if (borders) {
+    context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, border_size),
+        Color(0, 0, 0, 1.0f), LAYER_GUI-10);
+    context.draw_filled_rect(Vector(0, SCREEN_HEIGHT - border_size), Vector(SCREEN_WIDTH, border_size),
+        Color(0, 0, 0, 1.0f), LAYER_GUI-10);
+  }
 
-    context.pop_transform();
+  context.pop_transform();
 }
 
 void
 DisplayEffect::fade_out(float fadetime)
 {
-    black = false;
-    screen_fadetime = fadetime;
-    screen_fading = fadetime;
-    screen_fade = FADE_OUT;
+  black = false;
+  screen_fadetime = fadetime;
+  screen_fading = fadetime;
+  screen_fade = FADE_OUT;
 }
 
 void
 DisplayEffect::fade_in(float fadetime)
 {
-    black = false;
-    this->screen_fadetime = fadetime;
-    screen_fading = fadetime;
-    screen_fade = FADE_IN;
+  black = false;
+  this->screen_fadetime = fadetime;
+  screen_fading = fadetime;
+  screen_fade = FADE_IN;
 }
 
 void
 DisplayEffect::set_black(bool enabled)
 {
-    black = enabled;
+  black = enabled;
 }
 
 bool
 DisplayEffect::is_black()
 {
-    return black;
+  return black;
 }
 
 void