King Charles is missing his gold!

I ported this little pathfinding/game type demo.

It originally was 100% in dutch, including variables and comments. Its 100% in english now.
It was also not in standard Java.
I have fixed most, but not all the bugs.
There were other misc changes I have made since the original.

Summary:
There are these knights that go out and find the random gold(random each time you load) and return it back to the castle.
There is no real “game” to it right now, its more of a learning/shared code type of thing.

Features, things to look at:
Java2D
Random tile variation(take notice of the grass, the slight variation in color makes it look good)
All graphics are made on the fly in game…no reference “image files”
The encapsulation of how they handle the graphics for different elements.
A different approach to path finding ( not better, but different, then typical types )
-Take note of “why” the knights get jammed about 15% of the time, its quite obvious if you see them get stuck and admire the pathfinding correction.

(They only have the foresight of a couple of tiles and don’t know how well enough how to navigate around things, There needs to be either a “return home and try again” or “randomization” of where to go, given the limitations of the current pathfinding. Ideally youd want a different system all together though

Incorporates multiple useful elements,
–logging feature(disabled by default)(minor logging is enabled)
–swing buttons
–game window

The pathfinding uses a step pathfinding, and I wouldn’t recommend looking too much at it, because its really finicky, and you should be using A* pathfinding anyways. The knights sometimes get stuck, I’ve fixed a lot of their jams, but they still get jammed sometimes, especially if you add more knights.

Pictures:
http://code.newrog.com/sites/default/files/1kc.png
http://code.newrog.com/sites/default/files/2kc.png

Demo:
http://code.newrog.com/sites/default/files/goldHunters.jar
http://code.newrog.com/sites/default/files/goldHunters-small.jar (smaller window)

Source:
http://code.newrog.com/sites/default/files/goldhunters.rar

Very impressive! I ran it a couple times but the knights never got jammed for me :stuck_out_tongue:
However, the window was too big for my screen so the entire world wasn’t visible. :confused:
I’m on a 1280x800 screen.

EDIT: My luck ran out after I posted this. In one try, two of the knights kept looping around each other forever, in another try, three of the knights were just frozen next to each other.

In the World.java on line 74, there is a “BOXSIZE” that can be adjusted. and it will automatically adjust the resolution and Everything in the game, even the window.

I have added an additional jar for demonstration purposes with a smaller box size, hopefully it will fit properly. Please see the original post

Nice, thanks for the source :slight_smile:

Pretty cool. :slight_smile: I’d recommend allowing the knights to pass through each other, which would solve your issue. To actually deal with it, I’d suggest giving each knight an ID, and then the one with the lowest ID always stops and waits until he is not adjacent to the the higher ID, or something like that. This stops them from constantly trading spaces back and forth.

This is a nice application of pathfinding, if we need short-sigthed enemies. I think it’s cheating a little bit to tell them where to go though (coords of gold) :stuck_out_tongue:

bug. never finishes, trapped forever