Pro Java 9 Games Development Leveraging the JavaFX APIs

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

Now that you have a setupQ1S1gameplay() method code template, cut and paste it four times
underneath itself, change Q1S1 to Q1S2 through Q1S5, and change pickS1 to pickS2 through pickS5 in the
method name and if() code structures. Also, change the image file names in the Image() instantiations to
match the PNG texture map image assets you created in Chapter 18. The Java code, also shown in Figure 20-6,
should look like the following once you are done:


private void setupQ1S2gameplay() {
if (pickS2 == 0) {diffuse21 = new Image("gamequad1s2bird0.png", 512, 512, true, true, true);
Shader21.setDiffuseMap(diffuse21); }
if (pickS2 == 1) {diffuse21 = new Image("gamequad1s2bird1.png", 512, 512, true, true, true);
Shader21.setDiffuseMap(diffuse21); }
if (pickS2 == 2) {diffuse21 = new Image("gamequad1s2bird2.png", 512, 512, true, true, true);
Shader21.setDiffuseMap(diffuse21); }
}
private void setupQ1S3gameplay() {
if (pickS3 == 0) {diffuse21 = new Image("gamequad1s3bird0.png", 512, 512, true, true, true);
Shader21.setDiffuseMap(diffuse21); }
if (pickS3 == 1) {diffuse21 = new Image("gamequad1s3bird1.png", 512, 512, true, true, true);
Shader21.setDiffuseMap(diffuse21); }
if (pickS3 == 2) {diffuse21 = new Image("gamequad1s3bird2.png", 512, 512, true, true, true);
Shader21.setDiffuseMap(diffuse21); }
}
private void setupQ1S4gameplay() {
if (pickS4 == 0) {diffuse21 = new Image("gamequad1s4bird0.png", 512, 512, true, true, true);
Shader21.setDiffuseMap(diffuse21); }
if (pickS4 == 1) {diffuse21 = new Image("gamequad1s4bird1.png", 512, 512, true, true, true);
Shader21.setDiffuseMap(diffuse21); }


Figure 20-5. Clicking quadrant 1’s square 1 (Q1S1) texture maps the game board quadrant with the correct
image asset

Free download pdf