Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 14 ■ 3D MoDel hierarChy Creation: Using priMitives to Create a gaMe BoarD


Q3S4 also needs to position itself 750 units along X from the 0,0 origin, but this time, we’ll also need
to pull this square back down another 150 units in the Z direction in order to move it down along the
right side of your game board layout. This is done by again using two location method calls. One would be
.setTranslateZ( 600 ), and the other would still be set to .setTranslationX( 750 ). Again, be sure to set
.setMaterial(Shader14) to reference the matching Shader14 object, which then references and applies a
diffuse14 Image object as a diffuseMap property.
Q3S5 needs to position itself 750 units in the X direction from 0,0 and 450 units in the Z direction
so that this square is located near the middle right of this game board. This is again done using
two location method calls, to .setTranslateX( 750 ) and to .setTranslateZ( 450 ). Be sure to set
.setMaterial(Shader15) to reference your correct Shader15 object, which then references (and applies)
the diffuse15 Image object as the diffuseMap property.
The Java code for the construction of the second quadrant of the game board should look like the
following:


private void createGameBoardNodes() {
...
q3 = new Box(300, 5, 300); // Java code creating a third quadrant for the gameboard
q3.setTranslateX( 525 );
q3.setTranslateZ( 525 );
Q3S1 = new Box(150, 5, 150);
Q3S1.setTranslateZ( 750 );
Q3S1.setTranslateX( 450 );
Q3S1.setMaterial(Shader 11 );
Q3S2 = new Box(150, 5, 150);
Q3S2.setTranslateZ( 750 );
Q3S2.setTranslateX( 600 );
Q3S2.setMaterial(Shader 12 );
Q3S3 = new Box(150, 5, 150);
Q3S3.setTranslateZ( 750 );
Q3S3.setTranslateX( 750 );
Q3S3.setMaterial(Shader 13 );
Q3S4 = new Box(150, 5, 150);
Q3S4.setTranslateZ( 600 );
Q3S4.setTranslateX( 750 );
Q3S4.setMaterial(Shader 14 );
Q3S5 = new Box(150, 5, 150);
Q3S5.setTranslateZ( 450 );
Q3S5.setTranslateX( 750 );
Q3S5.setMaterial(Shader 15 );
... // Your fourth quadrant configuration code will go in here
q4 = new Box(300, 5, 300);
q4.setVisible(false);
}


Finally, let’s create the fourth quadrant of our game board by going back into the
createGameBoardNodes() method body and creating the fourth section of code for Box primitives
Q4S1 through Q4S5. Just copy your Q3S1 to Q3S5 statements (and q4 statements) and paste them again
underneath themselves; then change the object names and method call parameters (so that you do not have
to type all these Java statements into NetBeans 9 again).
The q4 Box object (fourth quadrant) will need to be moved back down by 300 units along the z-axis, so
your q4.setTranslateZ() method parameter needs to be decremented, from 525 to 225 , to accomplish this
fourth quadrant game board component positioning, as shown in Figure 14-24.

Free download pdf