// Use this for initialization public virtual void Initialize() { //m_Goal = new Vector2Int(9, 2); //m_Position = new Vector2Int(4, 4); CreatureOffset = new Vector3(0, Constants.Constants.m_HeightOffTheGrid, 0); m_Jump = 2; m_HasMovedForThisTurn = false; m_MovementHasStarted = false; m_InitalPosition = m_Position; m_Grid = Grid.Instance; Node_ObjectIsOn = m_Grid.GetNode(m_Position); Node_MovingTo = Node_ObjectIsOn; if (m_AiModel == null) { m_AiModel = transform.GetChild(0); } if (m_CreaturesAnimator == null) { m_CreaturesAnimator = GetComponentInChildren <Animator>(); } _Pathfinder = new Pathfinder(); }
private void TransitionToNewRoom(GameObject exitDoor) { if (exitDoor.CompareTag("DoorNextFloor") || exitDoor.CompareTag("DoorVillage")) { InstantiateNewLevel(); } else { //set the current room inactive DungeonFloorScript.MyInstance.GetCurrentNode().ActivateRoom(false); ItemsManagerScript.MyInstance.RemovePotionEffect(); //get the next room direction FloorNode.directionEnum direction = FloorNode.directionEnum.north; string spawnPointName = "SpawnDown"; if (exitDoor.CompareTag("DoorRight")) { direction = FloorNode.directionEnum.east; spawnPointName = "SpawnLeft"; } else if (exitDoor.CompareTag("DoorDown")) { direction = FloorNode.directionEnum.south; spawnPointName = "SpawnUp"; } else if (exitDoor.CompareTag("DoorLeft")) { direction = FloorNode.directionEnum.west; spawnPointName = "SpawnRight"; } //print("current room : " + DungeonFloorScript.MyInstance.GetCurrentNode().GetRoomName()); //print("next room : " + DungeonFloorScript.MyInstance.GetCurrentNode().GetNeighbourNode(direction).GetRoomName()); //get the next room node FloorNode nextNode = DungeonFloorScript.MyInstance.GetCurrentNode().GetNeighbourNode(direction); //change the current room node as the next room node we picked DungeonFloorScript.MyInstance.SetCurrentNode(nextNode); //activate the room DungeonFloorScript.MyInstance.GetCurrentNode().ActivateRoom(true); //update the mini map MinimapScript.MyInstance.AddRoom(DungeonFloorScript.MyInstance.GetCurrentNode(), false); MinimapScript.MyInstance.UpdateCurrentRoomDisplay(DungeonFloorScript.MyInstance.GetCurrentNode()); //reposition the player to the correct place of the room where he should spawn UpdatePlayerPosition(spawnPointName); //reset the room doors to get the doors of the new room GameManager.MyInstance.ResetRoomDoors(); AstarPath.active.Scan(); DestroyAllProjectiles(); } }
void triangulate_solid_floors() { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (map[x, y] == EMPTY || map[x, y] == BRIDGE) { FloorNode n00 = node_map[x + 0, y + 0].upleft; FloorNode n01 = node_map[x + 1, y + 0].upleft; FloorNode n10 = node_map[x + 0, y + 1].upleft; FloorNode n11 = node_map[x + 1, y + 1].upleft; index_vertices(n00, n01, n10, n11); triangles.Add(n10.index); triangles.Add(n11.index); triangles.Add(n01.index); triangles.Add(n00.index); triangles.Add(n10.index); triangles.Add(n01.index); } } } }
public virtual bool CheckIfNodeIsClearAndReturnNodeIndex(FloorNode aNode, Vector2Int m_Position) { // if the node is out of bounds, return -1 (an invalid tile index) if (aNode == null) { Debug.Log("YOU BROKE " + aNode.m_PositionInGrid.ToString()); } FloorNode nodeIndex = aNode; // if the node is already closed, return -1 (an invalid tile index) if (nodeIndex.m_HeuristicCalculated == true) { return(false); } if (nodeIndex.m_DomainCombatNode == FloorNode.DomainCombatNode.Domain) { return(false); } if (nodeIndex.m_NodeHeight > 0) { return(false); } // return a valid tile index return(true); }
public void UpdateCurrentRoomDisplay(FloorNode newCurrentNode) { if (roomDisplayed == null) { roomDisplayed = displayedRooms[shownNodes.IndexOf(newCurrentNode)]; } else { Color newColor = roomDisplayed.GetComponent <Image>().color; newColor.g = 255; newColor.b = 255; roomDisplayed.GetComponent <Image>().color = newColor; } roomDisplayed = displayedRooms[shownNodes.IndexOf(newCurrentNode)]; SetRoomTransparency(roomDisplayed, 0.6f); Color newColorRed = roomDisplayed.GetComponent <Image>().color; newColorRed.g = 0; newColorRed.b = 0; roomDisplayed.GetComponent <Image>().color = newColorRed; DisplayNodeNeighbours(newCurrentNode); }
public void SetPlayerMapPosition(FloorNode aFloorNode) { int index = m_CurrentFloorManager.m_FloorCore.GetIndex(aFloorNode.m_PositionInGrid.x, aFloorNode.m_PositionInGrid.y); m_Map.SetPlayerNode(index); }
public IEnumerator DirectMovement(Transform aObject, FloorNode aTargetNode, float aTimeUntilDone) { Vector3 NewNodePosition = new Vector3(aTargetNode.transform.position.x, aTargetNode.transform.position.y + Constants.Constants.m_HeightOffTheGrid, aTargetNode.transform.position.z); float timeTaken = 0.0f; m_IsMoving = true; while (aTimeUntilDone - timeTaken > 0) { if (Vector3.Distance(aObject.transform.position, NewNodePosition) < 0.05f) { timeTaken = aTimeUntilDone; } timeTaken += Time.deltaTime; aObject.position = Vector3.Lerp(aObject.position, NewNodePosition, timeTaken / aTimeUntilDone); yield return(null); } aObject.position = NewNodePosition; currentFloorNode = aTargetNode; aTargetNode.ActivateWalkOnTopTrigger(); m_IsMoving = false; yield return(0); }
public FloorNode GetNextNode() { Vector2Int m_PositiontoGoTo = m_OverworldEnemy.m_PathToFollow[m_PositionInPath]; FloorNode TargetNode = m_FloorManager.GetNode(m_PositiontoGoTo.x, m_PositiontoGoTo.y); return(TargetNode); }
public IEnumerator DirectMovement(Transform aObject, FloorNode aTargetNode, float aTimeUntilDone) { Vector3 NewNodePosition = new Vector3(aTargetNode.transform.position.x, aTargetNode.transform.position.y, aTargetNode.transform.position.z); float timeTaken = 0.0f; aTargetNode.SetWalkOnTopDelegate(WalkOnTopActivation); m_CurrentNode = aTargetNode; m_Animator.SetBool("b_IsWalking", true); while (aTimeUntilDone - timeTaken > 0) { if (Vector3.Distance(aObject.transform.position, NewNodePosition) < 0.05f) { timeTaken = aTimeUntilDone; } timeTaken += Time.deltaTime; aObject.position = Vector3.Lerp(aObject.position, NewNodePosition, timeTaken / aTimeUntilDone); yield return(null); } m_Animator.SetBool("b_IsWalking", false); aObject.position = NewNodePosition; MovementEnd(); yield return(0); }
public virtual bool CheckIfNodeIsClearForRange(FloorNode aNode) { // if the node is out of bounds, return -1 (an invalid tile index) if (aNode == null) { Debug.Log("YOU BROKE " + aNode.m_PositionInGrid.ToString()); } FloorNode nodeIndex = aNode; // if the node is already closed, return -1 (an invalid tile index) if (nodeIndex.m_HeuristicCalculated == true) { return(false); } // if the node can't be walked on, return -1 (an invalid tile index) if (nodeIndex.m_NodeHeight > 0) { return(false); } // return a valid tile index return(true); }
public void EnemyMovement() { FindAllPaths(); m_NodeInWalkableRange = GetAvailableEnemysInRange(m_Grid.m_GridPathList, Node_ObjectIsOn, m_EnemyRange); List <Creatures> m_AllysInRange = new List <Creatures>(); foreach (FloorNode node in m_NodeInWalkableRange) { if (CheckIfAllyIsOnNode(node)) { m_AllysInRange.Add(node.m_CreatureOnGridPoint); } } if (m_AllysInRange.Count > 0) { Creatures CharacterInRange = m_Behaviour.AllyToAttack(m_AllysInRange); FloorNode NodeNeightboringAlly = Grid.instance.CheckNeighborsForLowestNumber(CharacterInRange.m_CreatureAi.m_Position); if (NodeNeightboringAlly != null) { SetGoalPosition(NodeNeightboringAlly.m_PositionInGrid); return; } else { Debug.Log(gameObject.name + " Failed to be able to get to node "); return; } } }
public void GenerateNewFloor() { //destroy previous room prefabs and minimap foreach (FloorNode room in nodeList) { room.DestroyRoom(); } MinimapScript.MyInstance.ClearMap(); nodeList.Clear(); IncreaseFloorLevel(); //create a first room FloorNode newNode = new FloorNode(); newNode.SetRoomType(FloorNode.roomTypeEnum.regular); newNode.SetCoord(0, 0); nodeList.Add(newNode); SetCurrentNode(newNode); //create the number of regular rooms desired int roomNumber = basicRoomsNumber; while (roomNumber > 0) { CreateRandomNode(FloorNode.roomTypeEnum.regular); roomNumber--; } //add other rooms after AddSpecialRooms(); //when every nodes are placed and have their coordinates //we create each node's room prefab and disable them foreach (FloorNode node in nodeList) { node.SetRoom(node.GetRoomType(), dungeonLevel); node.CreateRoom(); node.ActivateRoom(false); } //create the first room on the minimap InitializeMap(nodeList[0].GetRoom()); //if the player has the item to reveal the map if (isMapRevealed) { MinimapScript.MyInstance.ShowFullMap(nodeList); } else { MinimapScript.MyInstance.AddRoom(newNode, false); } //update the display of the current room on the minimap MinimapScript.MyInstance.UpdateCurrentRoomDisplay(GetCurrentNode()); currentNodeIndex = 0; }
public Dictionary <FloorNode, List <FloorNode> > cacheRangePaths(List <FloorNode> cells, FloorNode aNodeHeuristicIsBasedOn) { var edges = m_Behaviour.GetGraphRangeEdges(cells, Node_ObjectIsOn); var paths = _Pathfinder.findAllPaths(edges, aNodeHeuristicIsBasedOn, m_Movement); return(paths); }
void triangulate_corner(FloorNode n0, FloorNode n1, FloorNode n2) { index_vertices(n0, n1, n2); triangles.Add(n2.index); triangles.Add(n1.index); triangles.Add(n0.index); }
//show the new room's neighbours as semi transparent rooms private void DisplayNodeNeighbours(FloorNode node) { List <FloorNode> neighbourNodes = node.GetNeigbours(); foreach (FloorNode neighbour in neighbourNodes) { AddRoom(neighbour, true); } }
//when possible to run from start void Awake() { //allow the object to be referenced with instance if (instance = null) { return; } instance = this; }
public virtual IEnumerator GetToGoal(List <FloorNode> aListOfNodes) { m_MovementHasStarted = true; m_CreaturesAnimator.SetBool("b_IsWalking", true); // GameManager.Instance.mMCombatCameraController.m_cameraState = CombatCameraController.CameraState.PlayerMovement; Node_ObjectIsOn.m_CreatureOnGridPoint = null; Node_ObjectIsOn.m_IsCovered = false; for (int i = 0; i < aListOfNodes.Count;) { if (Node_MovingTo == Node_ObjectIsOn) { Node_MovingTo = aListOfNodes[i]; Vector3 relativePos = aListOfNodes[i].gameObject.transform.position - transform.position + CreatureOffset; m_Position = Node_MovingTo.m_PositionInGrid; // GameManager.Instance.mMCombatCameraController.m_CameraPositionInGrid = m_Position; m_AiModel.rotation = Quaternion.LookRotation(relativePos, Vector3.up); CreatureOffset = new Vector3(0, Constants.Constants.m_HeightOffTheGrid + Node_MovingTo.m_NodeHeightOffset, 0); i++; yield return(new WaitUntil(() => Node_MovingTo == Node_ObjectIsOn)); } } //Camera no longer following the player; // GameManager.Instance.mMCombatCameraController.m_cameraState = CombatCameraController.CameraState.Normal; //Setting the Walk Animation m_CreaturesAnimator.SetBool("b_IsWalking", false); //The walk has been finished m_HasMovedForThisTurn = true; m_MovementHasStarted = false; //Changing the position from where the Creature was before m_Position = aListOfNodes[aListOfNodes.Count - 1].m_PositionInGrid; m_PreviousNode = Node_ObjectIsOn; //Setting the node you are on to the new one Node_ObjectIsOn = Grid.instance.GetNode(m_Position); Node_ObjectIsOn.SetCreatureOnTopOfNode(m_Creature); Node_ObjectIsOn.m_IsCovered = true; // m_PreviousNode.DomainOnNode.UndoDomainEffect(ref Node_ObjectIsOn.m_CreatureOnGridPoint); for (int i = aListOfNodes.Count; i < 0; i--) { aListOfNodes.RemoveAt(i); } }
public void SetupAction(Creatures aActionCreature, FloorNode aActionCommandNode) { m_ActionCreature = aActionCreature; m_ActionCommandNode = aActionCommandNode; m_PreviousActionCommandNode = m_ActionCreature.m_CreatureAi.Node_ObjectIsOn; CreatureOffset = new Vector3(0, Constants.Constants.m_HeightOffTheGrid, 0); Debug.Log(m_ActionCreature.Name + " Moved into " + m_ActionCommandNode.m_PositionInGrid); }
public void SetNodePosition(Vector2Int aPosition) { m_CurrentNode = m_FloorManager.GetNode(aPosition.x, aPosition.y); m_PreviousNode = m_CurrentNode; Vector3 nodePosition = m_CurrentNode.gameObject.transform.position; Vector3 NewNodePosition = new Vector3(nodePosition.x, nodePosition.y, nodePosition.z); transform.position = NewNodePosition; }
public void CreateLinkBetweenNodes(FloorNode a, FloorNode b, FloorNode.directionEnum directionFromAToB) { //if both nodes have no neighbour at the chosen direction if (a.GetNeighbourNode(directionFromAToB) == null && b.GetNeighbourNode(GetOppositeDirection(directionFromAToB)) == null) { //add the new room as a neighbour of the existing room a.SetNeighbourNode(directionFromAToB, b); //add the existing room as a neighbour of the new room b.SetNeighbourNode(GetOppositeDirection(directionFromAToB), a); } }
public bool CheckIfAllyIsOnNode(FloorNode aNode) { if (aNode.m_CreatureOnGridPoint != null && m_Creature != aNode.m_CreatureOnGridPoint) { if (aNode.m_CreatureOnGridPoint.charactertype == Creatures.Charactertype.Ally) { return(true); } } return(false); }
public void SpawnNode(int aRow, int aColumn, int aIndex) { FloorNode tempFloorNode = Instantiate(m_FloorNodePrefab, m_Node.transform); m_FloorNodes[aIndex] = tempFloorNode; m_FloorNodes[aIndex].m_PositionInGrid = new Vector2Int(aRow, aColumn); m_FloorNodes[aIndex].gameObject.name = aRow + " " + aColumn; m_FloorNodes[aIndex].transform.position = new Vector3(4 * aRow, 0.5f, 4 * aColumn); m_FloorNodes[aIndex].m_NodeFloorManager = this; // m_GridPathArray[x, y].m_Grid = m_Grid; }
public FloorNode CheckNeighborsForLowestNumber(Vector2Int grid) { float TempHeuristic = 100; FloorNode TempNode = null; foreach (Vector2Int direction in _directions) { if ((grid.x + direction.x) < m_GridDimensions.x && (grid.y + direction.y) < m_GridDimensions.y && grid.x + direction.x > -1 && (grid.y + direction.y) > -1) { FloorNode neighbour = m_GridPathArray[grid.x + direction.x, grid.y + direction.y]; if (neighbour == null) { Debug.Log("neighbour literally doesnt exist"); continue; } if (neighbour.m_IsWalkable == false) { Debug.Log("Walkable was false"); continue; } if (neighbour.m_IsCovered == true) { Debug.Log("Node Was covered by someone else"); continue; } if (neighbour.m_Heuristic == -1) { Debug.Log("Neighbour heuristic is -1"); continue; } if (neighbour.m_Heuristic < TempHeuristic) { TempHeuristic = neighbour.m_Heuristic; TempNode = neighbour; } } } if (TempNode == null) { Debug.Log("Check Neightbor is null"); Debug.Break(); } return(TempNode); }
public void SpawnCamera() { //Default Node FloorNode SpawnNode = GetNode(m_FloorCore.m_DefaultSpawnPosition.x, m_FloorCore.m_DefaultSpawnPosition.y); Vector3 StartNodePosition = SpawnNode.transform.position; m_OverworldPlayerMovementController.m_CurrentFloorManager = this; m_OverworldPlayerMovementController.currentFloorNode = SpawnNode; m_OverworldPlayerMovementController.transform.position = new Vector3(StartNodePosition.x, StartNodePosition.y + Constants.Constants.m_HeightOffTheGrid, StartNodePosition.z); m_OverworldPlayerMovementController.SetPlayerMapPosition(SpawnNode); }
public void EnemyMovement() { m_PreviousNode.SetWalkOnTopDelegate(null); FloorNode NextNode = GetNextNode(); if (NextNode == null) { Debug.Log("Cant Find Node "); return; } StartCoroutine(DirectMovement(transform, NextNode, 0.6f)); }
public void MoveForward() { FloorNode TargetNode = m_CurrentFloorManager.GetNode(currentFloorNode.m_PositionInGrid, CurrentDirection); if (TargetNode == null) { Debug.Log("Cant Find Node " + currentFloorNode.m_PositionInGrid); return; } StartCoroutine(DirectMovement(transform, TargetNode, 0.6f)); int index = m_CurrentFloorManager.m_FloorCore.GetIndex(TargetNode.m_PositionInGrid.x, TargetNode.m_PositionInGrid.y); m_Map.SetPlayerNode(index); }
// Update is called once per frame public virtual void Update() { if (Node_ObjectIsOn != Node_MovingTo) { transform.position = Vector3.MoveTowards (transform.position, Node_MovingTo.gameObject.transform.position + CreatureOffset, 8 * Time.deltaTime); } if (m_MovementHasStarted == true) { if (transform.position == Node_MovingTo.transform.position + CreatureOffset) { Node_ObjectIsOn = Node_MovingTo; } } }
private void CreateRoom(FloorNode node, bool isNeighbour) { //add the node to the list of shown rooms shownNodes.Add(node); //create a room on the minimap GameObject room = GameObject.Instantiate(mapRoom, panel.transform); room.transform.position = room.transform.parent.position; room.transform.position += new Vector3(node.GetCoord().x * 60, node.GetCoord().y * 20, 0); //handle the icon of specific rooms FloorNode.roomTypeEnum roomType = node.GetRoomType(); switch (roomType) { case FloorNode.roomTypeEnum.sellerRoom: room.transform.GetChild(0).GetComponent <Image>().sprite = iconSeller; break; case FloorNode.roomTypeEnum.bossRoom: case FloorNode.roomTypeEnum.miniBossRoom: room.transform.GetChild(0).GetComponent <Image>().sprite = iconBoss; break; case FloorNode.roomTypeEnum.exitRoom: room.transform.GetChild(0).GetComponent <Image>().sprite = iconExit; break; case FloorNode.roomTypeEnum.itemRoom: room.transform.GetChild(0).GetComponent <Image>().sprite = iconItem; break; default: Destroy(room.transform.GetChild(0).gameObject); break; } displayedRooms.Add(room); if (isNeighbour) { SetRoomTransparency(room, 0.3f); } }
public HashSet <FloorNode> GetNodesInRange(List <FloorNode> aCells, FloorNode aNodeHeuristicIsBasedOff, int aRange, DelegateReturnNodeIndex delegateReturnNodeIndex) { cachedPaths = new Dictionary <FloorNode, List <FloorNode> >(); var paths = cachePaths(aCells, aNodeHeuristicIsBasedOff, delegateReturnNodeIndex); foreach (var key in paths.Keys) { var path = paths[key]; var pathCost = path.Sum(c => 1); key.m_Heuristic = pathCost; if (pathCost <= aRange) { cachedPaths.Add(key, path); } } return(new HashSet <FloorNode>(cachedPaths.Keys)); }
public void AddRoom(FloorNode node, bool isNeighbour) { if (shownNodes == null) { this.Start(); } if (!shownNodes.Contains(node)) { if (!isNeighbour) { DisplayNodeNeighbours(node); CreateRoom(node, false); } else { CreateRoom(node, true); } } }