Game Development Reference
In-Depth Information
Figure 17-37 . Add an if(onScreen) level of processing inside the if(!takeSides) logic to animate sprite from the right
side
Inside the second if(takeSides) structure, in the if(!onScreen) structure, initialize
the destination location to 100 pixels, and nest another counter if(spriteMoveL <=
destination) structure. This time, you will move the sprite by two pixels per pulse us-
ing spriteMoveL+=2; in conjunction with
spriteFrame.setTranslateX(spriteMoveL); to move the sprite in the op-
posite direction. In the else portion, set the onScreen boolean flag variable to a true
value.
The logic for the second nested conditional if(onScreen) structure is again similar
to the first. You'll set your destination to -70 pixels, and this time, you'll iterate using
-=1 instead of +=1. In the else portion of the programming logic, we will again set the
onScreen boolean flag variable back to false , and we'll set the takeSides boolean vari-
able back to false , so that the Enemy will again alternate sides and use the other side of
the screen for his next attack.
Finally, since an attack sequence is completed, we will again set the callAttack
boolean flag variable to false . As you know, this will start up the attackCounter pro-
gram logic in the .update() method, which will give your player a few seconds to re-
cover from being attacked. The Java structure for this entire if(takeSides) conditional
structure, and its nested if(onScreen) conditional structures, is shown highlighted in
Figure 17-38 , and should look like the following:
if( takeSides ) {
spriteFrame.setScaleX(-1);
this.setIsFlipH(true);
if( !onScreen ) {
destination = 100 ;
if(spriteMoveL <= destination) {
spriteMoveL +=2 ;
spriteFrame.setTranslateX( spriteMoveL );
} else {
// ShootProjectile();
onScreen = true ;
}
if( onScreen ) {
destination = -70 ;
if(spriteMoveL >= destination) {
spriteMoveL -=1 ;
 
Search WWH ::




Custom Search