Game Development Reference
In-Depth Information
Figure 17-59 . Declaring bulletGravity and cheeseGravity double variables, and converting randomOffset to a double
What we want to do is to add a bulletGravity (or cheeseGravity) factor to the ran-
domOffset (Y location) on each frame, so we get a slight “tailing off” effect on the
shot. This will simulate gravity pulling the Projectile down to Earth. We will put this
inside of the if(bulletOffset >= bulletRange) counter loop so that gravity factor is only
applied when the projectile is visible flying across the screen. The Java code that incor-
porates bulletGravity and cheeseGravity adjustments to the Projectile object's trajector-
ies can be seen in Figure 17-60 , and should look like the following code:
private void shootProjectile() {
if(!bulletType && !takeSides) {
invinciBagel.iBullet.spriteFrame.setTranslateY(randomOffset);
invinciBagel.iBullet.spriteFrame.setScaleX(-0.5);
invinciBagel.iBullet.spriteFrame.setScaleY(0.5);
bulletRange = -50;
if(bulletOffset >= bulletRange) {
bulletOffset -=6 ;
invinciBagel.iBullet.spriteFrame.setTranslateX(bulletOffset);
randomOffset = randomOffset + bulletGravity;
} else { shootBullet = false; }
}
if(!bulletType && takeSides) {
invinciBagel.iBullet.spriteFrame.setTranslateY(randomOffset);
 
 
Search WWH ::




Custom Search