Game Development Reference
In-Depth Information
Figure 17-12 . Make all the previously unrelated if() structures into one if-else-if stucture by inserting else in between
ifs
Adding Bounty to the Game: The Treas-
ure.java Class
To make our game play more exciting, let's add a Treasure.java class, so that our
game players have something to look for during game play that allows them to add
points to their score now that the scoring engine is in place. This type of Treasure ob-
ject will take advantage of the hasValu and isBonus boolean flags, which we installed
in the abstract Actor class, and we will set these to a true value in the Treasure() con-
structor method, which we will code next, along with overriding the required .update()
method, so that later on in development we can add animation and treasure processing
logic. Like the Prop, PropV, PropH, and PropB classes, this class will use the xLoca-
tion and yLocation parameters to set the translateX and translateY properties for the
spriteFrame ImageView Node object, which will live inside of this Treasure object
(Actor object type, also Actor subclass) as part of the Treasure() constructor method
programming logic. The Java code for this class, which can also be seen in Figure
17-13 , should look like the following:
package invincibagel;
import javafx.scene.image.Image;
public class Treasure extends Actor {
public Treasure(String SVGdata, double xLocation,
double yLocation, Image... spriteCels){
super(SVGdata, xLocation, yLocation, spriteCels);
spriteFrame.setTranslateX(xLocation);
spriteFrame.setTranslateY(yLocation);
hasValu = true;
isBonus = true;
}
@Override
public void update() {
// Currently this is an
Empty but Implemented Method
}
}
 
Search WWH ::




Custom Search