- ////////////////////////
- ///////////////////////////////
- ///////////////////////////////////////
- //////////// INITIALIZING ///////////////////
- ///////////////////////////////////////
- ///////////////////////////////
- ////////////////////////
- var levelNum=1;
- //the sound seconds array
- var newArrowTimeArr=new Array(29,37,44,52,59,67,74,82,89,97,104,112,119,131,135,138,
- 142,144,148,152,158,165,173,182,189,197,205,213,220,228,235,242,250,258,270,277,283,
- 290,298,306,314,322,328,335,341,348,355,363,369,384,385,389);
- var arrayFlag=0;
- //
- var checkDirection;
- // points and score settings
- var theScore=0000;
- var pointsPerHit=5;
- var grpScore=new scoreGRP ;
- grpScore.x=115;
- grpScore.y=548;
- // a timer for compering the arrow arrival times
- var myTime=new Timer(10);
- //load the start screen + add current level to display
- var openingScreen=new startGameScreen ;
- stage.addChild(openingScreen);
- var currLevel=new level1 ;
- //
- ////////////////////////
- ///////////////////////////////
- ///////////////////////////////////////
- //////////// EVENT LISTENERS ///////////////////
- ///////////////////////////////////////
- ///////////////////////////////
- ////////////////////////
- // keys pressed
- stage.addEventListener("keyDown", seeIfHit);
- stage.addEventListener("keyUp", returnToZeroPosition);
- //
- openingScreen.addEventListener("click", loadLevel);
- stage.addEventListener("enterFrame", updateGrpScore);
- ////////////////////////
- ///////////////////////////////
- ///////////////////////////////////////
- ////////////////// FUNCTIONS ///////////////////
- ///////////////////////////////////////
- ///////////////////////////////
- ////////////////////////
- // load a level
- function loadLevel(eventData) {
- // load game map - currLevel: sleeping zehava
- stage.removeChild(openingScreen);
- stage.addChild(currLevel);
- stage.addChild(grpScore);
- currLevel.soundBeat.nextFrame();
- // start sending arrows up (begin game) as timer starts
- myTime.addEventListener("timer", newArrowTime);
- myTime.start();
- //
- }
- ////////////////////////////////////////////////
- ///////////////// load arrows//////////////////
- ////////////////////////////////////////////////
- // when timer reaches the right time (according to the array) - dispatch an arrow
- function newArrowTime(eventData) {
- if (myTime.currentCount==newArrowTimeArr[arrayFlag]) {
- arrayFlag=arrayFlag+1;
- addArrowToGame();
- }
- }
- // choose random color and direction for an arrow
- function addArrowToGame() {
- var aGameArrow=new gameArrow ;
- //var arrowColor=Math.floor(Math.random()*4)+1;
- var arrowDir=Math.floor(Math.random()*4)+1;
- aGameArrow.gotoAndStop(arrowDir);
- stage.addEventListener("enterFrame", goUP);
- function goUP(eventData) {
- aGameArrow.y=aGameArrow.y-10;//244.83;
- }
- // up arrow
- if (arrowDir==1) {
- aGameArrow.rotation=0;
- aGameArrow.x=168.2;
- checkDirection="up";
- }
- // right arrow
- if (arrowDir==2) {
- aGameArrow.rotation=90;
- aGameArrow.x=361.5;
- checkDirection="right";
- }
- // down arrow
- if (arrowDir==3) {
- aGameArrow.rotation=180;
- aGameArrow.x=264.8;
- checkDirection="down";
- }
- // left arrow
- if (arrowDir==4) {
- aGameArrow.rotation=270;
- aGameArrow.x=71.5;
- checkDirection="left";
- }
- aGameArrow.y=656.5;
- currLevel.loadArrows.addChild(aGameArrow);
- // total 710 pixls. in 2.9 seconds.
- }
- ///////////////////////////////////
- ////////// KEYS reaction //////////
- ///////////////////////////////////
- // when all keys are up - return to the first Zehava position
- function returnToZeroPosition(eventData) {
- currLevel.zehavaPose.gotoAndStop("zeroPos");
- }
- // move Zehave to the right position according to the pressed key - and check if hit was right.
- function seeIfHit(eventData) {
- if (eventData.keyCode==37) {
- currLevel.zehavaPose.gotoAndStop("leftKey");
- if ((checkDirection=="left") && (currLevel.soundBeat.numChildren >0)) {
- //trace("hit left");
- theScore=theScore+pointsPerHit;
- }
- }
- if (eventData.keyCode==38) {
- currLevel.zehavaPose.gotoAndStop("upKey");
- if ((checkDirection=="up") && (currLevel.soundBeat.numChildren >0)) {
- //trace("hit up");
- theScore=theScore+pointsPerHit;
- }
- }
- if (eventData.keyCode==40) {
- currLevel.zehavaPose.gotoAndStop("downKey");
- if ((checkDirection=="down") && (currLevel.soundBeat.numChildren >0)) {
- //trace("hit down");
- theScore=theScore+pointsPerHit;
- }
- }
- if (eventData.keyCode==39) {
- currLevel.zehavaPose.gotoAndStop("rightKey");
- if ((checkDirection=="right") && (currLevel.soundBeat.numChildren >0)) {
- //trace("hit right");
- theScore=theScore+pointsPerHit;
- }
- }
- }
- // updates graphic score
- function updateGrpScore(eventData) {
- if (String(theScore).length==1){
- grpScore.ahadot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-1,String(theScore).length))+1);
- }else if (String(theScore).length==2){
- grpScore.ahadot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-1,String(theScore).length))+1);
- grpScore.asarot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-2,String(theScore).length-1))+1);
- }else if (String(theScore).length==3){
- grpScore.ahadot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-1,String(theScore).length))+1);
- grpScore.asarot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-2,String(theScore).length-1))+1);
- grpScore.meot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-3,String(theScore).length-2))+1);
- }else if (String(theScore).length==4){
- grpScore.ahadot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-1,String(theScore).length))+1);
- grpScore.asarot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-2,String(theScore).length-1))+1);
- grpScore.meot.gotoAndStop(Number(String(theScore).slice(String(theScore).length-3,String(theScore).length-2))+1);
- grpScore.alafim.gotoAndStop(Number(String(theScore).slice(String(theScore).length-3,String(theScore).length-2))+1);
- }
- }