05-04-wall-blaster.js 864 B

123456789101112131415161718192021222324252627
  1. /**
  2. Ninjas are presented with the for loop, which they will use to build a scene,
  3. and then create a game utilizing the remove function.
  4. */
  5. //************************Scene Object: Initialize When Scene Starts***************//
  6. if($this.scene.state() == "PLAY" ) {
  7. var brickX = 4;
  8. var nbrick;
  9. $this.score = 0
  10. //for() loop to create the bricks across the screen
  11. for (var brickCount = 1; brickCount <= 9; brickCount++) {
  12. nbrick = brick.clone();
  13. nbrick.x(brickX + 80 * brickCount);
  14. nbrick.y(150)
  15. }
  16. }
  17. //************************brick Object: Update Every Frame Event*******************//
  18. if($this.isTouching(ball)) {
  19. ball.speedY(-ball.speedY()); //bounce the ball in opposite direction
  20. $this.remove(); //remove brick
  21. $this.scene.score += 10; //score update
  22. lblScore.text(parseInt($this.scene.score));
  23. }