I’m going to release the source for all of my games once I clean it up so it won’t be so embarrassing. We are allowed to display code post contest right?
I’ll give you the gist of how the game runs as is:
The game is basically a cellular automata where every cell has a bunch of things that get computed. Since there are way too many cell to iterate over every frame the game tries to do as many rows of the map as it can prior to the nextFrameTime.
Power is handled by doing a BFS every 60 or so frames but I realize this is killing the program because of how I have it built. Long story short, a really long array list is built and I use arrayList.in() which is causing the slow down. I built it this way originally so that I could have integer values for the amount of power in the power lines and there wasn’t a clear way of knowing if the BFS had visited a node before. This was a mistake. I’m going to fix this by switching power to being a binary thing that way I can keep the search from backtracking by simply not executing on nodes that are already on.
Traffic is calculated when someone moves in. A DFS is called along the roadway which stops if it hits max traffic at any square. All Squares visited are incremented. There is another array list here but it doesn’t seem to be slowing much down. I know this isn’t perfect since it can add traffic to non-driven roads but it seems to work pretty well.
Landvalue is calculated by averaging the land-value of all of the neighboring tiles with a certain bonus depending on the built structure. Powerplants give off a huge negative bonus which is why residential units won’t move in there.
I wanted to program in move outs and derelict buildings and fire and a whole bunch of other stuff but I hit 4k much faster than I thought I would.
One of my real downfalls in making this was that I didn’t really think out how the graphics were going to be done when I started construction. Currently every cell has a representative short in an array which tell the program which sprite to draw for that cell. When a cell needs to be changed the graphic array is sent to gNeedsUpdate which then sorts out which image to draw. This wouldn’t be so bad if I had a 1 : 1 correspondence between buildingCode and graphicCodes but I don’t because I failed to plan. I’m pretty sure this code could have been condensed had I thought about it a bit more.
TODO
Tonight my plans are to remove the MouseUp and Down logic that was noted by Mickelukas. I was trying to get an approximation of a click event by keeping track of when the program recieved both a mouseup and mousedown in the same frame. By changing this to operate only on mousedown I should save some bytes that might let me get the minimap in.
I’m also going to change the BFS for the power-plant so that it doesn’t require the vistednode array-list.
@Archibald thanks for the Water Idea, that will be really small to implement compared to me fixing the array bounds checking since it actually happens in lots of places in the code.
Also I’ll change the colors