示例#1
0
        static void Main(string[] args)
        {
            int count;

            do
            {
                Console.WriteLine("Enter a number between 1 and 8: ");
                count = int.Parse(Console.ReadLine());
            } while (count < 0 || count > 8);
            Mario mario = new Mario();

            mario.Build(count);
        }
示例#2
0
 public override void EmitPrize(Mario mario)
 {
     if (animate == true)
     {
         animate = false;
         frame = 4;
         foreach (Coin c in Game1.coins)
         {
             if (c.alive == false)
             {
                 c.alive = true;
                 c.position = new Vector2(position.X, position.Y - area.Height - 2);
                 c.hspeed = mario.hspeed;
                 c.vspeed = -4;
                 break;
             }
         }
     }
 }
示例#3
0
 public virtual void EmitPrize(Mario mario)
 {
 }
示例#4
0
 public override void EmitPrize(Mario mario)
 {
     if (mario.powerLevel > 0)
         BlockBreak();
 }
示例#5
0
 public void Update(Mario mario)
 {
     if (alive)
     {
         lifeTime++;
         foreach (Block o in Game1.blocks)
         {
             Rectangle collisionX = collision;
             collisionX.X += (int)hspeed;
             if (collisionX.Intersects(o.collision))
             {
                 if (hspeed < 0)
                 {
                     position.X = o.position.X + (o.collision.Width / 2) + (collisionX.Width / 2);
                     UpdateCollisionRect();
                     hspeed = -hspeed;
                     break;
                 }
                 if (hspeed > 0)
                 {
                     position.X = o.position.X - (o.collision.Width / 2) - (collisionX.Width / 2);
                     UpdateCollisionRect();
                     hspeed = -hspeed;
                     break;
                 }
             }
         }
         hspeed = MathHelper.Clamp(hspeed, -hspd, hspd);
         position += new Vector2(hspeed, 0);
         UpdateCollisionRect();
         rotation += hspeed * 4;
         if (grounded == false)
             vspeed += .5f;
         Rectangle collrect = collision;
         collrect.Y += (int)vspeed;
         bool canMove = true;
         foreach (Block o in Game1.blocks)
         {
             if (collrect.Intersects(o.collision))
             {
                 if (position.Y > o.position.Y)
                 {
                     position.Y = o.position.Y + (o.collision.Height / 2) + (collrect.Height / 2);
                     UpdateCollisionRect();
                     vspeed = -vspeed;
                     canMove = false;
                 }
                 if (position.Y < o.position.Y)
                 {
                     position.Y = o.position.Y - (o.collision.Height / 2) - (collrect.Height / 2);
                     UpdateCollisionRect();
                     vspeed = -vspeed + 1;
                     canMove = false;
                 }
             }
             Rectangle collisionRectangle = collision;
             collisionRectangle.Y += 1;
             if (collisionRectangle.Intersects(o.collision))
             {
                 grounded = true;
                 break;
             }
             grounded = false;
         }
         vspeed = MathHelper.Clamp(vspeed, -vspd, vspd);
         if (canMove)
         {
             position += new Vector2(0, vspeed);
             UpdateCollisionRect();
         }
         if (position.X - (area.Width / 2) < 0)
         {
             position.X -= hspeed;
             UpdateCollisionRect();
             hspeed = -hspeed;
         }
         if (position.X + (area.Width / 2) > Game1.graphics.PreferredBackBufferWidth)
         {
             position.X -= hspeed;
             UpdateCollisionRect();
             hspeed = -hspeed;
         }
         base.Update();
     }
 }
示例#6
0
 public void Update(Mario mario)
 {
     if (alive)
     {
         if (aliveprev != alive && mario.powerLevel < mario.powerLevelCap)
         {
             frame = mario.powerLevel;
         }
         if (aliveprev != alive && mario.powerLevel == mario.powerLevelCap)
         {
             frame = mario.powerLevel - 1;
         }
         foreach (Block o in Game1.blocks)
         {
             Rectangle collisionX = collision;
             collisionX.X += (int)hspeed;
             if (collisionX.Intersects(o.collision))
             {
                 if (hspeed < 0)
                 {
                     position.X = o.position.X + (o.collision.Width / 2) + (collisionX.Width / 2);
                     UpdateCollisionRect();
                     hspeed = -hspeed;
                     break;
                 }
                 if (hspeed > 0)
                 {
                     position.X = o.position.X - (o.collision.Width / 2) - (collisionX.Width / 2);
                     UpdateCollisionRect();
                     hspeed = -hspeed;
                     break;
                 }
             }
         }
         hspeed = MathHelper.Clamp(hspeed, -hspd, hspd);
         if (hspeed != 0)
         {
             if (hspeed > 0)
                 hspeed -= .02f;
             if (hspeed < 0)
                 hspeed += .02f;
         }
         if (Math.Abs(hspeed) < .02f)
         {
             hspeed = 0;
         }
         position += new Vector2(hspeed, 0);
         UpdateCollisionRect();
         rotation += hspeed * 4;
         if (grounded == false)
             vspeed += .5f;
         collision.Y += (int)vspeed;
         bool canMove = true;
         foreach (Block o in Game1.blocks)
         {
             if (collision.Intersects(o.collision))
             {
                 if (position.Y > o.position.Y)
                 {
                     position.Y = o.position.Y + (o.collision.Height / 2) + (collision.Height / 2);
                     UpdateCollisionRect();
                     vspeed = -vspeed;
                     canMove = false;
                 }
                 if (position.Y < o.position.Y)
                 {
                     position.Y = o.position.Y - (o.collision.Height / 2) - (collision.Height / 2);
                     UpdateCollisionRect();
                     if (vspeed >= 1)
                         vspeed = -vspeed + 1;
                     else vspeed = 0;
                     canMove = false;
                 }
             }
             Rectangle collisionRectangle = collision;
             collisionRectangle.Y += 1;
             if (collisionRectangle.Intersects(o.collision))
             {
                 grounded = true;
                 break;
             }
             grounded = false;
         }
         vspeed = MathHelper.Clamp(vspeed, -vspd, vspd);
         if (canMove)
         {
             position += new Vector2(0, vspeed);
             UpdateCollisionRect();
         }
         if (position.X - (area.Width / 2) < 0)
         {
             position.X -= hspeed;
             UpdateCollisionRect();
             hspeed = -hspeed;
         }
         if (position.X + (area.Width / 2) > Game1.graphics.PreferredBackBufferWidth)
         {
             position.X -= hspeed;
             UpdateCollisionRect();
             hspeed = -hspeed;
         }
         base.Update();
     }
     aliveprev = alive;
 }