Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.utils.Timer;
- import flash.text.TextField;
- import flash.events.MouseEvent;
- import flash.text.TextFormat;
- import flashx.textLayout.formats.BackgroundColor;
- import flash.media.Sound;
- import flash.media.SoundChannel;
- public class Game extends MovieClip
- {
- static var list:Array = new Array();
- static var timesdied:Number;
- static var gametimer:Number;
- static var achtimer:Number;
- static var ship:MovieClip;
- static var enemyShipTimer:Timer;
- static var specialShipTimer:Timer;
- static var enemieskilled;
- static var roundNumber:Number;
- static var myTextField:TextField;
- static var scoreText:TextField;
- static var score:Number;
- static var gameOverMenu:GameOverMenu;
- static var mainMenu:MainMenu;
- static var Background:Backgrounds;
- static var shiphittests:MovieClip;
- static var Paused:Boolean = false;
- static var shopMenu:ShopMenu;
- static var achMenu:AchMenu;
- static var BulletLength:Number;
- static var shrunk:Boolean = false;
- static var grown:Boolean = false;
- static var shieldactivate:Boolean = false;
- static var doubleenemies:Boolean = false;
- static var Instructions:instructions;
- static var enemyShip2Timer:Timer;
- static var enemyShip3Timer:Timer;
- static var enemyShip4Timer:Timer;
- static var enemyShip5Timer:Timer;
- static var playthegameach:Boolean = false;//
- static var asteroidkillerach:Boolean = false;//
- static var asteroidkiller2ach:Boolean = false;//
- static var asteroidkiller3ach:Boolean = false;//
- static var asteroidkiller4ach:Boolean = false;//
- static var a1minuteplayed:Boolean = false;//
- static var a5minuteplayed:Boolean = false;//
- static var a15minuteplayed:Boolean = false;//
- static var a30minuteplayed:Boolean = false;//
- static var a60minuteplayed:Boolean = false;//
- static var died1time:Boolean = false;//
- static var died10time:Boolean = false;//
- static var died50time:Boolean = false;//
- static var died100time:Boolean = false;//
- static var teleported1time:Boolean = false;//
- static var teleported100time:Boolean = false;//
- static var teleported1000time:Boolean = false;//
- static var randommax:Boolean = false;//
- static var fireratemax:Boolean = false;//
- static var shotpowermax:Boolean = false;//
- static var shotdistancemax:Boolean = false;//
- static var turnspeedmax:Boolean = false;//
- static var brakesmax:Boolean = false;//
- static var topspeedmax:Boolean = false;//
- static var thrustmax:Boolean = false;//
- static var duckyach:Boolean = false;//
- static var nduckyach:Boolean = false;//
- static var cantach:Boolean = false;//
- static var tinyach:Boolean = false;//
- static var miniach:Boolean = false;//
- static var averageach:Boolean = false;//
- static var largeach:Boolean = false;//
- static var gigantoach:Boolean = false;//
- static var mute1:Boolean = false;
- private var bgChannel:SoundChannel;
- function togglemusic(e:Event)
- {
- if (mute1 == true)
- {
- bgChannel.stop();
- }
- else
- {
- bgChannel.play();
- }
- }
- function Game()
- {
- if (Game.Paused == false)
- {
- var bgm:Sound = new bgmusic();
- bgChannel = bgm.play();
- timesdied = 0;
- gametimer = 0;
- achtimer = 0;
- enemieskilled = 0;
- BulletLength = 1;
- Key.initialize(stage);
- ship = new Ship();
- ship.x = 300;
- ship.y = 150;
- Background = new Backgrounds();
- addChild(Background);
- ship.visible = false;
- addChild(ship);
- myTextField= new TextField();
- addChild(myTextField);
- if (doubleenemies == false)
- {
- enemyShipTimer = new Timer(2000);
- }
- if (doubleenemies == true)
- {
- enemyShipTimer = new Timer(1000);
- }
- enemyShipTimer.addEventListener("timer", sendEnemy);
- enemyShipTimer.stop();
- if (doubleenemies == false)
- {
- enemyShip2Timer = new Timer(2000);
- }
- if (doubleenemies == true)
- {
- enemyShip2Timer = new Timer(1000);
- }
- enemyShip2Timer.addEventListener("timer", sendEnemy2);
- enemyShip2Timer.stop();
- if (doubleenemies == false)
- {
- enemyShip3Timer = new Timer(2000);
- }
- if (doubleenemies == true)
- {
- enemyShip3Timer = new Timer(1000);
- }
- enemyShip3Timer.addEventListener("timer", sendEnemy3);
- enemyShip3Timer.stop();
- if (doubleenemies == false)
- {
- enemyShip4Timer = new Timer(4000);
- }
- if (doubleenemies == true)
- {
- enemyShip4Timer = new Timer(2000);
- }
- enemyShip4Timer.addEventListener("timer", sendEnemy4);
- enemyShip4Timer.stop();
- if (doubleenemies == false)
- {
- enemyShip5Timer = new Timer(12000);
- }
- if (doubleenemies == true)
- {
- enemyShip5Timer = new Timer(6000);
- }
- enemyShip5Timer.addEventListener("timer", sendEnemy5);
- enemyShip5Timer.stop();
- if (doubleenemies == false)
- {
- specialShipTimer = new Timer(1000);
- }
- if (doubleenemies == true)
- {
- specialShipTimer = new Timer(500);
- }
- specialShipTimer.addEventListener("timer", sendspecialEnemy);
- specialShipTimer.stop();
- myTextField.text = String('');
- myTextField.width = 2500;
- myTextField.x = 25;
- myTextField.selectable = false;
- myTextField.y = 25;
- scoreText = new TextField();
- scoreText.x = 290;
- scoreText.y = 25;
- scoreText.text = String(0);
- addChild(scoreText);
- resetScore();
- gameOverMenu = new GameOverMenu();
- addChild(gameOverMenu);
- gameOverMenu.visible = false;
- gameOverMenu.playAgainButton.addEventListener("mouseDown", showmainmenu);
- mainMenu = new MainMenu();
- addChild(mainMenu);
- mainMenu.visible = true;
- mainMenu.x = 300;
- mainMenu.y = 300;
- mainMenu.startButton.addEventListener("mouseDown", newGame);
- mainMenu.achButton.addEventListener("mouseDown", showAch);
- mainMenu.shopButton.addEventListener("mouseDown", showShop);
- mainMenu.instructbutton.addEventListener("mouseDown", showInstruct);
- shopMenu = new ShopMenu();
- achMenu = new AchMenu();
- addChild(achMenu);
- Instructions = new instructions();
- addChild(Instructions);
- addChild(shopMenu);
- Instructions.visible = false;
- Instructions.x = 240;
- Instructions.y = 240;
- achMenu.visible = false;
- achMenu.x = 220;
- achMenu.y = 300;
- shopMenu.visible = false;
- shopMenu.x = 240;
- shopMenu.y = 240;
- achMenu.backbut.addEventListener("mouseDown", showmainmenu);
- shopMenu.BackButton.addEventListener("mouseDown", showmainmenu);
- shopMenu.ShieldButton.Upgrade.gotoAndStop(1);
- shopMenu.ThrustButton.Upgrade.gotoAndStop(1);
- shopMenu.BulletLengthButton.Upgrade.gotoAndStop(1);
- shopMenu.FireRateButton.Upgrade.gotoAndStop(1);
- shopMenu.BrakesButton.Upgrade.gotoAndStop(1);
- shopMenu.TopSpeedButton.Upgrade.gotoAndStop(1);
- shopMenu.TurnSpeedButton.Upgrade.gotoAndStop(1);
- shopMenu.NumberOfShotsButton.Upgrade.gotoAndStop(1);
- mainMenu.hardmodebox.addEventListener("mouseDown", togglehardmode);
- shopMenu.ShieldButton.addEventListener("mouseDown", UpgradeShield);
- shopMenu.ThrustButton.addEventListener("mouseDown", UpgradeThrust);
- shopMenu.BulletLengthButton.addEventListener("mouseDown", UpgradeBulletLength);
- shopMenu.FireRateButton.addEventListener("mouseDown", UpgradeFireRate);
- shopMenu.BrakesButton.addEventListener("mouseDown", UpgradeBrakes);
- shopMenu.TopSpeedButton.addEventListener("mouseDown", UpgradeTopSpeed);
- shopMenu.TurnSpeedButton.addEventListener("mouseDown", UpgradeTurnSpeed);
- shopMenu.NumberOfShotsButton.addEventListener("mouseDown", UpgradeNumberOfShots);
- shopMenu.ShieldButton.addEventListener(MouseEvent.ROLL_OVER, ShieldButtonCost);
- shopMenu.ShieldButton.addEventListener(MouseEvent.ROLL_OUT, CostReset);
- shopMenu.ThrustButton.addEventListener(MouseEvent.ROLL_OVER, ThrustButtonCost);
- shopMenu.ThrustButton.addEventListener(MouseEvent.ROLL_OUT, CostReset);
- shopMenu.BulletLengthButton.addEventListener(MouseEvent.ROLL_OVER, BulletLengthButtonCost);
- shopMenu.BulletLengthButton.addEventListener(MouseEvent.ROLL_OUT, CostReset);
- shopMenu.FireRateButton.addEventListener(MouseEvent.ROLL_OVER, FireRateButtonCost);
- shopMenu.FireRateButton.addEventListener(MouseEvent.ROLL_OUT, CostReset);
- shopMenu.BrakesButton.addEventListener(MouseEvent.ROLL_OVER, BrakesButtonCost);
- shopMenu.BrakesButton.addEventListener(MouseEvent.ROLL_OUT, CostReset);
- shopMenu.TopSpeedButton.addEventListener(MouseEvent.ROLL_OVER, TopSpeedButtonCost);
- shopMenu.TopSpeedButton.addEventListener(MouseEvent.ROLL_OUT, CostReset);
- shopMenu.TurnSpeedButton.addEventListener(MouseEvent.ROLL_OVER, TurnSpeedButtonCost);
- shopMenu.TurnSpeedButton.addEventListener(MouseEvent.ROLL_OUT, CostReset);
- shopMenu.NumberOfShotsButton.addEventListener(MouseEvent.ROLL_OVER, NumberOfShotsButtonCost);
- shopMenu.NumberOfShotsButton.addEventListener(MouseEvent.ROLL_OUT, CostReset);
- mainMenu.ShipMode.addEventListener("mouseDown", toggleshipmode);
- Instructions.instructionsbutton.addEventListener("mouseDown", instructback);
- var scoreFormat = new TextFormat("Joystix",10,0x663300);
- var scoreFormat2 = new TextFormat("Joystix",15,0x663300);
- myTextField.defaultTextFormat = scoreFormat;
- scoreText.defaultTextFormat = scoreFormat2;
- }
- }
- function instructback(e:Event)
- {
- Instructions.visible = false;
- mainMenu.visible = true;
- }
- function toggleshipmode(e:Event)
- {
- if (ship.ShieldPower > 4)
- {
- if (ship.isduck == false)
- {
- mainMenu.ShipMode.gotoAndStop(3);
- ship.isduck = true;
- }
- else
- {
- mainMenu.ShipMode.gotoAndStop(2);
- ship.isduck = false;
- }
- }
- }
- function togglehardmode(e:Event)
- {
- if (ship.ShieldPower > 6)
- {
- if (doubleenemies == false)
- {
- mainMenu.hardmodebox.gotoAndStop(3);
- doubleenemies = true;
- trace('banana');
- }
- else
- {
- mainMenu.hardmodebox.gotoAndStop(2);
- doubleenemies = false;
- }
- }
- }
- function ShieldButtonCost(e:Event)
- {
- shopMenu.BackButton.UpgradeText.visible = true;
- shopMenu.BackButton.UpgradeText.text = 1000 * ship.ShieldPower;
- }
- function ThrustButtonCost(e:Event)
- {
- shopMenu.BackButton.UpgradeText.visible = true;
- shopMenu.BackButton.UpgradeText.text = 500 * ship.thrustVar;
- }
- function BulletLengthButtonCost(e:Event)
- {
- shopMenu.BackButton.UpgradeText.visible = true;
- shopMenu.BackButton.UpgradeText.text = 750 * BulletLength;
- }
- function FireRateButtonCost(e:Event)
- {
- shopMenu.BackButton.UpgradeText.visible = true;
- shopMenu.BackButton.UpgradeText.text = 750 * ship.shootTimerVar;
- }
- function BrakesButtonCost(e:Event)
- {
- shopMenu.BackButton.UpgradeText.visible = true;
- shopMenu.BackButton.UpgradeText.text = 500 * ship.brakesVar;
- }
- function TopSpeedButtonCost(e:Event)
- {
- shopMenu.BackButton.UpgradeText.visible = true;
- shopMenu.BackButton.UpgradeText.text = 500 * ship.topSpeedVar;
- }
- function TurnSpeedButtonCost(e:Event)
- {
- shopMenu.BackButton.UpgradeText.visible = true;
- shopMenu.BackButton.UpgradeText.text = 500 * ship.turnSpeedVar;
- }
- function NumberOfShotsButtonCost(e:Event)
- {
- shopMenu.BackButton.UpgradeText.visible = true;
- shopMenu.BackButton.UpgradeText.text = 1000 * ship.numberOfBulletsVar;
- }
- function CostReset(e:Event)
- {
- shopMenu.BackButton.UpgradeText.visible = false;
- }
- static function gameOver()
- {
- timesdied += 1;
- if (timesdied == 1)
- {
- if (died1time == false)
- {
- updateach("Achievement Unlocked: Die");
- updateScore(50);
- died1time = true;
- achMenu.die.gotoAndStop(2);
- }
- }
- if (timesdied == 10)
- {
- if (died1time == false)
- {
- updateach("Achievement Unlocked: Persistent");
- updateScore(50);
- died10time = true;
- achMenu.pers.gotoAndStop(2);
- }
- }
- if (timesdied == 50)
- {
- if (died1time == false)
- {
- updateach("Achievement Unlocked: Just keep dieing");
- updateScore(50);
- died50time = true;
- achMenu.just.gotoAndStop(2);
- }
- }
- if (timesdied == 100)
- {
- if (died1time == false)
- {
- updateach("Achievement Unlocked: Suicidal");
- updateScore(50);
- died100time = true;
- achMenu.suic.gotoAndStop(2);
- }
- }
- gameOverMenu.visible = true;
- gameOverMenu.x = 300;
- gameOverMenu.y = 300;
- enemyShipTimer.stop();
- enemyShip2Timer.stop();
- enemyShip3Timer.stop();
- enemyShip4Timer.stop();
- enemyShip5Timer.stop();
- specialShipTimer.stop();
- ship.Round = 0;
- for (var i in list)
- {
- list[i].gameoverdie();
- }
- }
- function showmainmenu(e:Event)
- {
- shopMenu.visible = false;
- achMenu.visible = false;
- mainMenu.visible = true;
- gameOverMenu.visible = false;
- }
- function newGame(e:Event)
- {
- if (playthegameach == false)
- {
- updateach("Achievement Unlocked:Play the game");
- playthegameach = true;
- updateScore(50);
- achMenu.welc.gotoAndStop(2);
- }
- ship.changemode();
- mainMenu.visible = false;
- gameOverMenu.visible = false;
- ship.visible = true;
- ship.x = 300;
- ship.y = 300;
- ship.thrust = 0;
- ship.addEventListener("enterFrame", ship.move);
- ship.Round = 1;
- specialShipTimer.start();
- ship.invulnTimer = 0;
- ship.invulnUsed = false;
- }
- function showShop(e:Event)
- {
- mainMenu.visible = false;
- shopMenu.visible = true;
- }
- function showAch(e:Event)
- {
- mainMenu.visible = false;
- achMenu.visible = true;
- }
- function showInstruct(e:Event)
- {
- mainMenu.visible = false;
- Instructions.visible = true;
- }
- function showMainMenu(e:Event)
- {
- mainMenu.visible = true;
- shopMenu.visible = false;
- }
- function sendEnemy(e:Event)
- {
- var enemy = new EnemyShip();
- stage.addChild(enemy);
- }
- function sendEnemy2(e:Event)
- {
- var enemy2 = new EnemyShip2();
- stage.addChild(enemy2);
- }
- function sendEnemy3(e:Event)
- {
- var enemy3 = new EnemyShip3();
- stage.addChild(enemy3);
- }
- function sendEnemy4(e:Event)
- {
- var enemy4 = new EnemyShip4();
- stage.addChild(enemy4);
- }
- function sendEnemy5(e:Event)
- {
- var enemy5 = new EnemyShip5();
- stage.addChild(enemy5);
- }
- function sendspecialEnemy(e:Event)
- {
- if (Math.random() < .001 && ship.ShieldPower > 8)
- {
- var special = new SpecialShip();
- stage.addChild(special);
- }
- }
- static function updateScore(points)
- {
- score += points;
- scoreText.text = String(score);
- }
- static function updateach(ach)
- {
- achtimer = 0;
- myTextField.text = String(ach);
- }
- static function resetScore()
- {
- score = 0;
- scoreText.text = String(score);
- }
- function UpgradeShield(e:Event)
- {
- trace('banana');
- if (ship.ShieldPower == 5)
- {
- mainMenu.ShipMode.gotoAndStop(2);
- }
- if (ship.ShieldPower > 6)
- {
- mainMenu.hardmodebox.gotoAndStop(2);
- }
- if (Game.ship.ShieldPower < 11)
- {
- if (1000 * Game.ship.ShieldPower <= score)
- {
- if (Game.ship.ShieldPower == 10)
- {
- if (randommax == false)
- {
- randommax = true;
- updateach("Achievement Unlocked: Randomizer, Cant Touch This");
- updateScore(100);
- randommax = true;
- achMenu.rand.gotoAndStop(2);
- achMenu.cant.gotoAndStop(2);
- }
- }
- updateScore(-1000*ship.ShieldPower);
- Game.ship.ShieldPower += 1;
- shopMenu.ShieldButton.Upgrade.gotoAndStop(ship.ShieldPower);
- shopMenu.BackButton.UpgradeText.text = 1000 * ship.ShieldPower;
- }
- }
- }
- function UpgradeThrust(e:Event)
- {
- if (500 * Game.ship.thrustVar <= score)
- {
- if (Game.ship.thrustVar == 10)
- {
- if (thrustmax == false)
- {
- thrustmax = true;
- updateach("Achievement Unlocked: Thrusters Primed");
- updateScore(50);
- thrustmax = true;
- achMenu.thru.gotoAndStop(2);
- }
- }
- if (Game.ship.thrustVar < 11)
- {
- updateScore(-500*ship.thrustVar);
- Game.ship.thrustVar += 1;
- shopMenu.ThrustButton.Upgrade.gotoAndStop(ship.thrustVar);
- shopMenu.BackButton.UpgradeText.text = 500 * ship.thrustVar;
- }
- }
- }
- function UpgradeFireRate(e:Event)
- {
- if (750 * Game.ship.shootTimerVar <= score)
- {
- if (Game.ship.shootTimerVar == 10)
- {
- if (fireratemax == false)
- {
- fireratemax = true;
- updateach("Achievement Unlocked: QuickDraw");
- updateScore(50);
- fireratemax = true;
- achMenu.quic.gotoAndStop(2);
- }
- }
- if (ship.shootTimerVar < 11)
- {
- updateScore(-750*ship.shootTimerVar);
- Game.ship.shootTimerVar += 1;
- shopMenu.FireRateButton.Upgrade.gotoAndStop(ship.shootTimerVar);
- shopMenu.BackButton.UpgradeText.text = 750 * ship.shootTimerVar;
- }
- }
- }
- function UpgradeBulletLength(e:Event)
- {
- if (750 * BulletLength <= score)
- {
- if (BulletLength == 10)
- {
- if (shotdistancemax == false)
- {
- shotdistancemax = true;
- updateach("Achievement Unlocked: Sniper");
- updateScore(50);
- shotdistancemax = true;
- achMenu.snip.gotoAndStop(2);
- }
- }
- if (BulletLength < 11)
- {
- updateScore(-750*BulletLength);
- BulletLength += 1;
- shopMenu.BulletLengthButton.Upgrade.gotoAndStop(BulletLength);
- shopMenu.BackButton.UpgradeText.text = 750 * BulletLength;
- }
- }
- }
- function UpgradeBrakes(e:Event)
- {
- if (500 * Game.ship.brakesVar <= score)
- {
- if (Game.ship.brakesVar == 10)
- {
- if (brakesmax == false)
- {
- brakesmax = true;
- updateach("Achievement Unlocked: STOP!");
- updateScore(50);
- brakesmax = true;
- achMenu.brak.gotoAndStop(2);
- }
- }
- if (Game.ship.brakesVar < 11)
- {
- updateScore(-500*ship.brakesVar);
- Game.ship.brakesVar += 1;
- shopMenu.BrakesButton.Upgrade.gotoAndStop(Game.ship.brakesVar);
- shopMenu.BackButton.UpgradeText.text = 500 * ship.brakesVar;
- }
- }
- }
- function UpgradeTopSpeed(e:Event)
- {
- if (500 * Game.ship.topSpeedVar <= score)
- {
- if (Game.ship.topSpeedVar == 10)
- {
- if (topspeedmax == false)
- {
- topspeedmax = true;
- updateach("Achievement Unlocked: Super Fast");
- updateScore(50);
- topspeedmax = true;
- achMenu.tops.gotoAndStop(2);
- }
- }
- if (Game.ship.topSpeedVar < 11)
- {
- updateScore(-500*ship.topSpeedVar);
- Game.ship.topSpeedVar += 1;
- shopMenu.TopSpeedButton.Upgrade.gotoAndStop(Game.ship.topSpeedVar);
- shopMenu.BackButton.UpgradeText.text = 500 * ship.topSpeedVar;
- }
- }
- }
- function UpgradeTurnSpeed(e:Event)
- {
- if (500 * Game.ship.turnSpeedVar <= score)
- {
- if (Game.ship.turnSpeedVar == 10)
- {
- if (turnspeedmax == false)
- {
- turnspeedmax = true;
- updateach("Achievement Unlocked: Spin Spin Spin");
- updateScore(50);
- turnspeedmax = true;
- achMenu.turn.gotoAndStop(2);
- }
- }
- if (ship.turnSpeedVar < 11)
- {
- updateScore(-500*ship.turnSpeedVar);
- Game.ship.turnSpeedVar += 1;
- shopMenu.TurnSpeedButton.Upgrade.gotoAndStop(Game.ship.turnSpeedVar);
- shopMenu.BackButton.UpgradeText.text = 500 * ship.turnSpeedVar;
- }
- }
- }
- function UpgradeNumberOfShots(e:Event)
- {
- if (1000 * Game.ship.numberOfBulletsVar <= score)
- {
- if (Game.ship.numberOfBulletsVar == 10)
- {
- if (shotpowermax == false)
- {
- shotpowermax = true;
- updateach("Achievement Unlocked: Shoot EVERYTHING!");
- updateScore(50);
- shotpowermax = true;
- achMenu.shot.gotoAndStop(2);
- }
- }
- if (Game.ship.numberOfBulletsVar < 11)
- {
- updateScore(-1000*ship.numberOfBulletsVar);
- Game.ship.numberOfBulletsVar += 1;
- shopMenu.NumberOfShotsButton.Upgrade.gotoAndStop(ship.numberOfBulletsVar);
- shopMenu.BackButton.UpgradeText.text = 1000 * ship.numberOfBulletsVar;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement