Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 20 ■ Coding gameplay: Set Up gameplay methodS and animated Camera View

setupQ1S1gameplay() to setupQ1S2gameplay() through setupQ1S5gameplay(). Your new OnMouseClicked
event handling method body should look like the following Java 9 code, which is also shown in light blue and
yellow in Figure 20-7:


scene.setOnMouseClicked(event-> {
Node picked = event.getPickResult().getIntersectedNode();
if (picked != null) {
if (picked == Q1S1) { setupQ1S1gameplay(); }
if (picked == Q1S2) { setupQ1S2gameplay(); }
if (picked == Q1S3) { setupQ1S3gameplay(); }
if (picked == Q1S4) { setupQ1S4gameplay(); }
if (picked == Q1S5) { setupQ1S5gameplay(); }
if (picked == spinner) { resetTextureMaps();
int spin = random.nextInt(4);
if (spin == 0) {
... // 3D spinner UI logic
}
}
}
});


As you can tell from this chapter, we are now getting into the part of the Java coding process where we
will be generating hundreds if not thousands of lines of codes over the next few chapters, as we add in the
game content.
This will include this chapter, where we add in the infrastructure where the player can click the imagery
to select the game question they are going to answer and where we add camera animation to get a better
view of this content. It also includes the next chapter, where we’ll add questions and answers for each
question, along with a 2D UI that displays these answer options. We will also be adding digital audio spin
and zoom sound effects in Chapter 21 using the JavaFX 9 AudioClip class.


Figure 20-7. Copy the first if(picked==Q1S1) construct four more times to create the Q1S2 through Q1S5 if()
constructs

Free download pdf