Game Controller Engine

I needed to add some gamepad and joystick support for the new game I am working on, and a quick Google revealed that there isn’t much out there. So I whipped one together in Java using the JNI and put it on Github here.

It’s a real mix of technologies, so I learned a lot. It uses Ant so I can work on both the Java and C code in Eclipse, and it uses regular MinGW to build the 32-bit native library while using mingw-w64 to build the 64-bit target. I couldn’t really get mingw-w64 to make the 32-bit target, so I fell back on the vanilla. I could hack away at it, but I am too lazy.

Eclipse was really snooty about getting things just right for the JDK and which JRE it was using. There is a whole mess with JAVA_HOME and Ant that inspired me to give up and just blast a solution in (e.g., define JAVA_HOME and ignore the built in java.home property in Ant, which I think points to the directory that has the JRE that Eclipse/Ant are using to run, which is useless when you need to use the JDK).

The engine library currently only supports Windows, and I have only really tested it on Windows 7 64-bit. The 32-bit should work too, but I have to find a 32-bit machine to test it on. I think I have a Windows XP box laying around somewhere.

If you get an itch and want to add Linux or Mac support, feel free to do as thou wilt with the Github repository.

Ludum Dare 23 Tiny World Done: Atomic Bug!

Well, it was really rough this time but I finished. My original idea was kind of neat, I thought. I planned on having a construction system, starting from the tiniest world (quarks and gluons and neutrons, oh my!) and using them to build atoms, and using those to build cells, and using cells to build parts for bugs. Then those bugs could be sent out to solve puzzles to escape from a maze out into the big world.

I didn’t get close to making that! So halfway through Saturday I decided to take the atom idea and recalibrate…and make it so you blow stuff up. I guess that’s my destiny.

So the actual game output for Ludum Dare 23 is Atomic Bug, where you combine atoms to make weapons to kill a bunch of bugs. This is a tower-defense like game, but I didn’t really get to finish it. The obvious thing missing is more than one combination of atoms to make weapons. I wanted to add lots more enemies, and weapons that can block the lane. I will flesh this out over the next few days though and try out those ideas. I think this game could be fun!

My entry is here:

You can play Atomic Bug here.

Extracting Layers from Inkscape (Pulling Teeth)

Inkscape is probably the greatest thing since baloney on bread, and it’s free. That’s a real deal!

Basically, it is a powerful and feature-filled vector graphics editor, and I have an easier time using it than I do with Photoshop. That’s because I am an art noob. But armed with Dmitry Kirsanov’s The Book of Inkscape and things like these awesome tutorials from Chris Hildenbrand, you can get some really nice results.

One thing that I use Inkscape for is animating sprites. is very nice for this as well (just tabbing between frames is awesome), but I had to cobble together a batch file and the obscure pdn2png to get a good workflow for saving frames into a usable form. I basically wanted to be able to edit the frames of a sprite and hit a button to export everything out to PNG files. There are other programs that are specific for animation that make the process of animating much easier, but they generally cost money or are not very nice to edit art with

Inkscape has some exporting to PNG capabilities from the command line, but you need to know the SVG ID of the object you want to export. In my case each frame is a group within the drawing. Inkscape lets you name each group (groups are SVG objects as well), but this is an extension to the SVG specification. The actual ID that you need is obscured at the Inkscape level. So it is possible to export the group from the UI using the Inkscape label, but you must know the SVG ID to do this from the command line.

Needless to say I was bummed!

Even worse, I want to have each frame of animation have discrete parts. So if I have a character, I want each frame to have a sub-layer of the arms, the legs, the eyes, etc. That way I can grab that sub-frame PNG and animate it separately, allowing me to articulate different frame parts as an aggregate sprite.

So, I dropped using scripting and went full on code! I messed about with the SVG file format and basically just brute force wrote a parser in Java that will traverse the XML for the SVG format and extract layer groups by using the Inkscape label. The Java matches the Inkscape label to the SVG ID, and then calls the Inkscape program with command line arguments to make the PNG. This allows me to have an SVG drawing, make several layers and sub-layers of animation for a sprite, and run a batch file that calls my extractor to organize the frames in nice ways.

You can get ExtractInkscapeLayers for Windows here. I will get around to posting the source at some point if anyone cares!

Procedure for a Procedural Maze: Try a Lot of Stuff

Procedural generation of content is neat, but I wonder if its not better to just make it by hand! There are a lot of wrinkles to consider, but I wanted to focus on the labyrinth type. I had to try out a bunch of different methods, but this one seems to get the result I want. Basically, the maze generator test program generates a tightly packed series of rooms connected with twisty corridors. I hope that all the rooms connect!

MazeTest labyrinth maze generator

I have more to add to this test program, like a BSP tree room generator, a cavern generator, and adding canned rooms to a randomly generated map.  But most of that is done…this is the last bit of technology I need to finish testing before moving on to actually putting it all together in a game!

So try out the MazeTest!

Ludum Dare 22

Well, Ludum Dare 22 is a little more than four days away. The anticipation is killing me!

I am not really good under pressure anymore…I tend to think a lot before I do something in my old age. I think that a game-creation contest is good therapy for this. I think that the pressure of creating a game in 48 hours will force me to get rid of my tendency for internalization and get some things done.

I will be streaming live the whole time I am working (yes, there will be sleep and eats and some guitar playing if I get stuck). I am going to try to write up a time plan too, but that presumes I finish up the helper code I need to have ready before the compo starts. It has to be in my dropbox before the Friday deadline.

So watch me here:…it is sure to be a spellbinding video experience.  A whole two days of typos and bad doodles and hopefully a “finished” game!

The Video Age

I made a quick YouTube video of my graphics test program. Whee, it’s like the space age.

The neat thing (at least to me) is that the cutter beam from the game is actually a texture that is stretched and rotated to the location of the mouse. That solution seems to work really well.

Java Enumerations, or Hey, You Aren’t Just an En-number Anymore

Java has some cool features, but one thing I really like are enumerations. For my project I need a damage type, so I made a base class for it:

public abstract class Damage
    public enum Type

        private final String desc;
        private final String user;

         * Construct the enumeration with the description given
         * @param desc The description of the type
        private Type(String desc)
            // save the description in all uppercase

            // the user first character is upper case
            // make the characters after the first lowercase for the user description

         * Get the description of the type
         * @return A string describing the type
        public String getDesc()
            return desc;

         * Get the user-readable description of the type
         * @return A string for users describing the type
        public String getUser()
            return user;

        public String toString()
            return user;


     * Get the damage for the damage type
     * @return The damage caused.
    public abstract int getDamage();

     * Get the damage type for the damage
     * @return The damage type
    public abstract Type getType();

     * Get the type of the damage given a string describing the type
     * @param desc The description of the damage type
     * @return The type of the damage
     * @throws IllegalArgumentException if the description has no match to a damage type
    public Type getType(String desc) throws IllegalArgumentException
        // if the description is empty, then make this normal
            return Type.NORMAL;

        // loop through the values in the damage type enumeration
        // using the enhanced for loop after changing the enumeration to an array
        for(Type damageType : Type.values())
                // matched the damage type, return this type
                return damageType;


        // no match
        throw new IllegalArgumentException("Cannot match damage type to description "+ desc);



This base class is really just two things:  an interface to get the damage amount and type, and a container for the enumeration I use for the damage types. The neat thing I find is how I can match the damage type easily to a string by using Java’s enhanced for loop form and converting the enumeration to an array with the values() call.

That enhanced for loop may be old hat to Java programmers, but coming from a C++ world it is very cool. I am sure it boils down to the same-old-thing I would write in C once it goes through the byte code, but it is much more readable. Why not be able to iterate through the values in an enumeration? It is just intuitive and very usable.

But the really neat thing is how enumerations aren’t just for numbers anymore. I like being able to attach multiple data to the values in the enumeration. So it makes the enum type name a misnomer, but it is really useful. Just about every beginner Java book starts with an example of this a few sections in, and I believe that this is so they can show off this powerful capability to any C programmers delving into the language.

Well, I’m convinced. Programmer jealousy is a wonderful thing…maybe this will show up in C++ sometime? Strongly typed enumerations are not enough!