05-03-zapper-pt-2.js 683 B

1234567891011121314151617181920212223
  1. /**
  2. This activity is a combination of several functions from previous lessons.
  3. */
  4. //*****************Scene Object: Initialize When Scene Starts***********************//
  5. if($this.scene.state() == "PLAY") {
  6. createTimer(1000, function() {
  7. var nship = enemy.clone();
  8. nship.x(31);
  9. nship.y(12);
  10. })
  11. }
  12. //*****************enemy Object: Update Every Frame********************************//
  13. moveX($this);
  14. if($this.isTouching(beam) && beam.visible()) {
  15. $this.remove()
  16. }
  17. // ninjas may experiment with the conditions to make enemy move towards base
  18. if ($this.x() >= 700 || $this.x() <= 0) {
  19. $this.speedX(-$this.speedX());
  20. $this.y($this.y() + 100);
  21. }