Game Development Reference
In-Depth Information
The if(bulletType) conditional if structure that we are going to create will use a
.setTranslateY() method call, passing a randomLocation parameter, if bulletType
equates to a true value (iCheese), and will use the .setTranslateY() method call passing
the iBagelLocation parameter, if the bulletType equates to a false value (iBullet), using
the else{} portion of the if-else structure. In a second line of code inside each section of
the if-else structure, we'll remember to set the randomOffset variable, to add five
pixels to the randomLocation variable inside the if portion of the structure, or to add
five pixels to the iBagelLocation variable, inside the else portion, using the following
code, shown in Figure 17-58 :
if(attackCounter >= attackFrequency) {
attackCounter=0;
spriteMoveR = 700;
spriteMoveL = -70;
randomLocation = randomNum.nextInt(attackBoundary);
iBagelLocation = (int) invinciBagel.iBagel.getiY();
bulletType = randomNum.nextBoolean();
if( bulletType ) {
spriteFrame.setTranslateY( randomLocation );
randomOffset = randomLocation + 5;
} else {
spriteFrame.setTranslateY( iBagelLocation );
randomOffset = iBagelLocation + 5;
}
callAttack = true;
} else { attackCounter+=1; }
 
Search WWH ::




Custom Search