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!

  1. Modify the settings object in the main() 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.
  2. 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.
  3. Create a flat, 33-WU wide, orange Box() as the floor.
  4. Create a playerNode, a towerNode, and a creepNode, and attach them to the rootNode. Remember that nodes are invisible handles.
  5. Write code that creates (visible) geometries; one lying yellow Box() representing the player base, one tall green Box() 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.
  6. Attach the geometries to the playerNode, the towerNode, and the creepNode, respectively. Since these nodes are attached to the rootNode, your geometries are visible parts of the scene now.
  7. 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.
  8. 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.
  9. Copy the code that deactivates the StatsView object and FPS to the beginning of the simpleInitApp() 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.