//Check this when more awake, should be more efficent? public s_Tile GetClosestTileE(Vector3 posToCheckAgainst) { Vector3 pos = posToCheckAgainst; float minDist = s_Calculator.square(25); s_Tile toReturn = myTiles[0]; int posToCheckFrom = 0; for (int i = 0; i < myTiles.Count; i += GetColumnCount()) { if (s_Calculator.GetDistanceLessThan(myTiles[i].transform.position, pos, minDist)) { posToCheckFrom = myTiles[i].GetTilePosition(); } } minDist = s_Calculator.square(25); for (int j = posToCheckFrom; j < (posToCheckFrom + GetColumnCount() - 1); j++) { if (s_Calculator.GetDistanceLessThan(myTiles[j].transform.position, pos, minDist)) { minDist = s_Calculator.distanceSquare(myTiles[j].transform.position, pos); toReturn = myTiles[j]; } } return(toReturn); }
public void BeginStopInEnteredTile() { if (enteredTile != null && enteredTile.CanSupportBlock()) //checks to see if the tile below this one is empty or if there is no tile below this one { if (currentTile == null) { currentTile = enteredTile; //Sets the tile that block will have as its location to the current tile it is in s_Block otherSBlock = currentTile.GetTileOccupant(); if (otherSBlock == null || otherSBlock == this) { setState(states.STOPPING); //if it is empty then transitions to stopping } else { if (//((int)currentState < (int)otherSBlock.GetCurrentState()) || (otherSBlock.transform.position.y < transform.position.y)) { MoveUpATile(); } else { otherSBlock.MoveUpATile(); } } } } }
//resets tiles after unsuccessful match check public void ClearNoMatch() { checkedBy = null; checkedAdjacentTiles = false; for (int i = 0; i < sameColor.Count; i++) { sameColor[i].checkedBy = null; } sameColor.Clear(); }
public void AddToCheckList(s_Tile t) { if ((t.GetContents() != s_Tile.Contents.NONE && t.GetContents() != s_Tile.Contents.TRASH)) { if (!toCheckTiles.Contains(t)) { toCheckTiles.Add(t); } } }
void StartSquashAndStretch() { if (tetrisParent != null && tetrisParent.GetPurpose() != s_TetrisBlock.BlockPurpose.DISPLAYNEXT) { List <int> otherBlocksInCol = new List <int>(); for (int i = 0; i < tetrisParent.GetContainedBlocksArray().Count; i++) { s_Tile tempTile = tetrisParent.GetContainedBlocksArray()[i].GetLastTileEntered(); if (tempTile == null) { tempTile = owningPlayer.GetClosestTile(transform.position); } if (tempTile.GetColumnIn() == enteredTile.GetColumnIn()) { otherBlocksInCol.Add(tempTile.GetRowIn()); } } int height = otherBlocksInCol.Count; for (int i = 0; i < otherBlocksInCol.Count; i++) { if (otherBlocksInCol[i] > enteredTile.GetRowIn()) { height--; } } mySNS.StartSquash(currentTile, height); } else { if (enteredTile != null) { int h = 0; /*for (int i = 0; i < owningPlayer.GetSBlockList().Count; i++) * { * s_Tile tempTile = owningPlayer.GetSBlockList()[i].GetEnteredTile(); * if (tempTile != null) * { * if (tempTile.GetColumnIn() == enteredTile.GetColumnIn()) * { * if (tempTile.GetRowIn() < enteredTile.GetRowIn() && !tempTile.GetTileOccupant().hasSquashed) * { * h++; * } * } * } * }*/ mySNS.StartSquash(currentTile, h); hasSquashed = true; } } }
public bool WillBlockBeOutOfBounds(s_Tile val) { float dist = myTetrisBlock.GetHighestAndLowestDifferance(); if (val.transform.position.y + dist > myTiles[myTiles.Count - 1].transform.position.y + tileYOffset) { return(true); } return(false); }
//clears the tile, block and tile based variables public void ClearTile() { checkedBy = null; content = Contents.NONE; clearOccupant(); checkedAdjacentTiles = false; for (int i = 0; i < sameColor.Count; i++) { sameColor[i].checkedBy = null; } sameColor.Clear(); }
public void AddMatch(s_Tile tileToAdd) { if (tileToAdd.GetContents() != s_Tile.Contents.NONE && tileToAdd.GetContents() != s_Tile.Contents.TRASH && !matches.Contains(tileToAdd))// the tile is not already listed in matches as is not empty. { if (s_GameManager.GetDebug()) { Debug.Log("Adding tile " + tileToAdd.name + " with contents of " + tileToAdd.GetContents() + " to matches"); } matches.Add(tileToAdd); } }
public s_Tile GetClosestTile(Vector3 posToCheckAgainst) { Vector3 pos = posToCheckAgainst; float minDist = s_Calculator.square(25); s_Tile toReturn = myTiles[0]; foreach (s_Tile t in myTiles) { if (s_Calculator.GetDistanceLessThan(t.transform.position, pos, minDist)) { minDist = s_Calculator.distanceSquare(t.transform.position, pos); toReturn = t; } } return(toReturn); }
void setEnteredTileViaCalc() { //+ new Vector3(owningPlayer.GetTileXOffset() * 0.01f, owningPlayer.GetTileYOffset()*0.05f, 0) enteredTile = owningPlayer.GetClosestTile(transform.position); if (GetEnteredTile().CanSupportBlock()) { if (owningPlayer.Player == s_Player.PlayerNumber.ONE) { Debug.Log("tile below entered tile " + GetEnteredTile().name + " is " + (GetEnteredTile().GetDownTile() == null ? "null" : GetEnteredTile().GetDownTile().name) + " with a contents of " + (GetEnteredTile().GetDownTile() == null ? "null" : GetEnteredTile().GetDownTile().GetContents().ToString())); } } BeginStopInEnteredTile(); }
public void MoveUpATile() { string message = ""; if (s_GameManager.GetDebug()) { message = gameObject.name + "cannot reside in " + currentTile.GetTilePosition() + " because " + currentTile.GetTileOccupant().name + " is there so instead residing in "; } MoveUpsCalled++; if (MoveUpsCalled > owningPlayer.GetRowCount() * 2) { MoveUpsCalled = 0; Debug.Log("Break move up"); return; } if (currentTile != null) { if (currentTile.occupant == null || currentTile.occupant == this) { MoveUpsCalled = 0; transform.position = currentTile.transform.position + new Vector3(0, 0.1f, 0); setState(states.STOPPING); //if it is empty then transitions to stopping } else { currentTile = currentTile.GetUpTile(); MoveUpATile(); } } else { if (blockType != s_Tile.Contents.TRASH) { LoseGame(); } } if (s_GameManager.GetDebug()) { Debug.Log(message + currentTile.GetTilePosition()); } SetLastTileEntered(currentTile); }
public void SpawnTiles() { //spawns tiles in a grid pattern at evenly spaced intervals for (int j = 0; j < rows; j++) { for (int i = 0; i < cols; i++) { GameObject newTile = Instantiate(Tile, transform.position + new Vector3(colOffsets * i, rowOffsets * j, 0), Quaternion.identity); // spawns tiles at intervals newTile.name += " " + i.ToString() + "-" + j.ToString(); s_Tile myTile = newTile.GetComponent <s_Tile>(); myTile.SetOwningPlayer(owningPlayer); owningPlayer.AddTile(myTile); } } setAdjacentTiles(); for (int i = 0; i < owningPlayer.GetTileList().Count; i++) { owningPlayer.GetTileList()[i].transform.SetParent(transform); } }
void withOwningPlayer() { if (owningPlayer != null) { movement(); float yToCheckAgainst = owningPlayer.GetTileList()[0].transform.position.y; if (transform.position.y < yToCheckAgainst) { s_Tile nearest = owningPlayer.GetClosestTile(transform.position); nearest = nearest.FindFreeTileInColumn(); if (nearest != null) { enteredTile = nearest; currentTile = enteredTile; transform.position = new Vector3(transform.position.x, nearest.transform.position.y + 0.1f, transform.position.z); setState(states.STOPPING); } } } }
void clearAdjacentTrash(List <s_Tile> matchBeingCleared) { for (int i = 0; i < matchBeingCleared.Count; i++) { for (int j = 0; j < matchBeingCleared[i].adjacentTiles.Length; j++) { s_Tile tempTile = matchBeingCleared[i].adjacentTiles[j]; if (tempTile != null && tempTile.GetContents() == s_Tile.Contents.TRASH) { if (tempTile.GetUpTile() != null && tempTile.GetUpTile().GetContents() != s_Tile.Contents.NONE && tempTile.GetUpTile().GetContents() != s_Tile.Contents.TRASH) { toCheckSBlocks.Add(tempTile.GetUpTile().GetTileOccupant()); } matchBeingCleared[i].adjacentTiles[j].ClearTile(); } } } }
//compares the contents of the tile passed in with this tile's content returns true if they match bool compareTileContenets(s_Tile toCheck) { if (toCheck.GetTileOccupant() != null) // if there is a block in this toCheck tile { if (toCheck.content != toCheck.GetTileOccupant().GetBlockType()) // make sure the toCheck tile has the same content as the block { toCheck.content = toCheck.GetTileOccupant().GetBlockType(); //if toCheck does not then set them to match } } else { if (toCheck.content != Contents.NONE)// if the toCheck tile is empty make sure it registers as empty { toCheck.content = Contents.NONE; } } if (toCheck.content == content)// if the content of the tile that is being check { if (checkedBy == null || checkedBy != toCheck) { toCheck.SetCheckedBy(this); if (!sameColor.Contains(toCheck)) { sameColor.Add(toCheck);//adds the tile to thge adjacent tiles that are the same color and will need to also be checked for adjacent tiles } owningPlayer.AddMatch(toCheck); return(true); } else { if (s_GameManager.GetDebug()) { Debug.Log("Checked by was not valid for " + gameObject.name); } } } return(false); }
void setState(states toSetTo) { currentState = toSetTo; switch (currentState) { case states.MOVING: hasSquashed = false; toggleParticleEffect(); currentTile = null; break; case states.STOPPING: currentTile.SetTileOccupant(this); break; case states.STOPPED: if (tetrisParent != null && tetrisParent.GetPurpose() != s_TetrisBlock.BlockPurpose.DISPLAYNEXT) { transform.parent = null; if (tetrisParent != null) { tetrisParent.PauseMovement(); tetrisParent.RemoveBlock(this); } } StartSquashAndStretch(); toggleParticleEffect(); break; default: break; } }
//This code runs when a block enters a new tile protected void onEnter(Collider2D c) { s_Tile myTile = c.gameObject.GetComponent <s_Tile>(); //gets a referance to the tile the block just entered s_Block block = c.gameObject.GetComponent <s_Block>(); //gets a referance to the tile the block just entered if (canOccupyTile && tetrisParentTest(s_TetrisBlock.BlockPurpose.VIRTUAL, true)) { if (myTile != null)//if it has collided with a tile { SetLastTileEntered(myTile); if (myTile.GetTilePosition() < owningPlayer.GetColumnCount() && (myTile.occupant == null || myTile.occupant == this)) { currentTile = enteredTile; transform.position = currentTile.transform.position; setState(states.STOPPING); } else { BeginStopInEnteredTile(); } } } }
public List <s_Tile> sameColor = new List <s_Tile>(); // a list of the adjacent tiles to this one that are the same color, excludes the one that initally checked it //Sets the corresponding direction to the tile passed in public void SetLeftTile(s_Tile val) { adjacentTiles[(int)tileDirection.LEFT] = val; }
public void SetRightTile(s_Tile val) { adjacentTiles[(int)tileDirection.RIGHT] = val; }
public void SetCheckedBy(s_Tile tileThatIsChecking) { checkedBy = tileThatIsChecking; }
void checkTileBasedOnQueue() { int tempBlocksMatched = 0; SetFoundValidMatch(false); //currently there was no valid match found. convertSblockToCheckToTilesToCheck(); int listPosToCheck = toCheckTiles.Count - 1; //the first tile to check, this sets it to be the last one added to the que. for (int i = listPosToCheck; i > 0; i--) //starting at the most recently added and working backwards { matches.Clear(); //clears the match list so that we can check for a new match, i.e. tiles that were the previous match are not counted as part of this one if (toCheckTiles[i] != null) //if the tile is not null, reasonably speaking it should never be, but never hurts to check { currentlyChecking = toCheckTiles[i]; //the tile to currently check assigning it here is somewhat of a holdover from a previous version, but I left it here in case the need arose to make use of it. if (currentlyChecking.GetContents() != s_Tile.Contents.TRASH) { int mc = currentlyChecking.CheckMatch(); //initates the check with this tile as the origin point for the check if (mc >= GetMatchNumNeeded()) //if a match was made { tempBlocksMatched += mc; //record it in the tempBlocksMatched comboCount++; //increase the combo count by 1 AddToScore((((mc - GetMatchNumNeeded()) * 100) + 100) * comboCount); s_GameManager.Singleton.GetComboImage(MyComboMeter.transform.position + new Vector3(0.5f + (comboCount * (0.2f * (s_Calculator.GetOneInTwo() ? 1 : -1))), 0, 0)).OnSpawn(comboCount); if (comboCount > 1) { AudioControlerScript.Singleton.PlayPuyoCombo();//Play PuyoCombo sound } AddAnimations(comboCount); if (MyComboMeter != null) { MyComboMeter.SetBar(comboCount, 5); } } } } } if (foundValidMatch)//the logic here is that we only need to set tiles to fall if a match was found because if no match was found then none of the tiles would have moved so if nothing was in a position to fall it still will not be in a position to fall { foreach (s_Tile t in toFallColumns) { t.SetContentsToFall(); } toFallColumns.Clear(); totalBlocksMatched += tempBlocksMatched; //increase the total blocks matched by the number of blocks matched this pass itteration currentState = PlayerStates.FALLING; //we go to the falling state where all the tiles that no longer have support under them (due to matches) fall, from the falling state we exit back into the matching state and continue the loop until no matches are found } else { if (s_GameManager.GetDebug()) { Debug.Log("Combo Length of " + comboCount.ToString() + " with total blocks matched equaling: " + totalBlocksMatched.ToString()); } trashToAddToOther = ((totalBlocksMatched - (3 * comboCount)) * (comboCount));//sets the trash to add to the other stats_TrashDumpedOnOther += trashToAddToOther; handleTrashAdding(); spawnQueuedTrashDuringQueuePhase(); AddToUltimateCharge(4 * comboCount); //adds to the ultimate charge meter stats_BlocksMatched += totalBlocksMatched; stats_CombosMade += comboCount; totalBlocksMatched = 0; //resets total blocks matched if (comboCount > 1) { myAnimationQueue.AddAnimation(s_AnimationQueue.Animations.ATTACK2); } comboCount = 0; //resets the combo counter since we have now exited any chance of making more matches until thie next tetris piece has stopped moving if (MyComboMeter != null) { resetComboMeter.SetTimerShouldCountDown(true); } MyBlockSpawner.SpawnPiece(); //spawns a new tetris piece AudioControlerScript.Singleton.PlayPuyoMatch(); // play PuyoMatch } }
public void SetUpTile(s_Tile val) { adjacentTiles[(int)tileDirection.UP] = val; }
//Adds a tile to the master list of all tiles for this player in the game public void AddTile(s_Tile tileToAdd) { myTiles.Add(tileToAdd); }
public void SetLastTileEntered(s_Tile toBeLastEntered) { enteredTile = toBeLastEntered; }
public void SetDownTile(s_Tile val) { adjacentTiles[(int)tileDirection.DOWN] = val; }
public void AddToFallColumns(s_Tile tileToFall) { toFallColumns.Add(tileToFall); }