05-02-zapper-pt-1.js 719 B

12345678910111213141516171819202122232425
  1. /**
  2. A new application of the remove() function is presented. Instead of removing objects
  3. based on an x-coordinate condition, they’re removed on contact with another object.
  4. */
  5. //*****************Beam Object: Update Every Frame Event***************************//
  6. var spacePressed = isKeyPressed(Keys.space);
  7. if(spacePressed) {
  8. $this.visible(true);
  9. } else {
  10. $this.visible(false);
  11. }
  12. //*****************enemy Object: Update Every Frame Event***************************//
  13. // remove base if enemy reaches base
  14. if (!this.isTouching(base)) {
  15. moveBy($this);
  16. } else {
  17. base.remove();
  18. beam.remove();
  19. }
  20. // remove enemy when hit with beam
  21. if ($this.isTouching(beam) && beam.visible()) {
  22. $this.remove();
  23. }