04-03-ninja-snacks.js 639 B

1234567891011121314151617181920
  1. /**
  2. This activity further reinforces the logic that objects don’t need to be visible
  3. to be detected for collision purposes.
  4. **/
  5. //*******************Apple Object - Mouse Click Event******************//
  6. //When apple is click, move to target x and y
  7. $this.moveTo(400,285);
  8. $this.moveTo(mouth.x, mouth.y);
  9. //********************Apple Object - Update Every Frame***************//
  10. if($this.isTouching(mouth)){ //check if apple is touching mouth
  11. $this.remove();
  12. }
  13. //****************Ninja Object - Update Every Frame*******************//
  14. $this.moveForward(5);
  15. if ($this.y() <= -130 || $this.y() >= 50) {
  16. $this.flipDirection();
  17. }