// set ups rotation point and coordinates(relative to the center of tetramino) of cells that form a tetromino public Tetramino(TetraminoType type) { this.type = type; switch (type) { case TetraminoType.I: Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 } }); rotationPoint = new Vector2(3f / 2f, -1f / 2f); break; case TetraminoType.J: Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 1, 2 } }); rotationPoint = new Vector2(1f, 1f); break; case TetraminoType.L: Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 0, 2 } }); rotationPoint = new Vector2(0f, 1f); break; case TetraminoType.O: Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }); rotationPoint = new Vector2(1f / 2f, 1f / 2f); break; case TetraminoType.S: Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 2, 1 } }); rotationPoint = new Vector2(1f, 0f); break; case TetraminoType.T: Poses = GetPoses(new int[4, 2] { { 1, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 } }); rotationPoint = new Vector2(1f, 1f); break; case TetraminoType.Z: Poses = GetPoses(new int[4, 2] { { 0, 1 }, { 1, 1 }, { 1, 0 }, { 2, 0 } }); rotationPoint = new Vector2(1f, 0f); break; default: Debug.LogError("Unsupported tetramino type: " + type); break; } }
public void SpawnNext() { TetraminoType type = (TetraminoType)Random.Range(0, 7); tetramino.GetComponent <Tetramino>().SetType(type); nextTetramino = Instantiate(tetramino, Vector3.zero, Quaternion.identity); }
private void TimerTick(object sender, EventArgs e) { if (Cells == null) { //GetNextTetramino(); currentType = TetraminoTypeGenerator.GetTetraminoType(tetraminoCounter++); if (!GenerateTetramino()) { //game over _tmr.Stop(); _notificate(GameEvent.GameOver); } else { _notificate(GameEvent.CreateNewTetramino); } } else { //todo user input here switch (_input()) { case Move.Left: MoveLeft(); break; case Move.Right: MoveRight(); break; case Move.Rotate: Rotate(true); break; } if (timerCounter > (500 - ((GameSpeed - 1) * 50))) { timerCounter = 0; if (!MoveDown()) { Cells = null; CheckCompleteRow(); } } else { timerCounter += 33; } } }
private static void GenerateBag() { TetraminoType[] newBag = new TetraminoType[7]; //shuffle bag for (int i = 0; i < bag.Length; i++) { int index = rnd.Next(i, bag.Length); TetraminoType tmp = bag[index]; bag[index] = bag[i]; bag[i] = tmp; } for (int i = 0; i < bag.Length; i++) { newBag[i] = bag[i]; } listOfBag.Add(newBag); }
private void GetNextTetramino() { if (bagIndex >= bag.Length) { bagIndex = 0; } if (bagIndex == 0) { //shuffle bag for (int i = 0; i < bag.Length; i++) { int index = rnd.Next(i, bag.Length); TetraminoType tmp = bag[index]; bag[index] = bag[i]; bag[i] = tmp; } } currentType = bag[bagIndex++]; }
public GameObject GetTileByType(TetraminoType tetramino) { GameObject tile = null; switch (tetramino) { case TetraminoType.I: tile = _cyanTile; break; case TetraminoType.J: tile = _blueTile; break; case TetraminoType.L: tile = _orangeTile; break; case TetraminoType.O: tile = _yellowTile; break; case TetraminoType.S: tile = _greenTile; break; case TetraminoType.T: tile = _purpleTile; break; case TetraminoType.Z: tile = _redTile; break; } return(tile); }
// sets up rotation point and tetramino's cells coordinates // also sets up tetramino's type public Tetramino(TetraminoType type) { Builder.SetUp(this, type); }
public void SetType(TetraminoType type) { this.type = type; }
public void SpawnBlock() { TetraminoType tetramino = GetRandomType(); }
public Color GetColor(TetraminoType type) { return(typeToColor[type]); }
public Vector3 GetOffset(TetraminoType type) { return(typeToOffset[type]); }
public int[,,] GetShapes(TetraminoType type) { return(typeToShapes[type]); }
public Tetramino(TetraminoType type, Vector2[] coord) { this.Type = type; this.coord = coord; }