Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 5.91 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ////////////////////////
  2. ///////////////////////////////
  3. ///////////////////////////////////////
  4. //////////// INITIALIZING ///////////////////
  5. ///////////////////////////////////////
  6. ///////////////////////////////
  7. ////////////////////////
  8. var levelNum=1;
  9. //the sound seconds array
  10. var newArrowTimeArr=new Array(29,37,44,52,59,67,74,82,89,97,104,112,119,131,135,138,
  11. 142,144,148,152,158,165,173,182,189,197,205,213,220,228,235,242,250,258,270,277,283,
  12. 290,298,306,314,322,328,335,341,348,355,363,369,384,385,389);
  13. var arrayFlag=0;
  14. //
  15. var checkDirection;
  16. // points and score settings
  17. var theScore=0000;
  18. var pointsPerHit=5;
  19. var grpScore=new scoreGRP  ;
  20. grpScore.x=115;
  21. grpScore.y=548;
  22. // a timer for compering the arrow arrival times
  23. var myTime=new Timer(10);
  24. //load the start screen + add current level to display
  25. var openingScreen=new startGameScreen  ;
  26. stage.addChild(openingScreen);
  27. var currLevel=new level1  ;
  28. //
  29. ////////////////////////
  30. ///////////////////////////////
  31. ///////////////////////////////////////
  32. //////////// EVENT LISTENERS ///////////////////
  33. ///////////////////////////////////////
  34. ///////////////////////////////
  35. ////////////////////////
  36. // keys pressed
  37. stage.addEventListener("keyDown", seeIfHit);
  38. stage.addEventListener("keyUp", returnToZeroPosition);
  39. //
  40. openingScreen.addEventListener("click", loadLevel);
  41. stage.addEventListener("enterFrame", updateGrpScore);
  42. ////////////////////////
  43. ///////////////////////////////
  44. ///////////////////////////////////////
  45. ////////////////// FUNCTIONS ///////////////////
  46. ///////////////////////////////////////
  47. ///////////////////////////////
  48. ////////////////////////
  49. // load a level
  50. function loadLevel(eventData) {
  51.         // load game map - currLevel: sleeping zehava
  52.         stage.removeChild(openingScreen);
  53.         stage.addChild(currLevel);
  54.         stage.addChild(grpScore);
  55.         currLevel.soundBeat.nextFrame();
  56.         // start sending arrows up (begin game) as timer starts
  57.         myTime.addEventListener("timer", newArrowTime);
  58.         myTime.start();
  59.         //
  60. }
  61. ////////////////////////////////////////////////
  62. ///////////////// load arrows//////////////////
  63. ////////////////////////////////////////////////
  64. // when timer reaches the right time (according to the array) - dispatch an arrow
  65. function newArrowTime(eventData) {
  66.         if (myTime.currentCount==newArrowTimeArr[arrayFlag]) {
  67.                 arrayFlag=arrayFlag+1;
  68.                 addArrowToGame();
  69.         }
  70. }
  71. // choose random color and direction for an arrow
  72. function addArrowToGame() {
  73.         var aGameArrow=new gameArrow  ;
  74.         //var arrowColor=Math.floor(Math.random()*4)+1;
  75.         var arrowDir=Math.floor(Math.random()*4)+1;
  76.         aGameArrow.gotoAndStop(arrowDir);
  77.         stage.addEventListener("enterFrame", goUP);
  78.         function goUP(eventData) {
  79.                 aGameArrow.y=aGameArrow.y-10;//244.83;
  80.         }
  81.  
  82.         // up arrow
  83.         if (arrowDir==1) {
  84.                 aGameArrow.rotation=0;
  85.                 aGameArrow.x=168.2;
  86.                 checkDirection="up";
  87.         }
  88.         // right arrow
  89.         if (arrowDir==2) {
  90.                 aGameArrow.rotation=90;
  91.                 aGameArrow.x=361.5;
  92.                 checkDirection="right";
  93.         }
  94.         // down arrow
  95.         if (arrowDir==3) {
  96.                 aGameArrow.rotation=180;
  97.                 aGameArrow.x=264.8;
  98.                 checkDirection="down";
  99.         }
  100.         // left arrow
  101.         if (arrowDir==4) {
  102.                 aGameArrow.rotation=270;
  103.                 aGameArrow.x=71.5;
  104.                 checkDirection="left";
  105.         }
  106.         aGameArrow.y=656.5;
  107.         currLevel.loadArrows.addChild(aGameArrow);
  108.         // total 710 pixls. in 2.9 seconds.
  109.  
  110. }
  111. ///////////////////////////////////
  112. ////////// KEYS reaction //////////
  113. ///////////////////////////////////
  114. // when all keys are up - return to the first Zehava position
  115. function returnToZeroPosition(eventData) {
  116.         currLevel.zehavaPose.gotoAndStop("zeroPos");
  117. }
  118. // move Zehave to the right position according to the pressed key - and check if hit was right.
  119. function seeIfHit(eventData) {
  120.         if (eventData.keyCode==37) {
  121.                 currLevel.zehavaPose.gotoAndStop("leftKey");
  122.                 if ((checkDirection=="left") && (currLevel.soundBeat.numChildren >0)) {
  123.                         //trace("hit left");
  124.                         theScore=theScore+pointsPerHit;
  125.                 }
  126.         }
  127.         if (eventData.keyCode==38) {
  128.                 currLevel.zehavaPose.gotoAndStop("upKey");
  129.                 if ((checkDirection=="up") && (currLevel.soundBeat.numChildren >0)) {
  130.                         //trace("hit up");
  131.                         theScore=theScore+pointsPerHit;
  132.                 }
  133.         }
  134.         if (eventData.keyCode==40) {
  135.                 currLevel.zehavaPose.gotoAndStop("downKey");
  136.                 if ((checkDirection=="down") && (currLevel.soundBeat.numChildren >0)) {
  137.                         //trace("hit down");
  138.                         theScore=theScore+pointsPerHit;
  139.                 }
  140.         }
  141.         if (eventData.keyCode==39) {
  142.                 currLevel.zehavaPose.gotoAndStop("rightKey");
  143.                 if ((checkDirection=="right") && (currLevel.soundBeat.numChildren >0)) {
  144.                         //trace("hit right");
  145.                         theScore=theScore+pointsPerHit;
  146.                 }
  147.         }
  148.  
  149. }
  150. // updates graphic score
  151. function updateGrpScore(eventData) {
  152.         if (String(theScore).length==1){
  153.         grpScore.ahadot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-1,String(theScore).length))+1);
  154. }else if (String(theScore).length==2){
  155.         grpScore.ahadot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-1,String(theScore).length))+1);
  156.         grpScore.asarot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-2,String(theScore).length-1))+1);
  157. }else if (String(theScore).length==3){
  158.         grpScore.ahadot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-1,String(theScore).length))+1);
  159.         grpScore.asarot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-2,String(theScore).length-1))+1);
  160.         grpScore.meot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-3,String(theScore).length-2))+1);
  161. }else if (String(theScore).length==4){
  162.         grpScore.ahadot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-1,String(theScore).length))+1);
  163.         grpScore.asarot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-2,String(theScore).length-1))+1);
  164.         grpScore.meot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-3,String(theScore).length-2))+1);
  165.         grpScore.alafim.gotoAndStop(Number(String(theScore).slice(String(theScore).length-3,String(theScore).length-2))+1);
  166. }
  167. }