public MoveableBlockState(MoveableBlock block, IDictionary <string, IDoor> doors)
 {
     vy         = 0;
     vx         = 0;
     pushDelay  = 0;
     this.block = block;
     this.doors = doors;
 }
 public MovingBlockState(MoveableBlock block, IDictionary <string, IDoor> doors,
                         int vx, int vy)
 {
     this.vx    = vx;
     this.vy    = vy;
     pxMoved    = 0;
     this.block = block;
     this.doors = doors;
     Sounds.GetSecretSound().Play();
 }
예제 #3
0
        public void Handle()
        {
            if (block is Stairs)
            {
                if (block.Hitbox.Contains(player.Center))
                {
                    Stairs.StairDirection direction = (block as Stairs).Direction;
                    if (direction == Stairs.StairDirection.Down)
                    {
                        game.state = new ChangeRoomState("stairdown", player, game);
                    }
                    else
                    {
                        game.state = new ChangeRoomState("stairup", player, game);
                    }
                }
                return;
            }

            // computing this here so that link doesn't get double corrected if he runs
            // into two blocks at the same time
            Rectangle collision = Rectangle.Intersect(player.Footbox, block.Hitbox);

            IMoveableBlock moveableBlock;

            if (block is IMoveableBlock)
            {
                moveableBlock = block as IMoveableBlock;
            }

            else
            {
                moveableBlock = new MoveableBlock(doors);
            }

            if (collision.Width > collision.Height)
            {
                if (collision.Y == player.Footbox.Y)
                {
                    player.Y += collision.Height;
                    moveableBlock.MoveOnceUp();
                }
                else
                {
                    player.Y -= collision.Height;
                    moveableBlock.MoveOnceDown();
                }
            }
            else
            {
                if (collision.X == player.Footbox.X)
                {
                    player.X += collision.Width;
                    moveableBlock.MoveOnceLeft();
                }
                else
                {
                    player.X -= collision.Width;
                    moveableBlock.MoveOnceRight();
                }
            }
        }