private Vector2Int FindClosestOnSide(bool ally) { GameBoard gb = GameManager.Instance.MyGameBoard; Vector2Int myPosition = gb.GetTileEntityPosition(this); Tile myTile = gb.GetTile(this); TileEntity[] tileEntities = GameObject.FindObjectsOfType <TileEntity>(); float closest = float.MaxValue; // Default to moving around where you are Vector2Int ret = myPosition; for (int i = 0; i < tileEntities.Length; ++i) { Vector2Int pos = gb.GetTileEntityPosition(tileEntities[i]); float dist = Vector2Int.Distance(myPosition, pos); if (tileEntities[i] == this) { continue; } if (dist < closest) { if ( (ally && myTile.GetSide() == gb.GetTile(tileEntities[i]).GetSide()) || (!ally && myTile.GetSide() != gb.GetTile(tileEntities[i]).GetSide()) ) { ret = pos; } } } return(ret); }
// returns the entity which was shot (null if nothing was shot) public bool DoShoot() { GameBoard board = GameManager.Instance.MyGameBoard; Vector2Int entityPosition = board.GetTileEntityPosition(this.parentEntity); Tile entityTile = board.GetTile(this.parentEntity); // If on left side, shoot right. Otherwise if on right side, shoot left Vector3 bulletDirection = Tile.SIDE.LEFT.Equals(entityTile.GetSide()) ? new Vector3(1, 0, 0) : new Vector3(-1, 0, 0); Vector3 bulletSpawnPosition = this.parentEntity.transform.position + bulletDirection.normalized * 2; GameManager.Instance.SpawnStupidPhotonProjectile("BlasterBullet", bulletSpawnPosition, Quaternion.identity, bulletDirection, 50f, 1); //Vector2Int pos = entityPosition + direction; //for (int i = 0; i < this.shootRange && board.IsOnBoard(pos); ++i) //{ // Tile newTile = board.GetTile(pos); // if (!newTile.GetSide().Equals(entityTile.GetSide()) && // newTile.GetEntities() != null && newTile.GetEntities().Count > 0) // { // // Tell GameBoard to damage everything in square // foreach (TileEntity e in newTile.GetEntities()) // { // board.DoDamageToTileEntity(e, this.baseDamage); // } // return true; // } // pos += direction; //} Debug.Log(this.parentEntity.GetName() + " did not shoot anything "); return(false); }
protected Tile GetTile() { Vector2Int pos = gameBoard.GetTileEntityPosition(this); Tile entityTile = gameBoard.GetTile(pos.x, pos.y); return(entityTile); }