Archive for September, 2008

Mini Tutorial: Making Java Webstarts

Here is a quick an easy tutorial for making a Java Webstart version of a Slick based game with the help of Eclipse. A more thorough wiki on the subject is available here, and an older and I think slightly out of date document is here.

Create a Jar file

First, right-click on your project and select “Export…”

Second, select a Java – Jar File.

Third, choose “Export generated classes and resources”, and put checkmarks next to any folders in your project which contain either source files or resources (images, sounds, etc). Fill in a name for the exported jar file, and hit Next.

Fourth, (optional) select the “Save description…” box and put in a place to save your export properties. This will allow you to easily export your jar file again later when you want to update your webstart.

Create a JNLP file

Fifth, we create a .jnlp file. This provides the meta information about your project like where it is located on the web, and what other libraries it requires. In Eclipse, choose to create a new File, and name it yourproject.jnlp.

Sixth, fill in the file with this template (borrowed from the Slick wiki)

<?xml version="1.0" encoding="utf-8"?>
<jnlp
  spec="1.0+"
  codebase="http://www.mydomain.com/games"
  href="mygame.jnlp">
  <information>
    <title>My Game</title>
    <vendor>My Vendor Name</vendor>
    <homepage href="http://www.mydomain.com"/>
    <description>My Game</description>
    <description kind="short">My Game</description>
    <icon href="icon.gif"/>
  </information>
  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+" max-heap-size="128m"/>
    <jar href="mygame.jar"/>
    <extension href="http://slick.cokeandcode.com/demos/slick.jnlp" version="0.4"/>
  </resources>
  <application-desc main-class="MyMainStartupClass"/>
</jnlp>

Seventh, replace the generic info with the specifics of your project. In particular, you must specify:

  • codebase: the URL for the directory where your .jnlp and .jar files will eventually be stored
  • href: the name of the .jnlp file you just created

The title and homepage you can fill in as you wish.  In the <resources> section you can specify if your code requires a specific version of Java. The second line <jar href=”mygame.jar”/>, should be replaced with the name of the .jar file you made way back in step 3. Finally, the <application-desc main-class=”MyMainStartupClass”/> should specify the class in your project with the “main” method.

Send it to the web

You have now created the two files you need.  All that remains is to upload the .jar and .jnlp files to your webserver.  Be sure that you place the files into the same exact directory that you specified in the .jnlp file!

Tenth (sorry we skipped a few numbers), open up the URL of your .jnlp file and play your game!

What if it doesn’t work?!

A few things can go wrong.  Most comonly, you don’t set a path or file name right for either the .jnlp, .jar, or main class. Double check those first. Also, keep in mind that you cannot just change a local version of the .jnlp file on your desktop and double click it — you must upload the changed file to the server to make the changes have any effect.

If going to the .jnlp URL just results in showing you the text inside of the file, then you need to tweak some settings on your web server so it understands that web clients don’t want to read XML, they want to play your game! A couple of solutions to this are available here. Most likely you can fix the problem by adding these lines to a .htaccess file in the directory with your .jnlp:

AddType application/x-java-jnlp-file .jnlp

Hope that helps!

Leave a Comment

Isometric Terrain Generator

I’ve been trying to learn about automatic terrain generation and different types of tile maps.  Luckily, I stumbled on a great tutorial about generating nice random hilly terrain, as well as a few tutorials on rendering tilemaps both from overhead and isometric views.

I decided to put my new knowledge to work to make a simple heightmap generator combined with a tile viewer. Currently my tiles are just filled in squares, but I think it gives a nice feeling so far. It supports both an overhead view and an isometric perspective. The isometric view is generated by some simple transforms on the overhead one.  I’m hoping to write up the details of how to make this work later.

You can try it out here.

Controls:

  • <space> generates a new random set of terrain
  • <I> toggles between an overhead and isometric view

Resources

Leave a Comment

Pixel Art

I’ve been doing something completely different for a bit.  I’m taking a break from space ships to work on medieval fantasy world adventure sprites. This started when I stumbled on to the Free Pixel Project, which has become a collaborative effort to make a bunch of simple RPG-style sprites based on characters from a web comic (or so I gather).

Nobody had worked on the sprite sheet for a while, so I spent some time fixing the position of the sprites and filling in a few more animations.

Changes:

  • Standardized offset for all sprites. Now both forward and back facing sprites are 2 pixels above the bottom border.
  • Added walking up and down animations for the bald, dwarf looking dude.
  • Gave better haircuts to all the guys who used to have really short hair from the back.

Here is the top part of the updated sheet (Click for the full version):

And if it is of any use to anyone, here is a photoshop .psd file with the characters and background split into different layers. This makes it a lot easier to move them around and extract the ones you want.

For reference, the file I started with was this one.

Licensing: I relinquish all rights to the original creators, which released it as Creative Commons.

Comments (1)

Space Combat Test – A Failed Experiment

A while back I finished a very simple test for the combat planned for my game. Unfortunately, I’ve become (mostly) convinced that it’s not really going to be the feel that I’d like.

You can test it out here.

Use the arrow keys to turn and accelerate and space to fire.  You can restart with R and quit with escape.

I feel like the fast paced combat is too fast and hard to control in any interesting way.  Here are some possible ways to improve it:

  • Make lots of small weak enemies – If they can’t do too much damage, then it can be fun to zip around and watch them all explode.  This isn’t really the direction I want my combat to go though.
  • Reduce rate of fire significantly – Adding more strategy to aiming would probably require a change to a WASD+mouse control scheme. This would give the player a lot more precision in where they are shooting (although it does make the control scheme more complicated).
  • Add obstacles – Currently there are planets floating around which have no real purpose other than to give you a better sense of movement.  If these were asteroids that needed to be dodged, or could be used for cat and mouse style fights it would be more interesting. Unfortunately, this requires much more intelligent AI.
  • Add shields and colliding missles – Allow the player to deflect shots by pressing a key or to shoot down approaching missles.  If the player only has a limited amount of energy that is used for either shooting or shielding, this could be interesting.

There were a few more ideas suggested on the forum where I initially posted this.

In the end, I’ve decided to make a fairly large change and switch from realtime combat to a turn based system. My hope is to make the game more RPG-ish where the player has a small squad of ships (the “party”) each of which may have different specializations (“classes”).  I’m going to try a combat system along the lines of Final Fantasy first (not that I have much experience with the game).  Hopefully there will be enough options available to the player at each turn that it will be sufficiently interesting.  In any case, the RPG elements of leveling up your captain and improving your ships’ loadouts should add some extra interest.

Leave a Comment