03-02-hiding-ninjas.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //**************ninja1 - Mouse Click Event*********************//
  2. /**
  3. For the teaching, we want to ask ninjas what we want to happen
  4. next we need to know when we want it to happen
  5. and how will we make this happen -- try to ilicit if()
  6. should only happen IF ninja is visible
  7. **/
  8. if($this.visible()){
  9. //if the ninja is visible, we'll do the following:
  10. $this.toggleVisible();
  11. $this.scene.score+=1;
  12. lblScore.text($this.scene.score);
  13. }
  14. //*********Scene - initialize when scene starts**************//
  15. $this.score = 0;
  16. //following code is pre-populated:
  17. if($this.scene.state() == "PLAY"){
  18. var ninjaTime1 = random(3000, 1000)
  19. createTimer(ninjaTime1, function(){
  20. ninja_1.toggleVisible();
  21. });
  22. var ninjaTime2 = random(3000, 1000)
  23. createTimer(ninjaTime2, function(){
  24. ninja_2.toggleVisible();
  25. });
  26. var ninjaTime3 = random(3000, 1000)
  27. createTimer(ninjaTime3, function(){
  28. ninja_3.toggleVisible();
  29. });
  30. var ninjaTime4 = random(3000, 1000)
  31. createTimer(ninjaTime4, function(){
  32. ninja_4.toggleVisible();
  33. });
  34. }