public void MoveToCell(Cell cell) { // check if new cell contains entity ICellEntity cellEntity = entityManager.GetEntity(cell); if (cellEntity != null) { if (cellEntity.ExecuteActionEntity(this)) { Moving = true; entityManager.MoveEntity(Cell, cell); this.Cell = cell; entityManager.MoveCellObject(gameObject, gameObject.transform.position, cell.getCenterPositionForEntity(), enemyMoveTime, this); } } else { // to call enemy's action if enemy moves into the player (otherwise it will only destroy player if he moves into the enemy if (cell == player.GetCurrentCell()) { this.ExecuteAction(); } Moving = true; entityManager.MoveEntity(Cell, cell); this.Cell = cell; entityManager.MoveCellObject(gameObject, gameObject.transform.position, cell.getCenterPositionForEntity(), enemyMoveTime, this); } }
public ICellEntity[] GetNearbyCellEntities(Cell cell) { if (cell == null) { return(null); } Cell[] cells = grid.GetNearbyCells(cell); ICellEntity[] nearbyEntities = new ICellEntity[9]; int o = 0; for (int i = 0; i < cells.Length; i++) { if (cells[i] != null) { if (HasEntity(cells[i])) { nearbyEntities[o] = GetEntity(cells[i]); } } o++; } return(nearbyEntities); }
public void RenderHighlightedEntity(bool render_on) { if (grid.currentHighlightedCell != null && entityManager.HasEntity(grid.currentHighlightedCell)) { ICellEntity cellEntity = entityManager.GetEntity(grid.currentHighlightedCell); if (render_on) { cellEntity.gameObject.GetComponent <Renderer>().enabled = true; Renderer[] childrenRenderers = cellEntity.gameObject.GetComponentsInChildren <Renderer>(); for (int k = 0; k < childrenRenderers.Length; k++) { childrenRenderers[k].enabled = true; } } else { cellEntity.gameObject.GetComponent <Renderer>().enabled = false; Renderer[] childrenRenderers = cellEntity.gameObject.GetComponentsInChildren <Renderer>(); for (int k = 0; k < childrenRenderers.Length; k++) { childrenRenderers[k].enabled = false; } } // execute on found action cellEntity.Found(); } }
private void HandlePlayerInput() { /* Gets corresponding position from grid depending upon input * and then calls SetPosition. * only works when one key is pressed * */ if (Input.GetKeyDown("up") || Input.GetKeyDown("down") || Input.GetKeyDown("left") || Input.GetKeyDown("right") || Input.GetKeyDown("w") || Input.GetKeyDown("a") || Input.GetKeyDown("s") || Input.GetKeyDown("d")) { float x = Input.GetAxisRaw("Horizontal"); float y = Input.GetAxisRaw("Vertical"); // in case both horizontal and vertical are pressed, do nothing if (x != 0 && y != 0) { return; } if (x == 0 && y == 0) { return; } Cell nextCell; if (x == 0) { nextCell = grid.GetNextCellVerticalMove((int)y, currentCell); } else // y == 0 { nextCell = grid.GetNextCellHorizontalMove((int)x, currentCell); } // if cell has entity, check to see if entity is passable if (entityManager.HasEntity(nextCell)) { ICellEntity entity = entityManager.GetEntity(nextCell); if (entity.ExecuteAction()) { SetPosition(nextCell); } } else { SetPosition(nextCell); } } if (Input.GetKeyDown("t")) { ToggleLight(); } }
IEnumerator DestroyEntityAfter(ICellEntity entity, float time) { yield return(new WaitForSeconds(time)); Cell entityCell = entity.Cell; entities[entityCell.GetCellIndexX(), entityCell.GetCellIndexY()] = null; // remove from activated enemies list for (int i = 0; i < enemyIndex; i++) { if (activatedEnemies[i] == entity) { activatedEnemies[i] = null; } } Destroy(entity.gameObject); }
public void Eat(Creature creature) { if (creature.Genome.Commands.Count - 1 < creature.Genome.CurrentPointer + 1) { return; } var field = creature.Cell.Field; ICellEntity entity = null; var dir = SwitchDirectionWithStandardAnotation(creature.Genome.Commands[creature.Genome.CurrentPointer + 1].Type); entity = field.TryGetCreatureCellWithOffest(creature, dir.xOffest, dir.yOffest)?.Entity; if (entity != null && entity is IEateble eateble) { eateble.Destroy(); creature.Energy.AddPrimaryEnergy(eateble.EatPrimaryEnegry); } }
internal DSCell(ICellEntity host) : base(host) { }
public void DestroyEntity(ICellEntity entity, float time) { StartCoroutine(DestroyEntityAfter(entity, time)); }
public void MoveCellObject(GameObject obj, Vector3 source, Vector3 destination, float timeToMove, ICellEntity cellEntity) { StartCoroutine(MoveObject(obj, source, destination, timeToMove, cellEntity)); }
/* --------- Coroutine and public function to move an object ---------- */ IEnumerator MoveObject(GameObject obj, Vector3 source, Vector3 destination, float timeToMove, ICellEntity cellEntity) { float startTime = Time.time; while (Time.time - startTime < timeToMove) { obj.transform.position = Vector3.Lerp(source, destination, (Time.time - startTime) / timeToMove); yield return(null); } transform.position = destination; // for cell entities if (cellEntity != null) { cellEntity.HasFinishedMoving(); } }
public bool ExecuteActionEntity(ICellEntity entity) { return(true); }
public void AddObject(ICellEntity oe, int x, int y, int direction) { _map[x, y].Entity = oe; }
public bool ExecuteActionEntity(ICellEntity entity) { entityManager.DestroyEntity(entity, destroyTime); return(true); }