| 12345678910111213141516171819202122232425 |
- /**
- A new application of the remove() function is presented. Instead of removing objects
- based on an x-coordinate condition, they’re removed on contact with another object.
- */
- //*****************Beam Object: Update Every Frame Event***************************//
- var spacePressed = isKeyPressed(Keys.space);
- if(spacePressed) {
- $this.visible(true);
- } else {
- $this.visible(false);
- }
- //*****************enemy Object: Update Every Frame Event***************************//
- // remove base if enemy reaches base
- if (!this.isTouching(base)) {
- moveBy($this);
- } else {
- base.remove();
- beam.remove();
- }
- // remove enemy when hit with beam
- if ($this.isTouching(beam) && beam.visible()) {
- $this.remove();
- }
|