Exemplo n.º 1
0
        private bool isCollide(Block[,] figure, Vector2 position)
        {
            for (int i = 0; i < figure.GetLength(0); i++)
                for (int j = 0; j < figure.GetLength(1); j++)
                {
                    Block check;
                    if (((position.X + i) < 0) || ((position.X + i) >= field.GetLength(0)) || ((position.Y + j) >= field.GetLength(1)))
                        check = new Block(0);
                    else if ((position.Y + j) < 0)
                        check = new Block();
                    else
                        check = field[(int)position.X + i, (int)position.Y + j];

                    if (figure[i, j].isFill && check.isFill)
                        return true;
                }

            return false;
        }
Exemplo n.º 2
0
        bool CanMove(Point direction, Block[,] grid)
        {
            for (int y = 0; y < grid.GetLength(1); y++)
            {
                for (int x = 0; x < grid.GetLength(0); x++)
                {
                    if (grid[x, y] != null)
                    {
                        //This check if this block from the grid can move down on the world grid.
                        Point worldLocation = GetWorldLocation(x, y);

                        //Check for outside of screen
                        if (worldLocation.Y + direction.Y >= world.Rows)
                        {
                            //Went out the bottom
                            return false;
                        }
                        if (worldLocation.X + direction.X >= world.Columns)
                        {
                            //Went out the right
                            return false;
                        }
                        if (worldLocation.X + direction.X < 0)
                        {
                            //Went out the left
                            return false;
                        }

                        //Check collision with world blocks
                        if (world.Grid[worldLocation.X + direction.X, worldLocation.Y + direction.Y] != null)
                        {
                            //There is a block here!
                            return false;
                        }
                    }
                }
            }
            return true;
        }
Exemplo n.º 3
0
 private void FixFigure(Block[,] figure, Vector2 position)
 {
     for (int i = 0; i < figure.GetLength(0); i++)
         for (int j = 0; j < figure.GetLength(1); j++)
             if (figure[i, j].isFill)
                 if ((int)position.Y + j >= 0)
                     field[(int)position.X + i, (int)position.Y + j] = new Block(figure[i, j].hue);
                 else
                 {
                     ((Game1)gameTab.Game).ChangeState(Game1.GameStates.End);
                     return;
                 }
 }
Exemplo n.º 4
0
        public void setFigure(Block[,] figure)
        {
            this.figure = figure;

            position = new Vector2((int)((Constants.FIELDBLOCKZISE.X - figure.GetLength(0)) / 2), -figure.GetLength(1));
        }