public bool checkGround() { bool grounded = false; for (int i = 0; i < 5; i++) { float dir = -1 + (i % 2) * 2; Vector3 downward = transform.position - transform.up * downLazy + transform.right * 0.1f * Mathf.Ceil(i / 2f) * dir; RaycastHit2D hit = Physics2D.Raycast(downward, -transform.up, 0.5f, groundCheck); Debug.DrawRay(downward, -transform.up * 0.5f, Color.green); if (hit) { grounded = true; if (hit.transform.GetComponent <SquareBehavior>() != null) { SquareBehavior square = hit.transform.GetComponent <SquareBehavior>(); float minimumAmp = (centerOfGravity == null) ? 4 : 0.2f; if (square.GetComponent <SquareBehavior>().TotalAmplitude > minimumAmp) { bounceDirection += Vector2.up * square.GetComponent <SquareBehavior>().TotalAmplitude; if (centerOfGravity != null) { bounceDirection += Vector2.up * TerrainGenerator.instance.pulseAmplitudeMultiplier * 2; } bounceDirection.y *= waveBounciness / (jumped ? 3 : 1); square.GetComponent <SpriteRenderer>().color = Color.red; grounded = false; } break; } } } return(grounded); }
public bool checkGround() { bool grounded = false; for (int i = 0; i < 5; i++) { float dir = -1 + (i % 2) * 2; Vector3 downward = transform.position - transform.up * downLazy + transform.right * 0.1f * Mathf.Ceil(i / 2f) * dir; RaycastHit2D hit = Physics2D.Raycast(downward, -transform.up, 0.4f, groundCheck); Debug.DrawRay(downward, -transform.up, Color.red); if (hit) { grounded = true; if (hit.transform.GetComponent <SquareBehavior>() != null) { SquareBehavior square = hit.transform.GetComponent <SquareBehavior>(); if (square.GetComponent <SquareBehavior>().TotalAmplitude > 2f) { print("hoi"); bounceDirection += Vector2.up * square.GetComponent <SquareBehavior>().TotalAmplitude; bounceDirection.y *= bounceForce; square.GetComponent <SpriteRenderer>().color = Color.red; grounded = false; } break; } } } return(grounded); }
public void AddNewSquareToList(ModifiedSquare.TypeModification typeModif, SquareBehavior squareToAdd) { RemoveSquareFromList(squareToAdd); //remove object if it is already in list ModifiedSquare objectToAdd = new ModifiedSquare(typeModif, squareToAdd); _listSquareModified.Add(objectToAdd); }
public void NewGen() // The method to start a new generation { sLastGenTime = Time.time; lastGenTime = sLastGenTime; mainCamera.transform.localPosition = cameraLocalPosi; mainCamera.transform.parent = null; platformCount = 1; genNum++; Random.InitState(randomSeed); for (int i = 0; i < lastSquares.Length; i++) // Wipe out the previous stored squares { if (lastSquares[i] != null) { Destroy(lastSquares[i].gameObject); } } if (genNum == 1) // If it's the first gen { lastSquares = new SquareBehavior[populationEachGen]; } else { lastSquares = new SquareBehavior[populationEachGen]; squares.CopyTo(lastSquares, 0); SelectBestSquares(); for (int i = 0; i < bestSquares.Length; i++) // Replace some last generation squares by the best squares { Destroy(lastSquares[i].gameObject); lastSquares[i] = Instantiate(bestSquares[i].gameObject).GetComponent <SquareBehavior>(); lastSquares[i].basicLayer = new float[4 + 1, 11]; CopyNeuralLayer(bestSquares[i].basicLayer, lastSquares[i].basicLayer); lastSquares[i].gameObject.SetActive(false); } IfMakeNewPlatform(); } Instantiate(platform, Vector3.zero, Quaternion.identity); // Instantiate the new first platform for (int i = 0; i < populationEachGen; i++) // Instantiate new squares { squares[i] = Instantiate(square, Vector3.up * 10, Quaternion.identity).GetComponent <SquareBehavior>(); squares[i].id = i; } leadSquare = squares[0]; mainCamera.transform.parent = leadSquare.transform; mainCamera.transform.localPosition = cameraLocalPosi; neuralNetworkVisual.currentLead = leadSquare; }
public ModifiedSquare.TypeModification ReturnModfiOfSquare(SquareBehavior square) { ModifiedSquare.TypeModification TypeModifToReturn = ModifiedSquare.TypeModification.None; foreach (ModifiedSquare element in _listSquareModified) { if (element._square == square) { TypeModifToReturn = element._modifOnSquare; } } return(TypeModifToReturn); }
void OnCollisionEnter2D(Collision2D other) { velocity.y *= -1; SquareBehavior block = other.gameObject.GetComponent <SquareBehavior>(); if (block.squareValue < currentPower) { StartCoroutine(HitStop()); ScreenShake.shakeTime = 0.3f; currentPower += block.squareValue; Destroy(block.gameObject); } counter.text = "x " + currentPower; }
bool IsElementInList(SquareBehavior element) { bool toReturn = false; foreach (ModifiedSquare square in _listSquareModified) { if (square._square == element) { toReturn = true; } } return(toReturn); }
// Update is called once per frame void Update() { Time.timeScale = simSpeed; if (Time.time - sLastGenTime >= cycleDuration) { NewGen(); } foreach (SquareBehavior square in squares) // Find out which square is the leading square { if (square.travelDist > leadSquare.travelDist) { leadSquare = square; mainCamera.transform.parent = leadSquare.transform; mainCamera.transform.localPosition = cameraLocalPosi; neuralNetworkVisual.currentLead = leadSquare; } } }
public void RemoveSquareFromList(SquareBehavior _squareToRemove) { bool toRemove = false; ModifiedSquare elementToRemove = null; foreach (ModifiedSquare element in _listSquareModified) { if (element._square == _squareToRemove) { elementToRemove = element; toRemove = true; } } if (toRemove) { _listSquareModified.Remove(elementToRemove); } }
public void CalculateFitnessScore(SquareBehavior square) { square.fitnessScore = square.travelDist * travelDistanceScore + square.travelPlat * travelPlatformScore + square.timeStayedOnPlatform * squareOnPlatformScore; }
public TypeModification _modifOnSquare; //not on square because typemodif is associate to a unit, not a square public ModifiedSquare(TypeModification typeModif, SquareBehavior squareToAdd) //Constructor { _square = squareToAdd; _modifOnSquare = typeModif; _square.ChangeState(typeModif); }