Skip to content

Instantly share code, notes, and snippets.

@EliteIntegrity
Created March 5, 2019 11:37
Show Gist options
  • Save EliteIntegrity/17d9eafaaa3fdc0bdbfad9d0a55ed5ed to your computer and use it in GitHub Desktop.
Save EliteIntegrity/17d9eafaaa3fdc0bdbfad9d0a55ed5ed to your computer and use it in GitHub Desktop.
Add this after the call to invader.update and before the code which checks if an invader has bumped into the side of the screen
...
...
invader.update(fps)
// Does he want to take a shot?
if (invader.takeAim(playerShip.position.left,
playerShip.width,
waves)) {
// If so try and spawn a bullet
if (invadersBullets[nextBullet].shoot(invader.position.left
+ invader.width / 2,
invader.position.top, playerBullet.down)) {
// Shot fired
// Prepare for the next shot
nextBullet++
// Loop back to the first one if we have reached the last
if (nextBullet == maxInvaderBullets) {
// This stops the firing of bullet
// until one completes its journey
// Because if bullet 0 is still active
// shoot returns false.
nextBullet = 0
}
}
}
// If that move caused them to bump
// the screen change bumped to true
...
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment