Пример #1
0
 public static Block CreateRandomBlock()
 {
     Block block = new Block();
     int index = r.Next(7);
     block.ColorIndex = 1 + r.Next(MAX_COLORS);
     switch (index)
     {
         case 0:
             //I
             block.Matrices = new int[2, 4, 4];
             block.FillMatrixFromString(0, cI1);
             block.FillMatrixFromString(1, cI2);
             break;
         case 1:
             //T
             block.Matrices = new int[4, 4, 4];
             block.FillMatrixFromString(0, cT1);
             block.FillMatrixFromString(1, cT2);
             block.FillMatrixFromString(2, cT3);
             block.FillMatrixFromString(3, cT4);
             break;
         case 2:
             //L
             block.Matrices = new int[4, 4, 4];
             block.FillMatrixFromString(0, cL1);
             block.FillMatrixFromString(1, cL2);
             block.FillMatrixFromString(2, cL3);
             block.FillMatrixFromString(3, cL4);
             break;
         case 3:
             //J
             block.Matrices = new int[4, 4, 4];
             block.FillMatrixFromString(0, cJ1);
             block.FillMatrixFromString(1, cJ2);
             block.FillMatrixFromString(2, cJ3);
             block.FillMatrixFromString(3, cJ4);
             break;
         case 4:
             //Z
             block.Matrices = new int[2, 4, 4];
             block.FillMatrixFromString(0, cZ1);
             block.FillMatrixFromString(1, cZ2);
             break;
         case 5:
             //S
             block.Matrices = new int[2, 4, 4];
             block.FillMatrixFromString(0, cS1);
             block.FillMatrixFromString(1, cS2);
             break;
         case 6:
             //O
             block.Matrices = new int[1, 4, 4];
             block.FillMatrixFromString(0, cO1);
             break;
     }
     block.CalcBounds();
     block.RotateIndex = r.Next(block.Matrices.GetLength(0));
     return block;
 }
Пример #2
0
        void AddBlock(Direction origin)
        {
            //if (CurrentBlock != null)
            //    CurrentBlock = null;
            if (NextBlock == null)
                NextBlock = Block.CreateRandomBlock();

            CurrentBlock = NextBlock;
            NextBlock = Block.CreateRandomBlock();

            BoundingBox b = CurrentBlock.BlockBounds[CurrentBlock.RotateIndex];
            switch (origin)
            {
                case Direction.Right:
                    CurrentBlock.X = FIELD_X - 1 - b.Right;
                    CurrentBlock.Y = FIELD_Y / 2 - Block.BLOCK_CENTER_Y;
                    CurrentBlock.MoveDirection = Direction.Left;
                    //todo:
                    //alphaHorLine = LINE_INACTIVE_ALPHA;
                    //alphaVertLine = LINE_ACTIVE_ALPHA;
                    //next dir - from top
                    //nextblockdir rotation
                    break;

                case Direction.Left:
                    CurrentBlock.X = -CurrentBlock.BlockBounds[CurrentBlock.RotateIndex].Left;
                    CurrentBlock.Y = FIELD_Y / 2 - Block.BLOCK_CENTER_Y;
                    CurrentBlock.MoveDirection = Direction.Right;
                    break;

                case Direction.Top:
                    CurrentBlock.X = FIELD_X / 2 - 1 - Block.BLOCK_CENTER_X;
                    CurrentBlock.Y = -CurrentBlock.BlockBounds[CurrentBlock.RotateIndex].Top;
                    CurrentBlock.MoveDirection = Direction.Bottom;
                    break;

                case Direction.Bottom:
                    CurrentBlock.X = FIELD_X / 2 - 1 - Block.BLOCK_CENTER_X;
                    CurrentBlock.Y = FIELD_Y - CurrentBlock.BlockBounds[CurrentBlock.RotateIndex].Bottom - 1;
                    CurrentBlock.MoveDirection = Direction.Top;
                    break;
            }
        }
Пример #3
0
        public void Start()
        {
            Vector2 startPos = new Vector2(FieldTopLeft.position.x, FieldTopLeft.position.y);
            for (int i = 0; i < FIELD_X; i++)
                for (int j = 0; j < FIELD_Y; j++)
                {
                    Sprites[i, j] = (GameObject)Instantiate(blockPrefab, new Vector3(startPos.x + i * 0.35f, startPos.y - j * 0.35f, 0), Quaternion.identity);
                }

            //Start the game!
            CurrentSpeed = SPEED_START;
            CurrentCleanPeriod = CLEAN_PERIOD_START;
            timeToMove = 1.0f / CurrentSpeed;
            //timeToClean = 0;
            Scores = 0;
            CurrentBlock = null;
            AddBlock(Direction.Top);
            BeforeCleanCounter = CurrentCleanPeriod;
        }