Automate Everday Tasks with Ant
Alright, so I've got to confess that I love to write makefiles and similar things. There's something immediately rewarding about automating commonly performed tasks. That's why I thought I would share some of the cool things you can do with ant.
Ant is a tool written in Java which aims to improve the build process. It does this by providing a layer of abstraction so that your build files can run across platforms. In addition, ant provides a lot of useful tasks to bear on the build process effectively letting you write mini-scripts. Awesome.
Enough talk, let's take a look at how ant can speed up developing your next (Slick) game.
Setting up your development environment
Pesky native libraries make setting up Slick a real pain, especially for beginners...
<!-- Set up the game environment by preparing the natives. -->
<target name="setup" depends="check-setup" unless="setup.exists">
<mkdir dir="lib/natives" />
<unzip src="lib/natives-win32.jar" dest="lib/natives" />
<unzip src="lib/natives-mac.jar" dest="lib/natives" />
<unzip src="lib/natives-linux.jar" dest="lib/natives" />
</target>
<!-- Determines whether setup has been run. -->
<target name="check-setup">
<condition property="setup.exists">
<available file="lib/natives" type="dir" />
</condition>
</target>
So, let's say you've got a directory, lib which has three jar files in
it:
lib/natives-win32.jarlib/natives-mac.jarlib/natives-linux.jar
Wouldn't it be nice if you could extract all of the native libraries and
dump them into a lib/natives directory? Well that's exactly what the
above script does. Even better it will only create the lib/natives
directory once! The check-setup target looks for the lib/natives
directory and if it exists sets the property setup.exists to true thus
aborting the process. Great!
Compiling and archiving
Next up the hello world of build processes. Let's say you want to compile
all your code in src into class files in bin. Naturally, the next step
is to archive your bytecode and any resources in res so you can
distribute everything...
<!-- Compile and archive the game. -->
<target name="build">
<antcall target="compile" />
<antcall target="archive" />
</target>
<!-- Compile the code put results into bin. -->
<target name="compile">
<mkdir dir="bin" />
<javac destdir="bin" debug="on">
<src path="bin" />
<classpath>
<!-- Assumes Slick is in your lib dir! -->
<pathelement path="lib/slick.jar" />
</classpath>
</javac>
</target>
<!-- Jar compiled code and place result into current dir. -->
<target name="archive">
<jar destfile="./game.jar" manifest="manifest.txt">
<fileset dir="bin" />
<fileset dir="res" />
</jar>
</target>
Alright, so now you can call ant build to compile and archive the code!
Notice that this will include a manifest saved as manifest.txt. If
you're using Slick then I encourage you to adopt my manifest as a
template, here it is. Finally, notice that this creates game.jar
feel free to rename things, but make sure things are consistent across
your ant file!
Running the game
Last in this brief tutorial is a task to automate running the game. It turns out that you need to pass some command line arguments to the JVM in order to run Slick. This is necessary for lwjgl to find its native libraries, yuck. However, with this simple script you (or the noobs who want to play your game) will never have to worry about it.
<!-- Run the game. -->
<target name="run" depends="setup,build">
<java jar="./game.jar" fork="true" failonerror="true">
<jvmarg value="-Djava.library.path=lib/natives" />
</java>
</target>
This last command will try to execute the jar created by the build command passing the JVM the necessary arguments. Notice that it "depends" on setup and build. That's because it wouldn't work if the natives weren't in place and the jar didn't exist, so it makes sure they are by calling those tasks first.
So there you have it; just a few handy tricks for playing with Slick. If you want to see some more cool tricks then check out my build file. I've got some additional commands such as cleaning the workspace and preparing your jar for distribution as a webstart. If you have any cool ant tricks let me know in the comments!
Finally, here's the build file we just created. build.xml
Game Design and Iterative Development
I recently started developing my next game, Shade. The fundamental gameplay was outlined by Lost Garden but there are still a lot of unknowns. The truth is, for any game there are a lot of problems which will not be fully understood until further in the development process. For instance, in Shade the player moves around obstacles to collect mushrooms. The mushrooms only grow in shade cast by the obstacles. What should the obstacles look like? What makes collecting mushrooms fun? Where is the challenge? Sure, you can take a shot at answering these questions on paper, but it's ...
Read moreHow to Find and Use Artwork for Tile Based Games
Here's another article for the uninitiated. I found that creating artwork which was ready for use in a game was very difficult. I easily spent hours on this or that tileset only to find that I had messed up somewhere along the way or didn't know what to do with the end result. Now after spending the summer screwing up I feel like I've got the hang of it so I'm going to write it all down in case someone finds themselves in my position....
Read morePhysical Queries for the Math Challenged: Ray Casting
Hopefully, you've read my previous article on setting up the basic grid data structure and peforming collision detection. If not quickly go read the section on the grid since we'll be leveraging that data structure to perform ray casting. Ray casting is a powerful and reasonably simple technique which can be used to answer several questions about the environment....
Read moreGame Artwork: City Tileset
After Forte I dreamt up another game -- a RTS based in a city. Anyway, I'm still toying with the idea, but as things start to get busier I worry that I will never end up using the tileset I created for the game. That's why I thought I'd share the tileset now in case someone else can use it. Each tile is 48x48 pixels. Each tile is some building or relevant piece of scenery. Also, each building contains a score -- this can easily be modified via Photoshop or your favorite editor. Anyway, enough blather here's the tileset:...
Read more