Game Development Reference
In-Depth Information
CHAPTER 9
Controlling Your Action Figure:
Implementing Java Event Hand-
lers and Using Lambda Expres-
sions
Now that we have created the public abstract Actor and Hero classes, which I call the
“actor engine,” in Chapter 8 , let's get back into our InvinciBagel.java primary applica-
tion class coding here in Chapter 9 , and create the event handling framework that we
can use to control the primary hero for our game, the InvinciBagel himself. The event
handling that implements the interface between the player and your game programming
logic could be looked at as the “ interactivity engine ” for your game, if we follow the
engine paradigm we have been using thus far. There are many ways to interface with a
game, including arrow keys (also known as a DPAD for consumer electronics devices),
the keyboard , a mouse or trackball, a game controller , touchscreen , or even advanced
hardware, such as gyroscopes and accelerometers . One of the choices you will make
for your game development will be how a player will interface with the game, using the
hardware device they are playing the game on, and the input capabilities it supports.
During this chapter, we will be doing a number of upgrades to your InvinciBa-
gel.java class. The first is to add support for the game WIDTH and HEIGHT variables
in the form of Java constants . These will allow us to change the width and height of the
game play surface, which is the area inside of the game window that pops up, or the en-
tire screen, if your game player is using a consumer electronics device.
The second upgrade we will do is to add the Java code that will create a blank white
screen for us to design the game over (on top of) during the next several chapters. We'll
Search WWH ::




Custom Search