Not NaNo Day 7

I decided to put off fixing the serious issues around chunk generation and scrolling and instead work more on the networks. I created a set of white (as opposed to the orange) network sprites to use for the un-powered networks.

I implemented the A* algorithm, though in the future I may need change it to a Dijkstra’s as there will be multiple energy sources that can all supply a network. This worked fine, but I realized that I have no way of rechecking a network to see if it has been connected. The sprites don’t know how to update. This might be a good time to figure out how cocos2d’s event handling works, and have a network node whose status has changed have a way to tell others to update, though I’m not sure what the best route to take here is.

My first implementation can properly determine if a energy network node is connected when it’s built and draw it as powered/un-powered, but it doesn’t support updating yet.

cocos2d energy network status test.PNG
Un-powered energy network in white, powered in orange. Next up, redrawing the network on state changes so things can become powered and un-powered.

With the basics working, I moved on to making the network update when connections were added or removed. I did this by finding all of the nodes connected to an energy source, in this case the one city core, and powering them. If they’re not connected, they’re not powered. It works, but it starts getting really slow after about 50 nodes, so I’ll need to put some time into optimizing the graph traversal algorithm to make it usable with large networks, perhaps storing each disconnected sub-graph and only updating as needed.

cocos2d energy network redraw.gif
Networks now properly propagate whether or not they’re powered.

After that part was working and networks now properly deliver (or don’t deliver) energy to sinks of energy, I implemented protection towers switching on or off, including their safe areas when they lose energy. From a UI perspective, I should also give an indication on the tower that it’s off, not just have the safe area around it disappearing. Network propagation is still slow, taking nearly a second to switch the energy on and off in the below gif. I may need to address this sooner rather than later.

cocos2d energy network protection test.gif
Enabling and disabling safe area from protection towers by breaking their energy network connection. 

Things are continuing to look more and more game like as I add mechanics, but some of the potential serious performance issues may need addressing sooner than I’d like. Network changes are slow. The issue with chunks is currently less of a problem, as it seems to be more likely to be an arithmetic error than something more serious.

I also tweaked buildings to swap sprites when they’re on or not, giving a visual indication of whether or not they’re receiving energy or not. I also created sprites for off as well as on. Art is still placeholder art, because I don’t want to focus on art until I can properly display it.

cocos2d building energy toggle.gif
Buildings now visually change when they’re not receiving energy.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s