Outpost is a 3D Java demonstration game using the Eclipse IDE, the  JPCT 3D Java graphics engine, and SoundSystemJPCT, the JPCT friendly 3D sound library. The program was adapted from the Oupost game in “Tricks of the Windows Game Programming Gurus” by Andre LaMothe. LaMothe’s version is substantially different, being written in Visual C++ and using the DirectX engine. A screen shot is shown below:


 1. Gameplay

Being a demo game, the gampeplay of Outpost is minimal. There is space station surrounded some enemy gunships, some killer drones, and some asteroids. The player is flying the little white spaceship (the Wraith) and taking pot-shots at everybody else. If you’re in range, the enemy gunships will track you and open fire at timed intervals but to no effect. Similarly the killer drones will track and try to ram you, but all they do is blow themselves up.

There are limits to the game in that if the Wraith tries to go outside the range it will simply stop. The asteroids on the other hand will re-appear on the other side of the screen similar to a side-scrolling game.

In space, no one can hear you blow up, so I didn’t worry about explosion sound effects, but I did add sound for the Wraith and gunships lasers. The whole thing is accompanied by some cool Star Trek background music. .All the models were free models found online.

1.1 The Station

The space station is the centre of the game. Most objects will simply bounce off of it. Drones will helpfully blow themselves up on contact. If you open fire on the station it will explode as a grand finale.


1.2 The Wraith (the player)

The Wraith (named after the ship in LaMothe’s book) is the main player. It’s pretty much impervious to harm, but a transparent green force field will surround it during collisions (bullets, asteroids etc).


1.3 Enemy Gunship

The gunship is a not very effective AI controlled enemy. If the Wraith is within range, the gunship will track it and open fire at timed intervals (to no effect). A transparent red force field will surround the gunship during collisions (again to no effect). If the Wraith opens fire on the gunship it will blow up.


1.4 Killer Drones

The so-called killer drones will track the Wraith if its within range then try to ram it and explode. It looks nice but doesn’t do any damage yet. If you open fire you can blow it up.


1.5 Asteroid

There are only three asteroids in the game initially. If you shoot them they will break up into three more solid asteroids, until they get to a minimum size and disappear. Once you start splitting asteroids, you can have a fair number of them flying around  the screen

asteroid1.6 Heads Up Display

hudThe heads up display can be toggled on or off by pressing the ‘H’ key. The game objects are displayed in the following manner:

Space station   – large light green circle at the centre.
Wraith               – small red square
Drone                – small white square
Gunship             – small dark green square
Asteroid             – small brown square

2. Controls

Any relation between the laws of physics and the Wraith controls is purely coincidental. The camera is permanently positioned behind the Wraith. Pressing the ‘+’ and ‘-‘ keys on the numerical keypad allows you to zoom in and out of the view.

The other controls on the numerical keypad are as follows:

  • Up arrow  – applies forward thrust and increases your  forward  velocity.
  • Down Arrow  – applies reverse thrust and increases your reverse velocity (or decreases your forward velocity)
  • Left arrow  – rotates the ship counter-clockwise by a finite amount, then stops
  • Right arrow – rotates the ship counter-clockwise by a finite amount, then  stops
  • PgUp  – raises the ship a finite amount
  • PgDn  – lowers the ship a finite amount.
  • Spacebar – fires the Wraith’s lasers
  • ‘H’ – toggles the heads up display
  • ‘Esc’ – exits the game

 3. Running the Game

The game was written in Java using the eclipse IDE, so it can be run from eclipse, or it can be run from the executable jar file. In this case the native lwjgl libraries must reside in same folder as the executable jar in a \lib\native\windows sub folder. The executable jar file and native library can be downloaded here: Outpost_jar.zip

 4. The Software

Even for a demo game, the code can start to get pretty complex. To oversimplify, the Outpost code initializes the JPCT environment, loads the models, sets up the sound effects and camera then enters the main game loop. All the models and game objects have individual class instances which are stored in Array Lists which are updated in the game loop.

4.1 Java Library Path

java.library.path is a system property used by Java to search for native libraries. In this application, the native libraries consist of the Lightweight Java Gaming Library (lwjgl) dlls. To set the java.library.path property under program control, the following code must be run in the main() routine before the application is started:

// Set the java.library.path to the LWJGL native library
System.setProperty("java.library.path", "lib\\native\\windows");
Field fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" );
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );


 4.2 Loading Models

Models and textures are set-up in the EnvGen.java class. In order to create an executable jar file that can be “run” or  executed by double-clicking the jar file. The resources (images etc.) must be read as a runtime class. I usually place my resources (Images and Sounds) in the Eclipse  “src” folder for convenience. This way they will be transferred to the bin folder during the build process, and to the jar file during export. When the code is executed from the jar file, the getClass().getResourceAsStream() command looks for the resource in the jar file instead of any upper level folder. This is illustrated by the code snippet below:

InputStream inStr;

// Space station
inStr = getClass().getResourceAsStream("spacestation/SP_ST_25.jpg");
tm.addTexture("SP_ST_25.JPG",new Texture(inStr));

Modifications to existing or even new objects can be added in EnvGen.java

4.3 Source Code

The source code, resource folders (Images and Sounds),  and native library can be downloaded here: Outpost_source.zip

5. Things To Do

As mentioned, the gameplay is minimal, but a good deal of time can be wasted by blowing stuff up. Take out the gunships and drones, clear out the asteroids, then for a grand finale, blow up the space station.

Now that the hooks are in, and all the objects are in separate classes, it should be fairly easy to add some bells and whistles. The gunship and drone AIs could stand improvement. It hardly seems fair for for the Wraith to be impervious to harm. I should also add some overall game strategy other than random destruction.