Path follow mostly working - on to detecting adjacent nodes

This is my third blog post today. Well, technically today is the next day, but it still feels like yesterday. I promise they won’t be this frequent all the time. Today I’ve just had a lot to write about.

As far as I can tell in my tired state, path follow functionality is mostly done. The very core functionality, that is. That being:

  1. The player is able to select a base to draw a path from.

  2. The player is able to click on nodes to specify a path from the chosen base.

  3. The player is able to re-draw their path or clear it completely.

  4. The player is able to press ‘Go’ to spawn entities from the base and send them along the path to the destination.

  5. While the entities are moving, the player is able to start drawing another path from a different base.

There is still a long way to go with these paths. For example, I need to implement the following:

What I ended up doing with the arrays

Jack suggested earlier that maybe I should copy the path array into the moving entity when the Go button is clicked. This ended up being a life saver. What’s happening now is:

This has eliminated the need for the array of arrays and, while still using a global array and probably not being ideal, has made the code feel a lot less messy for me. Although I’m sure I’ll improve on it more later.

I have also added a deselectPath function to the controller class. This is called when one of the following happens:

It looks like this:

[crayon title=“playerController.js”] deselectPath: function() { for(var i =; i >= 0; i–){[i].active = false;[i].clickcount = 0; console.log (‘setting everything to inactive’); } = 0; }, [/crayon]

Every node-type entity (so the bases, the nodes, and the destination entities) have an “active” attribute which is always either true or false and a “clickcount” which is always either 1 or 0. So the for loop is able to iterate through all three types of entities and reset the same attributes for each. It then clears the path_array array.

Next up - adjacency

I now have to find a way to detect which nodes are adjacent to each other and only allow the user to build their path by using adjacent nodes. I was thinking of maybe somehow checking if there is a node between two nodes on either the X or Y axis and, if not, those two nodes are adjacent. Each instance of the node entity in a level might have its own array listing adjacent nodes in the controller class and then I can use this to see which nodes are selectable…

This is just a first thought and I’m not sure if it will work in practice, but I think it’s worth a shot. If it doesn’t work out I’ll scrap it and try something else.

© - 2021 · Liza Shulyayeva ·