static private List <PathNode> findAdjacentNodes(PathNode currentNode, PathNode endNode, bool flying = false) { List <PathNode> adjacentNodes = new List <PathNode>(); int X = currentNode.GridX; int Y = currentNode.GridY; bool upLeft = true; bool upRight = true; bool downLeft = true; bool downRight = true; if ((X > 0) && (map.getTileTypeFromTilePosition(X - 1, Y) == MapGeneration.TileType.Ground || flying)) { adjacentNodes.Add(new PathNode( currentNode, endNode, new Vector2(X - 1, Y), CostStraight + currentNode.DirectCost)); } else { upLeft = false; downLeft = false; } if ((map.getTileTypeFromTilePosition(X + 1, Y) == MapGeneration.TileType.Ground || flying)) { adjacentNodes.Add(new PathNode( currentNode, endNode, new Vector2(X + 1, Y), CostStraight + currentNode.DirectCost)); } else { upRight = false; downRight = false; } if ((Y > 0) && ((map.getTileTypeFromTilePosition(X, Y - 1) == MapGeneration.TileType.Ground || flying))) { adjacentNodes.Add(new PathNode( currentNode, endNode, new Vector2(X, Y - 1), CostStraight + currentNode.DirectCost)); } else { upLeft = false; upRight = false; } if ((map.getTileTypeFromTilePosition(X, Y + 1) == MapGeneration.TileType.Ground || flying)) { adjacentNodes.Add(new PathNode( currentNode, endNode, new Vector2(X, Y + 1), CostStraight + currentNode.DirectCost)); } else { downLeft = false; downRight = false; } if ((upLeft) && ((map.getTileTypeFromTilePosition(X - 1, Y - 1) == MapGeneration.TileType.Ground || flying))) { adjacentNodes.Add(new PathNode( currentNode, endNode, new Vector2(X - 1, Y - 1), CostDiagonal + currentNode.DirectCost)); } if ((upRight) && ((map.getTileTypeFromTilePosition(X + 1, Y - 1) == MapGeneration.TileType.Ground || flying))) { adjacentNodes.Add(new PathNode( currentNode, endNode, new Vector2(X + 1, Y - 1), CostDiagonal + currentNode.DirectCost)); } if ((downLeft) && ((map.getTileTypeFromTilePosition(X - 1, Y + 1) == MapGeneration.TileType.Ground || flying))) { adjacentNodes.Add(new PathNode( currentNode, endNode, new Vector2(X - 1, Y + 1), CostDiagonal + currentNode.DirectCost)); } if ((downRight) && ((map.getTileTypeFromTilePosition(X + 1, Y + 1) == MapGeneration.TileType.Ground || flying))) { adjacentNodes.Add(new PathNode( currentNode, endNode, new Vector2(X + 1, Y + 1), CostDiagonal + currentNode.DirectCost)); } return(adjacentNodes); }
private void Update() { if (!cutScene && !dead) { if (inventory != null) { horizontalInput = Input.GetAxisRaw("Horizontal"); verticalInput = Input.GetAxisRaw("Vertical"); if (Input.GetKey(KeyCode.LeftShift) || inventory.open) { halfSpeed = 2; } else { halfSpeed = 1; } if (!inventory.open)//rplace with menu is open later { if (Input.GetKeyUp(KeyCode.Q)) { if (inventory.totalTraps > 0) { inventory.trapOn = Mathf.Clamp(inventory.trapOn - 1, 0, inventory.totalTraps); } } else if (Input.GetKeyUp(KeyCode.E)) { if (inventory.totalTraps > 0) { inventory.trapOn = Mathf.Clamp(inventory.trapOn + 1, 0, inventory.totalTraps - 1); } } else if (Input.GetKeyUp(KeyCode.Space) && playerStats.traps.Count != 0) { if (!usingItem) { Vector2 coord = map.getTileFromPosition(transform.position.x, transform.position.y); if (map.getTileTypeFromTilePosition((int)coord.x, (int)coord.y) == MapGeneration.TileType.Ground) { usingItem = true; useTimer = new Timer(playerStats.traps[inventory.trapOn].useTime); useTimer.StartTimer(); timeBar.gameObject.SetActive(true); } } else { usingItem = false; useTimer.StopTimer(); timeBar.gameObject.SetActive(false); } } else if (Input.GetKeyUp(KeyCode.Escape)) { menu.Settings(); cutScene = true; } } if (Input.GetKeyUp(KeyCode.I)) { if (!inventory.open) { inventory.Show(); } else { inventory.Hide(); } } if (Input.GetKeyUp(KeyCode.C)) { if (!inventory.open) { inventory.ShowCrafting(); } else { if (inventory.crafting) { inventory.Hide(); } else { inventory.ShowCrafting(); } } } } else { Debug.LogError("Inventory not connected to Player. Where is Inventory?"); } } else { horizontalInput = 0; verticalInput = 0; if (dead) { if (fadeoutTime <= 0) { Destroy(PlayerStats.getInstacne().gameObject); gameObject.GetComponent <ChangeScene>().changeSceneTo("GameOver"); } else { fadeoutTime -= Time.deltaTime; } } } }