Game Development Reference
In-Depth Information
set allowing us to do X positioning. We will set the
randomLocation
variable equal to
the
randomNum.nextInt(attackBoundary)
logic, which used to be inside of the
.setTranslateY()
method call, and add
5
to this variable, to create the
randomOffset
variable data value. The new Java structure for these methods is error-free, as shown in
Figure 17-41
,
and should look like the following Java code:
int spriteMoveR, spriteMoveL, destination;
int
randomLocation
,
randomOffset
, bulletRange,
bulletOffset;
public void update() {
if(callAttack) {
if(attackCounter >= attackFrequency) {
attackCounter=0;
spriteMoveR = 700;
spriteMoveL = -70;
randomLocation
=
randomNum.nextInt(attackBoundary)
;
spriteFrame.setTranslateY(
randomLocation
);
randomOffset
=
randomLocation + 5
;
callAttack = true;
} else { attackCounter+=1; }
} else {
initiateAttack(); }
}