
Time for action – move it!
Here's an overview of the default key bindings; try them!

The SimpleApplication
class offers a few additional key bindings that developers commonly use during the development phase. Even if you deactivate WASD navigation, the following three keys are still available:

What just happened?
As you can see, the default input settings go a long way in your first SimpleApplication
class. As your own game grows, you will want to be able to have more fine-grained control over navigation and input handling. You may want to configure the Esc key to pause the game, or take users back to the settings screen of your application. You will implement custom game actions and want to set up keys that trigger them. For the final release, you will also want to deactivate the two default bindings that print debug information to the console.
In the next chapter, you learn how to interact with the user by setting up your own input handlers.
Have a go hero – tower defense
Over the course of this book, we want to build up a little tower defense game. In a tower defense game, the player defends his (immobile) base against incoming (mobile) baddies—the creeps. During the game, players position armed towers around their base. While the computer-controlled creeps storm in and try to break through the barrier, the players face the challenge of keeping the automatic defense system charged with ammo. The game is played from a third-person perspective; this means that players look down on the terrain from above and click towers to assign ammo depending on their budget.
In our little demo, we want to set the player base at the end of a valley. This means that the creeps can only approach from one side, and it only makes sense to place the towers along the valley. As a simplification, the game automatically positions the towers for the player in each level.

Create a new project from the BasicGame
template. Extend the SimpleApplication
class and amend the main()
method and the simpleInitApp()
method to initialize your scene. Use what you learned in this chapter!
- Modify the
settings
object in themain()
method and specify an image of your choice as a splash screen. Set the name of the game to, for example, My Tower Defense Demo. - Keep the default
flyCam
method active for now, so you can look at the scene while you create it. Remember that you will navigate using the mouse and the W, A, S, and D keys. - Create a flat, 33-WU wide, orange
Box()
as the floor. - Create a
playerNode
, atowerNode
, and acreepNode
, and attach them to therootNode
. Remember that nodes are invisible handles. - Write code that creates (visible) geometries; one lying yellow
Box()
representing the player base, one tall greenBox()
representing one tower, and one black, small cube that represents one creep. Optimally, these are three reusable helper methods that accept a location (Vector3f
) as an argument. - Attach the geometries to the
playerNode
, thetowerNode
, and thecreepNode
, respectively. Since these nodes are attached to therootNode
, your geometries are visible parts of the scene now. - Position the player base geometry at the origin. Placing a box at the origin is a good practice for orientation in the otherwise empty scene.
- Position one tower to the left and one to the right in front of the base, and some smaller creep cubes further down along the z axis. You will notice that the location is relative to the center of the box—if you don't want a box that is stuck halfway underground, move it up by half its height.
- Copy the code that deactivates the
StatsView
object and FPS to the beginning of thesimpleInitApp()
method, but leave it commented out for now. Watch how the statistics change when you add one box.
You can find an example implementation in the mygame
package.