public List <GridPosition> GetDialognaldPositions(GridPosition pos) { List <GridPosition> adjanced = new List <GridPosition>(); GridPosition temp = pos.Clone(); temp.x++; if (isInBounds(temp)) { adjanced.Add(temp.Clone()); } temp.y++; temp.x--; if (isInBounds(temp)) { adjanced.Add(temp.Clone()); } temp.x--; temp.y--; if (isInBounds(temp)) { adjanced.Add(temp.Clone()); } temp.y--; temp.x++; if (isInBounds(temp)) { adjanced.Add(temp.Clone()); } return(adjanced); }
public IEnumerator MoveTo(GridPosition pos) { if (walkingPath) { yield return(null); } if (pos != null) { GoToPos = pos; yield return(new WaitWhile(() => isMoving)); walkingPath = true; AStar pathfinder = AStar.GetPath(Position, GoToPos, GameGrid.currentGrid, null); currentPath = pathfinder.CellsFromPath(); while (currentPath.Count != 0) { WalkTo(currentPath[0]); currentPath.RemoveAt(0); yield return(new WaitWhile(() => isMoving)); } yield return(new WaitWhile(() => isMoving)); Position = GoToPos.Clone(); walkingPath = false; } }
public static int GetSortingOrder(GridPosition pos) { GridPosition tempPos = pos.Clone(); tempPos.z++; return((tempPos.y * GameGrid.currentGrid.GridSortingWeights[1]) - tempPos.x * GameGrid.currentGrid.GridSortingWeights[0] + tempPos.z * GameGrid.currentGrid.GridSortingWeights[2]); }
protected void WalkTo(GridPosition nextTile) { TruePosition = Position.Clone(); int lastDir = Faceddirection; Faceddirection = InputHandlerer.GetDirectionTo(Position, nextTile); SetAnimatorDirection(Faceddirection); if (lastDir != Faceddirection) { // Debug.Log("Turn " + Faceddirection); anim.Play("Walk"); } if (GameGrid.currentGrid.isInBounds(nextTile)) { GridPosition selectedTile; GameGrid.WalType canWalk = GameGrid.currentGrid.CanBeWalked(Position, nextTile, out selectedTile); if (canWalk == GameGrid.WalType.JumUp || Position.z != nextTile.z) { int height = nextTile.z - Position.z; if (height < 0) { height = 1; } Position = nextTile; StartJump(GameGrid.currentGrid.GetWalkPoint(nextTile) + topOffset, height - 1); } else if (canWalk == GameGrid.WalType.CanWalk) { Position = nextTile; iTween.MoveTo(body.gameObject, iTween.Hash("position", GameGrid.currentGrid.GetTile(selectedTile).CenterPoint + topOffset, "time", Options._instance.CharacterMovementSpeed, "easetype", iTween.EaseType.linear)); body.StartCoroutine(MovementMidpoint(Options._instance.CharacterMovementSpeed / 2)); body.StartCoroutine(MoveEnabler(Options._instance.CharacterMovementSpeed)); } } }
private List <GameTile> GetTilesAtDirection(int forwardRange, int sideWaysRange, int zRange, GridPosition startPos, GridPosition forward, GridPosition direction) { List <GameTile> forwardTiles = new List <GameTile>(); for (int x = 0; x < sideWaysRange + 1; x++) { GridPosition sidewaysPos = startPos.Clone(); for (int z = 0; z < zRange + 1; z++) { GridPosition forwardpos = sidewaysPos.Clone(); for (int i = 0; i < forwardRange + 1; i++) { if (GetTile(forwardpos) != null) { forwardTiles.Add(GetTile(forwardpos)); } if (GetTile(forwardpos + GridPosition.UP) != null) { if (forwardpos == startPos + forward) { Debug.Log("inFront!"); break; } else if (InRange(startPos, forwardpos, 0)) { Debug.Log("On sides!"); forwardpos += forward; continue; } else { break; } } forwardpos += forward; } sidewaysPos += GridPosition.UP; } startPos += direction; } return(forwardTiles); }
public void MoveInstant(GridPosition pos) { GameTile tile = GameGrid.currentGrid.GetTile(pos); if (tile) { body.transform.position = tile.CenterPoint + topOffset; Position = pos.Clone(); TruePosition = Position.Clone(); body.sRenderer.sortingOrder = InputHandlerer.GetSortingOrder(this); body.shadowRenderer.sortingOrder = body.sRenderer.sortingOrder - 1; } else { Debug.LogWarning("No Tile At Spawnpoint : " + pos); } }
public GridPosition GetHighestTileBellow(GridPosition frompos) { if (!HasTilesVertical(frompos)) { return(null); } GridPosition pos = frompos.Clone(); for (int i = pos.z; pos.z >= 0; pos.z--) { if (GetTile(pos)) { return(pos); } } return(null); }
public GridPosition GetHighestJumpablePosition(GridPosition pos) { GridPosition newpos = pos.Clone(); List <GameTile> tiles = GetAllTilesVertical(newpos, 0, false); bool tileFound = false; for (int i = 0; i < tiles.Count; i++) { if (tiles[i] != null) { tileFound = true; newpos.z = i; } else if (tiles[i] == null && tileFound) { return(newpos); } } return(newpos); }
public override void Update(GridPosition pos) { base.Update(pos); if (secondary != null) { return; } RangeDisplayControls(); if (pos.Equals(Target.CurrentPosition)) { return; } int selecteddir = InputHandlerer.GetDirectionFromInput(); if (pathDraw.GetPath().Count == 0) { activator.SetAnimatorDirection(selecteddir); } //Disable walking throught enemy if (pathDraw.GetPath().Count > 0) { if (Character.isOtherCharacterInTile(pathDraw.Last.Clone(), activator)) { if (pathDraw.GetPath().Count > 1) { if (!pathDraw.LastNode.Previous.Value.Equals(pos)) { GameManager._intance.StartCoroutine(GameManager.BlockInput(GameManager.controlsMode)); return; } } } } //Are we inside of character movement range if (currentMovementRange.Exists(item => item.Equals(pos))) { //Did we enter the movement range? if (!Target.isOutside) { Target.Clear(); bool characterInTile = Character.isCharacterInTile(pos); if (characterInTile) { Character chara = Character.GetCharacterAtTile(pos); if (chara != activator) { if (chara.TeamNumber != activator.TeamNumber && !activator.TurnActionsPreformed[0]) { if (pathDraw.AddPath(pos)) { AudioManager._instance.PlayClip("Click_Standard_03"); Target.Move(pos, Color.red); BattleUIContainer._instance.UnitView.SetDamagePreview(chara.stats, activator.stats); pathDraw.SetLastWaypointGraphic(Target.Indicator.gameObject); LastDirection = selecteddir; } } } else { //Return to same tiel as character pathDraw.Destroy(); Target.CurrentPosition = activator.Position; } } else { //No characters in tile if (pathDraw.AddPath(pos)) { AudioManager._instance.PlayClip("Click_Standard_03"); Target.CurrentPosition = pos.Clone(); LastDirection = selecteddir; } BattleUIContainer.RefreshUnitView(activator); BattleUIContainer._instance.UnitView.HideDamagePreview(); } } else { //If we return to walkarea from outside } } else { if (!Target.isOutside) { AudioManager._instance.PlayClip("Click_Standard_03"); secondary = new ViewAction(this, currentMovementRange); Target.Move(pos, Color.white); TurnManager._instance.AddCancel(secondary.Cancel); } //Move outside walkable range Target.isOutside = true; } GameManager._intance.StartCoroutine(GameManager.BlockInput(GameManager.controlsMode)); }
public WalType CanBeWalked(GridPosition currrentpos, GridPosition pos, out GridPosition tile, bool skipGap = false) { tile = null; if (!isInBounds(pos)) { return(WalType.CannotWalk); } if (!HasTilesVertical(pos.Clone())) { return(WalType.CannotWalk); } if (!HasTileOnTop(pos)) { if (GetTile(pos.x, pos.y, pos.z) != null && GetTile(pos.x, pos.y, pos.z).isWalkable) { tile = pos; return(WalType.CanWalk); } } else { if (CanBeJumpedTo(1, pos)) { tile = pos; GameTile roof = GetTile(currrentpos.x, currrentpos.y, currrentpos.z + 2); if (roof == null && GetTile(pos.x, pos.y, pos.z).isWalkable) { return(WalType.JumUp); } } } if (pos.z > 0) { tile = GetHighestJumpablePosition(pos); //ERWERTWETRYYRRYEWYREYRE if (GetHighestJumpablePosition(pos).z > currrentpos.z && GetTile(tile) != null) { GameTile roof = GetTile(currrentpos.x, currrentpos.y, currrentpos.z + 2); if (roof == null && GetTile(tile).isWalkable) { return(WalType.JumUp); } } else if (GetTile(tile) != null && GetTile(tile).isWalkable) { return(WalType.JumUp); } } if (skipGap) { GridPosition direction = currrentpos - pos; GridPosition tempPos = currrentpos.Clone(); while (GameGrid.currentGrid.isInBounds(tempPos)) { tempPos += direction; tile = GetHighestJumpablePosition(pos); if (tile != null) { return(WalType.CanWalk); } } } return(WalType.CannotWalk); }
public bool DoLine(int x1, int y1, int z1, int x2, int y2, int z2) { int i, dx, dy, dz, l, m, n, x_inc, y_inc, z_inc, err_1, err_2, dx2, dy2, dz2; int[] point = new int[] { x1, y1, z1 }; dx = x2 - x1; dy = y2 - y1; dz = z2 - z1; x_inc = (dx < 0) ? -1 : 1; l = Mathf.Abs(dx); y_inc = (dy < 0) ? -1 : 1; m = Mathf.Abs(dy); z_inc = (dz < 0) ? -1 : 1; n = Mathf.Abs(dz); dx2 = l << 1; dy2 = m << 1; dz2 = n << 1; GridPosition lastDirection = new GridPosition(0, 0, 0); GridPosition currentDirection = new GridPosition(0, 0, 0); if ((l >= m) && (l >= n)) { err_1 = dy2 - l; err_2 = dz2 - l; currentDirection = new GridPosition(0, 0, x_inc); for (i = 0; i <= l; i++) { if (GetTile(new GridPosition(point[2] + z_inc, point[1], point[0]))) { return(false); } if (err_1 > 0) { point[1] += y_inc; err_1 -= dx2; currentDirection.y = y_inc; } if (err_2 > 0) { point[2] += z_inc; err_2 -= dx2; currentDirection.z = z_inc; } err_1 += dy2; err_2 += dz2; point[0] += x_inc; if (currentDirection.z != 0) { GridPosition diff = new GridPosition(point[2], point[1], point[0]) - lastDirection; // if (GetTile(diff)) return false; } lastDirection = currentDirection.Clone(); } } else if ((m >= l) && (m >= n)) { err_1 = dx2 - m; err_2 = dz2 - m; currentDirection = new GridPosition(0, y_inc, 0); for (i = 0; i <= m; i++) { if (GetTile(new GridPosition(point[2] + z_inc, point[1], point[0]))) { return(false); } if (err_1 > 0) { point[0] += x_inc; err_1 -= dy2; currentDirection.x = x_inc; } if (err_2 > 0) { point[2] += z_inc; err_2 -= dy2; currentDirection.z = z_inc; } err_1 += dx2; err_2 += dz2; point[1] += y_inc; if (currentDirection.z != 0) { GridPosition diff = new GridPosition(point[2], point[1], point[0]) - lastDirection; // if (GetTile(diff)) return false; } lastDirection = currentDirection.Clone(); } } else { err_1 = dy2 - n; err_2 = dx2 - n; currentDirection = new GridPosition(z_inc, 0, 0); for (i = 0; i <= n; i++) { if (GetTile(new GridPosition(point[2] + z_inc, point[1], point[0]))) { return(false); } if (err_1 > 0) { point[1] += y_inc; err_1 -= dz2; currentDirection.y = y_inc; } if (err_2 > 0) { point[0] += x_inc; err_2 -= dz2; currentDirection.x = x_inc; } err_1 += dy2; err_2 += dx2; point[2] += z_inc; if (currentDirection.z != 0) { GridPosition diff = new GridPosition(point[2], point[1], point[0]) - lastDirection; // if (GetTile(diff)) return false; } lastDirection = currentDirection.Clone(); } } return(true); }
public List <GridPosition> GetVisibleTiles(GridPosition pos, GridPosition forward, int range, bool debug = false, bool playermode = false) { List <GridPosition> _visibleTiles = new List <GridPosition>(); List <GridPosition> BannedTiles = new List <GridPosition>(); GridPosition checkpos = pos.Clone(); forward = new GridPosition(0, 0, 1); int faceRange = range; for (int up = 0; up < range + range + 1; up++) { for (int iforward = 0; iforward < faceRange + range + 1; iforward++) { GridPosition tempPos = checkpos.Clone() + forward.GetReversed() * range + (forward * iforward) + GridPosition.Left(forward) * range + (GridPosition.UP * (range + 1)).GetReversed() + GridPosition.UP * up; if (tempPos.x == pos.x && forward.x != 0 && range != -1) { continue; } if (tempPos.y == pos.y && forward.y != 0 && range != -1) { continue; } for (int right = 0; right < range * 2 + 1; right++) { GridPosition Bpos = tempPos.Clone() + GridPosition.Left(forward).GetReversed() * right; GameTile tile = GetTile(Bpos); if (tile) { if (DoLine(checkpos.x, checkpos.y, checkpos.z, Bpos.x, Bpos.y, Bpos.z)) { _visibleTiles.Add(Bpos); } } if (HasTileOnTop(Bpos)) { if (checkpos.x > Bpos.x && checkpos.y < Bpos.y) { int[,] positions = { { 0, 1, 0 }, { 0, 1, -1 }, { 0, 0, -1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x > Bpos.x && checkpos.y > Bpos.y) { int[,] positions = { { 0, -1, 0 }, { 0, -1, -1 }, { 0, 0, -1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x < Bpos.x && checkpos.y < Bpos.y) { int[,] positions = { { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x < Bpos.x && checkpos.y > Bpos.y) { int[,] positions = { { 0, -1, 0 }, { 0, -1, 1 }, { 0, 0, 1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (InRange(checkpos, Bpos, 3)) { if (checkpos.x == Bpos.x && checkpos.y < Bpos.y) { int[,] positions = { { 0, 1, 0 }, { 0, 1, -1 }, { 0, 1, 1 }, { 0, 0, 1 }, { 0, 0, -1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x == Bpos.x && checkpos.y > Bpos.y) { int[,] positions = { { 0, -1, 0 }, { 0, -1, 1 }, { 0, -1, -1 }, { 0, 0, -1 }, { 0, 0, 1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x > Bpos.x && checkpos.y == Bpos.y) { int[,] positions = { { 0, -1, 0 }, { 0, -1, -1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, 1, -1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x < Bpos.x && checkpos.y == Bpos.y) { int[,] positions = { { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 }, { 0, -1, 0 }, { 0, -1, 1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } } } } } } if (playermode) { List <GridPosition> adjancedPositions = GetAdjancedPositions(pos); foreach (GridPosition gp in adjancedPositions) { if (GetTile(gp) == null) { _visibleTiles.Add(GetHighestTileBellow(gp)); } } } List <GridPosition> diagonals = GetDialognaldPositions(pos); foreach (GridPosition diag in diagonals) { if (HasTileOnTop(diag)) { List <GridPosition> corners = GetDialognaldPositions(diag); foreach (GridPosition corner in corners) { if (GetTile(corner) != null) { } BannedTiles.Add(corner); do { _visibleTiles.Remove(corner); } while (_visibleTiles.Contains(corner)); } } } foreach (GridPosition tile in BannedTiles) { for (int i = 0; i < _visibleTiles.Count; i++) { if (tile.Equals(_visibleTiles[i])) { _visibleTiles.RemoveAt(i); } } } foreach (GridPosition tile in _visibleTiles) { if (tile != null) { GameTile tl = GetTile(tile); if (tl) { VisibleTiles.Add(tl); if (debug) { tl.Srenderer.color *= Color.red; } } } } return(_visibleTiles); }