Ejemplo n.º 1
0
 public override void DoCollision(IEntity entity)
 {
     if (entity is Peach peach)
     {
         AABB peachBounds = peach.BoundingBox();
         AABB blockBounds = BoundingBox();
         if (blockBounds.Bottom - peachBounds.Top <= 10 && peach.ActionState is JumpingState)
         {
             Debug.WriteLine("Glass state: " + this.BlockState);
             if (Bump && this.BlockState is NewGlassBlockState)
             {
                 BumpBrickBlockTransition();
             }
             else if (this.BlockState is CrackedGlassBlockState)
             {
                 Debug.WriteLine("Block state is Cracked Glass Block State");
                 int count = ContainedItems.Count;
                 for (int i = Constants.ZERO; i < count; i++)
                 {
                     ExplodeBrickBlockTransition();                            //remove the brickblock from screen and deregister it
                     ExplodingBlock child = (ExplodingBlock)ContainedItems[i]; // must do following for all four exploding blocks
                     child.Visible = true;
                     if (i == 1)
                     {
                         child.Sprite.Velocity = new Vector2(-300, -300);             // make the blocks go in different directions
                     }
                     else if (i == 2)
                     {
                         child.Sprite.Velocity = new Vector2(300, 300);
                     }
                     else if (i == 3)
                     {
                         child.Sprite.Velocity = new Vector2(300, -300);
                     }
                     else if (i == 4)
                     {
                         child.Sprite.Velocity = new Vector2(-300, 300);
                     }
                     child.ExplodingBlockTransition();
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public override void DoCollision(IEntity entity)
 {
     if (entity is Peach peach)
     {
         AABB peachBounds = peach.BoundingBox();
         AABB blockBounds = BoundingBox();
         if (blockBounds.Bottom - peachBounds.Top <= 10 && peach.ActionState is JumpingState)
         {
             BumpHiddenBlockTransition();
             if (Bump && peach.PowerUpState is StandardState)
             {
                 BumpedBy = peach;
                 if (ContainedItems.Count != Constants.ZERO)
                 {
                     IEntity child = ContainedItems[0];
                     if (!(child is ExplodingBlock))
                     {
                         child.Checkable = true;
                         child.Visible   = true;
                     }
                     if (child is SuperMushroom)
                     {
                         sound.Play();
                         if (peachBounds.Center.X > blockBounds.Center.X)
                         {
                             child.Sprite.Velocity = new Vector2(100, Constants.ZERO);
                         }
                         else
                         {
                             child.Sprite.Velocity = new Vector2(-100, Constants.ZERO);
                         }
                     }
                     else if (child is OneUpMushroom)
                     {
                         sound.Play();
                         if (peachBounds.Center.X > blockBounds.Center.X)
                         {
                             child.Sprite.Velocity = new Vector2(-100, Constants.ZERO);
                         }
                         else
                         {
                             child.Sprite.Velocity = new Vector2(100, Constants.ZERO);
                         }
                     }
                     else if (child is Star)
                     {
                         sound.Play();
                         if (peach.Sprite.HReflect)
                         {
                             child.Sprite.Velocity = new Vector2(-200, -300);
                         }
                         else
                         {
                             child.Sprite.Velocity = new Vector2(200, -300);
                         }
                     }
                     RemoveContainedItem(child);
                 }
             }
             else if (Bump)
             {
                 int count = ContainedItems.Count;
                 for (int i = Constants.ZERO; i < count; i++)
                 {
                     if (ContainedItems[i] is ExplodingBlock)
                     {
                         ExplodeBrickBlockTransition();                            //remove the brickblock from screen and deregister it
                         ExplodingBlock child = (ExplodingBlock)ContainedItems[i]; // must do following for all four exploding blocks
                         child.Visible = true;
                         if (i == 1)
                         {
                             child.Sprite.Velocity = new Vector2(-300, -300);         // make the blocks go in different directions
                         }
                         else if (i == 2)
                         {
                             child.Sprite.Velocity = new Vector2(300, 300);
                         }
                         else if (i == 3)
                         {
                             child.Sprite.Velocity = new Vector2(300, -300);
                         }
                         else if (i == 4)
                         {
                             child.Sprite.Velocity = new Vector2(-300, 300);
                         }
                         child.ExplodingBlockTransition();
                     }
                 }
             }
         }
     }
 }