public J(Texture2D color, Vector2 startPos) { this.color = color; this.startPos = startPos; jMatrix = new TetrisObject[3, 3]; //piece = new TetrisObject(Vector2.Zero, color); ////Contents of the I, looping through the dubbelarray setting positions and textures for (int i = 0; i < jMatrix.GetLength(0); i++) { for (int j = 0; j < jMatrix.GetLength(1); j++) { jMatrix[i, j] = new TetrisObject(Vector2.Zero, color); jMatrix[i, j].PosX = startPos.X + i * color.Width; jMatrix[i, j].PosY = startPos.Y + j * color.Height; } } formation = iblockState.one;//Default formation of the I figure UpdateFormation(); }
public TetrisObject[,] NextRotatePosition(bool clockwise) { TetrisObject[,] newPosition = new TetrisObject[zMatrix.GetLength(0), zMatrix.GetLength(1)]; for (int i = 0; i < newPosition.GetLength(0); i++) { for (int j = 0; j < newPosition.GetLength(1); j++) { newPosition[i, j] = new TetrisObject(Vector2.Zero, Color); newPosition[i, j].PosX = zMatrix[0, 0].PosX + i * Color.Width; newPosition[i, j].PosY = zMatrix[0, 0].PosY + j * Color.Height; } } if (clockwise) { switch (Formation) { case BlockState.one: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[2, 0].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[2, 1].ChangeState(false); newPosition[1, 2].ChangeState(false); break; case BlockState.two: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[0, 1].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[1, 2].ChangeState(false); newPosition[2, 2].ChangeState(false); break; case BlockState.three: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[1, 0].ChangeState(false); newPosition[0, 1].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[0, 2].ChangeState(false); break; case BlockState.four: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[0, 0].ChangeState(false); newPosition[1, 0].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[2, 1].ChangeState(false); break; } } else if (!clockwise) { switch (Formation) { case BlockState.one: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[1, 0].ChangeState(false); newPosition[0, 1].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[0, 2].ChangeState(false); break; case BlockState.two: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[0, 0].ChangeState(false); newPosition[1, 0].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[2, 1].ChangeState(false); break; case BlockState.three: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[2, 0].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[2, 1].ChangeState(false); newPosition[1, 2].ChangeState(false); break; case BlockState.four: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[0, 1].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[1, 2].ChangeState(false); newPosition[2, 2].ChangeState(false); break; } } return(newPosition); }
public bool AllowRotation(bool clockwise, Vector2 maxValues, Vector2 minValues) { TetrisObject[,] newPosition = new TetrisObject[sMatrix.GetLength(0), sMatrix.GetLength(1)]; for (int i = 0; i < newPosition.GetLength(0); i++) { for (int j = 0; j < newPosition.GetLength(1); j++) { newPosition[i, j] = new TetrisObject(Vector2.Zero, Color); newPosition[i, j].PosX = sMatrix[0, 0].PosX + i * Color.Width; newPosition[i, j].PosY = sMatrix[0, 0].PosY + j * Color.Height; } } if (clockwise) { switch (Formation) { case BlockState.one: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[1, 0].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[2, 1].ChangeState(false); newPosition[2, 2].ChangeState(false); break; case BlockState.two: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[1, 1].ChangeState(false); newPosition[2, 1].ChangeState(false); newPosition[0, 2].ChangeState(false); newPosition[1, 2].ChangeState(false); break; case BlockState.three: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[0, 0].ChangeState(false); newPosition[0, 1].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[1, 2].ChangeState(false); break; case BlockState.four: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[1, 0].ChangeState(false); newPosition[2, 0].ChangeState(false); newPosition[0, 1].ChangeState(false); newPosition[1, 1].ChangeState(false); break; } } else if (!clockwise) { switch (Formation) { case BlockState.one: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[0, 0].ChangeState(false); newPosition[0, 1].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[1, 2].ChangeState(false); break; case BlockState.two: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[1, 0].ChangeState(false); newPosition[2, 0].ChangeState(false); newPosition[0, 1].ChangeState(false); newPosition[1, 1].ChangeState(false); break; case BlockState.three: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[1, 0].ChangeState(false); newPosition[1, 1].ChangeState(false); newPosition[2, 1].ChangeState(false); newPosition[2, 2].ChangeState(false); break; case BlockState.four: foreach (TetrisObject item in newPosition) { item.ChangeState(true); } newPosition[1, 1].ChangeState(false); newPosition[2, 1].ChangeState(false); newPosition[0, 2].ChangeState(false); newPosition[1, 2].ChangeState(false); break; } } return(minValues.X <= MinValues(newPosition).X&& maxValues.X >= MaxValues(newPosition).X&& maxValues.Y >= MaxValues(newPosition).Y); }