PageRenderTime 22ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ circle-madness-nme/Source/Main.hx

http://circle-madness-nme.googlecode.com/
Haxe | 917 lines | 736 code | 118 blank | 63 comment | 45 complexity | 51bc6b897211d412ae5f5010455712d9 MD5 | raw file
  1. import flash.display.BitmapData;
  2. import flash.display.Bitmap;
  3. import flash.geom.Rectangle;
  4. import flash.geom.Point;
  5. import flash.events.Event;
  6. import flash.events.KeyboardEvent;
  7. import flash.display.Sprite;
  8. import flash.ui.Keyboard;
  9. import flash.text.TextField;
  10. import flash.text.TextFieldAutoSize;
  11. import flash.text.TextFormat;
  12. import flash.text.TextFormatAlign;
  13. import flash.filters.GlowFilter;
  14. import haxe.FastList;
  15. import flash.events.MouseEvent;
  16. // import flash.net.SharedObject;
  17. import flash.Lib;
  18. import haxe.Log;
  19. //import flash.utils.Timer;
  20. import haxe.Timer;
  21. import flash.events.Event;
  22. import flash.display.MovieClip;
  23. import flash.media.SoundChannel;
  24. import flash.media.Sound;
  25. import Images;
  26. import Scene;
  27. import InstructionPage;
  28. import UpgradePage;
  29. import CreditsPage;
  30. import OptionsPage;
  31. import SoundPlayer;
  32. import PauseMenu;
  33. import Kongregate;
  34. import Logo;
  35. import CustomSprite;
  36. import HelperMethods;
  37. import GameData;
  38. import nme.Assets;
  39. class Main extends Sprite{
  40. private var ground : Int;
  41. private var currentLevel : Int;
  42. private var Scenes : Array<Scene>;
  43. //Because the levels are so similiar i can do this. It's probably be to have a class for each level that inherents from the scence.
  44. private var Level1 : Scene;
  45. private var State : String;
  46. private var savedData:SaveData;
  47. private var ContinueGameButton:Sprite;
  48. private var StartGameButton:Sprite;
  49. private var InfiniteGameButton:Sprite;
  50. private var FreeModeButton:Sprite;
  51. private var StartGameDifficulty:Sprite;
  52. private var MainMenuButton:Sprite;
  53. private var InstructionsButton:Sprite;
  54. private var CreditsButton:Sprite;
  55. private var OptionsButton:Sprite;
  56. public var CenterCircle: Sprite;
  57. public var CenterCircleText: TextField;
  58. private var Title:TextField;
  59. private var myLogo : Logo;
  60. private var label1:TextField;
  61. private var TryAgainPic:Sprite;
  62. var myTimer:Timer;
  63. private var player:SoundPlayer;
  64. private var BackgroundImage : Bitmap;
  65. public var Instruction : InstructionPage;
  66. public var Upgrade : UpgradePage;
  67. public var Credit: CreditsPage;
  68. public var OptionsMenu : OptionsPage;
  69. var mKeyDown:Array<Bool>;
  70. var pausePosition:Float;
  71. var music:Sound;
  72. var volume:Bool;
  73. var sound:Bool;
  74. var framerate:Int;
  75. var kongVar : CKongregate;
  76. public function new(){
  77. super();
  78. #if flash
  79. haxe.remoting.AMFConnection.registerClassAlias("GameData",GameData);
  80. #end
  81. Scenes = [];
  82. savedData = new SaveData();
  83. getLevelData();
  84. initLevels();
  85. volume = true;
  86. //Add Main to Current Flash
  87. flash.Lib.current.addChild(this);
  88. //Create Menu (own Class?)
  89. Title = new TextField();
  90. Title.x = 50; Title.y = 20;
  91. Title.width = Constants.flashWidth-100; Title.height = Constants.flashHeight;
  92. Title.multiline = true;
  93. var myFormat:TextFormat = new TextFormat();
  94. myFormat.size = 25;
  95. myFormat.align = TextFormatAlign.CENTER;
  96. Title.defaultTextFormat = myFormat;
  97. Title.htmlText = "Circle Madness";
  98. StartGameButton = new Sprite();
  99. StartGameButton.graphics.lineStyle(1);
  100. StartGameButton.graphics.beginFill(0xcc1367);
  101. StartGameButton.graphics.drawCircle(0, 0,50);
  102. StartGameButton.graphics.endFill();
  103. var buttonText = new TextField();
  104. buttonText.htmlText = "<font color='#FFFFFF' size='16'>Story Mode</font>";
  105. buttonText.selectable = false;
  106. buttonText.mouseEnabled = false;
  107. buttonText.x = -38;buttonText.y=-13;
  108. StartGameButton.addChild(buttonText);
  109. StartGameButton.x = 345;
  110. StartGameButton.y = 110;
  111. StartGameButton.buttonMode = true;
  112. StartGameButton.addEventListener(MouseEvent.ROLL_OVER,onStartGameHover);
  113. StartGameButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  114. StartGameButton.addEventListener(MouseEvent.CLICK, onStartGameButtonClick);
  115. StartGameDifficulty = new Sprite();
  116. StartGameDifficulty.graphics.lineStyle(1);
  117. StartGameDifficulty.graphics.beginFill(0xFFFFFF);
  118. StartGameDifficulty.graphics.drawCircle(0, 0,230);
  119. StartGameDifficulty.graphics.endFill();
  120. StartGameDifficulty.x = 400;
  121. StartGameDifficulty.y = 245;
  122. var easyGame = new Sprite();
  123. easyGame.graphics.lineStyle(1);
  124. easyGame.graphics.beginFill(0x00FF00);
  125. easyGame.graphics.drawCircle(0, 0,50);
  126. easyGame.graphics.endFill();
  127. var text = new TextField();
  128. text.htmlText = "Easy";
  129. easyGame.addChild(text);
  130. text.x = -15;text.y =-10;
  131. text.selectable = false;
  132. text.mouseEnabled = false;
  133. StartGameDifficulty.addChild(easyGame);
  134. easyGame.x = -110;
  135. easyGame.buttonMode = true;
  136. easyGame.addEventListener(MouseEvent.CLICK, onEasyGameButtonClick);
  137. var mediumGame = new Sprite();
  138. mediumGame.graphics.lineStyle(1);
  139. mediumGame.graphics.beginFill(0xFFFF00);
  140. mediumGame.graphics.drawCircle(0, 0,50);
  141. mediumGame.graphics.endFill();
  142. var text = new TextField();
  143. text.htmlText = "Medium";
  144. mediumGame.addChild(text);
  145. text.x = -25;text.y =-10;
  146. text.selectable = false;
  147. text.mouseEnabled = false;
  148. StartGameDifficulty.addChild(mediumGame);
  149. mediumGame.x = 00;
  150. mediumGame.buttonMode = true;
  151. mediumGame.addEventListener(MouseEvent.CLICK, onMediumGameButtonClick);
  152. var hardGame = new Sprite();
  153. hardGame.graphics.lineStyle(1);
  154. hardGame.graphics.beginFill(0xFF0000);
  155. hardGame.graphics.drawCircle(0, 0,50);
  156. hardGame.graphics.endFill();
  157. var text = new TextField();
  158. text.htmlText = "Hard";
  159. hardGame.addChild(text);
  160. text.x = -15;text.y =-10;
  161. text.selectable = false;
  162. text.mouseEnabled = false;
  163. StartGameDifficulty.addChild(hardGame);
  164. hardGame.x = 110;
  165. hardGame.buttonMode = true;
  166. hardGame.addEventListener(MouseEvent.CLICK, onHardGameButtonClick);
  167. ContinueGameButton = new Sprite();
  168. ContinueGameButton.graphics.lineStyle(1);
  169. ContinueGameButton.graphics.beginFill(0xf8320d);
  170. ContinueGameButton.graphics.drawCircle(0, 0,50);
  171. ContinueGameButton.graphics.endFill();
  172. var buttonText = new TextField();
  173. buttonText.htmlText = "<font size='15' color='#000000'>Continue Story</font>";
  174. buttonText.selectable = false;
  175. buttonText.mouseEnabled = false;
  176. buttonText.x = -50;buttonText.y=-12;
  177. ContinueGameButton.addChild(buttonText);
  178. ContinueGameButton.x = 455;
  179. ContinueGameButton.y = 110;
  180. ContinueGameButton.buttonMode = true;
  181. ContinueGameButton.addEventListener(MouseEvent.CLICK, onContinueGameButtonClick);
  182. ContinueGameButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  183. ContinueGameButton.addEventListener(MouseEvent.ROLL_OVER,onContinueGameHover);
  184. InfiniteGameButton = new Sprite();
  185. InfiniteGameButton.graphics.lineStyle(1);
  186. InfiniteGameButton.graphics.beginFill(0xed4c0d);
  187. InfiniteGameButton.graphics.drawCircle(0, 0,50);
  188. InfiniteGameButton.graphics.endFill();
  189. var buttonText = new TextField();
  190. buttonText.htmlText = "<font size='16'>Infinite Game</font>";
  191. buttonText.selectable = false;
  192. buttonText.mouseEnabled = false;
  193. buttonText.x = -48;buttonText.y=-12;
  194. InfiniteGameButton.addChild(buttonText);
  195. InfiniteGameButton.x = 520;
  196. InfiniteGameButton.y = 200;
  197. InfiniteGameButton.buttonMode = true;
  198. InfiniteGameButton.addEventListener(MouseEvent.CLICK, onInfiniteModeButtonClick);
  199. InfiniteGameButton.addEventListener(MouseEvent.ROLL_OVER,onInfiniteModeHover);
  200. InfiniteGameButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  201. FreeModeButton = new Sprite();
  202. FreeModeButton.graphics.lineStyle(1);
  203. FreeModeButton.graphics.beginFill(0x640981);
  204. FreeModeButton.graphics.drawCircle(0, 0,50);
  205. FreeModeButton.graphics.endFill();
  206. var buttonText = new TextField();
  207. buttonText.htmlText = "<font size='16' color='#FFFFFF'>Free Mode</font>";
  208. buttonText.selectable = false;
  209. buttonText.mouseEnabled = false;
  210. buttonText.x = -40;buttonText.y=-12;
  211. FreeModeButton.addChild(buttonText);
  212. FreeModeButton.x = 275;
  213. FreeModeButton.y = 200;
  214. FreeModeButton.buttonMode = true;
  215. FreeModeButton.addEventListener(MouseEvent.CLICK, onFreeModeButtonClick);
  216. FreeModeButton.addEventListener(MouseEvent.ROLL_OVER,onFreeModeHover);
  217. FreeModeButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  218. InstructionsButton = new Sprite();
  219. InstructionsButton.graphics.lineStyle(1);
  220. InstructionsButton.graphics.beginFill(0xf7f732);
  221. InstructionsButton.graphics.drawCircle(0, 0,50);
  222. InstructionsButton.graphics.endFill();
  223. var buttonText = new TextField();
  224. buttonText.htmlText = "<font size='14' color='#111111'>Instructions</font>";
  225. buttonText.selectable = false;
  226. buttonText.mouseEnabled = false;
  227. buttonText.x = -33;buttonText.y=-10;
  228. InstructionsButton.addChild(buttonText);
  229. InstructionsButton.x = 495;
  230. InstructionsButton.y = 305;
  231. InstructionsButton.buttonMode = true;
  232. InstructionsButton.addEventListener(MouseEvent.CLICK, onInstrutionsButtonClick);
  233. InstructionsButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  234. InstructionsButton.addEventListener(MouseEvent.ROLL_OVER,onInstrutionsHover);
  235. Instruction = new InstructionPage();
  236. Instruction.addEventListener("Back",onInstrutionsBack);
  237. Upgrade = new UpgradePage();
  238. Upgrade.addEventListener("Back",onUpgradeBack);
  239. CreditsButton = new Sprite();
  240. CreditsButton.graphics.lineStyle(1);
  241. CreditsButton.graphics.beginFill(0x1b077f);
  242. CreditsButton.graphics.drawCircle(0, 0,50);
  243. CreditsButton.graphics.endFill();
  244. var buttonText = new TextField();
  245. buttonText.htmlText = "<font size='17' color='#CCCCCC'>Credits</font>";
  246. buttonText.selectable = false;
  247. buttonText.mouseEnabled = false;
  248. buttonText.x = -29;buttonText.y=-12;
  249. CreditsButton.addChild(buttonText);
  250. CreditsButton.x = 305;
  251. CreditsButton.y = 305;
  252. CreditsButton.buttonMode = true;
  253. CreditsButton.addEventListener(MouseEvent.CLICK, onCreditsButtonClick);
  254. CreditsButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  255. CreditsButton.addEventListener(MouseEvent.ROLL_OVER,onCreditsHover);
  256. Credit = new CreditsPage();
  257. Credit.addEventListener("Back",onCreditsBack);
  258. OptionsButton = new Sprite();
  259. OptionsButton.graphics.lineStyle(1);
  260. OptionsButton.graphics.beginFill(0x0a8c37);
  261. OptionsButton.graphics.drawCircle(0, 0,50);
  262. OptionsButton.graphics.endFill();
  263. var buttonText = new TextField();
  264. buttonText.htmlText = "<font size='16' color='#000000'>Options</font>";
  265. buttonText.selectable = false;
  266. buttonText.mouseEnabled = false;
  267. buttonText.x = -30;buttonText.y=-12;
  268. OptionsButton.addChild(buttonText);
  269. OptionsButton.x = 400;
  270. OptionsButton.y = 365;
  271. OptionsButton.buttonMode = true;
  272. OptionsButton.addEventListener(MouseEvent.CLICK, onOptionsButtonClick);
  273. OptionsButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  274. OptionsButton.addEventListener(MouseEvent.ROLL_OVER,onOptionsHover);
  275. OptionsMenu = new OptionsPage();
  276. OptionsMenu.addEventListener("Back",onOptionsMenuBack);
  277. OptionsMenu.addEventListener("ResetSavedData",onOptionsMenuResetSavedData);
  278. OptionsMenu.addEventListener("VolumeToggle",onOptionsMenuVolumeToggle);
  279. OptionsMenu.addEventListener("SoundEffectsToggle",onOptionsMenuSoundEffectsToggle);
  280. this.addEventListener(Event.ENTER_FRAME, OnEnter);
  281. // myTimer = new Timer(12);
  282. // myTimer.addEventListener("timer", OnEnter);
  283. // myTimer.start();
  284. CenterCircle = new Sprite();
  285. CenterCircle.graphics.lineStyle(1);
  286. CenterCircle.graphics.beginFill(0xFFFFFF);
  287. CenterCircle.graphics.drawCircle(0, 0,70);
  288. CenterCircle.graphics.endFill();
  289. CenterCircleText = new TextField();
  290. CenterCircleText.htmlText = "<font size='16' color='#000000'></font>";
  291. CenterCircleText.autoSize = TextFieldAutoSize.CENTER;
  292. CenterCircleText.width = 100;
  293. CenterCircleText.wordWrap = true;
  294. CenterCircleText.multiline = true;
  295. CenterCircleText.selectable = false;
  296. CenterCircleText.mouseEnabled = false;
  297. CenterCircleText.x = -48;
  298. CenterCircle.addChild(CenterCircleText);
  299. CenterCircleText.y=-5+((-CenterCircleText.length));
  300. CenterCircle.x = 400;
  301. CenterCircle.y = 225;
  302. OptionsButton.buttonMode = true;
  303. OptionsButton.addEventListener(MouseEvent.CLICK, onOptionsButtonClick);
  304. label1 = new TextField();
  305. label1.x = 0; label1.y = 0;
  306. label1.width = Constants.flashWidth; label1.height = 100;
  307. label1.autoSize = TextFieldAutoSize.CENTER;
  308. TryAgainPic = new Sprite();
  309. TryAgainPic.graphics.lineStyle(1);
  310. TryAgainPic.graphics.beginFill(0xFFFFFF);
  311. TryAgainPic.graphics.drawCircle(0, 0, 50);
  312. TryAgainPic.graphics.endFill();
  313. TryAgainPic.x = 400;
  314. TryAgainPic.y = 80;
  315. var buttonText = new TextField();
  316. buttonText.htmlText = "<font size='16' color='#000000'>Yay!</font>";
  317. buttonText.selectable = false;
  318. buttonText.mouseEnabled = false;
  319. buttonText.x = -30;buttonText.y=-12;
  320. TryAgainPic.addChild(buttonText);
  321. MainMenuButton = new Sprite();
  322. MainMenuButton.graphics.beginBitmapFill(new MainMenu());
  323. MainMenuButton.graphics.drawRect(0, 0, 250 ,48);
  324. MainMenuButton.x = 285;
  325. MainMenuButton.y = 135;
  326. MainMenuButton.buttonMode = true;
  327. MainMenuButton.addEventListener(MouseEvent.CLICK, onMainMenuButtonClick);
  328. //The State Will determine whether to load a level, or show Main Menu, or whatever. Used in the OnEnterEvent.
  329. State = "LoadMainMenu";
  330. //State = "LoadMainMenu";
  331. music = Assets.getSound("assets/Background.mp3");
  332. //preloader = new PreloaderHost();
  333. BackgroundImage = new Bitmap(new Background());
  334. player = new SoundPlayer(music);
  335. volume = true;
  336. sound = true;
  337. myLogo = new Logo();
  338. addChild(myLogo);
  339. try
  340. {
  341. kongVar = new CKongregate();
  342. }
  343. catch (msg:Dynamic)
  344. {
  345. }
  346. mKeyDown = [];
  347. stage.addEventListener(KeyboardEvent.KEY_DOWN, OnKeyDown );
  348. stage.addEventListener(KeyboardEvent.KEY_UP, OnKeyUp );
  349. //preloader.addEventListener(Event.ENTER_FRAME, OnMovieEnter);
  350. }
  351. public function OnKeyUp (event:KeyboardEvent)
  352. {
  353. mKeyDown[event.keyCode] = false;
  354. //lastUp = event.keyCode;
  355. }
  356. public function OnKeyDown(event:KeyboardEvent)
  357. {
  358. // When a key is held down, multiple KeyDown events are generated.
  359. // This check means we only pick up the first one.
  360. if (!mKeyDown[event.keyCode])
  361. {
  362. // Store for use in game
  363. mKeyDown[event.keyCode] = true;
  364. //I do this here, because if they hold down P,
  365. // it won't pause and unpause constantly.
  366. if(mKeyDown[ 77 ] == true)
  367. {
  368. volume = !volume;
  369. }
  370. }
  371. }
  372. function loadMenu()
  373. {
  374. addChild(BackgroundImage);
  375. addChild(Title);
  376. addChild(StartGameButton);
  377. addChild(InfiniteGameButton);
  378. addChild(FreeModeButton);
  379. addChild(ContinueGameButton);
  380. addChild(InstructionsButton);
  381. addChild(CreditsButton);
  382. addChild(OptionsButton);
  383. addChild(CenterCircle );
  384. }
  385. function removeMenu()
  386. {
  387. removeChild(Title);
  388. removeChild(StartGameButton);
  389. removeChild(InfiniteGameButton);
  390. removeChild(FreeModeButton);
  391. removeChild(ContinueGameButton);
  392. removeChild(BackgroundImage);
  393. removeChild(InstructionsButton);
  394. removeChild(CreditsButton);
  395. removeChild(OptionsButton);
  396. removeChild(CenterCircle);
  397. }
  398. //Change to stat Menu
  399. function loadTryAgainMenu(text:String)
  400. {
  401. addChild(label1);
  402. label1.htmlText = "<font size='15'>" + text + "</font>";
  403. addChild(MainMenuButton);
  404. addChild(TryAgainPic);
  405. }
  406. function removeTryAgainMenu()
  407. {
  408. removeChild(label1);
  409. removeChild(MainMenuButton);
  410. removeChild(TryAgainPic);
  411. }
  412. function initLevels()
  413. {
  414. //Postion, MoveSpeed, JumpSpeed, AttackSpeed, Health, Bitmap)
  415. }
  416. function OnEnter(e:flash.events.Event)
  417. {
  418. if(player !=null)
  419. {
  420. if(!volume)
  421. {
  422. pausePosition = player.getPosition();
  423. player.stop();
  424. }
  425. else
  426. {
  427. player.play(pausePosition);
  428. }
  429. }
  430. if(State == "LoadMainMenu")
  431. {
  432. loadMenu();
  433. State = "MainMenu";
  434. }
  435. if(State == "MainMenu" )
  436. {
  437. return;
  438. }
  439. if(State == "TryAgain")
  440. {
  441. //AnimateTryAgainPic();
  442. return;
  443. }
  444. if(State == "InitLoad")
  445. {
  446. // addChild(preloader);
  447. // preloader.play();
  448. State = "InitLoading";
  449. }
  450. if(State == "InitLoading")
  451. {
  452. //Always Playing. Possible error with swfmill
  453. //Skipping for now.
  454. // if(!preloader.playing)
  455. // {
  456. // preloader.stop();
  457. // removeChild(preloader);
  458. myLogo.start();
  459. State = "LoadingLogo";
  460. // }
  461. }
  462. if(State == "LoadingLogo")
  463. {
  464. if(!myLogo.play())
  465. {
  466. State = "LoadMainMenu";
  467. }
  468. }
  469. if(State == "InfiniteMode")
  470. {
  471. Level1 = new Scene(10,100,
  472. 0,0,
  473. 0,0,1,
  474. 0);
  475. loadCurrentLevel(false);
  476. }
  477. if(State == "FreeMode")
  478. {
  479. Level1 = new Scene(10,100,
  480. 0,0,
  481. 0,0,1,
  482. -1);
  483. loadCurrentLevel(false);
  484. }
  485. if(State == "StartGame")
  486. {
  487. Level1 = new Scene(savedData.gameData.ShipSize,savedData.gameData.MaxHealth,
  488. savedData.gameData.PowerUpAppearanceRate,savedData.gameData.InvincibilityLength,
  489. savedData.gameData.PowerUpFadeRate,savedData.gameData.MoneyMultiplier,savedData.gameData.ShotsFiredRate,
  490. savedData.gameData.Difficulty);
  491. loadCurrentLevel(false);
  492. }
  493. if(State == "ContinueGame")
  494. {
  495. Level1 = new Scene(savedData.gameData.ShipSize,savedData.gameData.MaxHealth,
  496. savedData.gameData.PowerUpAppearanceRate,savedData.gameData.InvincibilityLength,
  497. savedData.gameData.PowerUpFadeRate,savedData.gameData.MoneyMultiplier,savedData.gameData.ShotsFiredRate,
  498. savedData.gameData.Difficulty);
  499. loadCurrentLevel(true);
  500. }
  501. if(State == "Playing")
  502. {
  503. if(Scenes[currentLevel-1] != null)
  504. {
  505. if(Scenes[currentLevel-1].running)
  506. {
  507. if(!volume)
  508. {
  509. pausePosition = player.getPosition();
  510. player.stop();
  511. }
  512. else
  513. {
  514. player.play(pausePosition);
  515. }
  516. return;
  517. }
  518. else if(Scenes[currentLevel-1].State == 'EndScreen')
  519. {
  520. //Load Upgrades screem
  521. return;
  522. }
  523. else
  524. {
  525. return;
  526. }
  527. }
  528. loadCurrentLevel(true);
  529. }
  530. // try
  531. // {
  532. // // var req:flash.net.URLRequest = new flash.net.URLRequest("http://av.adobe.com/podcast/csbu_dev_podcast_epi_2.mp3");
  533. // //
  534. // // Sound.load(req);
  535. // var music = new BackgroundMusic();
  536. // music.play();
  537. // }
  538. // catch (err:flash.Error)
  539. // {
  540. // trace(err.message);
  541. // }
  542. }
  543. public function AnimateTryAgainPic()
  544. {
  545. var randomNumber = Std.random(24);
  546. if(randomNumber == 1)
  547. TryAgainPic.x = TryAgainPic.x + 5;
  548. if(randomNumber == 2)
  549. TryAgainPic.x = TryAgainPic.x - 5;
  550. }
  551. //Loads Level based on Current Level
  552. public function loadCurrentLevel(inContinue:Bool) : Bool
  553. {
  554. currentLevel = 1;
  555. Scenes[currentLevel-1] = null;
  556. Scenes[currentLevel-1] = Level1;
  557. Scenes[currentLevel-1].addEventListener("SceneFinished",onSceneFinished);
  558. Scenes[currentLevel-1].addEventListener("SceneWon",onSceneWon);
  559. Scenes[currentLevel-1].addEventListener("SceneQuit",onSceneQuit);
  560. State = "Playing";
  561. Level1.Load();
  562. // Scenes[currentLevel-1].Load(volume,sound,inContinue);
  563. Scenes[currentLevel-1].pauseMenu.renderVolume(volume);
  564. // Scenes[currentLevel-1].pauseMenu.renderSoundEffects(sound);
  565. Scenes[currentLevel-1].addEventListener("VolumeToggle",onSceneVolumeToggle);
  566. // Scenes[currentLevel-1].addEventListener("SoundEffectsToggle",onSceneSoundEffectsToggle);
  567. return true;
  568. }
  569. public function getLevelData()
  570. {
  571. currentLevel = 1;
  572. pausePosition = 0;
  573. savedData.Init();
  574. //Load Save Data
  575. savedData.Load();
  576. currentLevel = savedData.currentLevel;
  577. pausePosition = savedData.pausePosition;
  578. }
  579. public function removeClip(preloader)
  580. {
  581. removeChild(preloader);
  582. }
  583. private function onHoverOut(event:MouseEvent)
  584. {
  585. CenterCircleText.htmlText = "<font size='16' color='#000000'></font>";
  586. }
  587. private function onStartGameButtonClick(event:MouseEvent) {
  588. currentLevel = 1;
  589. pausePosition = 0;
  590. addChild(StartGameDifficulty);
  591. //removeMenu();
  592. //State = "StartGame";
  593. }
  594. private function onStartGameHover(event:MouseEvent)
  595. {
  596. CenterCircleText.htmlText = "<font size='16' color='#000000'>I use the term \"Story\" very lightly.</font>";
  597. CenterCircleText.y = -5+((-CenterCircleText.length));
  598. }
  599. private function onFreeModeButtonClick(event:MouseEvent)
  600. {
  601. removeMenu();
  602. State = "FreeMode";
  603. }
  604. private function onFreeModeHover(event:MouseEvent)
  605. {
  606. CenterCircleText.htmlText = "<font size='14' color='#000000'>No Enemies. No Upgrades. See how many Shots you can fire in one setting.</font>";
  607. CenterCircleText.y = -5+((-CenterCircleText.length)*.7);
  608. }
  609. private function onInfiniteModeButtonClick(event:MouseEvent)
  610. {
  611. removeMenu();
  612. State = "InfiniteMode";
  613. }
  614. private function onInfiniteModeHover(event:MouseEvent)
  615. {
  616. CenterCircleText.htmlText = "<font size='14' color='#000000'>Hold off a swarm of Infinitly generated enemies as long as you can.</font>";
  617. CenterCircleText.y = -5+((-CenterCircleText.length)*.7);
  618. }
  619. private function onEasyGameButtonClick(event:MouseEvent)
  620. {
  621. removeChild(StartGameDifficulty);
  622. removeMenu();
  623. State = "StartGame";
  624. savedData.gameData = new GameData();
  625. savedData.gameData.Difficulty = 1;
  626. }
  627. private function onMediumGameButtonClick(event:MouseEvent)
  628. {
  629. removeChild(StartGameDifficulty);
  630. removeMenu();
  631. State = "StartGame";
  632. savedData.gameData = new GameData();
  633. savedData.gameData.Difficulty = 2;
  634. }
  635. private function onHardGameButtonClick(event:MouseEvent)
  636. {
  637. removeChild(StartGameDifficulty);
  638. removeMenu();
  639. State = "StartGame";
  640. savedData.gameData = new GameData();
  641. savedData.gameData.Difficulty = 3;
  642. }
  643. private function onContinueGameButtonClick(event:MouseEvent) {
  644. removeMenu();
  645. State = "ContinueGame";
  646. }
  647. private function onContinueGameHover(event:MouseEvent)
  648. {
  649. CenterCircleText.htmlText = "<font size='14' color='#000000'>Continue an Existing Game</font>";
  650. CenterCircleText.y = -5+((-CenterCircleText.length)*.7);
  651. }
  652. private function onMainMenuButtonClick(event:MouseEvent) {
  653. removeTryAgainMenu();
  654. State = "LoadMainMenu";
  655. }
  656. private function onInstrutionsButtonClick(event:MouseEvent) {
  657. removeMenu();
  658. addChild(Instruction);
  659. }
  660. private function onInstrutionsHover(event:MouseEvent)
  661. {
  662. CenterCircleText.htmlText = "<font size='14' color='#000000'>Keyboard Moves. Space fires. Click For More</font>";
  663. CenterCircleText.y = -5+((-CenterCircleText.length)*.7);
  664. }
  665. private function onCreditsButtonClick(event:MouseEvent) {
  666. removeMenu();
  667. addChild(Credit);
  668. }
  669. private function onCreditsHover(event:MouseEvent)
  670. {
  671. CenterCircleText.htmlText = "<font size='14' color='#000000'>This is where I give people credit for making the game. Mostly me.</font>";
  672. CenterCircleText.autoSize = TextFieldAutoSize.CENTER;
  673. CenterCircleText.y = -5+((-CenterCircleText.length)*.7);
  674. }
  675. private function onOptionsButtonClick(event:MouseEvent) {
  676. removeMenu();
  677. addChild(OptionsMenu);
  678. OptionsMenu.renderVolume(volume);
  679. OptionsMenu.renderSoundEffects(sound);
  680. }
  681. private function onOptionsHover(event:MouseEvent)
  682. {
  683. CenterCircleText.htmlText = "<font size='14' color='#000000'>Disable Sound or Reset Saved Data</font>";
  684. CenterCircleText.y = -5+((-CenterCircleText.length)*.7);
  685. }
  686. private function onInstrutionsBack(event:InstructionPageEvent)
  687. {
  688. removeChild(Instruction);
  689. loadMenu();
  690. }
  691. private function onUpgradeBack(event:UpgradePageEvent)
  692. {
  693. savedData.Save();
  694. removeChild(Upgrade);
  695. Level1 = new Scene(savedData.gameData.ShipSize,savedData.gameData.MaxHealth,
  696. savedData.gameData.PowerUpAppearanceRate,savedData.gameData.InvincibilityLength,
  697. savedData.gameData.PowerUpFadeRate,savedData.gameData.MoneyMultiplier,savedData.gameData.ShotsFiredRate,
  698. savedData.gameData.Difficulty);
  699. loadCurrentLevel(true);
  700. }
  701. private function onSceneFinished(event:Event)
  702. {
  703. savedData.gameData.Money += Scenes[currentLevel-1].TotalMoney;
  704. removeScenesEventListeners();
  705. Upgrade.gameData = savedData.gameData;
  706. addChild(Upgrade);
  707. }
  708. private function onSceneWon(event:Event)
  709. {
  710. removeScenesEventListeners();
  711. loadTryAgainMenu("You Won");
  712. try
  713. {
  714. if(savedData.gameData.Difficulty == 3)
  715. {
  716. kongVar.SubmitStat("HardBeaten",Scenes[currentLevel-1].numOfFrames);
  717. }
  718. if(savedData.gameData.Difficulty == 2)
  719. {
  720. kongVar.SubmitStat("MediumBeaten",Scenes[currentLevel-1].numOfFrames);
  721. }
  722. if(savedData.gameData.Difficulty == 1)
  723. {
  724. kongVar.SubmitStat("EasyBeaten",Scenes[currentLevel-1].numOfFrames);
  725. }
  726. }
  727. catch(msg: Dynamic)
  728. {
  729. }
  730. State = "TryAgain";
  731. }
  732. private function removeScenesEventListeners()
  733. {
  734. Scenes[currentLevel-1].removeEventListener("SceneFinished",onSceneFinished);
  735. Scenes[currentLevel-1].removeEventListener("SceneQuit", onSceneQuit);
  736. Scenes[currentLevel-1].removeEventListener("SceneWon", onSceneWon);
  737. }
  738. private function onSceneQuit(event:Event)
  739. {
  740. removeScenesEventListeners();
  741. State = "InitLoading";
  742. }
  743. private function onOptionsMenuBack(event:OptionsPageEvent)
  744. {
  745. removeChild(OptionsMenu);
  746. loadMenu();
  747. }
  748. private function onOptionsMenuVolumeToggle(event:OptionsPageEvent)
  749. {
  750. volume = !volume;
  751. OptionsMenu.renderVolume(volume);
  752. }
  753. private function onOptionsMenuSoundEffectsToggle(event:OptionsPageEvent)
  754. {
  755. sound = !sound;
  756. OptionsMenu.renderSoundEffects(sound);
  757. }
  758. private function onSceneVolumeToggle(event:PauseMenuEvent)
  759. {
  760. volume = !volume;
  761. //Scenes[currentLevel-1].volume = volume;
  762. Scenes[currentLevel-1].pauseMenu.renderVolume(volume);
  763. }
  764. private function onSceneSoundEffectsToggle(event:PauseMenuEvent)
  765. {
  766. sound = !sound;
  767. // Scenes[currentLevel-1].sound = sound;
  768. // Scenes[currentLevel-1].pauseMenu.renderSoundEffects(sound);
  769. }
  770. private function onOptionsMenuResetSavedData(event:OptionsPageEvent)
  771. {
  772. savedData.Reset();
  773. }
  774. private function onCreditsBack(event:CreditsPageEvent)
  775. {
  776. removeChild(Credit);
  777. loadMenu();
  778. }
  779. public static function main() {
  780. // Log.trace("Starting preloader");
  781. //Lib.current.roott.addEventListener(Event.ENTER_FRAME, onEnterFrame);
  782. try
  783. {
  784. new Main();
  785. }
  786. catch (err:Dynamic)
  787. {
  788. trace(err.message);
  789. }
  790. // Create the request object...
  791. // var loader = new flash.display.Loader();
  792. // // When the image is ready, instanciate the game class...
  793. // loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE,
  794. // function(_) { new Main(untyped loader.content.bitmapData); });
  795. // // Fire off the request and wait...
  796. // loader.load(new flash.net.URLRequest("img/file.gif"));
  797. //new Main();
  798. }
  799. }