public override List <S_Tile> GetValidTiles(S_Tile origin) { List <S_Tile> result = new List <S_Tile>(); for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (dx != 0 && dy != 0) { continue; } if (dx == 0 && dy == 0) { continue; } bool good = true; for (int dist = 1; dist <= 3; dist++) { S_Tile t = Level.Get(gameObject).GetTile(origin.x + dx * dist, origin.y + dy * dist); if (t == null) { good = false; break; } } if (good) { result.Add(Level.Get(gameObject).GetTile(origin.x + 3 * dx, origin.y + 3 * dy)); } } } return(result); }
public override List <S_Tile> GetValidTiles(S_Tile origin) { List <S_Tile> result = new List <S_Tile>(); for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if ((dx == 0) == (dy == 0)) { continue; } List <S_Tile> possibles = origin.GetTilesInLine(dx, dy); foreach (S_Tile poss in possibles) { if (poss.occupier != null) { result.Add(poss); break; } } } } return(result); }
public override List <S_Tile> GetValidTiles(S_Tile origin) { List <S_Tile> result = new List <S_Tile>(); for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (dx != 0 && dy != 0) { continue; } if (dx == 0 && dy == 0) { continue; } List <S_Tile> line = origin.GetTilesInLine(dx, dy); if (line.Count > 0) { result.Add(line[line.Count - 1]); } } } return(result); }
public override void Use(S_Player player, S_Tile tile) { S_Enemy swappee = (S_Enemy)tile.occupier; float time = 0.2f; Color col = Colours.GREEN; int width = (S_Tile.width - S_Camera.scale) / S_Camera.scale; int height = S_Tile.height / S_Camera.scale; GameObject flasher = S_Flasher.CreateFlasher(width, height, col, time); Util.SetLayer(flasher, Util.LayerName.UI, 0); flasher.transform.SetParent(tile.transform, false); flasher = S_Flasher.CreateFlasher(width, height, col, time); Util.SetLayer(flasher, Util.LayerName.UI, 0); flasher.transform.SetParent(player.currentTile.transform, false); swappee.CancelMove(); swappee.MoveToTile(player.currentTile, true); player.MoveToTile(tile, true); swappee.Stun(1); Sounds.PlaySound(Sounds.teleport); SuccessfulUse(); Level.Get(gameObject).EnemyTurn(); }
public void SetTile(S_Tile tile) { if (previousTile != null && previousTile.occupier==this) { previousTile.occupier = null; } currentTile = tile; currentTile.occupier = this; }
public void SetTile(S_Tile tile) { if (previousTile != null && previousTile.occupier == this) { previousTile.occupier = null; } currentTile = tile; currentTile.occupier = this; }
public override void Use(S_Player player, S_Tile tile) { int dx = tile.x - player.currentTile.x; int dy = tile.y - player.currentTile.y; if ((dx == 0) == (dy == 0)) { UnsuccessfulUse(); return; } Use(player, Util.ProperSign(dx), Util.ProperSign(dy)); }
public override void Use(S_Player player, S_Tile tile) { if (!GetValidTiles(player.currentTile).Contains(tile)) { return; } player.MoveToTile(tile, false); Sounds.PlaySound(Sounds.move, 1, Random.Range(1.4f, 1.6f)); SuccessfulUse(); }
public override void Use(S_Player player, int dx, int dy) { S_Tile target = Level.Get(gameObject).GetTile(player.currentTile.x + dx * 3, player.currentTile.y + dy * 3); if (target == null) { return; } Use(player, target); }
internal void UpdateGridHighlightedness() { foreach (GameObject go in highlightRectangles) { GameObject.Destroy(go); } highlightRectangles.Clear(); foreach (S_Tile tile in allTiles) { tile.SetHighlight(false); } S_Ability activeAbility = abilityPanel.activeAbility; if (activeAbility != null) { //bunch of long codey bits because it's paperwork to do this sort of thing in unity it seems switch (activeAbility.GetTargetingType()) { case S_Ability.TargetingType.Line: foreach (S_Tile tile in activeAbility.GetValidTiles(player.currentTile)) { int baseWidth = tile.x - player.currentTile.x; int baseHeight = tile.y - player.currentTile.y; int rWidth = baseWidth == 0 ? 1 : baseWidth; int rHeight = baseHeight == 0 ? 1 : baseHeight; rWidth *= S_Tile.height; rHeight *= S_Tile.width; rWidth += -S_Camera.scale * Util.ProperSign(rWidth); rHeight += -S_Camera.scale * Util.ProperSign(rHeight); GameObject go = Primitives.CreateRectangle(rWidth, rHeight, S_Camera.scale, Colours.LIGHT); Util.SetLayerContainer(go, Util.LayerName.Entities, 5); S_Tile origin = player.currentTile; if (baseWidth > 0) { origin = origin.GetTile(1, 0); } else if (baseHeight > 0) { origin = origin.GetTile(0, 1); } go.transform.position = new Vector2(origin.transform.position.x + (baseWidth < 0 ? -S_Camera.scale : 0), origin.transform.position.y + (baseHeight < 0 ? -S_Camera.scale : 0)); highlightRectangles.Add(go); go.transform.SetParent(Game.GetMisc("effects").transform); } break; case S_Ability.TargetingType.SingleTile: foreach (S_Tile tile in activeAbility.GetValidTiles(player.currentTile)) { tile.SetHighlight(true); } break; } } }
public S_Tile PathTo(S_Tile target) { if (target == this) { return(null); } return(PathTo(new List <S_Tile>() { target })); }
public override void MoveToTile(S_Tile tile, bool instant) { bool lost = tile.occupier != null; if (lost) { Sounds.PlaySound(Sounds.spike); Game.Get().Lose(); } base.MoveToTile(tile, instant); }
public S_Tile MakeTile(int x, int y) { GameObject tile = (GameObject)(GameObject.Instantiate(Resources.Load("prefabs/tile"))); S_Tile tileScript = tile.GetComponent <S_Tile>(); tiles[x, y] = tileScript; tileScript.SetPosition(x, y); tileScript.transform.SetParent(grid.transform, false); tile.name = "tile " + x + ":" + y; allTiles.Add(tileScript); return(tileScript); }
public void PathTowardsPlayer() { S_Tile playerTile = Level.Get(gameObject).player.currentTile; targetTile = currentTile.PathTo(playerTile); if (playerTile == currentTile) { return; } //if there's no path, pick a tile that's vaguely in the right direction if (targetTile == null) { List <S_Tile> potentials = currentTile.GetTilesWithin(1, false); int bestWeirdDist = 999; foreach (S_Tile t in potentials) { if (t.IsBlocked()) { continue; } int xDist = t.x - playerTile.x; int yDist = t.y - playerTile.y; int calcDist = xDist * xDist + yDist * yDist; if (calcDist < bestWeirdDist) { bestWeirdDist = calcDist; targetTile = t; } } } if (targetTile != null) { int dx = targetTile.x - currentTile.x; int dy = targetTile.y - currentTile.y; int rotation = 0; if (dx == -1) { rotation = 180; } else if (dy == 1) { rotation = 90; } else if (dy == -1) { rotation = 270; } eyes.transform.rotation = Quaternion.AngleAxis(rotation + 180, Vector3.forward); targetTile.Block(); } }
public override List<S_Tile> GetValidTiles(S_Tile origin) { List<S_Tile> result = new List<S_Tile>(); for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (dx != 0 && dy != 0) continue; if (dx == 0 && dy == 0) continue; List<S_Tile> line = origin.GetTilesInLine(dx, dy); if(line.Count>0){ result.Add(line[line.Count-1]); } } } return result; }
public List <S_Tile> GetTilesInLine(int dx, int dy, bool includeSelf = false) { List <S_Tile> result = new List <S_Tile>(); if (includeSelf) { result.Add(this); } S_Tile tile = GetTile(dx, dy); while (tile != null) { result.Add(tile); tile = tile.GetTile(dx, dy); } return(result); }
public virtual void MoveToTile(S_Tile tile, bool instant) { if (tile == null || tile==currentTile) return; previousTile = currentTile; SetTile(tile); if (previousTile != null){ currentDX = currentTile.x - previousTile.x; currentDY = currentTile.y - previousTile.y; } if (instant) { moveTicker = 1; positionSetter.transform.localPosition = currentTile.transform.localPosition; tile.Enter(this); } else { StartMoving(); } }
override public void ChooseMove() { if (CanSeePlayer()) { S_Tile playerTile = Level.Get(gameObject).player.currentTile; int newCDX = Util.ProperSign(playerTile.x - currentTile.x); int newCDY = Util.ProperSign(playerTile.y - currentTile.y); if (playerTile == currentTile) { return; } if (newCDX != chargeDX || newCDY != chargeDY) { charging = 0; } chargeDX = newCDX; chargeDY = newCDY; if (targetTile != null) { targetTile.UnBlock(); } targetTile = null; eyes.SetActive(false); charging++; if (charging == 3) { Fire(); return; } else { Sounds.PlaySound(Sounds.charge, 1, charging == 1?1:1.8f); } } else { chargeDX = 0; chargeDY = 0; charging = 0; PathTowardsPlayer(); } UpdateTargeting(); }
public S_Tile PathTo(List <S_Tile> targets) { List <S_Tile> open = new List <S_Tile>(); List <S_Tile> closed = new List <S_Tile>(); open.Add(this); while (open.Count > 0) { S_Tile current = open[0]; open.RemoveAt(0); closed.Add(current); foreach (S_Tile potential in current.GetTilesWithin(1, false)) { if (closed.Contains(potential)) { continue; } potential.previous = current; if (targets.Contains(potential)) { S_Tile result = potential; while (result.previous != this) { result = result.previous; } return(result); } if (potential.IsBlocked()) { continue; } open.Add(potential); } } if (targets.Count == 1) { //if the path is blocked, also check nearby tiles return(PathTo(targets[0].GetTilesWithin(1, false))); } return(null); }
public void ActivateTile(S_Tile tile) { //check for validity if (moving || tile == null) { return; } Sounds.PlaySound(Sounds.move, 1, Random.Range(.9f, 1.1f)); if (Level.Get(gameObject).abilityPanel.activeAbility != null) { Level.Get(gameObject).abilityPanel.activeAbility.Use(this, tile); } else { if (tile.GetDistance(currentTile) != 1) { return; } MoveToTile(tile, false); } }
public List <S_Tile> GetTilesWithin(int dist, bool includeSelf) { List <S_Tile> result = new List <S_Tile>(); for (int dx = -dist; dx <= dist; dx++) { for (int dy = -dist; dy <= dist; dy++) { if (dy == 0 && dx == 0 && !includeSelf) { continue; } S_Tile at = GetTile(dx, dy); if (at != null && at.TileDistance(this) <= dist) { result.Add(at); } } } return(result); }
void UpdateTargeting() { if (Game.Get().state != Game.GameState.Normal) { return; } ClearTargets(); if (charging > 0) { S_Tile playerTile = Level.Get(gameObject).player.currentTile; int dx = Util.ProperSign(playerTile.x - currentTile.x); int dy = Util.ProperSign(playerTile.y - currentTile.y); foreach (S_Tile tile in currentTile.GetTilesInLine(dx, dy)) { GameObject go = Primitives.CreateActor(dx == 0 ? Sprites.charge_v : Sprites.charge_h); Util.SetLayer(go, Util.LayerName.Tiles, 20); go.transform.SetParent(tile.transform, false); go.GetComponent <SpriteRenderer>().color = charging == 1 ? Colours.GREEN : Colours.LIGHT; targets.Add(go); } } }
void ActivateDirection(int dx, int dy) { if (!(dx != 0 || dy != 0)) { return; } nextDx = -5; nextDy = -5; if (Level.Get(gameObject).abilityPanel.activeAbility != null) { Level.Get(gameObject).abilityPanel.activeAbility.Use(this, dx, dy); } else { S_Tile newTile = currentTile.GetTile(dx, dy); if (newTile != null) { ActivateTile(newTile); } } }
public virtual void MoveToTile(S_Tile tile, bool instant) { if (tile == null || tile == currentTile) { return; } previousTile = currentTile; SetTile(tile); if (previousTile != null) { currentDX = currentTile.x - previousTile.x; currentDY = currentTile.y - previousTile.y; } if (instant) { moveTicker = 1; positionSetter.transform.localPosition = currentTile.transform.localPosition; tile.Enter(this); } else { StartMoving(); } }
public abstract void Use(S_Player player, S_Tile tile);
public abstract List <S_Tile> GetValidTiles(S_Tile origin);
public int GetDistance(S_Tile other) { return Math.Abs(other.x - x) + Mathf.Abs(other.y - y); }
public int TileDistance(S_Tile to) { return Mathf.Abs(to.x - x) + Mathf.Abs(to.y - y); }
public int TileDistance(S_Tile to) { return(Mathf.Abs(to.x - x) + Mathf.Abs(to.y - y)); }
public abstract List<S_Tile> GetValidTiles(S_Tile origin);
public S_Tile PathTo(S_Tile target) { if (target == this) return null; return PathTo(new List<S_Tile>() { target }); }
public int GetDistance(S_Tile other) { return(Math.Abs(other.x - x) + Mathf.Abs(other.y - y)); }