public void CreateNanomachine(Vector3 localPosition) { GameObject newInstance = Instantiate(this.nanomachinePrefab, localPosition, Quaternion.identity); Nanomachine nanomachine = newInstance.GetComponent <Nanomachine>(); nanomachine.Health = this.startingHealth; nanomachine.DirectionalForce = nanomachine.transform.localPosition; this.survivers.Add(nanomachine); }
public void DivideNanomachine(Nanomachine original) { int randomDirection = Random.Range(1, 9); Vector3 spawnToPosition = original.transform.localPosition + Direction.Vector[randomDirection]; CreateNanomachine(original.transform.localPosition); CreateNanomachine(spawnToPosition); int originalIndex = this.active.IndexOf(original); this.active[originalIndex] = null; Destroy(original.gameObject); this.gameSystem.AddEnergy(0.05f); if (this.divideSound != null) { AudioPlayer.Play(this.divideSound); } }
private void ProcessNanomachine(int index, int[] adjacentBacteria) { Nanomachine nanomachine = this.active[index]; if (nanomachine.Draggable.BeingDragged) { return; } if (IsOverwhelmed(adjacentBacteria)) { nanomachine.Health--; if (nanomachine.Health < 1) { if (this.deathSound != null) { AudioPlayer.Play(this.deathSound); } Destroy(nanomachine.gameObject); this.active[index] = null; return; } } if (adjacentBacteria[0] > 0) { nanomachine.Health += adjacentBacteria[0]; Vector3Int cell = this.grid.WorldToCell(nanomachine.transform.position); Debug.Log("Eating: " + cell); if (this.eatSound != null) { AudioPlayer.Play(this.eatSound); } foreach (BrothViewControl broth in this.broths) { broth.Broth[cell.x, cell.y] = false; broth.Broth.NextCells[cell.x, cell.y] = false; int maxIndex = broth.Broth.Size - 1; if (cell.x > 0) { broth.Broth[cell.x - 1, cell.y] = false; broth.Broth.NextCells[cell.x - 1, cell.y] = false; } if (cell.y > 0) { broth.Broth[cell.x, cell.y - 1] = false; broth.Broth.NextCells[cell.x, cell.y - 1] = false; } if (cell.x < maxIndex) { broth.Broth[cell.x + 1, cell.y] = false; broth.Broth.NextCells[cell.x + 1, cell.y] = false; } if (cell.y < maxIndex) { broth.Broth[cell.x, cell.y + 1] = false; broth.Broth.NextCells[cell.x, cell.y + 1] = false; } } if (nanomachine.Health >= this.healthToDivide) { DivideNanomachine(nanomachine); } return; } int largestBacteriaCount = adjacentBacteria.Max(); int moveDirection = adjacentBacteria.First(count => count == largestBacteriaCount); nanomachine.DirectionalForce = Direction.Vector[moveDirection] * (-1); //Debug.Log("Moving toward (" + largestBacteriaCount + "): " + Direction.Vector[moveDirection]); }