public void PrepCharge(Constant.QuadDir dir) { chargeDir = dir; Face(dir); anim.Play("Shield"); blocking = true; }
// given src grid, directon and distance, return the Grid, dist grids away, in dir direction public Grid GetGrid(int srcGridX, int srcGridY, Constant.QuadDir dir, int dist) { GameManager gm = GameManager.Instance; GameObject[,] grids = gm.gridTiles; Grid targGrid = null; //print("src " + srcGridX +" "+ srcGridY+" "+ dir); // TODO bound check if (dir == Constant.QuadDir.Up && srcGridY < maxY) { targGrid = grids[srcGridX, srcGridY + 1].GetComponent <Grid>(); } else if (dir == Constant.QuadDir.Left && srcGridX >= 1) { targGrid = grids[srcGridX - 1, srcGridY].GetComponent <Grid>(); } else if (dir == Constant.QuadDir.Down && srcGridY >= 1) { targGrid = grids[srcGridX, srcGridY - 1].GetComponent <Grid>(); } else if (dir == Constant.QuadDir.Right && srcGridX < maxX) { targGrid = grids[srcGridX + 1, srcGridY].GetComponent <Grid>(); } else { Debug.Log("bad direction"); } return(targGrid); }
public bool MoveInDirection(Constant.QuadDir dir) { GameObject[,] grids = GameManager.Instance.gridTiles; Grid destGrid = null; if (dir == Constant.QuadDir.Up) { destGrid = grids[gridX, gridY + 1].GetComponent <Grid>(); } else if (dir == Constant.QuadDir.Left) { destGrid = grids[gridX - 1, gridY].GetComponent <Grid>(); } else if (dir == Constant.QuadDir.Down) { destGrid = grids[gridX, gridY - 1].GetComponent <Grid>(); } else if (dir == Constant.QuadDir.Right) { destGrid = grids[gridX + 1, gridY].GetComponent <Grid>(); } if (destGrid && destGrid.CanMoveTo()) { MoveToGrid(destGrid); } else { Debug.LogFormat("{0} tried to move {1} but cannot move to", this, dir); return(false); } Face(dir); return(true); }
public void Face(Constant.QuadDir dir) { Vector3 targetPos = transform.position; if (dir == Constant.QuadDir.Up) { targetPos.z += 1; } else if (dir == Constant.QuadDir.Left) { targetPos.x -= 1; } else if (dir == Constant.QuadDir.Down) { targetPos.z -= 1; } else if (dir == Constant.QuadDir.Right) { targetPos.x += 1; } Vector3 targetDir = targetPos - transform.position; this.targetDir = targetDir; }
public override void GetPickedUp(Player player) { GameManager gm = GameManager.Instance; Constant.QuadDir oppositeSide = Constant.Opposite(side); gm.EnterDoor(this); // going to left room comes out next room from right base.GetPickedUp(player); }
private void Awake() { if (Instance == null) { Instance = this; } turn = 1; roomEntranceDir = Constant.QuadDir.Down; level = 1; room = 0; roomTypes = new List <string>(); roomTypes.AddRange(rTypes); }
//private void OnDrawGizmos() //{ // Handles.Label(transform.position, "hp: "+health); //} public void MoveRandom() { GameManager gm = GameManager.Instance; List <Constant.QuadDir> options = new List <Constant.QuadDir>(); //print("enemy move random"); //print("at " + this); Grid upGrid = gm.GetGrid(gridX, gridY, Constant.QuadDir.Up, 1); if (upGrid != null && upGrid.EnemyCanMoveHere()) { options.Add(Constant.QuadDir.Up); } Grid downGrid = gm.GetGrid(gridX, gridY, Constant.QuadDir.Down, 1); if (downGrid != null && downGrid.EnemyCanMoveHere()) { options.Add(Constant.QuadDir.Down); } Grid leftGrid = gm.GetGrid(gridX, gridY, Constant.QuadDir.Left, 1); if (leftGrid != null && leftGrid.EnemyCanMoveHere()) { options.Add(Constant.QuadDir.Left); } Grid rightGrid = gm.GetGrid(gridX, gridY, Constant.QuadDir.Right, 1); if (rightGrid != null && rightGrid.EnemyCanMoveHere()) { options.Add(Constant.QuadDir.Right); } if (options.Count == 0) { print(this + " no where to move randomly"); } else { Constant.QuadDir dir = GameManager.RandomElement(options); MoveInDirection(dir); } }
public void InteractInDirection(Constant.QuadDir dir) { GameManager gm = GameManager.Instance; Grid targetGrid = gm.GetGrid(gridX, gridY, dir, 1); if (targetGrid.CanMoveTo()) { MoveInDirection(dir); if (targetGrid.GetOccupantWithTag("Loot") != null) { anim.Play("Interact"); } } else if (targetGrid.GetOccupantWithTag("Enemy") != null) { Enemy enemy = (Enemy)targetGrid.GetOccupantWithTag("Enemy"); Attack(enemy); } else if (targetGrid.GetOccupantWithTag("Npc") != null) { Npc npc = (Npc)targetGrid.GetOccupantWithTag("Npc"); Interact(npc); } else if (targetGrid.GetOccupantWithTag("Loot") != null) { Door door = (Door)targetGrid.GetOccupantWithTag("Loot"); anim.Play("Interact"); if (!door.enterable) { gm.Think("It's locked..."); } } else { Debug.Log("Nothing to interact at " + targetGrid); } Face(dir); StartCoroutine(EndTurn()); }
public Door GenerateRoom(Constant.QuadDir entranceDir) { print("generating room entrance at " + entranceDir); maxX = Random.Range(5, 8); maxY = Random.Range(4, 6); print("maxX " + maxX + " maxY " + maxY); gridTiles = new GameObject[maxX + 1, maxY + 1]; GenerateGrid(); SpawnWalls(); roomEntranceDir = entranceDir; if (entranceDir == Constant.QuadDir.Down) { SpawnDoor(Constant.QuadDir.Right); SpawnDoor(Constant.QuadDir.Left); } else if (entranceDir == Constant.QuadDir.Left) { SpawnDoor(Constant.QuadDir.Up); SpawnDoor(Constant.QuadDir.Right); } else if (entranceDir == Constant.QuadDir.Right) { SpawnDoor(Constant.QuadDir.Up); SpawnDoor(Constant.QuadDir.Left); } Door entranceDoor = SpawnEntranceDoor(entranceDir); entranceDoor.monsterLocked = false; entranceDoor.ChangeColor(Color.black); OnTurnEndSubscribers = null; return(entranceDoor); }