A top-downturn based project where the player can move their characters to another tile and perform unique actions.
The gif below demonstrates how characters are currently teleported to the chosen tile and the images of code display the functions or nodes utilised to achieve this effect and display the dynamic UI for possible character actions.
After choosing a character and selecting a tile to move to, all tiles in the path to follow array have their highlight color opacity set to 0. Before performing the A* algorithm, the array is cleared of all elements.
After performing the A* algorithm, each tile that is part of the determined path is added to the path to follow array and has its highlight color set to light blue.
The chosen character is teleported to the location of the last tile in the path and the previous tile has its reference to its occupant set to null.
The character has its reference to the tile it is standing set to the current tile and the tile has its occupant reference set to the chosen player character. A flood fill algorithm is performed from the tile at the end of the path or occupied tile and uses the characters attack range as its depth value.
While performing the flood fill algorithm, each tile is checked for a valid occupant class that is not the same as the chosen character and if it is successful then its added to array of possible occupant targets. After looping through all tiles, an enum is set in order to control when two characters can initiate their battle animations.
The get all actions function, adds all action components on the chosen character to an array. Get possible actions will loop through the actions array input and check if an action can be performed. As an example, a healing action will only work if an ally is missing health or combat can be initiated if an enemy character is within attack range.
After determining which actions can be performed, an action widget is spawned with dynamic buttons and text. The possible actions that can be performed are set to an instance editable array of action components before setting the input mode and showing the mouse cursor.
During the development of this project, an issue I encountered was creating buttons dynamically when the player chooses an action to perform. This was solved by binding an on clicked event in a button widget to trigger an action component's effect.