// Update is called once per frame void Update() { timer -= Time.deltaTime; if (timer <= 0) { //Use these lines to trace by column and row. location.x++; if (location.x >= tgs.columnCount) { location.x = 0; location.y++; if (location.y >= tgs.rowCount) { location.y = 0; } } Cell cell = tgs.CellGetAtPosition((int)location.x, (int)location.y); int cellIndex = tgs.CellGetIndex(cell); if (cellIndex >= 0) { transform.position = tgs.CellGetPosition(cellIndex); } timer = 2.0f; } }
// Highlight cells sequentially on each frame IEnumerator HighlightCell() { currentCol++; // run across the grid row by row if (currentCol >= tgs.columnCount) { currentCol = 0; currentRow++; if (currentRow >= tgs.rowCount) { currentRow = 0; } } // get cell at current grid position and color it with fade out option Cell cell = tgs.CellGetAtPosition(currentCol, currentRow); if (cell != null) { int cellIndex = tgs.CellGetIndex(cell); float duration = Random.value * 2.5f + 0.5f; Color color = new Color(Random.value, Random.value, Random.value); tgs.CellFadeOut(cellIndex, color, duration); } // trigger next iteration after this frame yield return(new WaitForEndOfFrame()); StartCoroutine(HighlightCell()); }
// Update is called once per frame void Update() { // Blinks the new territory under the sphere Territory terr = tgs.TerritoryGetAtPosition(transform.position, true); int terrIndex = tgs.TerritoryGetIndex(terr); if (terrIndex != lastTerrIndex) { lastTerrIndex = terrIndex; tgs.TerritoryBlink(terrIndex, Color.red, 0.5f); } // Check ball state switch (state) { case State.IDLE: break; case State.MOVING: if (moveCounter < moveList.Count) { Move(tgs.CellGetPosition(moveList [moveCounter])); } else { moveCounter = 0; state = State.MOVESELECT; } break; case State.MOVESELECT: if (Input.GetMouseButtonUp(0)) //gets path when left mouse is released and over terrain { int t_cell = tgs.cellHighlightedIndex; tgs.CellFadeOut(t_cell, Color.red, 50); if (t_cell != -1) //checks if we selected a cell { int startCell = tgs.CellGetIndex(tgs.CellGetAtPosition(transform.position, true)); float totalCost; moveList = tgs.FindPath(startCell, t_cell, out totalCost); if (moveList == null) { return; } Debug.Log("Total move cost: " + totalCost); tgs.CellFadeOut(moveList, Color.green, 5f); moveCounter = 0; state = State.MOVING; } else { Debug.Log("NULL_CELL"); } } break; } }
void TriggerRandomCell(Color color) { // We get a random vector from -0.5..0.5 on both X and Y (z is ignored) Vector2 localPosition = Random.onUnitSphere * 0.5f; Cell cell = tgs.CellGetAtPosition(localPosition); if (cell != null) { int cellIndex = tgs.CellGetIndex(cell); float duration = Random.value * 2.5f + 0.5f; tgs.CellFadeOut(cellIndex, color, duration); } }
// Highlight neighbour cells around character posiiton void ShowNeighbours(Vector3 position) { Cell characterCell = tgs.CellGetAtPosition(position, true); List <Cell> neighbours = tgs.CellGetNeighbours(characterCell); if (neighbours != null) { foreach (Cell cell in neighbours) { tgs.CellFadeOut(cell, Color.red, 2.0f); } } }
// Orient the ball toward current selected cell and highlight cell beneath the ball void Update() { if (transform.position.y < -10) { Destroy(gameObject); } // Move ball towards the currently selected cell if (tgs.cellHighlightedIndex >= 0) { Vector3 position = tgs.CellGetPosition(tgs.cellHighlightedIndex); Vector3 direction = (position - transform.position).normalized; rb.AddForce(direction * 100); } // Highlight cell under ball Cell terrainCell = tgs.CellGetAtPosition(transform.position, true); int cellIndex = tgs.CellGetIndex(terrainCell); if (cellIndex >= 0) { tgs.CellFadeOut(cellIndex, Color.yellow, 1f); } }
// Update is called once per frame void Update() { // Debug.Log(rendezvousCell == null); Debug.Log(state); //if(nearAnimal == true){ // social meter decreases over time //Update neighboring cells with for() loop //Always run this EvaluateConsiderations(); switch (bigStates) { case BigStates.PICKGOAL: goalFound = false; goalReward = 0; //if (Vector3.Distance(transform.position, _player.transform.position) < interactDistance) //{ // bigStates = BigStates.NEARPLAYER; // state = State.IDLE; //} Random.InitState(System.DateTime.Now.Millisecond); float decider = Random.Range(0f, 100f); if (decider < hungerPercentage) { bigStates = BigStates.EAT; state = State.SEARCHWORLD; if (skinned) { model.GetComponent <SkinnedMeshRenderer>().material.color = Color.red; } else { model.GetComponent <MeshRenderer>().material.color = Color.red; } } if (decider >= hungerPercentage && decider < sleepPercentage) { if (skinned) { model.GetComponent <SkinnedMeshRenderer>().material.color = Color.blue; } else { model.GetComponent <MeshRenderer>().material.color = Color.blue; } float closestNestDistance = 10000f; for (int i = 0; i < nestObject.Length; i++) { float currentDist = Vector3.Distance(transform.position, nestObject[i].transform.position); if (currentDist < closestNestDistance) { closestNestDistance = currentDist; goalObject = nestObject[i]; } } nextCell = tgs.CellGetAtPosition(goalObject.transform.position, true); goalFound = true; bigStates = BigStates.SLEEP; state = State.MOVESELECT; } if (decider >= sleepPercentage) { bigStates = BigStates.SEARCHFORANIMAL; state = State.SEARCHWORLD; if (skinned) { model.GetComponent <SkinnedMeshRenderer>().material.color = Color.green; } else { model.GetComponent <MeshRenderer>().material.color = Color.green; } } //Debug.Log(decider); break; case BigStates.EAT: //if(memoryBankHunger != null) //{ // // find Cell in memBank with highest # of successful attempts // //for(int i = 0; i < memoryBankHunger.Count; i++) // //{ // // memoryBankHunger.Values[i] // //} // //nextCell = memoryBankHunger.Keys[i]; //} isInEatState = true; isInSleepState = false; isInSocialState = false; isMoving(fruit); Debug.Log(" EAT called is moving"); //Is Moving-- MOVESELECT // Eat(); //Goal met, Remember Cell -- memoryBankHunger.Add(groundTile, 0) or ++ its int Value; break; case BigStates.SLEEP: //if(memoryBankSleep != null) //{ //memoryBankSleep //} isInEatState = false; isInSleepState = true; isInSocialState = false; isMoving(nest); Debug.Log("SLEEP called is moving"); //Is Moving-- MOVESELECT //Sleep(); //Goal met, Remember Cell -- memoryBankSleep.Add(groundTile, 0) or ++ its int Value; break; case BigStates.SEARCHFORANIMAL: //if(memoryBankSocial != null) //{ // //memoryBankSocial //} isInEatState = false; isInSleepState = false; isInSocialState = true; isMoving(animal); Debug.Log("SOCIAL called is moving"); //Is Moving -- MOVESELECT //InteractWithAnimal(); // Goal met, Remember Cell -- memoryBankSocial.Add(groundTile, 0) or ++ its int Value; break; case BigStates.NEARPLAYER: // what do?? // need to make sure can Eat, if eats, follows player, change music // look in fruit script perhaps // transform.LookAt(_player.transform); // play sound //play "tentative interact animation" Vector3.MoveTowards(transform.position, _player.transform.position - new Vector3(1, 0, 1), moveSpeed); break; } }