05-06-py-lift-off.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. The ninja can activate the objects either by clicking or by dragging.
  3. This example solution uses dragging.
  4. Decomposition:
  5. * variable created to count supplies
  6. *
  7. */
  8. //****************Scene Object: Initialize When Scene Starts Event***************//
  9. $this.totalSupplies = 0;
  10. //******************Scene Object: Update Every Frame Event***********************//
  11. if ($this.totalSupplies >= 4) {
  12. //animate on ship sprite
  13. spaceShip.animation("thrust");
  14. spaceShip.incrementAnimation();
  15. rocket.moveY(-100);
  16. }
  17. //***************supply_1 Object: Mouse Button Up Event*************************//
  18. if($this.isTouching(rocket)) {
  19. $this.scene.totalSupplies += 1;
  20. $this.remove();
  21. } else {
  22. //return to original position
  23. $this.x(44);
  24. $this.y(436);
  25. }
  26. //***********************supply_2 Object: Mouse Button Up Event*******************//
  27. if($this.isTouching(rocket)) {
  28. $this.scene.totalSupplies += 1;
  29. $this.remove();
  30. } else {
  31. //return to original position
  32. $this.x(182);
  33. $this.y(412);
  34. }
  35. //**********************supply_3 Object: Mouse Button Up Event*******************//
  36. if($this.isTouching(rocket)) {
  37. $this.scene.totalSupplies += 1;
  38. $this.remove();
  39. } else {
  40. //return to original position
  41. $this.x(254);
  42. $this.y(446);
  43. }
  44. //************************supply_4 Object: Mouse Button Up Event*******************//
  45. if($this.isTouching(rocket)) {
  46. $this.scene.totalSupplies += 1;
  47. $this.remove();
  48. } else {
  49. //return to original position
  50. $this.x(374);
  51. $this.y(444);
  52. }