Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  City4k  (Read 5060 times)
0 Members and 1 Guest are viewing this topic.
Offline RussS

Junior Duke


Projects: 3



« Posted 2012-02-24 06:22:59 »

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 cheaper
Time till next payday is displayed as a white bar
3 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.


http://www.java4k.com/index.php?action=games&method=view&gid=397
Offline UprightPath
« Reply #1 - Posted 2012-02-24 06:39:27 »

Several Comments from me:

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...

Offline Mike

JGO Wizard


Medals: 86
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #2 - Posted 2012-02-24 06:49:17 »

People refuse to move into my houses even though I tried to build my city precisely like in your screenshot above Sad

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Archibald

Junior Duke


Projects: 1



« Reply #3 - Posted 2012-02-24 09:48:12 »

Cute! SimCity in 4kb, I never knew it is possible Cheesy

Interface:
- make 3 buttons in a row instead of 2, also use 2 letters, this will reduce confusion. The first row is zones "RZ" "CZ", "IZ". The second is special "PP" "PL" "R" (road is one letter).

Balance:
- too difficult, can't reach even 1 population
- the maintenance cost for roads seems too high

Bugs:
- an empty zone does not relay power
Offline Aeroren

Senior Newbie


Medals: 1



« Reply #4 - Posted 2012-02-24 11:32:31 »

Took me a few tries to get people to move in, but I got it now.

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 Tongue)
Offline RussS

Junior Duke


Projects: 3



« Reply #5 - Posted 2012-02-24 16:04:40 »

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.

Thanks again and try V2!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2012-02-24 16:23:33 »

Either I'm missing something, or there are quite a few bugs.

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.

 Emo

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

Junior Duke


Projects: 3



« Reply #7 - Posted 2012-02-24 16:29:16 »

@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.

----         
OOO
OOO
XXX

Can you detail the problem with a picture?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2012-02-24 16:37:30 »


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

Junior Duke


Projects: 3



« Reply #9 - Posted 2012-02-24 16:43:52 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2012-02-24 16:57:44 »

Thanks, I built a nice town, then this happened:

1  
2  
3  
Exception in thread "Thread-11" java.lang.ArrayIndexOutOfBoundsException: 4130
   at a.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
I was building at the edge of the map.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2012-02-24 17:05:58 »

At a population of ~200 and ~100 roads, the game grinds to a halt. No exception, just 100% CPU usage and failing to respond to input. Undecided

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

Junior Duke


Projects: 3



« Reply #12 - Posted 2012-02-24 17:12:10 »

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 ... Huh I have 4 days left right Smiley 
Offline Aeroren

Senior Newbie


Medals: 1



« Reply #13 - Posted 2012-02-24 17:22:21 »

I made a quick image of a scenario where the game slows down a lot:

http://imageshack.us/photo/my-images/823/city4k.png/

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 Smiley)

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.
Offline RussS

Junior Duke


Projects: 3



« Reply #14 - Posted 2012-02-24 17:25:37 »

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.

Thanks everyone for your support!
Offline Mike

JGO Wizard


Medals: 86
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #15 - Posted 2012-02-24 19:03:12 »

Ah, you need to build power lines on roads but you cannot build roads on power lines, that explains it all Smiley

Got to 550 people but by then the game was so slow it was unplayable (I made more money than I could spend because scrolling or clicking buttons took forever).

Nicely done Smiley

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline Archibald

Junior Duke


Projects: 1



« Reply #16 - Posted 2012-02-24 20:54:30 »

Minimap - instead make the map smaller (it will prevent players from "losing" the city). And/or map coordinates display.

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).


Any chance of releasing the source code by the way?
Offline RussS

Junior Duke


Projects: 3



« Reply #17 - Posted 2012-02-24 22:43:46 »

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 Smiley
Offline Archibald

Junior Duke


Projects: 1



« Reply #18 - Posted 2012-02-25 00:18:53 »

Yes, you can make your code public anytime.

"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.
Offline RussS

Junior Duke


Projects: 3



« Reply #19 - Posted 2012-02-25 01:20:37 »

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

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
while (!searchList.isEmpty()) {
                        Integer currCell = searchList.get(0);
                        power[currCell] = true;
                        searchList.remove(0);
                        for (i = 0; i < 4; i++) {
                            offset = upDownLeftRight[i];
                            if (currCell + offset > 0 && buildType[currCell + offset] > TRANSMITSPOWER) {
                                if (!power[currCell+offset])) { // This used to check a list of visited cells hence the slowdown
                                    searchList.add(currCell + offset);
                                }
                            }
                        }

                    }

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  Grin
Offline StephR

Senior Duke


Medals: 9



« Reply #20 - Posted 2012-02-25 01:43:15 »

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.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #21 - Posted 2012-02-25 02:03:10 »

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
Offline RussS

Junior Duke


Projects: 3



« Reply #22 - Posted 2012-02-25 02:08:05 »

Good suggestion!
Offline ReBirth
« Reply #23 - Posted 2012-02-25 04:23:16 »

I don't understand. Why can't I get population?

Offline RussS

Junior Duke


Projects: 3



« Reply #24 - Posted 2012-02-25 08:50:30 »

If people won't move into your residential units either
The 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 job
There is no residential demand
There is no electricity


--- Algorithm changes
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.
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.
Offline Aeroren

Senior Newbie


Medals: 1



« Reply #25 - Posted 2012-02-25 11:14:22 »

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 experiencing
EDIT3: it doesn't seem to slow down much more after that, I'm up to 1000 population right now Smiley 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.

I do really like the game btw, in case that wasn't obvious Smiley
Offline Archibald

Junior Duke


Projects: 1



« Reply #26 - Posted 2012-02-25 12:41:00 »

Power was checked based on time because I wasn't thinking straight when I implemented it Smiley
Yeah, it is strange how often we code things that makes us later puzzled how we could have done it that obviously stupid way Smiley 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 Smiley

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." Smiley 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...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (38 views)
2014-10-27 03:28:38

TehJavaDev (29 views)
2014-10-27 03:27:51

DarkCart (43 views)
2014-10-26 19:37:11

Luminem (24 views)
2014-10-26 10:17:50

Luminem (29 views)
2014-10-26 10:14:04

theagentd (35 views)
2014-10-25 15:46:29

Longarmx (63 views)
2014-10-17 03:59:02

Norakomi (61 views)
2014-10-16 15:22:06

Norakomi (50 views)
2014-10-16 15:20:20

lcass (46 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!