//////////////////////////////
// Fire & Ice
// Tiina Vuorenmaa
// MM3312 CBT/ID4E
// Started: Nov 6, 2009
// Game that teaches adding integers to 6th graders
//////////////////////////////
// UPDATES
// 10/28/2010: Changing code to an external class
// 10/28/2010: adjusted sounds for new fireballs
// 10/28/2010: clean up library
// 10/28/2010: create a volume button
package
{
// IMPORTS
//main imports
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.net.SharedObject;
import flash.net.URLRequest;
import flash.ui.Mouse;
import flash.utils.Timer;
import flash.media.SoundMixer;
// Tweener is a non-native class and must be imported
import caurina.transitions.Tweener;
//curve modifiers for the tweening of the fireballs
import caurina.transitions.properties.CurveModifiers;
public class Main extends MovieClip
{
//// VARIABLES ////
//sounds
private var theSounds:SoundChannel;
private var theVolume:SoundTransform;
private var dropIceCube:Sound;
private var bonusDing:Sound;
private var sweepingGrumbling:Sound;
private var machineWhirr:Sound;
private var oppositePop:Sound;
private var nearBonusPop:Sound;
private var nearBonusHiss:Sound;
private var cloudHiss:Sound;
private var bonusBallSplat:Sound;
private var suckNextIce:Sound;
private var theCloudPoof:Sound;
private var throwTheCube:Sound;
private var throwTheFireball:Sound;
private var nearBonusTick:Sound;
//user variables (scores, level, bonus)
private var currentScore:Number = 0;
private var savedScore:Number = 0;
private var topScore:Number = 300;
private var currentLevel:Number = 1;
private var savedLevel:Number = new Number();
private var currentNumberOfBonusSums:Number = 0;
private var savedNumberOfBonusSums:Number = new Number();
//the ice cubes
//the one that will be used in the equations
private var currentIceCubeNumber:Number = new Number();
//which ice cube movieclip is where
//use numbers 1-4 to relate to the 4 ice cube movieclips in rotation
private var bottomIceCube:Number = new Number();
private var middleIceCube:Number = new Number();
private var topIceCube:Number = new Number();
private var currentIceCube:Number = new Number();
//starting points for the iceCubes
private var iceCubeStartX:Number = 45;
private var iceCubeStartY:Number = 147;
private var iceCubeTopY:Number = 260;
private var iceCubeMiddleY:Number = 314;
private var iceCubeBottomY:Number = 367;
//location out of the cube
private var iceCubeEndX:Number = 190;
private var iceCubeEndY:Number = 397;
//is the ice cube left (-1) or right (1)?
private var iceCubeFace = 1;
//the fireballs
//each fireball is a random number put into an array position
//each array position is put in the same spot, but since the number is random
//it will feel like a random arrangement each time
private var fireballNumberArray:Array = new Array();
//position of each fireball (will be random in a small section for each one)
private var fireballPositionXArray:Array = new Array();
private var fireballPositionYArray:Array = new Array();
//a place to keep all the movie clips so that they can be removed at the end of the round
private var fireballMovieClipArray:Array = new Array();
//how many fireballs?
private var numberOfFireballs:Number = 12;
private var fireballsHit:Number = 0;
private var pauseClicking = false;
//holds the number of the selected fireball
private var selectedFireballNumber:Number = new Number();
//holds the movieclip of the selected fireball
private var selectedFireball;
//the location of the selected fireball
private var selectedFireballX:Number = new Number();
private var selectedFireballY:Number = new Number();
//starting points for the fireballs
private var fireballStartX:Number = 565;
private var fireballStartY:Number = 280;
//for randomly throwing the fireballs
private var alternatingFireball:Number = new Number();
//for hitting the fireball
//the goal number or Bonus Sum
//user gets extra points when they reach this number
private var goalNumber:Number = new Number();
private var randomImageArray:Array;
//the answer
//this changes with each equation
private var answer:Number = new Number();
//points if they get near a bonus sum
private var nearBonusPoints:Number = 40;
private var distanceToGoalNumber:Number = new Number();
private var soClose:Boolean = false;
//arrays to hold the ball movieclips
private var oppositeBallArray:Array = new Array();
private var bonusBallArray:Array = new Array();
private var eggArray:Array = new Array();
private var numOfLights:Number;
//boolean variables
//lets the functions know when to go
private var machineIsLoaded:Boolean = false;
private var gameHasStarted:Boolean = false;
private var wantToQuit:Boolean = false;
private var nextLevel:Boolean = false;
private var savedGame:Boolean = false;
//saving the user data in a shared object on the client's computer
private var savedGameInfo:SharedObject = SharedObject.getLocal("saved_game_info");
////////// FUNCTIONS //////////
public function Main():void
{
//loading the sounds
dropIceCube = new Sound(new URLRequest("sounds/cubedrops.mp3"));
bonusDing = new Sound(new URLRequest("sounds/dingbonus.mp3"));
sweepingGrumbling = new Sound(new URLRequest("sounds/grumbling.mp3"));
machineWhirr = new Sound(new URLRequest("sounds/machine.mp3"));
oppositePop = new Sound(new URLRequest("sounds/opposite.mp3"));
nearBonusPop = new Sound(new URLRequest("sounds/nearbonus.mp3"));
//mySound = new Sound(new URLRequest("sounds/popicecube.mp3"));
nearBonusHiss = new Sound(new URLRequest("sounds/soclose.mp3"));
cloudHiss = new Sound(new URLRequest("sounds/endcloud.mp3"));
bonusBallSplat = new Sound(new URLRequest("sounds/splat.mp3"));
suckNextIce = new Sound(new URLRequest("sounds/suckcubepop.mp3"));
theCloudPoof = new Sound(new URLRequest("sounds/thecloud.mp3"));
throwTheCube = new Sound(new URLRequest("sounds/throwcube.mp3"));
throwTheFireball = new Sound(new URLRequest("sounds/throwfireball.mp3"));
nearBonusTick = new Sound(new URLRequest("sounds/tickdown.mp3"));
//initializing the curve modifiers for the tweens
CurveModifiers.init();
//check the volume
theVolume = new SoundTransform(1, 0);
flash.media.SoundMixer.soundTransform = theVolume;
volumeButtons.volumeOffButton.addEventListener(MouseEvent.CLICK, turnOffVolume);
//start with the opening screens
showOpeningScreen();
}
private function turnOffVolume(event:MouseEvent):void
{
theVolume = new SoundTransform(0, 0);
flash.media.SoundMixer.soundTransform = theVolume;
volumeButtons.volumeOffButton.removeEventListener(MouseEvent.CLICK, turnOffVolume);
volumeButtons.volumeOffButton.x = 500;
volumeButtons.volumeOnButton.addEventListener(MouseEvent.CLICK, turnOnVolume);
volumeButtons.volumeOnButton.x = 26.65;
}
private function turnOnVolume(event:MouseEvent):void
{
theVolume = new SoundTransform(1, 0);
flash.media.SoundMixer.soundTransform = theVolume;
volumeButtons.volumeOnButton.removeEventListener(MouseEvent.CLICK, turnOnVolume);
volumeButtons.volumeOnButton.x = 500;
volumeButtons.volumeOffButton.addEventListener(MouseEvent.CLICK, turnOffVolume);
volumeButtons.volumeOffButton.x = 26.65;
}
////////////////// HOVER FUNCTIONS ///////////////
//allows the crosshairs to follow the mouse
private function followMouse(event:Event):void
{
if ((mouseX>=450 && mouseX<=640)&&(mouseY>=0 && mouseY<=40))
{
crossHairs.x = -500;
crossHairs.y = -500;
Mouse.show();
}
else
{
crossHairs.x = mouseX;
crossHairs.y = mouseY;
Mouse.hide();
crossHairs.mouseEnabled = false;
crossHairs.mouseChildren = false;
}
}
private function highlightFireball(event:MouseEvent):void
{
//when the mouse hovers over the fireball
//the fireball changes color
event.target.fireballHover.alpha = 1;
//the middles cross disappears
crossHairs.middleCross.alpha = 0;
crossHairs.alpha = 0.5;
//the machine equation changes
machineOnTop.equationText.text = currentIceCubeNumber + " + " + event.target.fireballNumber.text + " = ?";
}
private function unHighlightFireball(event:MouseEvent):void
{
//when the mouse goes away from a fireball
//the fireball changes back
event.target.fireballHover.alpha = 0;
//the middles cross comesback
crossHairs.middleCross.alpha = 1;
//the machine equation changes
machineOnTop.equationText.text = currentIceCubeNumber + " + ? = ?";
}
private function hoverOverLake(event:MouseEvent):void
{
iceCubeLake.lakeHover.alpha = 1;
crossHairs.middleCross.alpha = 0;
crossHairs.alpha = 0.5;
iceCubeLake.lakeSignText.text = "Click Here";
}
private function hoverOffLake(event:MouseEvent):void
{
iceCubeLake.lakeHover.alpha = 0;
crossHairs.middleCross.alpha = 1;
crossHairs.alpha = 1;
iceCubeLake.lakeSignText.text = "Throw Out Ice";
}
private function hoverOverVolcano(event:MouseEvent):void
{
volcano.volcanoHover.alpha = 1;
crossHairs.middleCross.alpha = 0;
crossHairs.alpha = 0.5;
//volcano.volcanoText.text = "Click Here";
}
private function hoverOffVolcano(event:MouseEvent):void
{
volcano.volcanoHover.alpha = 0;
crossHairs.middleCross.alpha = 1;
crossHairs.alpha = 1;
//volcano.volcanoText.text = "New Fireballs";
}
//shows the crosshairs
//listens for hovering
private function showCursor():void
{
pauseClicking = true;
//show new equation
machineOnTop.equationText.text = currentIceCubeNumber + " + ? = ?";
//shows the GoalNumber even if it has changed or not
//this will refresh it
showGoalNumber();
getNewSmashingSum();
crossHairs.alpha = 1;
crossHairs.mouseEnabled = true;
stage.addChild(crossHairs);
}
///////////// INFO SCREEN FUNCTIONS /////////////
private function keepButtonsOnTop():void
{
stage.addChild(infoScreen);
stage.addChild(helpButton);
stage.addChild(quitButton);
stage.addChild(volumeButtons);
}
//brings up a screen asking the user to load or play a game
private function showQuitScreen(event:MouseEvent):void
{
wantToQuit = true;
keepButtonsOnTop();
pauseClicking = false;
//bring up information box
infoScreen.x = (stage.stageWidth)/2;
infoScreen.y = (stage.stageHeight)/2;
//write in the title and text and buttons
infoScreen.infoTitle.text = "Do you want to Quit?";
infoScreen.infoLine1.text = " ";
infoScreen.infoLine2.text = "Hint: Click on the volcano for new fireballs!";
infoScreen.infoButton1.infoButtonText.text = "Quit";
infoScreen.infoButton2.infoButtonText.text = "Restart";
infoScreen.infoButton3.infoButtonText.text = "Back";
infoScreen.introScreen.alpha = 0;
infoScreen.endOfLevelScores.alpha = 0;
//show the buttons
infoScreen.infoButton1.alpha = 1;
infoScreen.infoButton2.alpha = 1;
infoScreen.infoButton3.alpha = 1;
infoScreen.infoButton1.buttonMode = true;
infoScreen.infoButton2.buttonMode = true;
infoScreen.infoButton3.buttonMode = true;
//add event listeners for buttons
infoScreen.infoButton1.addEventListener(MouseEvent.CLICK, quitGame);
infoScreen.infoButton2.addEventListener(MouseEvent.CLICK, startGame);
infoScreen.infoButton3.addEventListener(MouseEvent.CLICK, clearQuitScreen);
//make sure the buttonmode for the close button is off
//infoScreen.closeButton.buttonMode = false;
infoScreen.closeHelpButton.alpha = 0;
infoScreen.scoreLinkButton.y = -1000;
infoScreen.helpLinkButton.y = -1000;
//show the mouse again
Mouse.show();
stage.removeEventListener(Event.ENTER_FRAME, followMouse);
crossHairs.alpha = 0;
}
//clears the opening screen
private function clearQuitScreen(event:MouseEvent):void
{
wantToQuit = false;
//clear the buttons
infoScreen.infoButton1.alpha = 0;
infoScreen.infoButton2.alpha = 0;
infoScreen.infoButton3.alpha = 0;
infoScreen.infoButton1.buttonMode = false;
infoScreen.infoButton2.buttonMode = false;
infoScreen.infoButton3.buttonMode = false;
//remove event listeners for buttons
infoScreen.infoButton1.removeEventListener(MouseEvent.CLICK, startGame);
infoScreen.infoButton2.removeEventListener(MouseEvent.CLICK, startGame);
infoScreen.infoButton3.removeEventListener(MouseEvent.CLICK, clearQuitScreen);
infoScreen.introScreen.alpha = 0;
infoScreen.infoLine1.text = "";
infoScreen.infoLine2.text = "";
//remove infoscreen
infoScreen.x = -1000;
showCursor();
//show the mouse again
Mouse.hide();
stage.addEventListener(Event.ENTER_FRAME, followMouse);
crossHairs.alpha = 1;
}
//brings up a screen asking the user to load or play a game
private function showOpeningScreen():void
{
keepButtonsOnTop();
//bring up information box
infoScreen.x = (stage.stageWidth)/2;
infoScreen.y = (stage.stageHeight)/2;
//write in the title and text and buttons
infoScreen.infoTitle.text = "Put Out The Fireballs!";
infoScreen.infoLine1.text = "Smash two numbers into one!" + "\n" + "\n" + "\n" + "How close can YOU come?";
infoScreen.infoLine2.text = "";
infoScreen.infoButton1.infoButtonText.text = "Play";
infoScreen.infoButton2.infoButtonText.text = "Continue";
infoScreen.infoButton3.infoButtonText.text = "Help?";
infoScreen.introScreen.alpha = 1;
infoScreen.endOfLevelScores.alpha = 0;
//show the buttons
infoScreen.infoButton1.alpha = 1;
infoScreen.infoButton2.alpha = 1;
infoScreen.infoButton3.alpha = 1;
infoScreen.infoButton1.buttonMode = true;
infoScreen.infoButton2.buttonMode = true;
infoScreen.infoButton3.buttonMode = true;
//get the saved info at the start
getSavedGameInfo();
trace("saved score = " +savedScore);
if (savedScore != 0)
{
savedGame = true;
}
//add event listeners for buttons
infoScreen.infoButton1.addEventListener(MouseEvent.CLICK, startGame);
infoScreen.infoButton2.addEventListener(MouseEvent.CLICK, startGame);
infoScreen.infoButton3.addEventListener(MouseEvent.CLICK, showHelpIntegerScreen);
//make sure the buttonmode for the close button is off
//infoScreen.closeButton.buttonMode = false;
infoScreen.closeHelpButton.alpha = 0;
infoScreen.scoreLinkButton.y = -1000;
infoScreen.helpLinkButton.y = -1000;
}
//clears the opening screen
private function clearOpeningScreen():void
{
//clear the buttons
infoScreen.infoButton1.alpha = 0;
infoScreen.infoButton2.alpha = 0;
infoScreen.infoButton3.alpha = 0;
infoScreen.infoButton1.buttonMode = false;
infoScreen.infoButton2.buttonMode = false;
infoScreen.infoButton3.buttonMode = false;
//remove event listeners for buttons
infoScreen.infoButton1.removeEventListener(MouseEvent.CLICK, startGame);
infoScreen.infoButton2.removeEventListener(MouseEvent.CLICK, startGame);
infoScreen.infoButton3.removeEventListener(MouseEvent.CLICK, showHelpIntegerScreen);
infoScreen.introScreen.alpha = 0;
infoScreen.infoLine1.text = "";
infoScreen.infoLine2.text = "";
//remove infoscreen
infoScreen.x = -1000;
}
private function showHelpIntegerScreen(event:MouseEvent):void
{
keepButtonsOnTop();
pauseClicking = false;
clearOpeningScreen();
//bring up information box
infoScreen.x = (stage.stageWidth)/2;
infoScreen.y = (stage.stageHeight)/2;
//write title
infoScreen.infoTitle.text = "";
//show the integer information
infoScreen.helpIntegers.alpha = 1;
infoScreen.helpScoring.alpha = 0;
infoScreen.endOfLevelScores.alpha = 0;
//add event listeners for buttons
infoScreen.closeHelpButton.alpha = 1;
infoScreen.closeHelpButton.addEventListener(MouseEvent.CLICK, clearHelpScreen);
//link to switch help screens
infoScreen.scoreLinkButton.y = -104.6;
infoScreen.helpLinkButton.y = -1000;
infoScreen.scoreLinkButton.addEventListener(MouseEvent.CLICK, showHelpScoringScreen);
infoScreen.helpLinkButton.removeEventListener(MouseEvent.CLICK, showHelpIntegerScreen);
helpButton.removeEventListener(MouseEvent.CLICK, showHelpIntegerScreen);
//show the mouse again
Mouse.show();
stage.removeEventListener(Event.ENTER_FRAME, followMouse);
crossHairs.alpha = 0;
}
private function showHelpScoringScreen(event:MouseEvent):void
{
clearOpeningScreen();
//bring up information box
infoScreen.x = (stage.stageWidth)/2;
infoScreen.y = (stage.stageHeight)/2;
//write title
infoScreen.infoTitle.text = "";
//show the integer information
infoScreen.helpScoring.alpha = 1;
infoScreen.helpIntegers.alpha = 0;
infoScreen.endOfLevelScores.alpha = 0;
//add event listeners for buttons
infoScreen.closeHelpButton.alpha = 1;
infoScreen.closeHelpButton.addEventListener(MouseEvent.CLICK, clearHelpScreen);
//link to switch help screens
infoScreen.scoreLinkButton.y = -1000;
infoScreen.helpLinkButton.y = -104.2;
infoScreen.scoreLinkButton.removeEventListener(MouseEvent.CLICK, showHelpScoringScreen);
infoScreen.helpLinkButton.addEventListener(MouseEvent.CLICK, showHelpIntegerScreen);
}
//clears the opening screen
private function clearHelpScreen(event:MouseEvent):void
{
//remove event listeners for buttons
infoScreen.closeHelpButton.removeEventListener(MouseEvent.CLICK, clearHelpScreen);
//clear the screen
infoScreen.helpIntegers.alpha = 0;
infoScreen.helpScoring.alpha = 0;
infoScreen.x = -1000;
//if the game has started, go back
if (gameHasStarted)
{
showCursor();
//show the mouse again
Mouse.hide();
stage.addEventListener(Event.ENTER_FRAME, followMouse);
crossHairs.alpha = 1;
}
else
{
//else show the opening screen again
showOpeningScreen();
}
}
//brings up a screen at the end of the level
private function showEndOfLevelScreen():void
{
//bring up information box
infoScreen.x = (stage.stageWidth)/2;
infoScreen.y = (stage.stageHeight)/2;
//write in the title and text and buttons
infoScreen.infoTitle.text = "Congratulations!";
if (currentLevel == 2)
{
infoScreen.infoLine1.text = "You've finished Level 2" + "\n" + "Your game is saved.";
}
else
{
infoScreen.infoLine1.text = "You've finished Level 1" + "\n" + "Your game is saved.";
}
infoScreen.infoLine2.text = "Do you want to replay the level again?";
//shows the current score in the textbox scoreText
infoScreen.endOfLevelScores.scoreText.text = currentScore.toString();
//shows current bonuses in the textbox
infoScreen.endOfLevelScores.bonusSumText.text = currentNumberOfBonusSums.toString();
infoScreen.infoButton1.infoButtonText.text = "Replay";
infoScreen.infoButton2.infoButtonText.text = "Continue";
infoScreen.infoButton3.infoButtonText.text = "Help?";
infoScreen.introScreen.alpha = 0;
infoScreen.endOfLevelScores.alpha = 1;
//show the buttons
infoScreen.infoButton1.alpha = 1;
infoScreen.infoButton2.alpha = 1;
infoScreen.infoButton3.alpha = 1;
infoScreen.infoButton1.buttonMode = true;
infoScreen.infoButton2.buttonMode = true;
infoScreen.infoButton3.buttonMode = true;
//add event listeners for buttons
nextLevel = true;
infoScreen.infoButton1.addEventListener(MouseEvent.CLICK, startGame);
infoScreen.infoButton2.addEventListener(MouseEvent.CLICK, startGame);
infoScreen.infoButton3.addEventListener(MouseEvent.CLICK, showHelpIntegerScreen);
//make sure the buttonmode for the close button is off
//infoScreen.closeButton.buttonMode = false;
infoScreen.closeHelpButton.alpha = 0;
infoScreen.scoreLinkButton.y = -1000;
infoScreen.helpLinkButton.y = -1000;
}
//clears the end of level screen
private function clearEndOfLevelScreen():void
{
//remove event listeners for buttons
//infoScreen.infoButton1.removeEventListener(MouseEvent.CLICK, startGame);
infoScreen.x = -1000;
}
/////////////// END OF LEVEL ACTION ////////////
//ends the level
private function endTheLevel():void
{
//record the score
//savedScore = currentScore;
saveSavedGameInfo();
getSavedGameInfo();
//remove the ice cubes
iceCube1.x = iceCubeStartX;
iceCube2.x = iceCubeStartX;
iceCube3.x = iceCubeStartX;
iceCube4.x = iceCubeStartX;
iceCube1.y = iceCubeStartY;
iceCube2.y = iceCubeStartY;
iceCube3.y = iceCubeStartY;
iceCube4.y = iceCubeStartY;
//remove the fireballs from the array
fireballMovieClipArray = new Array();
//remove listeners and clear arrays for the opposite and bonus balls
for (var i:int = 0; i=10)
{
for( var i:int = 0; igoalNumber)
{
//if the answer is higher subtract it down
answer--;
theCloud.cloudAnswer.x+=70/distanceToGoalNumber;
}
else if (goalNumber>answer)
{
//if the goal number is higher add up the answer
answer++;
theCloud.cloudAnswer.x+=70/distanceToGoalNumber;
}
//show it
//play the tick sound
theSounds = nearBonusTick.play();
theCloud.cloudAnswer.cloudAnswerText.text=answer.toString();
theCloud.cloudBonus.cloudBonusText.text=goalNumber.toString();
}
private function showPointsCountingDown(event:TimerEvent):void
{
//subtract the points per tick
nearBonusPoints-=10;
floatingPoints.floatingPointsText.text=nearBonusPoints.toString()+" points";
}
private function startNearBonusAnimation(event:TimerEvent):void
{
//clear the distance to the goal number before calculating it
distanceToGoalNumber= new Number();
//show the points at first
//position it in the cloud
floatingPoints.x=selectedFireballX;
floatingPoints.y=selectedFireballY-17;
trace("points = " +nearBonusPoints);
//show the points
stage.addChild(floatingPoints);
floatingPoints.alpha=1;
nearBonusPoints=40;
floatingPoints.floatingPointsText.text=nearBonusPoints.toString()+" points";
//add the answer and cloud boxes
theCloud.cloudAnswer.x=theCloud.cloudBonus.x-140;
theCloud.cloudEquationText.text="";
theCloud.cloudAnswer.alpha=1;
theCloud.cloudAnswer.cloudAnswerText.text=answer.toString();
theCloud.cloudBonus.alpha=1;
theCloud.cloudBonus.cloudBonusText.text=goalNumber.toString();
//get the distance to the goal number
if (answer>goalNumber)
{
distanceToGoalNumber = (answer - goalNumber);
trace("distanceToGoalNumber = " +distanceToGoalNumber);
}
else if (goalNumber>answer)
{
distanceToGoalNumber = (goalNumber - answer);
trace("distanceToGoalNumber = " +distanceToGoalNumber);
}
//start the timer for ticking down the points/answer
//added a plus one to show the answer first
var soCloseTimer:Timer=new Timer(300,distanceToGoalNumber);
soCloseTimer.addEventListener(TimerEvent.TIMER, showDistanceFromGoalNumber);
soCloseTimer.addEventListener(TimerEvent.TIMER, showPointsCountingDown);
// check if the distance is too far, end it with nothing
if (distanceToGoalNumber>3)
{
theCloud.commentText.text="awwwww...";
soCloseTimer.addEventListener(TimerEvent.TIMER_COMPLETE, changeScoreAtEnd);
//notBonusTimer.start();
}
else if (distanceToGoalNumber<=3)
{
//else if the distance is close, end it with an egg
theCloud.commentText.text="getting there!";
theSounds = nearBonusPop.play();
soCloseTimer.addEventListener(TimerEvent.TIMER_COMPLETE, dropNearBonusEgg);
}
soCloseTimer.start();
}
//check the answer of the selected fireball and current ice cube
private function checkAnswer():void
{
//show answer in the cloud
//theCloud.cloudEquationText.text=answer.toString();
var cloudTimer:Timer=new Timer(1000,1);
//if the answer is the bonus sum
if (answer==goalNumber)
{
currentScore+=50;
goalNumber=getGoalNumber();
trace("currentScore is "+ currentScore);
//add a comment
theSounds = bonusDing.play();
theCloud.commentText.text="woohoo!";
//wait
cloudTimer.addEventListener(TimerEvent.TIMER_COMPLETE, startBonusAnimation);
cloudTimer.start();
numOfLights = 0;
}
else if (answer == 0)
{
currentScore+=5;
trace("currentScore is "+ currentScore);
//add a comment
theSounds = oppositePop.play();
theCloud.commentText.text="nice.";
//wait
cloudTimer.addEventListener(TimerEvent.TIMER_COMPLETE, startOppositeAnimation);
cloudTimer.start();
numOfLights++;
}
else
{
soClose=true;
//wait
cloudTimer.addEventListener(TimerEvent.TIMER_COMPLETE, startNearBonusAnimation);
cloudTimer.start();
numOfLights++;
}
showThreeLights();
}
private function showThreeLights():void
{
switch(numOfLights)
{
case 0:
machineOnTop.threeLights.gotoAndPlay("smashingSum");
Tweener.addTween(machineOnTop.smashingSum, {scaleX:1.5, scaleY:1.5, time:1, transition:"easeOutBack"});
Tweener.addTween(machineOnTop.smashingSum, {scaleX:1, scaleY:1, time:1, delay:1, transition:"easeOutBack"});
break;
case 1:
machineOnTop.threeLights.gotoAndPlay("oneHit");
break;
case 2:
machineOnTop.threeLights.gotoAndPlay("twoHit");
break;
case 3:
machineOnTop.threeLights.gotoAndPlay("threeHit");
Tweener.addTween(machineOnTop.smashingSum, {scaleX:0, scaleY:0, time:1, transition:"easeOutBack"});
//getNewSmashingSum();
break;
default:
break;
}//end switch
}
private function getNewSmashingSum():void
{
if(numOfLights >= 3)
{
goalNumber = getGoalNumber();
showGoalNumber();
numOfLights = 0;
Tweener.addTween(machineOnTop.smashingSum, {scaleX:1, scaleY:1, time:1, transition:"easeOutBack"});
machineOnTop.threeLights.gotoAndStop("off");
}
else if(numOfLights == 0)
{
machineOnTop.threeLights.gotoAndStop("off");
}
}
private function showCloud():void
{
//show changed equation on the machine
answer=selectedFireballNumber+currentIceCubeNumber;
machineOnTop.equationText.text=currentIceCubeNumber+" + "+selectedFireballNumber+" = "+answer;
trace("answer: " + answer);
trace("goal number is "+ goalNumber);
//show the cloud with the equation
//create the cloud
stage.addChild(theCloud);
theCloud.x=selectedFireballX;
theCloud.y=selectedFireballY;
theCloud.cloudBonus.alpha=0;
theCloud.cloudAnswer.alpha=0;
theCloud.alpha=0;
theCloud.scaleX=0.1;
theCloud.scaleY=0.1;
theSounds = theCloudPoof.play();
Tweener.addTween(theCloud, {alpha:1, scaleX:1, scaleY:1, time:1, transition:"easeOutBack", onComplete:checkAnswer});
theCloud.cloudEquationText.text=currentIceCubeNumber+" + "+selectedFireballNumber+" = "+answer;
stage.removeChild(selectedFireball);
}
//if the ice cube is thrown away
private function missFireball(event:MouseEvent):void
{
//if a fireball has not been hit yet, go through
// hide the cursor
if (event.target.name=="helpButton")
{
//don't throw the cube
trace("help has been clicked");
}
else
{
if (pauseClicking)
{
theSounds = throwTheCube.play();
//make crosshairs lighter
crossHairs.alpha=0.2;
//make it so they can't click on anything
crossHairs.mouseEnabled=true;
//a ice cube has been thrown
//no other fireballs can be clicked
pauseClicking=false;
//change score
currentScore-=10;
showScore();
trace(event.target.name + " is hit!");
//loop through the fireball array in order to find the one that is hit
//find the location of the target
var throwCubeX:Number=mouseX;
var throwCubeY:Number=mouseY;
//move ice cube toward the fireball
//get the current icecube
switch (currentIceCube)
{
case 1 :
Tweener.addTween(iceCube1, {x:throwCubeX, y:throwCubeY, _bezier:{x:throwCubeX+50, y:throwCubeY-100}, scaleX:0, scaleY:0, time:1, transition:"EaseOutQuad", onComplete:getNextIce});
break;
case 2 :
Tweener.addTween(iceCube2, {x:throwCubeX, y:throwCubeY, _bezier:{x:throwCubeX+50, y:throwCubeY-100}, scaleX:0, scaleY:0, time:1, transition:"EaseOutQuad", onComplete:getNextIce});
break;
case 3 :
Tweener.addTween(iceCube3, {x:throwCubeX, y:throwCubeY, _bezier:{x:throwCubeX+50, y:throwCubeY-100}, scaleX:0, scaleY:0, time:1, transition:"EaseOutQuad", onComplete:getNextIce});
break;
case 4 :
Tweener.addTween(iceCube4, {x:throwCubeX, y:throwCubeY, _bezier:{x:throwCubeX+50, y:throwCubeY-100}, scaleX:0, scaleY:0, time:1, transition:"EaseOutQuad", onComplete:getNextIce});
break;
default :
}//end switch
}//end if
}//end if it is the help button
}
//if the fireball is hit, checks the answer and points
private function hitFireball(event:MouseEvent):void
{
//if a fireball has not been hit yet, go through
// hide the cursor
crossHairs.alpha=0.2;
crossHairs.mouseEnabled=true;
if (pauseClicking)
{
theSounds = throwTheCube.play();
//a fireball has been hit
//no other fireballs can be clicked
pauseClicking=false;
fireballsHit++;
trace(event.target.name + " is hit!");
//loop through the fireball array in order to find the one that is hit
//find the location of the target
selectedFireballX=event.target.x;
selectedFireballY=event.target.y;
//get the number of the selected fireball
selectedFireballNumber=Number(event.target.fireballNumber.text);
//remove the event listener
event.target.removeEventListener(MouseEvent.CLICK, hitFireball);
event.target.addEventListener(MouseEvent.MOUSE_OVER, highlightFireball);
event.target.addEventListener(MouseEvent.MOUSE_OUT, unHighlightFireball);
//move ice cube toward the fireball
//get the current icecube
switch (currentIceCube)
{
case 1 :
Tweener.addTween(iceCube1, {x:selectedFireballX, y:selectedFireballY, _bezier:{x:selectedFireballX+50, y:selectedFireballY-100}, scaleX:0.8, scaleY:0.8, time:0.7, transition:"EaseOutQuad", onComplete:showCloud});
break;
case 2 :
Tweener.addTween(iceCube2, {x:selectedFireballX, y:selectedFireballY, _bezier:{x:selectedFireballX+50, y:selectedFireballY-100}, scaleX:0.8, scaleY:0.8, time:0.7, transition:"EaseOutQuad", onComplete:showCloud});
break;
case 3 :
Tweener.addTween(iceCube3, {x:selectedFireballX, y:selectedFireballY, _bezier:{x:selectedFireballX+50, y:selectedFireballY-100}, scaleX:0.8, scaleY:0.8, time:0.7, transition:"EaseOutQuad", onComplete:showCloud});
break;
case 4 :
Tweener.addTween(iceCube4, {x:selectedFireballX, y:selectedFireballY, _bezier:{x:selectedFireballX+50, y:selectedFireballY-100}, scaleX:0.8, scaleY:0.8, time:0.7, transition:"EaseOutQuad", onComplete:showCloud});
break;
default :
}
//search for the fireball to remove it on showCloud
var s:int=0;
while (s=topScore)
{
topScore=currentScore;
showTopScore();
}
}
////////////// BEGINNING FUNCTIONS //////////////
//sets up the random numbers, score, level etc.
private function setUpPreGameVariables():void
{
numOfLights = 0;
fireballPositionXArray=[220,420,520,320,150,250,380,470,170,340,270,540];
fireballPositionYArray=[100,115,110,125,140,180,240,190,220,190,270,230];
//assign the fireballs a random number and random-ish position
for (var f:Number = 0; f < numberOfFireballs; f++)
{
//assigns the number in the array
fireballNumberArray[f]=getFireballNumber();
//trace(fireballNumberArray[f]);
//adjusts the position in the position arrays
//the math is to get a random number between -10 and 10
fireballPositionXArray[f] += ((Math.random() * 20) - 10 );
fireballPositionYArray[f] += ((Math.random() * 20) - 10 );
//puts a number in there that will get "popped" when used in throw Fireballs
//randomThrowerTotalArray.push(f);
}
fireballsHit=0;
goalNumber=getGoalNumber();
//trace(goalNumber);
gameHasStarted=true;
randomImageArray = new Array();
}//end setUpPreGameVariables
private function getIceCubeNumber():Number
{
if (currentLevel==2)
{
//the ice cube number for level 2
//random number between -1 and -15
return Math.floor(Math.random() * 15) - 15;
}
else
{
//the ice cube number for level 1
//random number between -1 and -9
return Math.floor(Math.random() * 9) - 9;
}
}
private function getFireballNumber():Number
{
if (currentLevel==2)
{
//the fireball number for level 2
//these need to be more lower because they do not get created a lot of times
var level2FireballNum:Number;
//two numbers to choose from
//random number between 1 and 9
var smallerRandomNum:Number = Math.floor(Math.random() * 9) + 1;
//random number between 01 and 15
var largerRandomNum:Number = Math.floor(Math.random() * 5) + 10;
//the chance of which of the two numbers we get (choose from 1-3)
var randomizerNum:Number = Math.floor(Math.random() * 3) + 1;
if (randomizerNum <=2)
{
level2FireballNum = smallerRandomNum;
}
else
{
//only get the largerRandomNum if the randomizerNum is 3
level2FireballNum = largerRandomNum;
}
return level2FireballNum;
}
else
{
//the fireballs number for level 1
//random number between 1 and 9
return Math.floor(Math.random() * 9) + 1;
}
}
private function getGoalNumber():Number
{
var theGNum:Number = new Number();
if (currentLevel==2)
{
//for level 2
//random number between -9 and 9 without zero
//get a random number between 1 or 2
var positiveOrNegative2:Number=Math.floor(Math.random()*2)+1;
switch (positiveOrNegative2)
{
case 1 :
//random number between 1 and 9
theGNum=Math.floor(Math.random()*9)+1;
break;
case 2 :
//random number between -1 and -9
theGNum=Math.floor(Math.random()*9)-9;
break;
default :
//won't ever return 0, if so, then something is going wrong
theGNum=0;
}//end switch
}
else
{
//for level 1
//random number between -5 and 5 without zero
//get a random number between 1 or 3
var positiveOrNegative1:Number=Math.floor(Math.random()*2)+1;
switch (positiveOrNegative1)
{
case 1 :
//random number between 1 and 5
theGNum=Math.floor(Math.random()*5)+1;
break;
case 2 :
//random number between -1 and -5
theGNum=Math.floor(Math.random()*5)-5;
break;
default :
//won't ever return 0, if so, then something is going wron
theGNum=0;
}//end switch
}
return theGNum;
}
private function showTopScore():void
{
//shows the current score in the textbox topScoreText
topScoreText.text=topScore.toString();
}
private function showScore():void
{
//shows the current score in the textbox scoreText
scoreText.text=currentScore.toString();
}
private function showLevel():void
{
//shows the current level in the textbox levelText
levelText.text=currentLevel.toString();
}
private function showBonusSum():void
{
//shows the current round in the textbox roundText
bonusSumText.text=currentNumberOfBonusSums.toString();
}
private function showGoalNumber():void
{
//shows the goal number in the textbox machineOnTop.smashingSum.goalNumText
machineOnTop.smashingSum.goalNumText.text=goalNumber.toString();
}
private function getNextIce():void
{
trace("get next Ice");
//check to see which numbered ice is the bottom ice
theSounds = suckNextIce.play();
theSounds = machineWhirr.play();
//theSounds = dropIceCube.play(5,3);
switch (bottomIceCube)
{
//if the bottom Icecube is icecube1
case 1 :
//bottom ice shrinks and drops
Tweener.addTween(iceCube1, {y:iceCube1.y+50, scaleX:0, scaleY:0, time:0.5, transition:"linear"});
//bottom ice becomes current ice
currentIceCubeNumber=Number(iceCube1.iceCubeNumber.text);
currentIceCube=1;
//current ice grows and pops up
Tweener.addTween(iceCube1, {x:iceCubeEndX-20, y:iceCubeEndY+50, time:0.5, delay:0.5, transition:"linear"});
Tweener.addTween(iceCube1, {x:iceCubeEndX, y:iceCubeEndY, scaleX:1, scaleY:1, time:0.5, delay:1, transition:"easeOutBounce"});
//drop middle cube to bottom
//once tween is done go to middle cube tween
Tweener.addTween(iceCube2, {y:iceCubeBottomY, time:0.5, delay:0.5, transition:"easeOutBounce"});
//middle cube is now bottom cube
bottomIceCube=2;
//drop top cube to middle
Tweener.addTween(iceCube3, {y:iceCubeMiddleY, time:0.5, delay:1, transition:"easeOutBounce"});
middleIceCube=3;
//drop new top cube
iceCube4.x=iceCubeStartX;
iceCube4.y=iceCubeStartY;
iceCube4.scaleX=1;
iceCube4.scaleY=1;
iceCube4.iceCubeNumber.text=getIceCubeNumber().toString();
topIceCube=4;
Tweener.addTween(iceCube4, {y:iceCubeTopY, time:0.5, delay:1.5, transition:"easeOutBounce", onComplete:showCursor});
//new top ice drops
break;
//if the bottom Icecube is icecube2
case 2 :
//bottom ice shrinks and drops
Tweener.addTween(iceCube2, {y:iceCube2.y+50, scaleX:0, scaleY:0, time:0.5, transition:"linear"});
//bottom ice becomes current ice
currentIceCubeNumber=Number(iceCube2.iceCubeNumber.text);
currentIceCube=2;
//current ice grows and pops up
Tweener.addTween(iceCube2, {x:iceCubeEndX-20, y:iceCubeEndY+50, time:0.5, delay:0.5, transition:"linear"});
Tweener.addTween(iceCube2, {x:iceCubeEndX, y:iceCubeEndY, scaleX:1, scaleY:1, time:0.5, delay:1, transition:"easeOutBounce"});
//drop middle cube to bottom
//once tween is done go to middle cube tween
Tweener.addTween(iceCube3, {y:iceCubeBottomY, time:0.5, delay:0.5, transition:"easeOutBounce"});
//middle cube is now bottom cube
bottomIceCube=3;
//drop top cube to middle
Tweener.addTween(iceCube4, {y:iceCubeMiddleY, time:0.5, delay:1, transition:"easeOutBounce"});
middleIceCube=4;
//drop new top cube
iceCube1.x=iceCubeStartX;
iceCube1.y=iceCubeStartY;
iceCube1.scaleX=1;
iceCube1.scaleY=1;
iceCube1.iceCubeNumber.text=getIceCubeNumber().toString();
topIceCube=1;
Tweener.addTween(iceCube1, {y:iceCubeTopY, time:0.5, delay:1.5, transition:"easeOutBounce", onComplete:showCursor});
//new top ice drops
break;
//if the bottom Icecube is icecube3
case 3 :
//bottom ice shrinks and drops
Tweener.addTween(iceCube3, {y:iceCube3.y+50, scaleX:0, scaleY:0, time:0.5, transition:"linear"});
//bottom ice becomes current ice
currentIceCubeNumber=Number(iceCube3.iceCubeNumber.text);
currentIceCube=3;
//current ice grows and pops up
Tweener.addTween(iceCube3, {x:iceCubeEndX-20, y:iceCubeEndY+50, time:0.5, delay:0.5, transition:"linear"});
Tweener.addTween(iceCube3, {x:iceCubeEndX, y:iceCubeEndY, scaleX:1, scaleY:1, time:0.5, delay:1, transition:"easeOutBounce"});
//drop middle cube to bottom
//once tween is done go to middle cube tween
Tweener.addTween(iceCube4, {y:iceCubeBottomY, time:0.5, delay:0.5, transition:"easeOutBounce"});
//middle cube is now bottom cube
bottomIceCube=4;
//drop top cube to middle
Tweener.addTween(iceCube1, {y:iceCubeMiddleY, time:0.5, delay:1, transition:"easeOutBounce"});
middleIceCube=1;
//drop new top cube
iceCube2.x=iceCubeStartX;
iceCube2.y=iceCubeStartY;
iceCube2.scaleX=1;
iceCube2.scaleY=1;
iceCube2.iceCubeNumber.text=getIceCubeNumber().toString();
topIceCube=2;
Tweener.addTween(iceCube2, {y:iceCubeTopY, time:0.5, delay:1.5, transition:"easeOutBounce", onComplete:showCursor});
//new top ice drops
break;
//if the bottom Icecube is icecube4
case 4 :
//bottom ice shrinks and drops
Tweener.addTween(iceCube4, {y:iceCube4.y+50, scaleX:0, scaleY:0, time:0.5, transition:"linear"});
//bottom ice becomes current ice
currentIceCubeNumber=Number(iceCube4.iceCubeNumber.text);
currentIceCube=4;
//current ice grows and pops up
Tweener.addTween(iceCube4, {x:iceCubeEndX-20, y:iceCubeEndY+50, time:0.5, delay:0.5, transition:"linear"});
Tweener.addTween(iceCube4, {x:iceCubeEndX, y:iceCubeEndY, scaleX:1, scaleY:1, time:0.5, delay:1, transition:"easeOutBounce"});
//drop middle cube to bottom
//once tween is done go to middle cube tween
Tweener.addTween(iceCube1, {y:iceCubeBottomY, time:0.5, delay:0.5, transition:"easeOutBounce"});
//middle cube is now bottom cube
bottomIceCube=1;
//drop top cube to middle
Tweener.addTween(iceCube2, {y:iceCubeMiddleY, time:0.5, delay:1, transition:"easeOutBounce"});
middleIceCube=2;
//drop new top cube
iceCube3.x=iceCubeStartX;
iceCube3.y=iceCubeStartY;
iceCube3.scaleX=1;
iceCube3.scaleY=1;
iceCube3.iceCubeNumber.text=getIceCubeNumber().toString();
topIceCube=3;
Tweener.addTween(iceCube3, {y:iceCubeTopY, time:0.5, delay:1.5, transition:"easeOutBounce", onComplete:showCursor});
//new top ice drops
break;
default :
//do nothing.
}//end switch
//remove the cloud and floating points out of the way
theCloud.x=-1000;
floatingPoints.x=-1000;
theCloud.commentText.text="";
}
//loads the machine with bottom, middle and top ice
//then goes to getNextIce
private function loadMachine():void
{
//theSounds = machineWhirr.play();
theSounds = dropIceCube.play(3,3);
//position ice cubes at the top of the machine
iceCube1.x=iceCubeStartX;
iceCube2.x=iceCubeStartX;
iceCube3.x=iceCubeStartX;
iceCube4.x=iceCubeStartX;
iceCube1.y=iceCubeStartY;
iceCube2.y=iceCubeStartY;
iceCube3.y=iceCubeStartY;
iceCube4.y=iceCubeStartY;
// fill in the numbers
iceCube1.iceCubeNumber.text=getIceCubeNumber().toString();
bottomIceCube=1;
iceCube2.iceCubeNumber.text=getIceCubeNumber().toString();
middleIceCube=2;
iceCube3.iceCubeNumber.text=getIceCubeNumber().toString();
topIceCube=3;
//move bottom cube
//start tween
//once tween is done go to middle cube tween
Tweener.addTween(iceCube1, {y:iceCubeBottomY, time:0.5, transition:"easeOutBounce"});
//drop middle cube
//once tween is done go to top cube tween
Tweener.addTween(iceCube2, {y:iceCubeMiddleY, time:0.5, delay:0.4, transition:"easeOutBounce"});
//drop top cube
//delay for both tweens aboves
//once tween is done, get the next ice
Tweener.addTween(iceCube3, {y:iceCubeTopY, time:0.5, delay:0.8, transition:"easeOutBounce", onComplete:getNextIce});
}
//throws the fireballs out
//adds event listeners and instance names to each ball
private function throwFireballs():void
{
//trace("throw fireballs!");
theSounds = throwTheFireball.play(1,1);
for (var m:Number = 0; m < fireballNumberArray.length; m++)
{
//get a random number between 1 and 3
alternatingFireball=Math.floor(Math.random()*3)+1;
//get a random number between 1 and the number of fireballs at first
//randomThrower=getRandomThrowerNumber();
//trace ("fireball number: "+alternatingFireball);
//use switch to pick the type of fireball (1-3)
switch (alternatingFireball)
{
case 1 :
//make an instance of the fireball
//trace("in case 1");
var fireballOne:FireballOne = new FireballOne();
//add fireball to an array for removal later
fireballMovieClipArray.push(fireballOne);
//name that fireball
fireballOne.name="fireball"+m.toString();
//make it clickable
fireballOne.buttonMode=true;
//but not the dynamic text
fireballOne.mouseChildren=false;
//add fireball number to the text box of a fireball
fireballOne.fireballNumber.text=fireballNumberArray[m].toString();
//position it behind the volcano and small
fireballOne.x=fireballStartX;
fireballOne.y=fireballStartY;
fireballOne.scaleX=.1;
fireballOne.scaleY=.1;
fireballOne.rotation=100;
//put the fireball on the screen
stage.addChild(fireballOne);
//add the volcano overit
stage.addChild(volcano);
//throw it
Tweener.addTween(fireballOne, {x:fireballPositionXArray[m], y:fireballPositionYArray[m], _bezier:{x:fireballStartX, y:fireballPositionYArray[m]-200}, scaleX: 1, scaleY:1, rotation:0, time:1.5, delay:(0 + (0.2 * m)), transition:"easeInQuint"});
//listen to see if it is hit, hover or up
fireballOne.addEventListener(MouseEvent.CLICK, hitFireball);
fireballOne.addEventListener(MouseEvent.MOUSE_OVER, highlightFireball);
fireballOne.addEventListener(MouseEvent.MOUSE_OUT, unHighlightFireball);
break;
case 2 :
//trace("in case 2");
//make an instance of the fireball
var fireballTwo:FireballTwo = new FireballTwo();
//add fireball to an array for removal later
fireballMovieClipArray.push(fireballTwo);
//name that fireball
fireballTwo.name="fireball"+m.toString();
//make it clickable
fireballTwo.buttonMode=true;
//but not the dynamic text
fireballTwo.mouseChildren=false;
//add fireball number to the text box of a fireball
fireballTwo.fireballNumber.text=fireballNumberArray[m].toString();
//position it behind the volcano and small
fireballTwo.x=fireballStartX;
fireballTwo.y=fireballStartY;
fireballTwo.scaleX=.1;
fireballTwo.scaleY=.1;
fireballTwo.rotation=100;
//put the fireball on the screen
stage.addChild(fireballTwo);
//add the volcano overit
stage.addChild(volcano);
//throw it
Tweener.addTween(fireballTwo, {x:fireballPositionXArray[m], y:fireballPositionYArray[m], _bezier:{x:fireballStartX, y:fireballPositionYArray[m]-200}, scaleX: 1, scaleY:1, rotation:0, time:1.5, delay:(0 + (0.2 * m)), transition:"easeInQuint"});
//listen to see if it is hit
fireballTwo.addEventListener(MouseEvent.CLICK, hitFireball);
fireballTwo.addEventListener(MouseEvent.MOUSE_OVER, highlightFireball);
fireballTwo.addEventListener(MouseEvent.MOUSE_OUT, unHighlightFireball);
break;
case 3 :
//trace("in case 3");
//make an instance of the fireball
var fireballThree:FireballThree = new FireballThree();
//add fireball to an array for removal later
fireballMovieClipArray.push(fireballThree);
//name that fireball
fireballThree.name="fireball"+m.toString();
//make it clickable
fireballThree.buttonMode=true;
//but not the dynamic text
fireballThree.mouseChildren=false;
//add fireball number to the text box of a fireball
fireballThree.fireballNumber.text=fireballNumberArray[m].toString();
//position it behind the volcano and small
fireballThree.x=fireballStartX;
fireballThree.y=fireballStartY;
fireballThree.scaleX=.1;
fireballThree.scaleY=.1;
fireballThree.rotation=100;
//put the fireball on the screen
stage.addChild(fireballThree);
//add the volcano overit
stage.addChild(volcano);
//throw it
Tweener.addTween(fireballThree, {x:fireballPositionXArray[m], y:fireballPositionYArray[m], _bezier:{x:fireballStartX, y:fireballPositionYArray[m] -200}, scaleX: 1, scaleY:1, rotation:0, time:1.5, delay:(0 + (0.2 * m)), transition:"easeInQuint"});
//listen to see if it is hit
fireballThree.addEventListener(MouseEvent.CLICK, hitFireball);
fireballThree.addEventListener(MouseEvent.MOUSE_OVER, highlightFireball);
fireballThree.addEventListener(MouseEvent.MOUSE_OUT, unHighlightFireball);
break;
default :
//do nothing.
}//end switch
}//end for loop
//add the ice cubes and machineOnTop back in front
stage.addChild(iceCube1);
stage.addChild(iceCube2);
stage.addChild(iceCube3);
stage.addChild(iceCube4);
stage.addChild(machineOnTop);
}
private function quitGame(event:MouseEvent):void
{
//remove the fireballs
removeOldFireballs();
//remove the ice cubes
iceCube1.x=iceCubeStartX;
iceCube2.x=iceCubeStartX;
iceCube3.x=iceCubeStartX;
iceCube4.x=iceCubeStartX;
iceCube1.y=iceCubeStartY;
iceCube2.y=iceCubeStartY;
iceCube3.y=iceCubeStartY;
iceCube4.y=iceCubeStartY;
//remove listeners for the lake and volcano
volcano.removeEventListener(MouseEvent.MOUSE_OVER, hoverOverVolcano);
volcano.removeEventListener(MouseEvent.MOUSE_OUT, hoverOffVolcano);
volcano.removeEventListener(MouseEvent.CLICK, tweenOutOldFireballs);
iceCubeLake.removeEventListener(MouseEvent.CLICK, missFireball);
iceCubeLake.removeEventListener(MouseEvent.MOUSE_OVER, hoverOverLake);
iceCubeLake.removeEventListener(MouseEvent.MOUSE_OUT, hoverOffLake);
//show the first screen
showOpeningScreen();
gameHasStarted=false;
}
private function startGame(event:MouseEvent):void
{
//check if it is a saved game or they are continuing the game
if (savedGame&&event.target.name=="infoButton2")
{
//initialize the variables
currentScore=savedScore;
currentNumberOfBonusSums=savedNumberOfBonusSums;
if (nextLevel)
{
currentLevel=2;
}
else
{
currentLevel=savedLevel;
}
}
else
{
//else it is a first game
//setUp the variables
currentScore=0;
currentNumberOfBonusSums=0;
//check for the level
if (nextLevel&&event.target.name=="infoButton2")
{
currentLevel=2;
nextLevel=false;
}
else
{
currentLevel=1;
nextLevel=false;
}
}
//be sure to remove old fireballs
if (gameHasStarted)
{
//they want to restart the level
removeOldFireballs();
//reset the variable
}
clearOpeningScreen();
setUpPreGameVariables();
//start the mouse following crosshairs
stage.addEventListener(Event.ENTER_FRAME, followMouse);
//check for the top score
stage.addEventListener(Event.ENTER_FRAME, checkTopScore);
//listen if they need help
helpButton.addEventListener(MouseEvent.CLICK, showHelpIntegerScreen);
//listne if they want to quit
quitButton.addEventListener(MouseEvent.CLICK, showQuitScreen);
//listen for the volcano
volcano.buttonMode=true;
volcano.mouseChildren=false;
volcano.addEventListener(MouseEvent.MOUSE_OVER, hoverOverVolcano);
volcano.addEventListener(MouseEvent.MOUSE_OUT, hoverOffVolcano);
volcano.addEventListener(MouseEvent.CLICK, tweenOutOldFireballs);
//stage.addEventListener(Event.MOUSE_LEAVE, removeCursor);
iceCubeLake.addEventListener(MouseEvent.CLICK, missFireball);
iceCubeLake.addEventListener(MouseEvent.MOUSE_OVER, hoverOverLake);
iceCubeLake.addEventListener(MouseEvent.MOUSE_OUT, hoverOffLake);
crossHairs.alpha=0.2;
//show all the scores, etc.
showTopScore();
showScore();
showLevel();
showBonusSum();
//start the animations
loadMachine();
throwFireballs();
//showGoalNumber();
gameHasStarted=true;
}
}//end class
}//end package