28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8<br />

Creating Your Actor Engine: Design<br />

the Characters for Your Game and<br />

Define Their Capabilities<br />

Now that we have created the game play timing loop in Chapter 7, let’s get into some scratch coding here in Chapter 8,<br />

and create the public abstract class framework that we can use to create the different types of sprites that we will be<br />

using in our InvinciBagel game. This essentially equates to your “Actor Engine” for your game, as you’ll define and<br />

design the various types of game components that your game will include as actors, and these two classes will be<br />

used to create all of the other classes that will be used to create the objects (components) that are in your game. These<br />

would include things such as the InvinciBagel himself (the Bagel class), his adversaries (the Enemy class), all the<br />

treasure he looks for during the game (the Treasure class), things that are shot at him (the Projectile class), things that<br />

he navigates over and around (the Prop classes), all providing game objectives that InvinciBagel must try and achieve.<br />

During this chapter, we will create two public abstract class constructs. The first, the Actor class, will be the<br />

superclass of the other, the Hero subclass. These two abstract classes can be used during the book to create both our<br />

fixed sprites, which are sprites that do not move (obstacles and treasure), using the Actor superclass, and sprites that<br />

move around the screen, using a Hero subclass of the Actor class. The Hero class will provide additional methods and<br />

variables for motion sprites (the superhero, and his arch enemies in the multi-player version of the game). These will<br />

track things like collision and physics characteristics, as well as Actor animation (motion states). Having lots of motion<br />

on the screen will make game play more interesting, and allow us to make the game more challenging for the player.<br />

Creating the Actor Engine up front will give you experience in creating public abstract classes. As you recall<br />

from Chapter 3, public abstract classes are used to create other class (and object) structures in <strong>Java</strong>, but are not used<br />

directly in the actual game programming logic. This is the reason I am terming creating these two “blueprint” classes<br />

creating the Actor Engine, as we are essentially defining the lowest level of the game, the “actors” during this chapter.<br />

As we progress in the design of the game during the book, we’ll create the Treasure subclass using the Actor<br />

(fixed sprite) class, for “fixed” treasures that will get picked up by InvinciBagel during the game play. We’ll also create<br />

the Prop class using this Actor superclass, for the obstacles in the game that InvinciBagel has to navigate up, over,<br />

under, around, or through, successfully. We’ll also create sprites that move around on the screen using the Hero<br />

subclass of the Actor superclass, such as the Bagel class. We’ll eventually create an Enemy class and Projectile class.<br />

Besides designing the two key public abstract Actor classes during this chapter, we will also define our main<br />

InvinciBagel character’s digital image states using less than ten PNG32 digital image assets. We will do this during<br />

this chapter so that this is in place before we’ll want to use these classes and sprite image states in the next chapter<br />

of the book, when we’ll look at event handling, so that the player can control where the InvinciBagel goes around<br />

the screen and what states (stand, run, jump, leap, fly, land, miss, crouch, etc.) he is using to navigate the obstacles<br />

in his world.<br />

www.it-ebooks.info<br />

165

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!