Cyberbase

Introduction
Having picked up some Java and then the basics of Android apps, I decided the time was ripe for a first person shooter game. I used the Android SDK version 3.3.1 incorporating the jPCT-AE 3D engine to come up with an action packed (albeit rudimentary) game with  killer robots and fiendish mazes in an abandoned training base.

1. Gameplay
Originally, the Cyberbase of the title was an advanced training facility for cybernetic soldiers. Unfortunately the robot soldiers turned evil (as they will) and polished off the human staff. The object of the game is to work your way through the training maze and destroy as many of the robots as you can before you reach the exit, a green pillar at the end of the maze, and a green block on the heads up display (HUD). Unfortunately the robots all have self replenishing ammunition, but there are ammo packs and first aid kits scattered around to give the player a fighting chance.

As mentioned, this is a basic FPS, so there are no extra levels, hidden puzzles, or surprise bad guys. The only way to keep score is by the number of evil robots destroyed before you get killed. With luck you’ll make to the end and will have saved the world from the scourge of evil robots, which should be sufficient reward in itself.

1.1 The Player
The player is represented by the weapon of choice, a MK3A1 jackhammer shotgun (modified to shoot laser blasts). Using the touch screen controls, the player can move forwards or backwards, turn left or right, look up or down, or open fire.

1.2 Evil Robots
They’re evil, but not overly bright. They’ll stand around idly until they sense that you’re in range. Once they sense the player’s presence, they’ll wander around in a basic search pattern until the player is in sight. Once the player is in sight, they’ll attack with guns blazing, so be careful out there.

1.3 The Maze
The training maze has been constructed from a text file (level1.txt in the assets directory). Each character in the text file represents an element of the game: A,B,C,D represent doors of various orientations, ‘^’ represents a robot, ‘E’ represents the end location of the game etc. If you’re feeling ambitious, there is considerable opportunity for customizing the game by modifying the level text file.

1.4 Ammunition and Med-kits
While the robots may have an inexhaustible supply of ammunition, the player doesn’t. Fortunately there are spare ammunition boxes and medical kits scattered around the maze. The medical kits and ammunition boxes will increase the player’s health and ammunition supply by about 20 points each. There’s not an unlimited supply, so use them well.

1.5 Heads Up Display
The Heads Up Display (HUD) shown in the upper left hand corner of the screen is a representation of the maze. As such, it shows the maze, the position of the player (the red dot), and the end point of the game (the green block).

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 assets here Cyberbase_src.zip. Create a New Project from the SDK using an Empty Activity with no layout file. Call the activity Cyberbase. I’ve used the package name net.games.dbc.cyberbase. If you use a different package name, make sure use the same name in the source files. Make sure that the jPct library file jpct_ae.jar is located in the Cyberbase/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 cyberbase_apk.zip to the device Download folder. Tapping the .apk file in the device File Manager will then install the game. Make sure that the device is configured to allow installation of apps from unknown sources.

4. The Software
Even for a basic first person shooter, the Cyberbase code can get pretty complex. Basically, the Cyberbase.java 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 Landscape Screen Display
I’ve opted to lock the game into the landscape mode, leaving the status and navigation bars intact. This involves making the following changes to the AndroidMainifest.xml file:

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