Tux can peek to the left and to the right as far as the camera would move in best...
[supertux.git] / src / object / player.cpp
index 6e04514..4aab47f 100644 (file)
@@ -144,6 +144,7 @@ Player::init()
   dead = false;
 
   dying = false;
+  peeking = AUTO;
   last_ground_y = 0;
   fall_mode = ON_GROUND;
   jumping = false;
@@ -314,10 +315,7 @@ Player::update(float elapsed_time)
   on_ground_flag = false;
 
   // when invincible, spawn particles
-  if (invincible_timer.started() &&
-     (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING
-      || size_t(game_time*20)%2)
-     && !dying)
+  if (invincible_timer.started() && !dying)
   {
     if (systemRandom.rand(0, 2) == 0) {
       float px = systemRandom.randf(bbox.p1.x+0, bbox.p2.x-0);
@@ -325,7 +323,17 @@ Player::update(float elapsed_time)
       Vector ppos = Vector(px, py);
       Vector pspeed = Vector(0, 0);
       Vector paccel = Vector(0, 0);
-      Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "small", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
+      // draw bright sparkle when there is lots of time left, dark sparkle when invincibility is about to end
+      if (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING) {
+       // make every other a longer sparkle to make trail a bit fuzzy
+       if (size_t(game_time*20)%2) {
+         Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "small", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
+       } else {
+         Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "medium", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
+       }
+      } else {
+        Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "dark", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
+      }
     }
   } 
 
@@ -607,6 +615,20 @@ Player::handle_input()
       grabbed_object = NULL;
     }
   }
+
+  /* Peeking */
+  if( controller->released( Controller::PEEK_LEFT ) ) {
+    peeking = AUTO;
+  } 
+  if( controller->released( Controller::PEEK_RIGHT ) ) {
+    peeking = AUTO;
+  }
+  if( controller->pressed( Controller::PEEK_LEFT ) ) {
+    peeking = LEFT;
+  } 
+  if( controller->pressed( Controller::PEEK_RIGHT ) ) {
+    peeking = RIGHT;
+  }
  
   /* Handle horizontal movement: */
   if (!backflipping) handle_horizontal_input();
@@ -731,6 +753,10 @@ void
 Player::set_visible(bool visible)
 {
   this->visible = visible;
+  if( visible ) 
+    set_group(COLGROUP_MOVING);
+  else
+    set_group(COLGROUP_DISABLED);
 }
 
 bool
@@ -1008,7 +1034,7 @@ Player::kill(bool completely)
   if(dying || deactivated)
     return;
 
-  if(!completely && safe_timer.started() || invincible_timer.started())
+  if(!completely && (safe_timer.started() || invincible_timer.started()))
     return;                          
   
   sound_manager->play("sounds/hurt.wav");