Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 19 ■ Game Content enGine: ai LoGiC with random Content SeLeCtion methodS


For your first populateQuadrantOne() method body, you will have sections for each of your five
game board squares. The first statement will generate your random number pick for that square, the
second three will evaluate it, and the last will set the Shader to that diffuse color map texture using the
.setDiffuesMap(Image object) method call. The Java statements for this method body should look like the
following, as highlighted in Figure 19-7:


int pickS1 = random.nextInt(3);
if (pickS1 == 0){diffuse1 = new Image("/gamesquare1bird0.png", 256, 256, true, true, true);}
if (pickS1 == 1){diffuse1 = new Image("/gamesquare1bird1.png", 256, 256, true, true, true);}
if (pickS1 == 2){diffuse1 = new Image("/gamesquare1bird2.png", 256, 256, true, true, true);}
Shader1.setDiffuseMap(diffuse1);
int pickS2 = random.nextInt(3);
if (pickS2 == 0){diffuse2 = new Image("/gamesquare2bird0.png", 256, 256, true, true, true);}
if (pickS2 == 1){diffuse2 = new Image("/gamesquare2bird1.png", 256, 256, true, true, true);}
if (pickS2 == 2){diffuse2 = new Image("/gamesquare2bird2.png", 256, 256, true, true, true);}
Shader2.setDiffuseMap(diffuse2);
int pickS3 = random.nextInt(3);
if (pickS3 == 0){diffuse3 = new Image("/gamesquare3bird0.png", 256, 256, true, true, true);}
if (pickS3 == 1){diffuse3 = new Image("/gamesquare3bird1.png", 256, 256, true, true, true);}
if (pickS3 == 2){diffuse3 = new Image("/gamesquare3bird2.png", 256, 256, true, true, true);}
Shader3.setDiffuseMap(diffuse3);


Figure 19-6. In the .setOnFinished() event handler, check the quadrantLanding variable for degree offsets to
determine quadrant

Free download pdf