Game Development Reference
In-Depth Information
CHAPTER 17
Enhancing Game Play: Creating
a Scoring Engine, Adding Treas-
ure and an Enemy Auto-Attack
Engine
Now that we've implemented collision detection for our game, as well as putting the
foundation in place for a scoring engine, let's finish coding the scoring engine that is
called from the
.checkCollisions()
method, and then add some more game play elements
to take advantage of this scoring engine, as well as to make the game play more interest-
ing. To implement our scoring engine display, we will create a
gameScore
integer vari-
able and
scoreText
Text object in our InvinciBagel.java class. We will also create a
scoreFont
Font object, and use it to style the scoreText Text object, to make it stand out
better. We will also learn how to use the Java
instanceof
evaluator in the conditional if()
statement in the
.scoringEngine()
method that we will be creating, and use this to de-
termine what type of Actor object the InvinciBagel has collided with. Of course, we will
then increment our gameScore variable accordingly.
We'll also create a
Treasure.java
class, so that we can add valuable bounty to the
game for our InvinciBagel character to pick up, while he is evading constant Enemy at-
tacks from the
InvinciBeagle
, or iBeagle for short, who can shoot both deadly bullets
(iBullets) as well as Cream Cheese Balls (iCheese) Projectile objects. We will also be
creating these
Enemy.java
and
Projectile.java
classes during this chapter, so we will be
using all of the knowledge that you've learned during this topic to create some very ad-
vanced Java 8 classes and methods during the course of this chapter.