Sometimes you do need to be away from a problem to realize what the solution is to it. Within five minutes of sitting down to figure out why I couldn’t remove sprites, I’d figured out a solution. I realized that I was already doing it with the selection cursor that followed the mouse around. Why I didn’t realize that when I went to try to remove buildings, I’m not sure. Name the sprite something meaningful, and them call remove() on it. Simple, and I spend way too much time yesterday not realizing what I needed to do.
Next I worked on removing the safe area overlay hexagons. This was relatively straightforward, once I finally realized what an error message was trying to tell me.
The algorithm I implemented is probably going to be pretty slow with more than a few chunks, so I need to figure out how to mark only specific tiles as dirty so that only they can be updated when it’s time to re-render the scene. I also still need to limit drawing to the viewport.
One thing I may need to figure out before is how to merge sprites. There are 6 edges to a hexagon, and that means that there are 26 (64) possible combinations of anywhere from 0 to 6 edges. I’m probably not going to draw (definitely not by hand) all of the combinations, so I might generate them dynamically and runtime. I say “may need to figure out” because drawing up to six sprites on a hex might also continue to work fine. We’ll see.
I also noticed that I’d inadvertently made removing a protection tower made safe areas that weren’t around a city core unsafe, even if another protection tower was making that area safe. Now adding a tower makes the area +2 safer, and removing it makes it -2 safer. I doubt there’s going to be any game mechanic around it, but it was a quick code fix.
In testing this, I noticed that I have some serious issues with scrolling and chunk generation. Chunks generated at the beginning align properly, but after that, everything seems to go off the rails. Something in my math is wrong and coordinates aren’t lining up with each other properly. I’ll need to fix this soon.
I decided to work on something fun, and getting new things drawing (or not drawing) is more fun than figuring out why existing things aren’t drawing properly. So I created a test sprite for the energy network. It doesn’t quite align as nicely as I’d like, but call it placeholder art for now.
Having already worked out the hard part of adding and removing sprites that depended on their neighbours, adding and deleting the networks was relatively straightforward. The only wrinkle was that neighbours needed to have their connection removed. My implementation removes all of the connections from the neighbours right now, but I’ll try to fix that later.
Next, I want energy networks to be connected energy networks. Right now a disconnected network is the same as a connected network, but energy shouldn’t flow to networks that aren’t connected to an energy source. Adding this is going to take some work, and I’m going to need to run a graph traversal algorithm to find out if all of the network pieces are reachable from the source (and multiple sources in the future), and if not to power them off. This will change the sprite, but weapons and protection towers should shut off as well. Right now protection towers are always on.
I’ll also work on implementing the control network next. I haven’t decided if I want networks to overlap. I think so, otherwise building networking will be a nightmare or impossible, but I might limit how they cross, depending on how it feels to play. I’m happy to be getting into subjective things such as how building networks actually feels.
The header image, shown below as well, is sort of the sum of the progress right now in terms of building. There are a couple things I’d like to tweak if I’ve got the time, because I don’t like how the networks form triangles at junctions. It makes sense, of course, but it doesn’t look good. I also don’t like the jagged path vertical networks take, but there isn’t really anything I can do about that with my hex limitations.