I love city building games and wanted to see if I could fit one in 4k. So all of you simcity fans have at it. Let me know about any balancing issues you might have and I'll try to make some quick updates.

V2:Roads are cheaperTime till next payday is displayed as a white bar3 Icons per row!

V3:Minimaps!Sped up traffic and power algorithms!Better color coordination!

For an easy start make sure that your first residential units are at least ~7 squares away from the power-plant. My basic start is Check out your land value overlay for more info.

It's difficult to gauge the time step in the game. Having some sort of indicator would be useful so that you can understand when things are going to happen, especially the removing of money due to maintenance. It's sort of difficult to figure out what's going on. I'm not sure what I'm doing wrong, but it doesn't seem like time is passing while I'm trying to play.

A reset button of some sort would also be nice. Having to reload the page when I just realized that I completely botched things (By building too many roads too early) is a PITA since my desktop's Java drivers are out of date and I have to do the whole "Run this time" thing each time.

A Bulldozer feature would be nice as well. Just something to remove what's placed there, like a road that you realized you didn't need.

Not sure how much more you space you have, or whether you can even implement these, but...

However, after I got a reasonable village (about 180 people, 4 industrial areas and 3 commercial areas) the game started to get extremely slow and the window turned white for some time. It seems like there is some loop that's taking up a lot of time.

Other than that I think a bulldoze function would be nice (and if it fits maybe a minimap, I keep losing my city when I go to other windows )

Thanks for all the feedback!I've changed the game around a bit so it should be a bit easier and run a little faster.

Unfortunately i'm pushing up against 4k really hard now so there isn't really room for a Minimap. I also had bulldoze in the game before but again 4k is maybe just a little too small for a full featured Simcity. Imagine that there is a very vocal group of activists in the town who insist on preserving everything.

I think the traffic detection loop may be causing slowdowns, if someone can post a screenshot with a really slow game that would be a big help.

I didn't really want power to flow through unbuilt zones but if that would be useful I can add it.

When I connect powerlines to the residential zone, which have roads connecting them to the Industry zone, they *might* start building houses. After restarting the game 3 times, I got them to build houses only once.

Initially, when you have a connected R-zone, you see the houses are built near the roads. Fair enough, so expand the road network to connect more houses to the industry... nothing happens, no new houses are built.

Hi, appreciate more people! Σ ♥ = ¾Learn how to award medals... and work your way up the social rankings!

@Riven, Are you sure you have a road reaching enough industry tiles? If a road borders an industry tile it only has access to jobs two deep. A road needs to be run on both sides of the zone to allow access to all of the tiles.

Oh I see. That Residential zone is in a poor land value zone due to the proximity to the industrial region and the Power Plant. People won't move in when the land value starts getting orange~red. If you click on the overlay you'll see that the residential zone you placed is almost in pure red. Too move people in that close to industry you have to start by building a little further away and then inch you way closer and closer as the newly built houses will increase nearby land value.

Blargh. You found me out, to save some bytes I was a little fast and loose on the edge of map calculations. I'll see if i can put in some failsafes that don't cost to much memory. As for the other slowdown ... I have 4 days left right

btw, is the placing of items bound to the mouseUp event? when I click somewhere and move the mouse during a slowdown the tile get's placed at the position where my mouse ends up (hence the odd road and powerline in the screenshot )

If the slowdowns are indeed because of traffic calculations, you don't have to update them each step, only when something on the map changes. It could be solved with a simple boolean check, so it shouldn't take up too much space.

I just jury rigged the game to skip traffic, so Now i'm sure its the power calculations. Its all a relic from when I had these grand plans of trying to limit the amount of power one plant could give, but that just ended up taking way too much space. I have to go to real work now but I'll try to fix this tonight.

Edge of the map failsafe - instead put 3 tiles of water around the map. Should be cheaper and it will make the game look better (you are on an island).

Speed - traffic and other calculations don't have to be done each cycle. Make a counter and update traffic like every 10 cycles. Or even better make the traffic update cycle based on number of population (the more population the rarer the traffic updates are, while interface behaves fast). Also, if you have other calculations (like energy) do these in other cycles that traffic.

Colours - you should make the colour of the button and building identical (it's confusing right now).

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.

"Traffic is calculated when someone moves in." - that explains the weird traffic behaviour (I first built all residentials and then built additioanl roads, but no one used it)

"Power is handled by doing a BFS every 60 or so frames" - why do you check power based on time? Shouldn't it be event based (when something is built it set all neighbouring tiles as powered)?

What's the point of landvalue? Does residential upgrade?

Pathfinding - I think the use of graph algorithms for such mini game is a waste. The map is rather small plus you have basicly unlimited memory, it would be more logical to use some fixed table algorithm like flood fill (since size is irrelevant). Plus it probably would let you save some bytes.

Power was checked based on time because I wasn't thinking straight when I implemented it

Land Value dictates whether or not a zone tile will be considered for buildup. If the land value is low, like near a power plant, no homes or comm businesses will move in. I wanted to make there be different classes of house but I'll need to find a lot more space for that.

I'm not sure I understand your point about graph algorithms. My implementation of BFS is the iterative approach which is basically identical to a 4way Flood Fill.

The traffic path-finding is basically the same as the above code but it instead of appending to the searchList we push. And it has to keep track of nodes visited.If you can think if a better traffic approach I'd love to hear it. Especially if I can implement it quickly

This City4K seems to be a complicated but very interesting game. My comment about it will not be as deep as some others : I just regret one can't move the map with the arrow keys or by grabbing it with the mouse.

This being a 4k entry, you can probably work around the entire issue by making 150 inhabitants the end goal. Then calculate a score based in the time it took to finish the game. This even adds some additional replay value. Win-win solution :-)

Hi, appreciate more people! Σ ♥ = ¾Learn how to award medals... and work your way up the social rankings!

If people won't move into your residential units eitherThe land value is too low, (Click on the purple V in the lower Left Hand Corners, if the Squares with power are red or orange they won't develop)There is no road they can use to get to a jobThere is no residential demandThere is no electricity

--- Algorithm changesI've changed any usage of arraylists to a strict array based approachThe array has to indexes one representing the top and the other representing the bottom. This means I can reuse the structure without any object creation or garbage collection.For Traffic I use a BFS to find the nearest job with an additional array tracking the optimal path to any given square (Dynamic Programming style.) Then after finding the job we walk back along the path array to get to the start position adjusting traffic along the way.

Regarding the power; if I understand correctly the only way to disrupt power right now is to build a road over a wire, right? So if you change that so it makes a road under the wire (like when you place a wire on a road) the power can only expand to new cells (cells that are powered will never lose power). That way you only need to check the neighbors of each new cell to see if it's powered (there are no new cells that require power but don't spread it, so this should work)

EDIT: just played it again and it seems to do a lot better already. The limiting factor seems to be the drawing now, when I click on the traffic overview the game suddenly runs a lot smoother (pop 450 city).EDIT2: I do realize this doesn't make any sense, trees shouldn't bee easier to render than buildings, but that's what I'm experiencingEDIT3: it doesn't seem to slow down much more after that, I'm up to 1000 population right now I did notice the traffic calculations might be wrong. I have a single road connecting my entire residential/commercial area to my entire industrial area and it's only slightly congested.

Power was checked based on time because I wasn't thinking straight when I implemented it

Yeah, it is strange how often we code things that makes us later puzzled how we could have done it that obviously stupid way Also, that's why I love competitions like that, it let you learn on OTHER people mistakes, which is always nicer than learning on your own mistakes

I'm not sure I understand your point about graph algorithms. My implementation of BFS is the iterative approach which is basically identical to a 4way Flood Fill.

I was trying to suggest this: "I've changed any usage of arraylists to a strict array based approach. The array has to indexes one representing the top and the other representing the bottom. This means I can reuse the structure without any object creation or garbage collection." So, has it worked out better?

Land value - do not make any checks if people can inhabit it or not (can always inhabit). Instead make the income of R and C zones equal to base income*land value. It will be both more realistic and use less code.

Classes of buildings - well, maybe you could make simply numerical levels of these (without gfx) and when you hover the mouse over it you see the house level? Or dynamically change the colour of the building without changing the image? Not sure if these would work through...

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org