public void AppendLast(GameObject value) { lock (addingLock) { BListObject newListObject = new BListObject(); newListObject.value = value; if (first == null) { first = newListObject; last = newListObject; count++; return; } if (count == 1) { first.leftNeighbour = newListObject; newListObject.rightNeighbour = first; last = newListObject; count++; return; } last.leftNeighbour = newListObject; newListObject.rightNeighbour = last; last = newListObject; count++; } }
public static bool GetPosForNewBall(BListObject collidingObject, GameObject newBall, out Vector3 posForNewBall, Vector3 posForFirstBall, Vector3 posForLastBall) { bool isRight = false; if (Vector3.Distance(collidingObject.value.transform.position, GameManagerScript.levelSpawningPosition) < GameManagerScript.spawningSafeDistance) { posForLastBall = GameManagerScript.levelSpawningPosition; } float distToLeft = (collidingObject.leftNeighbour != null ? Vector3.Distance(collidingObject.leftNeighbour.value.transform.position, newBall.transform.position) : Vector3.Distance(posForLastBall, newBall.transform.position)); float distToRight = (collidingObject.rightNeighbour != null ? Vector3.Distance(collidingObject.rightNeighbour.value.transform.position, newBall.transform.position) : Vector3.Distance(posForFirstBall, newBall.transform.position)); if (distToLeft < distToRight) { isRight = true; posForNewBall = collidingObject.value.transform.position; } else { posForNewBall = (collidingObject.rightNeighbour != null ? collidingObject.rightNeighbour.value.transform.position : posForFirstBall); } newBall.GetComponent <BallScript>().ballObj.destination = collidingObject.value.GetComponent <BallScript>().ballObj.destination; return(isRight); }
public void ChangeBallDirection(GameObject ball) { BListObject listObj = balls.Find(ball); if (listObj != null) { listObj.mustBeCenterPoint = true; while (listObj != null && (listObj.value == ball || listObj.value.GetComponent <BallReturningScript>() == null)) { if (listObj.value.GetComponent <BallScript>().ballObj.forwardBackward < 0) { listObj.value.GetComponent <BallScript>().ballObj.forwardBackward = -listObj.value.GetComponent <BallScript>().ballObj.forwardBackward; listObj.value.GetComponent <BallScript>().ballObj.destination++; } MovementManager.CalculateLerpVector(listObj.value.GetComponent <BallScript>().ballObj); if (listObj.leftNeighbour != null) { listObj.value.GetComponent <BallScript>().ballObj.actualSpeedLevel++; while (Vector3.Distance(listObj.value.transform.position, listObj.leftNeighbour.value.transform.position) < spawningSafeDistance) { MovementManager.MoveBall(listObj); } listObj.value.GetComponent <BallScript>().ballObj.actualSpeedLevel--; } listObj.value.GetComponent <BallScript>().ballObj.DecreaseSpeedLevel(); listObj = listObj.rightNeighbour; } ballsThatCouldBeInSequence.Add(balls.Find(ball)); } }
public static void MoveBall(BListObject ballListObj) { GameObject ball = ballListObj.value; BallObject ballObj = ball.GetComponent <BallScript>().ballObj; CalculateLerpVector(ballObj); int movementSpeed = ballObj.forCounter; bool special = ballObj.specialMove; for (int i = 0; i < movementSpeed; ++i) { CalculateLerpVector(ballObj); AddLerpVector(ball, ballObj); if (Vector3.Distance(ball.transform.position, ballObj.destinationPosition) <= safeDistance) { ChangeToNextDestination(ballObj); if (special) { break; } } } if (ballObj.specialMove) { changeSpecialMoveToFalse = false; } }
public static bool CheckIfIsRightAndFindNewPositions(GameObject newBall, BListObject collidingBall, out Vector3 posForNewBall, out Vector3 posForFirstBall, GameObject first) { posForFirstBall = FindNewPositionForFirstLastBallOnBallAdding(first, 1); Vector3 posForLastBall = FindNewPositionForFirstLastBallOnBallAdding(collidingBall.value, -1); return(GetPosForNewBall(collidingBall, newBall, out posForNewBall, posForFirstBall, posForLastBall)); }
public void DestroyBallsWithSpecificColor(Color color) { BListObject actualBall = balls.InitEnumerationFromLeftBListObject(); if (actualBall != null) { do { if (actualBall.value.GetComponent <BallScript>().ballObj.color == color) { List <BListObject> ballsToRemove = FindBallsInSequence(actualBall.value); foreach (BListObject ball in ballsToRemove) { balls.Remove(ball); if (ball.value.transform.FindChild("Bonus") != null) { ball.value.transform.FindChild("Bonus").GetComponent <BonusScript>().canWork = false; } Destroy(ball.value); } actualBall = balls.InitEnumerationFromLeftBListObject(); } } while ((actualBall = balls.NextBListObject()) != null); if (deleteSequence != null) { deleteSequence(GetAllColorsOnBoard()); } } }
public static bool MoveBalls(BList balls, float safeDistance) { changeSpecialMoveToFalse = specialMove; playing = true; BListObject actualBall = balls.InitEnumerationFromLeftBListObject(); if (actualBall != null) { do { if (!specialMove || actualBall.value.GetComponent <BallScript>().ballObj.specialMove) { MoveBall(actualBall); } } while ((actualBall = balls.NextBListObject()) != null); } if (changeSpecialMoveToFalse) { changeSpecialMoveToFalse = false; specialMove = false; CheckBallsCorrectDestinations(balls); CheckBallsCorrectDistances(balls, GameManagerScript.spawningSafeDistance); } //CheckBallsCorrectDistances(balls, GameManagerScript.spawningSafeDistance); return(playing); }
private List <BListObject> FindAndUseBonuses(List <BListObject> ballsToRem) { List <BListObject> additionalBallsToRemove = new List <BListObject>(); foreach (BListObject ballObj in ballsToRem) { Transform child = ballObj.value.transform.FindChild("Bonus"); if (child != null) { if (child.GetComponent <BonusScript>().bonusData.bonusKind == BonusKind.ballsNeighboursDestroy) { int neighbourDeleteTreshold = child.GetComponent <BonusScript>().bonusData.range; BListObject actual = ballObj; for (int i = 0; i < neighbourDeleteTreshold; ++i) { actual = actual.rightNeighbour; if (actual == null) { break; } if (!ballsToRem.Contains(actual)) { additionalBallsToRemove.Add(actual); if (ballsThatHasToReturnWithSequence.Contains(actual)) { ballsThatHasToReturnWithSequence.Remove(actual); } } } if (actual != null && actual.rightNeighbour != null) { AddAndConfigureReturningComponents(actual.rightNeighbour); } actual = ballObj; for (int i = 0; i < neighbourDeleteTreshold; ++i) { actual = actual.leftNeighbour; if (actual == null) { break; } if (!ballsToRem.Contains(actual)) { additionalBallsToRemove.Add(actual); } } } } } foreach (BListObject ball in additionalBallsToRemove) { ballsToRem.Add(ball); } return(ballsToRem); }
public BListObject NextBListObject() { if (actual != null) { actual = actual.rightNeighbour; return(actual); } return(null); }
public BListObject PreviousBListObject() { if (actual != null) { actual = actual.leftNeighbour; return(actual); } return(null); }
private void CheckAndRemoveBallsByColor(BListObject ballInSequence) { if (CheckBallsToRemove(ballInSequence)) { RemoveBallsInSequence(ballInSequence.value); if (deleteSequence != null) { deleteSequence(GetAllColorsOnBoard()); } } }
private void ClearSpeedLevels(BList balls) { BListObject ball = balls.InitEnumerationFromLeftBListObject(); if (ball != null) { do { ball.value.GetComponent <BallScript>().ballObj.RestartSpeedLevel(); } while ((ball = balls.NextBListObject()) != null); } }
public void RevertBallsDirection() { BListObject actualBall = balls.InitEnumerationFromLeftBListObject(); if (actualBall != null) { do { actualBall.value.GetComponent <BallScript>().ballObj.RevertDirection(); } while ((actualBall = balls.NextBListObject()) != null); } }
public GameObject InitEnumerationFromLeft() { actual = last; if (actual != null) { return(actual.value); } else { return(null); } }
public GameObject Previous() { if (actual != null) { actual = actual.leftNeighbour; if (actual != null) { return(actual.value); } } return(null); }
public GameObject Next() { if (actual != null) { actual = actual.rightNeighbour; if (actual != null) { return(actual.value); } } return(null); }
public BListObject Find(GameObject obj) { BListObject bListObj = InitEnumerationFromLeftBListObject(); do { if (bListObj.value == obj) { return(bListObj); } } while ((bListObj = NextBListObject()) != null); return(null); }
private void AddAndConfigureReturningComponents(BListObject ball) { if (!ballsThatHasToReturnWithSequence.Contains(ball) && ball.value.GetComponent <BallReturningScript>() == null) { ballsThatHasToReturnWithSequence.Add(ball); ball.value.AddComponent <BallReturningScript>(); Rigidbody rigid; if ((rigid = ball.value.GetComponent <Rigidbody>()) == null) { rigid = ball.value.AddComponent <Rigidbody>(); } rigid.useGravity = false; rigid.isKinematic = false; rigid.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; } }
private void Debugging() { if (Input.GetKeyDown(KeyCode.N)) { string names = ""; BListObject actual = balls.InitEnumerationFromLeftBListObject(); if (actual != null) { do { names += actual.value.name + ", "; } while ((actual = balls.NextBListObject()) != null); } Debug.Log(names); } }
public BListObject Insert(GameObject objectToInsert, GameObject neighbour, bool neighbourIsRight) { BListObject newObj = new BListObject(); lock (addingLock) { newObj.value = objectToInsert; BListObject obj = Find(neighbour); if (neighbourIsRight) { newObj.leftNeighbour = obj.leftNeighbour; newObj.rightNeighbour = obj; if (obj.leftNeighbour != null) { obj.leftNeighbour.rightNeighbour = newObj; } else { last = newObj; } obj.leftNeighbour = newObj; } else { newObj.leftNeighbour = obj; newObj.rightNeighbour = obj.rightNeighbour; if (obj.rightNeighbour != null) { obj.rightNeighbour.leftNeighbour = newObj; } else { first = newObj; } obj.rightNeighbour = newObj; } count++; } return(newObj); }
public static void CheckBallsCorrectDestinations(BList balls) { BListObject actualBall = balls.InitEnumerationFromLeftBListObject(); int destination = -1; if (actualBall != null) { do { destination = actualBall.value.GetComponent <BallScript>().ballObj.destination; if (actualBall.rightNeighbour != null && actualBall.rightNeighbour.value.GetComponent <BallScript>().ballObj.destination < destination) { actualBall.rightNeighbour.value.GetComponent <BallScript>().ballObj.destination = destination; } } while ((actualBall = balls.NextBListObject()) != null); } }
private void SetBallsToReturn(BListObject ball) { while (ball != null) { if (ball.value != null) { //Debug.Log(ball.value.name); if (ball.value.GetComponent <BallScript>().ballObj.forwardBackward > 0) { ball.value.GetComponent <BallScript>().ballObj.forwardBackward = -ball.value.GetComponent <BallScript>().ballObj.forwardBackward; ball.value.GetComponent <BallScript>().ballObj.destination--; } ball.value.GetComponent <BallScript>().ballObj.IncreaseSpeedLevel(false); } ball = ball.rightNeighbour; } }
public void Remove(BListObject ballToRemove) { if (ballToRemove.rightNeighbour != null) { ballToRemove.rightNeighbour.leftNeighbour = ballToRemove.leftNeighbour; } if (ballToRemove.leftNeighbour != null) { ballToRemove.leftNeighbour.rightNeighbour = ballToRemove.rightNeighbour; } if (ballToRemove == first) { if (ballToRemove.rightNeighbour != null) { first = ballToRemove.rightNeighbour; } else if (ballToRemove.leftNeighbour != null) { first = ballToRemove.leftNeighbour; } else { first = null; } } if (ballToRemove == last) { if (ballToRemove.leftNeighbour != null) { last = ballToRemove.leftNeighbour; } else if (ballToRemove.rightNeighbour != null) { last = ballToRemove.rightNeighbour; } else { last = null; } } count--; }
private void ChangeBallsDirectionOnInsert(GameObject newBall, Vector3 positionForFirstBall, Vector3 posForNewBall) { BListObject actual = balls.InitEnumerationFromRightBListObject(); BallObject ballObj = actual.value.GetComponent <BallScript>().ballObj; bool curveChange = false; ballObj.destination--; ballObj.destinationPosition = positionForFirstBall; ballObj.IncreaseSpeedLevel(); if (actual.value != newBall) { while ((actual = balls.PreviousBListObject()) != null && actual.value != newBall) { ballObj = actual.value.GetComponent <BallScript>().ballObj; ballObj.destination--; if (actual.rightNeighbour.value.GetComponent <BallScript>().ballObj.destination > ballObj.destination && !curveChange) { ballObj.destination++; curveChange = true; } else if (curveChange) { curveChange = false; } ballObj.destinationPosition = actual.rightNeighbour.value.transform.position; ballObj.IncreaseSpeedLevel(); } ballObj = actual.value.GetComponent <BallScript>().ballObj; ballObj.destination--; if (actual.rightNeighbour.value.GetComponent <BallScript>().ballObj.destination > ballObj.destination && !curveChange) { ballObj.destination++; curveChange = true; } ballObj.destinationPosition = posForNewBall; ballObj.IncreaseSpeedLevel(); } }
public List <Color> GetAllColorsOnBoard() { List <Color> colors = new List <Color>(); if (balls != null) { BListObject actual = balls.InitEnumerationFromLeftBListObject(); if (actual != null) { do { Color color = actual.value.GetComponent <BallScript>().ballObj.color; if (!colors.Contains(color)) { colors.Add(color); } } while ((actual = balls.NextBListObject()) != null); } } return(colors); }
private List <BListObject> FindBallsInSequence(GameObject ballInSequence) { List <BListObject> ballsToRemove = new List <BListObject>(); Color color = ballInSequence.GetComponent <BallScript>().ballObj.color; BListObject pivotBall = balls.Find(ballInSequence); BListObject actualListObj = pivotBall; while (actualListObj != null && actualListObj.value.GetComponent <BallScript>().ballObj.color == color) { ballsToRemove.Add(actualListObj); actualListObj = actualListObj.rightNeighbour; } if (actualListObj != null) { // Debug.Log(actualListObj.value.name + " " + Time.time); AddAndConfigureReturningComponents(actualListObj); } if (pivotBall != null) { actualListObj = pivotBall.leftNeighbour; } else { actualListObj = null; } while (actualListObj != null && actualListObj.value.GetComponent <BallScript>().ballObj.color == color) { ballsToRemove.Add(actualListObj); actualListObj = actualListObj.leftNeighbour; } return(FindAndUseBonuses(ballsToRemove)); }
public static void CheckBallsCorrectDistances(BList balls, float safeDistance) { BListObject actualBall = balls.InitEnumerationFromLeftBListObject(); if (actualBall != null) { do { if (actualBall.leftNeighbour != null) { CalculateLerpVector(actualBall.value.GetComponent <BallScript>().ballObj); int prevSpeedLevel = actualBall.value.GetComponent <BallScript>().ballObj.actualSpeedLevel; actualBall.value.GetComponent <BallScript>().ballObj.actualSpeedLevel = 2; while (GetDistance(actualBall.value, actualBall.leftNeighbour.value) < safeDistance) { MoveBall(actualBall); } actualBall.value.GetComponent <BallScript>().ballObj.actualSpeedLevel = prevSpeedLevel; } } while ((actualBall = balls.NextBListObject()) != null); } }
private bool CheckBallsToRemove(BListObject ballInSequence) { Color color = ballInSequence.value.GetComponent <BallScript>().ballObj.color; BListObject listObject = ballInSequence; if (listObject.rightNeighbour != null) { if (listObject.leftNeighbour != null) { if (listObject.rightNeighbour.value.GetComponent <BallScript>().ballObj.color == color && listObject.leftNeighbour.value.GetComponent <BallScript>().ballObj.color == color) { return(true); } } if (listObject.rightNeighbour.rightNeighbour != null && !ballInSequence.mustBeCenterPoint) { if (listObject.rightNeighbour.value.GetComponent <BallScript>().ballObj.color == color && listObject.rightNeighbour.rightNeighbour.value.GetComponent <BallScript>().ballObj.color == color) { return(true); } } } if (listObject.leftNeighbour != null) { if (listObject.leftNeighbour.leftNeighbour != null) { if (listObject.leftNeighbour.value.GetComponent <BallScript>().ballObj.color == color && listObject.leftNeighbour.leftNeighbour.value.GetComponent <BallScript>().ballObj.color == color) { return(true); } } } return(false); }
public BListObject InitEnumerationFromLeftBListObject() { actual = last; return(actual); }
public BListObject InitEnumerationFromRightBListObject() { actual = first; return(actual); }