Friday, March 8, 2013

Google Code Repository

I have opened up a Google Code repository where you can go and checkout the source code as we work through it. Check it out at

The code is licensed under the New BSD (BSD 3-clause) which more or less says you may do whatever you want with the code, but I won't assume any liability for anything about it.  The code is hosted using Subversion, for which you can download an eclipse plugin.

To check out a particular version of the code
  1. Install the plugin
  2. In Eclipse say File->Import
  3. Find the option "Project from SVN" and click it
  4. Say "Create a new repository location"
  5. Under URL, say ""
    • Or replace the date with whichever version you want
  6. Go with the Head Revision (I don't really know what this means...)
  7. Check out as a project configured using the New Project Wizard
  8. Give the project whatever name
  9. Do the same for /GameXYZ-desktop
  10. You still have to put the .jars in the buildpath and set project dependencies, but then it should work!

To check out the most recent
Use this URL: ""

As time goes on, that most recent version may become outdated.  When that happens, right click on the project, go to Team->Update.

There are a few changes to this code from my last blog update that need to be mentioned:
  • MapTools can calculate the "raw" distance between two cells, that is, how many cells they are apart from each other.  This was confusing to do for a hex map, and probably isn't very optimal, but it works!
  • The resource "images" file structure is a little updated
  • I created my own sprite character animation that fits well into a grid cell (32x32 image) - it was fun to do, and I may post a tutorial on how I did it later (note - I suck as an artist, so even if you have no artistic talent you may be able to do something like these)
  • n, wmult, and hmult have been moved to from MidpointDisplacement to HexMapGenerator.  I will probably someday move smoothness and all the thresholds there as well
  • The GameMap component now has a Texture which builds itself upon instantiation, holding an image of the overall map where each cell takes up a single pixel.  This was done using Pixmap from libgdx.  The code is pretty straightforward except for using Pixmap.Format.RBGA8888 - I'm not totally sure what this format means and why I had to use it.  But when I used the other formats, it looked terrible.  My getColor() method hardcodes which color to use for each terrain type.  MapRenderSystem has a line commented out which draws this map at (0,0).
  • I added a FloatPair class, so I can have a Pair not just with ints.  I wanted to redo Pair as a generic class (i.e. Pair<Class1,Class2>) but when I did that  Java wouldn't let me make an array of Pair<Integer,Integer>, which I use to return a list coordinates of neighbors.  It's supposedly possible to do it by using raw types, and not telling the compiler that they are supposed to be Integers, but that seems dirty and may not be available forever.  So I just made a separate class for floats.
  • MapTools has a method which window2world() can figure out what hex cell you're clicking on, depending on where the cursor is in the window.  This replaced the hardcode in PlayerInputSystem which did the same thing.  I want to implement the reverse, world2window(), but haven't gotten around to it yet.
Here's a screenshot of its current incarnation:

You have gained 50 XP.  Progress to Level 3: 350/600

1 comment:

  1. Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.IndexOutOfBoundsException: 0
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$
    Caused by: java.lang.IndexOutOfBoundsException: 0
    at com.badlogic.gdx.utils.Array.get(
    at com.artemis.EntitySystem.process(
    at com.badlogic.gdx.Game.render(
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$

    I got this Error when import your "2013-03-08/GameXYZ" project, can you recheck the project again plz.