internal void FireLaser (uint x, uint y, uint width, uint height, Direction4D direction, Block[,] grid, ContentManager Content, LaserbeamManager laserManager, ref int laserIndex)
 {
     SilverBotMirrorPosition[] mirrorPositions = new SilverBotMirrorPosition[0];
     if (silverBot != null)
         mirrorPositions = GetSilverBotPositions(new Vector2(silverBot.gridPos.X, silverBot.gridPos.Y));
     Laserbeam current = laserManager.GetBeam(laserIndex);
     current.SetStartDirection(direction);
     Vector2 currentPosition = new Vector2(x, y) + direction.ToVector2();
     while(true)
     {
         if (currentPosition.X == -1 || currentPosition.Y == -1)
             break;
         if (currentPosition.X == width)
             break;
         if (currentPosition.Y == height)
             break;
         foreach (var mirror in mirrorPositions)
         {
             if (mirror == currentPosition)
             {
                 direction = mirror.Mirror(direction.Reverse());
                 break;
             }
         }
         if(grid[(int)currentPosition.X, (int)currentPosition.Y].LaserPassesThrough())
         {
             current.Add(currentPosition);
             currentPosition += direction.ToVector2();
         }
         else
         {
             break;
         }
     }
     current.SetEndDirection(direction);
     laserIndex++;
 }
        public bool TryStep(Direction4D moveDirection, out Vector2 moveTo)
        {
            isPushing = false;
            moveTo = new Vector2();
            if (moveDirection == Direction4D.None)
                return false;

            facing = moveDirection;
            moveTo = moveDirection.ToVector2() + gridPos;
            if (moveTo.X < 0 || moveTo.Y < 0 ||
                moveTo.X >= grid.GetLength(0) || moveTo.Y >= grid.GetLength(1) ||
                (isSilverBot ? (moveTo.X == grid.GetLength(0) - 1 || (moveTo.Y == grid.GetLength(1) - 1)) : false))
            {
                return false;
            }
            Block moveToBlock = grid[(int)moveTo.X, (int)moveTo.Y];
            Block moveToBlock1XPlus = default(Block);
            Block moveToBlock1YPlus = default(Block);
            Block moveToBlock1XYPlus = default(Block);
            if (isSilverBot)
            {
                moveToBlock1XPlus = grid[(int)moveTo.X + 1, (int)moveTo.Y];
                moveToBlock1YPlus = grid[(int)moveTo.X, (int)moveTo.Y + 1];
                moveToBlock1XYPlus = grid[(int)moveTo.X + 1, (int)moveTo.Y + 1];
            }
            if (moveToBlock == Block.Crate)
            {
                Vector2 crateMovePlus = moveDirection.ToVector2();
                if (IsTouchingSilverBot(crateMovePlus + moveTo) || isSilverBot)
                    return false;

                Point targetPos = new Point( (int)(moveTo.X + crateMovePlus.X), (int)(moveTo.Y + crateMovePlus.Y) );
                if (targetPos.X < 0 || targetPos.Y < 0 || targetPos.X >= grid.GetLength(0) || targetPos.Y >= grid.GetLength(1))
                    return false;
                if (grid[targetPos.X, targetPos.Y].IsSolid())
                    return false;

                grid[targetPos.X, targetPos.Y] = Block.Crate;
                grid[(int)(moveTo.X), (int)moveTo.Y] = Block.Floor;
                game.AddPushAnim(Block.Crate, targetPos, this, moveDirection);

                gridPos = moveTo;
                animTarget = gridPos * 32.0f;
                game.ReloadLasers();
                isPushing = true;
                sounds.cratePush.Play();
                return true;
            }
            if (IsTouchingSilverBot(moveTo))
            {
                if (game.silverBot.GotPushed(moveDirection, this))
                {
                    isPushing = true;
                }
                else
                {
                    return false;
                }
            }
            if (isSilverBot)
                goto SkipForeach;
            SkipForeach:
            if ((!MainGame.IsSolid(moveToBlock) || moveToBlock == Block.Panel || moveToBlock == Block.Exit) &&
                (!isSilverBot || (!MainGame.IsSolid(moveToBlock1XPlus) && !MainGame.IsSolid(moveToBlock1YPlus) && !MainGame.IsSolid(moveToBlock1XYPlus))))
            {
                gridPos = moveTo;
                animTarget = gridPos * 32.0f;
                game.ReloadLasers();
                return true;
            }

            return false;
        }
        public bool GotPushed(Direction4D direction, PlayerAvatar sender)
        {
            Vector2 offset = direction.ToVector2();
            Point position = (gridPos + offset).ToPoint();

            if (isSilverBot)
            {
                if (!IsPositionFree(position))
                    return false;
                if (!IsPositionFree(position + new Point(1,0)))
                    return false;
                if (!IsPositionFree(position + new Point(0,1)))
                    return false;
                if (!IsPositionFree(position + new Point(1,1)))
                    return false;
            }
            else
            {
                if (!IsPositionFree(position))
                    return false;

                if( position.X == game.silverBot.gridPos.X || position.X == game.silverBot.gridPos.X+1 )
                {
                    if( position.Y == game.silverBot.gridPos.Y || position.Y == game.silverBot.gridPos.Y+1 )
                    {
                        //can't push things into silverbot
                        return false;
                    }
                }
            }

            gridPos += offset;
            animTarget = gridPos * 32.0f;
            isPushing = true;
            return true;
        }
 internal void AddPushAnim(Block block, Point destination, PlayerAvatar pusher, Direction4D moveDirection)
 {
     switch(block)
     {
         case Block.Crate:
             pushAnims.Add( new PushAnim(textures.crate, pusher, moveDirection.ToVector2() * widthOfBlock, destination) );
             break;
     }
 }