Outpost AE

Introduction
A couple of years ago, I finally acquired an Android tablet. After playing with it for a while, I realized that it might be useful to learn how to write some apps. After wading through the usual “Teach Yourself…” and “… For Dummies” books the next step was to try some original apps.

I had learned some Java a while ago, and even written some game demos using the jPCT game engine. It turns out that there is an Android version of jPCT called jPCT-AE which can be incorporated into the Android Studio SDK. My “Outpost” game demo was already written in Java, and used the Java jPCT library so why not update it to a proper game with touch-screen controls, and more menacing opponents. It sounds like a cut-and-paste job …almost.

1. Game-play
The game-play is similar to the Java version. There is space station surrounded by 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. Each shot will decrease your shield strength until your ship finally explodes. Similarly the killer drones will track and try to ram you. They explode on contact, but decrease your shield strength. If you collide with an asteroid, your shield strength decreases, so its best to fire on them and split them into smaller asteroids.

In this version, I added some explosion sound effects along with 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
Destroying the space station is ostensibly the object 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 however, damage will be inflicted as shown by the green status bar and it will explode as a grand finale.

station1.2 The Wraith (the player)
The Wraith (named after the ship in Andre LaMothe’s book “Tricks of the Windows Game Programming Gurus”) is the main player. Collisions with enemy lasers, asteroids, or drones are indicated by a fading transparent green force field until the ship is finally destroyed. The health of the Wraith is shown by the white status bar.
wraith1.3 Enemy Gunship
The gunship is an enemy spaceship controlled by a very basic AI. If the Wraith is within range, the gunship will track it and open fire at timed intervals. A fading transparent red force field will surround the gunship during collisions (laser blasts from the Wraith or collisions with asteroids). Eventually the force field will disappear and the gunship will explode.
gunship1.4 Killer Drones
The so-called killer drones will track the Wraith if its within range then try to ram it and explode. If the drone collides with the Wraith, it will cause damage as indicated by the force field strength and white status bar, but if you open fire on it you can safely blow it up.
mine1.5 Asteroids
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. If they collide with the Wraith, Gunships or Drones, they will inflict damage, but the will simply bounce off the space station.
asteroid1.6 Heads Up Display
The Heads Up Display is shown in the upper left corner of the screen:
hudThe game objects in the Heads Up Display 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

1.7 Status Bars
The two status bars are shown in the upper right corner of the screen.
The green bar represents the health of the station under enemy fire. The white bar represents the health of the Wraith after various enemy collisions.

2. Controls
The touchscreen controls are shown as follows:

3. Running the Game
The game was written in Java using Android Studio SDK (ver 3.3.1), so it can be run from the Android SDK using the the source code and resources here OutpostAE_src.zip. Create a New Project from the SDK using an Empty Activity with no layout file. Call the activity Outpost. I’ve used the package name net.project.dbc.outpostae. If you use a different package name, make sure use the same name in the source files. Make sure than the jPct library file jpct_ae.jar is located in the OutpostAE/app/libs directory. Select Dependencies from the Project Structure menu and click the ‘+’ icon. From the Select Path pop-up menu, select the library file in the libs folder and click OK.

For best results, the game should be run on a real device, as opposed to an emulator.

Another option to run the game is to copy the Android ‘.apk’ file to the device Download folder. Tapping the .apk file in the device File Manager will then install the game. A zipped version of the .apk file can be found here oupostae-release.zip. Make sure that the device is configured to allow installation of apps from unknown sources.

4. The Software
Even for a basic game, the Outpost code can get pretty complex. Basically, the Outpost code initializes the jPCT AE environment, loads and initializes 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 are stored in Array Lists which are updated in the game loop. The main game loop is actually a state machine which responds to events in the game (controls, explosions etc.) and adjusts the game status accordingly.

4.1 Full Screen Display
I’ve opted to lock the game into the landscape/full-screen mode. This involves making changes to the AndroidMainifest.xml file and the Outpost.java file.

Modify the AndroidManifest.xml file to set the Landscape mode:

<activity android:name=".Outpost"  android:screenOrientation="landscape">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Add the following lines to the onResume() method of Outpost.java to set the Fullscreen mode:

getWindow().getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);