Pro Java 9 Games Development Leveraging the JavaFX APIs

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

In Chapter 22 , we will add a scoring engine, which is also quite a bit of code. So, from this point onward,
your lines of Java 9 code are going to increase dramatically as we continue to flesh out how our gameplay is
going to function. Once we are done with that, we will look at how NetBeans 9 allows you to test what your
code is doing and then optimize it. Let’s use a Run ➤ Project work process and see whether when we click
squares 2 to 5, it puts a correct image in the center of the quadrant. As you’ll see in Figure 20-8, the Java code
works, and we can create the other 15 methods.


Now we can copy and paste these setupQ1S1gameplay() through setupQ1S5gameplay() method
structures underneath themselves to create the setupQ2S1gameplay() through setupQ2S5gameplay()
method structures. You’ll also need to add the next five if(picked == Q2S1) through if(picked == Q2S5)
event handling structures (shown in Figure 20-7) before you test your code, as well as confirm that your
populateQuadrantTwo() method references the correct image assets. Your new methods should look like the
following code, shown in Figure 20-9, once you edit them:


private void setupQ2S1gameplay() {
if (pickS6 == 0) {diffuse22 = new Image("gamequad2s1vegi0.png", 512, 512, true, true, true);
Shader22.setDiffuseMap(diffuse22); }
if (pickS6 == 1) {diffuse22 = new Image("gamequad2s1vegi1.png", 512, 512, true, true, true);
Shader22.setDiffuseMap(diffuse22); }
if (pickS6 == 2) {diffuse22 = new Image("gamequad2s1vegi2.png", 512, 512, true, true, true);
Shader22.setDiffuseMap(diffuse22); }
}


Figure 20-8. Use a Run ➤ Project work process to test; ensure each square populates the quadrant with the
correct image

Free download pdf