PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Main.hx

http://portable-monsters.googlecode.com/
Haxe | 877 lines | 675 code | 97 blank | 105 comment | 42 complexity | b37f3d5b6e1ac4be23042e7479f2edbc 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.media.Sound;
  9. import flash.ui.Keyboard;
  10. import flash.text.TextField;
  11. import flash.text.TextFieldAutoSize;
  12. import flash.text.TextFormat;
  13. import flash.text.TextFormatAlign;
  14. import flash.filters.GlowFilter;
  15. import haxe.FastList;
  16. import flash.events.MouseEvent;
  17. import flash.net.SharedObject;
  18. import flash.Lib;
  19. import haxe.Log;
  20. import flash.utils.Timer;
  21. import haxe.Timer;
  22. import flash.events.Event;
  23. import flash.display.MovieClip;
  24. import flash.media.SoundChannel;
  25. //imports
  26. import Images;
  27. //import Sounds;
  28. //Pages
  29. import InstructionPage;
  30. import CreditsPage;
  31. import OptionsPage;
  32. import PauseMenu;
  33. //Levels
  34. import CustomSprite;
  35. import Kongregate;
  36. import Logo;
  37. import SoundPlayer;
  38. class Main extends Sprite{
  39. private var ground : Int;
  40. private var currentLevel : Int;
  41. private var damageTaken : Int;
  42. private var difficultly : Int;
  43. private var BaseLevels : Array<World>;
  44. private var State : String;
  45. private var savedData:SharedObject;
  46. private var ContinueGameButton:Sprite;
  47. private var StartGameButton:Sprite;
  48. private var MainMenuButton:Sprite;
  49. private var InstructionsButton:Sprite;
  50. private var CreditsButton:Sprite;
  51. private var OptionsButton:Sprite;
  52. private var BoxyPic:CustomSprite;
  53. private var Title:TextField;
  54. private var myLogo : Logo;
  55. private var label1:TextField;
  56. private var TryAgainPic:Sprite;
  57. private var TryAgainMenu:Sprite;
  58. var myTimer:Timer;
  59. var music:Sound;
  60. private var player:SoundPlayer;
  61. private var BackgroundImage : Sprite;
  62. private var StartGameDifficulty:Sprite;
  63. private var StartGameDifficultyAdded:Bool;
  64. public var Instruction : InstructionPage;
  65. public var Credit: CreditsPage;
  66. public var OptionsMenu : OptionsPage;
  67. public var MouseImage : Sprite;
  68. public var KeysImage : Sprite;
  69. public var textBubble : Sprite;
  70. public var textBubbleText : TextField;
  71. var mKeyDown:Array<Bool>;
  72. var pausePosition:Float;
  73. // music.play();
  74. var volume:Bool;
  75. var sound:Bool;
  76. var framerate:Int;
  77. var kongVar : CKongregate;
  78. public function new(){
  79. super();
  80. BaseLevels = [];
  81. //CutScences = [];
  82. getLevelData();
  83. //inPostion,inMoveSpeed,inJumpSpeed,inAttackSpeed,inHealth:Int
  84. initLevels();
  85. var txtFormat:TextFormat = new TextFormat();
  86. txtFormat.align = TextFormatAlign.CENTER;
  87. //Add Main to Current Flash
  88. flash.Lib.current.addChild(this);
  89. //Create Menu (own Class?)
  90. Title = new TextField();
  91. Title.x = 50; Title.y = 20;
  92. Title.width = Constants.flashWidth-100; Title.height = Constants.flashHeight;
  93. Title.multiline = true;
  94. var myFormat:TextFormat = new TextFormat();
  95. myFormat.size = 25;
  96. myFormat.align = TextFormatAlign.CENTER;
  97. Title.defaultTextFormat = myFormat;
  98. Title.htmlText = "<font color='#FFFFFF'>Boxy Boxumber</font>";
  99. Title.selectable = false;
  100. //It seems like there should be a better way to add a bitmap to a Sprite than filling the background with the bitmap. But this works.
  101. StartGameButton = new Sprite();
  102. StartGameButton.graphics.beginFill(0xFFFFFF);
  103. StartGameButton.graphics.lineStyle(1,0x000000);
  104. StartGameButton.graphics.drawRect(0, 0, 250 ,48);
  105. var StartGameButtonText = new TextField();
  106. StartGameButtonText.htmlText = "<font size='26'>"+"Start Game"+"</font>";
  107. StartGameButtonText.width = 250;
  108. StartGameButtonText.x = 0;
  109. StartGameButtonText.y = 5;
  110. StartGameButtonText.setTextFormat(txtFormat);
  111. StartGameButtonText.selectable = false;
  112. StartGameButtonText.mouseEnabled = false;
  113. StartGameButton.addChild(StartGameButtonText);
  114. StartGameButton.x = 20;
  115. StartGameButton.y = 20;
  116. StartGameButton.buttonMode = true;
  117. StartGameButton.addEventListener(MouseEvent.ROLL_OVER,onStartGameHover);
  118. StartGameButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  119. StartGameButton.addEventListener(MouseEvent.CLICK, onStartGameButtonClick);
  120. ContinueGameButton = new Sprite();
  121. ContinueGameButton.graphics.beginFill(0xFFFFFF);
  122. ContinueGameButton.graphics.lineStyle(1,0x000000);
  123. ContinueGameButton.graphics.drawRect(0, 0, 250 ,48);
  124. var ContinueGameButtonText = new TextField();
  125. ContinueGameButtonText.htmlText = "<font size='26'>"+"Continue Game"+"</font>";
  126. ContinueGameButtonText.width = 250;
  127. ContinueGameButtonText.x = 0;
  128. ContinueGameButtonText.setTextFormat(txtFormat);
  129. ContinueGameButtonText.y = 5;
  130. ContinueGameButtonText.selectable = false;
  131. ContinueGameButtonText.mouseEnabled = false;
  132. ContinueGameButton.addChild(ContinueGameButtonText);
  133. ContinueGameButton.x = 20;
  134. ContinueGameButton.y = 80;
  135. ContinueGameButton.buttonMode = true;
  136. ContinueGameButton.addEventListener(MouseEvent.ROLL_OVER,onContinueGameHover);
  137. ContinueGameButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  138. ContinueGameButton.addEventListener(MouseEvent.CLICK, onContinueGameButtonClick);
  139. InstructionsButton = new Sprite();
  140. InstructionsButton.graphics.beginFill(0x000000);
  141. InstructionsButton.graphics.lineStyle(1,0xFFFFFF);
  142. InstructionsButton.graphics.drawRect(0, 0, 250 ,48);
  143. var InstructionsButtonText = new TextField();
  144. InstructionsButtonText.htmlText = "<font size='26' color='#FFFFFF'>"+"Instructions"+"</font>";
  145. InstructionsButtonText.width = 250;
  146. InstructionsButtonText.x = 0;
  147. InstructionsButtonText.setTextFormat(txtFormat);
  148. InstructionsButtonText.y = 5;
  149. InstructionsButtonText.selectable = false;
  150. InstructionsButtonText.mouseEnabled = false;
  151. InstructionsButton.addChild(InstructionsButtonText);
  152. InstructionsButton.x = 20;
  153. InstructionsButton.y = 0;
  154. InstructionsButton.buttonMode = true;
  155. InstructionsButton.addEventListener(MouseEvent.CLICK, onInstrutionsButtonClick);
  156. Instruction = new InstructionPage();
  157. Instruction.addEventListener("Back",onInstrutionsBack);
  158. CreditsButton = new Sprite();
  159. CreditsButton.graphics.beginFill(0xFFFFFF);
  160. CreditsButton.graphics.lineStyle(1,0x000000);
  161. CreditsButton.graphics.drawRect(0, 0, 250 ,48);
  162. var CreditsButtonText = new TextField();
  163. CreditsButtonText.htmlText = "<font size='14'>"+"Everything by ZeroCreativity1"+"</font>";
  164. CreditsButtonText.width = 250;
  165. CreditsButtonText.x = 0;
  166. CreditsButtonText.setTextFormat(txtFormat);
  167. CreditsButtonText.y = 5;
  168. CreditsButtonText.selectable = false;
  169. CreditsButtonText.mouseEnabled = false;
  170. CreditsButton.addChild(CreditsButtonText);
  171. CreditsButton.x = 20;
  172. CreditsButton.y = 140;
  173. CreditsButton.buttonMode = false;
  174. CreditsButton.addEventListener(MouseEvent.ROLL_OVER,onCreditsHover);
  175. CreditsButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  176. //CreditsButton.addEventListener(MouseEvent.CLICK, onCreditsButtonClick);
  177. Credit = new CreditsPage();
  178. Credit.addEventListener("Back",onCreditsBack);
  179. OptionsButton = new Sprite();
  180. OptionsButton.graphics.beginFill(0xFFFFFF);
  181. OptionsButton.graphics.lineStyle(1,0x000000);
  182. OptionsButton.graphics.drawRect(0, 0, 250 ,48);
  183. var OptionsButtonText = new TextField();
  184. OptionsButtonText.htmlText = "<font size='26'>"+"Options"+"</font>";
  185. OptionsButtonText.width = 250;
  186. OptionsButtonText.x = 0;
  187. OptionsButtonText.setTextFormat(txtFormat);
  188. OptionsButtonText.y = 5;
  189. OptionsButtonText.selectable = false;
  190. OptionsButtonText.mouseEnabled = false;
  191. OptionsButton.addChild(OptionsButtonText);
  192. OptionsButton.x = 20;
  193. OptionsButton.y = 200;
  194. OptionsButton.buttonMode = true;
  195. OptionsButton.addEventListener(MouseEvent.ROLL_OVER,onOptionsHover);
  196. OptionsButton.addEventListener(MouseEvent.ROLL_OUT,onHoverOut);
  197. OptionsButton.addEventListener(MouseEvent.CLICK, onOptionsButtonClick);
  198. OptionsMenu = new OptionsPage();
  199. OptionsMenu.addEventListener("Back",onOptionsMenuBack);
  200. OptionsMenu.addEventListener("ResetSavedData",onOptionsMenuResetSavedData);
  201. OptionsMenu.addEventListener("VolumeToggle",onOptionsMenuVolumeToggle);
  202. OptionsMenu.addEventListener("PrevTrack",onPrevTrack);
  203. OptionsMenu.addEventListener("NextTrack",onNextTrack);
  204. OptionsMenu.addEventListener("SoundEffectsToggle",onOptionsMenuSoundEffectsToggle);
  205. //this.addEventListener(Event.ENTER_FRAME, OnEnter);
  206. myTimer = new Timer(12);
  207. myTimer.addEventListener("timer", OnEnter);
  208. myTimer.start();
  209. label1 = new TextField();
  210. TryAgainMenu = new Sprite();
  211. //TryAgainMenu.width = Constants.flashWidth;
  212. TryAgainMenu.graphics.beginFill(0x000000);
  213. TryAgainMenu.graphics.drawRect(0,0,Constants.flashWidth,Constants.flashHeight);
  214. TryAgainMenu.graphics.endFill();
  215. label1.width = 600;
  216. label1.height = Constants.flashHeight;
  217. label1.x = 25;
  218. label1.y = 25;
  219. label1.wordWrap = true;
  220. label1.selectable = false;
  221. label1.htmlText = "<font size='30' color='#FFFFFF'>" +"Play Again" + "</font>";
  222. TryAgainMenu.addChild(label1);
  223. TryAgainPic = new Sprite();
  224. TryAgainPic.graphics.beginBitmapFill(new Menu());
  225. TryAgainPic.graphics.drawRect(0, 0, 46,52);
  226. TryAgainPic.x = 300;
  227. TryAgainPic.y = 75;
  228. MainMenuButton = new Sprite();
  229. MainMenuButton.graphics.beginFill(0x000000);
  230. MainMenuButton.graphics.lineStyle(1,0xFFFFFF);
  231. MainMenuButton.graphics.drawRect(0, 0, 250 ,48);
  232. var MainMenuButtonText = new TextField();
  233. MainMenuButtonText.htmlText = "<font size='30' color='#FFFFFF'>"+"Main Menu"+"</font>";
  234. MainMenuButtonText.width = 250;
  235. MainMenuButtonText.x = 50;
  236. MainMenuButtonText.y = 5;
  237. MainMenuButtonText.selectable = false;
  238. MainMenuButtonText.mouseEnabled = false;
  239. MainMenuButton.addChild(MainMenuButtonText);
  240. MainMenuButton.x = 200;
  241. MainMenuButton.y = 300;
  242. MainMenuButton.buttonMode = true;
  243. MainMenuButton.addEventListener(MouseEvent.CLICK, onMainMenuButtonClick);
  244. MouseImage = new Sprite();
  245. MouseImage.graphics.beginBitmapFill(new RightClick());
  246. MouseImage.graphics.drawRect(0, 0, 200,200);
  247. MouseImage.x = 290;
  248. MouseImage.y = 270;
  249. var MouseImageText = new TextField();
  250. MouseImageText.htmlText = "<font size='20' color='#FFFFFF'>"+"Shoot"+"</font>";
  251. MouseImageText.width = 250;
  252. MouseImageText.x = 70;
  253. MouseImageText.y =180;
  254. MouseImageText.selectable = false;
  255. MouseImage.addChild(MouseImageText);
  256. textBubble = new Sprite();
  257. textBubble.graphics.beginBitmapFill(new Bubble());
  258. textBubble.graphics.drawRect(0, 0, 250,213);
  259. textBubble.x = 390;
  260. textBubble.y = 40;
  261. textBubbleText = new TextField();
  262. textBubbleText.htmlText = "<font size='16' color='#000000'></font>";
  263. textBubbleText.autoSize = TextFieldAutoSize.CENTER;
  264. textBubbleText.width = 180;
  265. textBubbleText.wordWrap = true;
  266. textBubbleText.multiline = true;
  267. textBubbleText.selectable = false;
  268. textBubbleText.mouseEnabled = false;
  269. textBubbleText.x = 25;
  270. textBubble.addChild(textBubbleText);
  271. textBubbleText.y=25;
  272. KeysImage = new Sprite();
  273. KeysImage.graphics.beginBitmapFill(new Keys());
  274. KeysImage.graphics.drawRect(0, 0, 172,116);
  275. KeysImage.x = 450;
  276. KeysImage.y = 320;
  277. var KeysImageText = new TextField();
  278. KeysImageText.htmlText = "<font size='20' color='#FFFFFF'>"+"Jump"+"</font>";
  279. KeysImageText.width = 250;
  280. KeysImageText.x = 62;
  281. KeysImageText.y =-25;
  282. KeysImageText.selectable = false;
  283. KeysImage.addChild(KeysImageText);
  284. var LeftText = new TextField();
  285. LeftText.htmlText = "<font size='20' color='#FFFFFF'>"+"Left"+"</font>";
  286. LeftText.width = 250;
  287. LeftText.x = 10;
  288. LeftText.y =105;
  289. LeftText.selectable = false;
  290. KeysImage.addChild(LeftText);
  291. var RightText = new TextField();
  292. RightText.htmlText = "<font size='20' color='#FFFFFF'>"+"Right"+"</font>";
  293. RightText.width = 250;
  294. RightText.x = 115;
  295. RightText.y =105;
  296. RightText.selectable = false;
  297. KeysImage.addChild(RightText);
  298. //The State Will determine whether to load a level, or show Main Menu, or whatever. Used in the OnEnterEvent.
  299. //State = "StartGame";
  300. State = "LoadMainMenu";
  301. // track1 = new Track1();
  302. // track2 = new Track2();
  303. // track3 = new Track3();
  304. //preloader = new PreloaderHost();
  305. BackgroundImage = new Sprite();
  306. BackgroundImage.graphics.beginFill(0xFFFFFF);
  307. BackgroundImage.graphics.drawRect(0,0,Constants.flashWidth,Constants.flashHeight);
  308. BackgroundImage.graphics.endFill();
  309. //player = new SoundPlayer(track1,track2,track3);
  310. volume = true;
  311. sound = true;
  312. myLogo = new Logo();
  313. addChild(myLogo);
  314. try
  315. {
  316. kongVar = new CKongregate();
  317. }
  318. catch (msg:Dynamic)
  319. {
  320. }
  321. mKeyDown = [];
  322. stage.addEventListener(KeyboardEvent.KEY_DOWN, OnKeyDown );
  323. stage.addEventListener(KeyboardEvent.KEY_UP, OnKeyUp );
  324. //preloader.addEventListener(Event.ENTER_FRAME, OnMovieEnter);
  325. }
  326. public function OnKeyUp (event:KeyboardEvent)
  327. {
  328. mKeyDown[event.keyCode] = false;
  329. //lastUp = event.keyCode;
  330. }
  331. public function OnKeyDown(event:KeyboardEvent)
  332. {
  333. // When a key is held down, multiple KeyDown events are generated.
  334. // This check means we only pick up the first one.
  335. if (!mKeyDown[event.keyCode])
  336. {
  337. // Store for use in game
  338. mKeyDown[event.keyCode] = true;
  339. //I do this here, because if they hold down P,
  340. // it won't pause and unpause constantly.
  341. if(mKeyDown[ 77 ] == true)
  342. {
  343. volume = !volume;
  344. BaseLevels[currentLevel-1].pauseMenu.renderVolume(volume);
  345. }
  346. }
  347. }
  348. function loadMenu()
  349. {
  350. addChild(BackgroundImage);
  351. addChild(Title);
  352. addChild(StartGameButton);
  353. addChild(ContinueGameButton);
  354. //addChild(InstructionsButton);
  355. addChild(CreditsButton);
  356. // addChild(OptionsButton);
  357. // addChild(BoxyPic);
  358. // addChild(textBubble);
  359. // addChild(MouseImage);
  360. // addChild(KeysImage);
  361. }
  362. function removeMenu()
  363. {
  364. removeChild(Title);
  365. removeChild(StartGameButton);
  366. removeChild(ContinueGameButton);
  367. removeChild(BackgroundImage);
  368. //removeChild(InstructionsButton);
  369. removeChild(CreditsButton);
  370. // removeChild(OptionsButton);
  371. // removeChild(BoxyPic);
  372. // removeChild(textBubble);
  373. // removeChild(MouseImage);
  374. // removeChild(KeysImage);
  375. if(StartGameDifficultyAdded)
  376. {removeChild(StartGameDifficulty);StartGameDifficultyAdded=false;}
  377. }
  378. //Change to stat Menu
  379. function loadTryAgainMenu(text:String)
  380. {
  381. try
  382. {
  383. }
  384. catch(msg: Dynamic)
  385. {
  386. }
  387. addChild(TryAgainMenu);
  388. addChild(MainMenuButton);
  389. //addChild(TryAgainPic);
  390. //player.stop();
  391. }
  392. function removeTryAgainMenu()
  393. {
  394. removeChild(TryAgainMenu);
  395. removeChild(MainMenuButton);
  396. //removeChild(TryAgainPic);
  397. }
  398. function initLevels()
  399. {
  400. BaseLevels[currentLevel-1] = new World();
  401. }
  402. function OnEnter(e:flash.events.Event)
  403. {
  404. if(player !=null)
  405. {
  406. if(!volume)
  407. {
  408. pausePosition = player.getPosition();
  409. player.stop();
  410. }
  411. else
  412. {
  413. player.play(pausePosition);
  414. }
  415. }
  416. if(State == "LoadMainMenu")
  417. {
  418. loadMenu();
  419. State = "MainMenu";
  420. }
  421. if(State == "MainMenu" )
  422. {
  423. return;
  424. }
  425. if(State == "TryAgain")
  426. {
  427. AnimateTryAgainPic();
  428. return;
  429. }
  430. if(State == "InitLoad")
  431. {
  432. // addChild(preloader);
  433. // preloader.play();
  434. State = "InitLoading";
  435. }
  436. if(State == "InitLoading")
  437. {
  438. initLevels();
  439. //Always Playing. Possible error with swfmill
  440. //Skipping for now.
  441. // if(!preloader.playing)
  442. // {
  443. // preloader.stop();
  444. // removeChild(preloader);
  445. State = "LoadingLogo";
  446. myLogo.start();
  447. // }
  448. }
  449. if(State == "LoadingLogo")
  450. {
  451. if(!myLogo.play())
  452. {
  453. State = "LoadMainMenu";
  454. }
  455. }
  456. if(State == "StartGame")
  457. {
  458. //player.play(pausePosition);
  459. currentLevel =1;
  460. loadCurrentLevel(false);
  461. }
  462. if(State == "ContinueGame")
  463. {
  464. //player.play(pausePosition);
  465. loadCurrentLevel(true);
  466. }
  467. if(State == "Playing")
  468. {
  469. if(BaseLevels[currentLevel-1] != null)
  470. {
  471. if(!volume)
  472. {
  473. pausePosition = player.getPosition();
  474. player.stop();
  475. }
  476. else
  477. {
  478. player.play(pausePosition);
  479. }
  480. return;
  481. // else
  482. // {
  483. //
  484. // try
  485. // {
  486. // //kongVar.SubmitStat("Won",1);
  487. // }
  488. // catch(msg: Dynamic)
  489. // {
  490. //
  491. // }
  492. //
  493. // loadTryAgainMenu("Try Again?");
  494. // State = "TryAgain";
  495. // return;
  496. // }
  497. }
  498. }
  499. // try
  500. // {
  501. // // var req:flash.net.URLRequest = new flash.net.URLRequest("http://av.adobe.com/podcast/csbu_dev_podcast_epi_2.mp3");
  502. // //
  503. // // Sound.load(req);
  504. // var music = new BackgroundMusic();
  505. // music.play();
  506. // }
  507. // catch (err:flash.Error)
  508. // {
  509. // trace(err.message);
  510. // }
  511. }
  512. public function AnimateTryAgainPic()
  513. {
  514. var randomNumber = Std.random(24);
  515. if(randomNumber == 1)
  516. TryAgainPic.x = TryAgainPic.x + 5;
  517. if(randomNumber == 2)
  518. TryAgainPic.x = TryAgainPic.x - 5;
  519. }
  520. public function loadCutScence() : Bool
  521. {
  522. State="CutScence";
  523. return true;
  524. }
  525. //Loads Level based on Current Level
  526. public function loadCurrentLevel(inContinue:Bool) : Bool
  527. {
  528. State = "Playing";
  529. if(currentLevel > BaseLevels.length)
  530. {State="TryAgain";loadTryAgainMenu("YOU WON");}
  531. BaseLevels[currentLevel-1].addEventListener("Won",onLevelFinished);
  532. BaseLevels[currentLevel-1].addEventListener("LevelQuit",onLevelQuit);
  533. BaseLevels[currentLevel-1].addEventListener("VolumeToggle",onBaseLevelVolumeToggle);
  534. BaseLevels[currentLevel-1].addEventListener("PrevTrack",onPrevTrack);
  535. BaseLevels[currentLevel-1].addEventListener("NextTrack",onNextTrack);
  536. State = "Playing";
  537. //Level1.Load();
  538. BaseLevels[currentLevel-1].Load(inContinue,volume,kongVar);
  539. // BaseLevels[currentLevel-1].pauseMenu.renderVolume(volume);
  540. // BaseLevels[currentLevel-1].pauseMenu.renderSoundEffects(sound);
  541. // BaseLevels[currentLevel-1].addEventListener("SoundEffectsToggle",onBaseLevelSoundEffectsToggle);
  542. return true;
  543. }
  544. public function getLevelData()
  545. {
  546. currentLevel = 1;
  547. pausePosition = 0;
  548. damageTaken = 0;
  549. difficultly = 2;
  550. //Load Save Data
  551. savedData = SharedObject.getLocal("LevelData");
  552. if(savedData.data.Level != null)
  553. {
  554. currentLevel = savedData.data.Level;
  555. pausePosition = savedData.data.SoundPosition;
  556. damageTaken = savedData.data.damageTaken;
  557. difficultly = savedData.data.difficultly;
  558. }
  559. }
  560. public function removeClip(preloader)
  561. {
  562. removeChild(preloader);
  563. }
  564. private function onStartGameButtonClick(event:MouseEvent) {
  565. removeMenu();
  566. State = "StartGame";
  567. }
  568. private function onEasyGameButtonClick(event:MouseEvent)
  569. {
  570. removeMenu();
  571. State = "StartGame";
  572. savedData.data.Level = 1;
  573. savedData.data.damageTaken = 0;
  574. savedData.data.difficultly = 1;
  575. }
  576. private function onMediumGameButtonClick(event:MouseEvent)
  577. {
  578. removeMenu();
  579. State = "StartGame";
  580. savedData.data.Level = 1;
  581. savedData.data.damageTaken = 0;
  582. savedData.data.difficultly = 2;
  583. }
  584. private function onHardGameButtonClick(event:MouseEvent)
  585. {
  586. removeMenu();
  587. State = "StartGame";
  588. savedData.data.Level = 1;
  589. savedData.data.damageTaken = 0;
  590. savedData.data.difficultly = 3;
  591. }
  592. private function onContinueGameButtonClick(event:MouseEvent) {
  593. removeMenu();
  594. State = "ContinueGame";
  595. }
  596. //Hover Texts
  597. private function onStartGameHover(event:MouseEvent)
  598. {
  599. textBubbleText.htmlText = "<font size='16' color='#000000'>This will erase saved game information</font>";
  600. }
  601. private function onContinueGameHover(event:MouseEvent)
  602. {
  603. textBubbleText.htmlText = "<font size='16' color='#000000'>Continue an Existing Game</font>";
  604. }
  605. private function onOptionsHover(event:MouseEvent)
  606. {
  607. textBubbleText.htmlText = "<font size='16' color='#000000'>Disable Sound or Reset Saved Data</font>";
  608. textBubbleText.autoSize = TextFieldAutoSize.CENTER;
  609. }
  610. private function onCreditsHover(event:MouseEvent)
  611. {
  612. textBubbleText.htmlText = "<font size='16' color='#000000'>This is where I give people credit for making the game. Mostly me.</font>";
  613. textBubbleText.autoSize = TextFieldAutoSize.CENTER;
  614. }
  615. private function onEasyGameHover(event:MouseEvent)
  616. {
  617. textBubbleText.htmlText = "<font size='16' color='#000000'>You have 20 health and enemies have 5 health. It will be a piece of cake</font>";
  618. textBubbleText.autoSize = TextFieldAutoSize.CENTER;
  619. }
  620. private function onMediumGameHover(event:MouseEvent)
  621. {
  622. textBubbleText.htmlText = "<font size='16' color='#000000'>You have 10 health and enemies have 10 health. This may take some effort</font>";
  623. textBubbleText.autoSize = TextFieldAutoSize.CENTER;
  624. }
  625. private function onHardGameHover(event:MouseEvent)
  626. {
  627. textBubbleText.htmlText = "<font size='16' color='#000000'>You have 8 health and enemies have 15 health. Only for the Hard Core gamers.</font>";
  628. textBubbleText.autoSize = TextFieldAutoSize.CENTER;
  629. }
  630. private function onHoverOut(event:MouseEvent)
  631. {
  632. textBubbleText.htmlText = "<font size='16' color='#000000'>I'm Boxy!</font>";
  633. }
  634. private function onLevelFinished(event:Event)
  635. {
  636. removeLevelEventListeners();
  637. State = "InitLoading";
  638. }
  639. private function onLevelQuit(event:Event)
  640. {
  641. removeLevelEventListeners();
  642. State = "InitLoading";
  643. }
  644. private function removeLevelEventListeners()
  645. {
  646. BaseLevels[currentLevel-1].removeEventListener("LevelFinished",onLevelFinished);
  647. BaseLevels[currentLevel-1].removeEventListener("LevelQuit",onLevelQuit);
  648. BaseLevels[currentLevel-1].removeEventListener("PrevTrack",onPrevTrack);
  649. BaseLevels[currentLevel-1].removeEventListener("NextTrack",onNextTrack);
  650. }
  651. private function removeCutScencesEventListeners()
  652. {
  653. //CutScences[currentLevel-1].removeEventListener("LevelFinished",onLevelFinished);
  654. }
  655. private function onMainMenuButtonClick(event:MouseEvent) {
  656. removeTryAgainMenu();
  657. State = "LoadMainMenu";
  658. }
  659. private function onInstrutionsButtonClick(event:MouseEvent) {
  660. removeMenu();
  661. addChild(Instruction);
  662. }
  663. private function onCreditsButtonClick(event:MouseEvent) {
  664. removeMenu();
  665. addChild(Credit);
  666. }
  667. private function onOptionsButtonClick(event:MouseEvent) {
  668. removeMenu();
  669. addChild(OptionsMenu);
  670. OptionsMenu.renderVolume(volume);
  671. //OptionsMenu.renderSoundEffects(sound);
  672. }
  673. private function onInstrutionsBack(event:InstructionPageEvent)
  674. {
  675. removeChild(Instruction);
  676. loadMenu();
  677. }
  678. private function onOptionsMenuBack(event:OptionsPageEvent)
  679. {
  680. removeChild(OptionsMenu);
  681. loadMenu();
  682. }
  683. private function onPrevTrack(event:Event)
  684. {
  685. if(volume && player != null)
  686. {player.getPrevTrack();}
  687. }
  688. private function onNextTrack(event:Event)
  689. {
  690. if(volume && player != null)
  691. {player.getNextTrack();}
  692. }
  693. private function onOptionsMenuVolumeToggle(event:OptionsPageEvent)
  694. {
  695. volume = !volume;
  696. OptionsMenu.renderVolume(volume);
  697. }
  698. private function onOptionsMenuSoundEffectsToggle(event:OptionsPageEvent)
  699. {
  700. sound = !sound;
  701. OptionsMenu.renderSoundEffects(sound);
  702. }
  703. private function onBaseLevelVolumeToggle(event:PauseMenuEvent)
  704. {
  705. volume = !volume;
  706. BaseLevels[currentLevel-1].volume = volume;
  707. BaseLevels[currentLevel-1].pauseMenu.renderVolume(volume);
  708. }
  709. private function onBaseLevelSoundEffectsToggle(event:PauseMenuEvent)
  710. {
  711. sound = !sound;
  712. //BaseLevels[currentLevel-1].sound = sound;
  713. //BaseLevels[currentLevel-1].pauseMenu.renderSoundEffects(sound);
  714. }
  715. private function onOptionsMenuResetSavedData(event:OptionsPageEvent)
  716. {
  717. savedData.data.Level = 1;
  718. savedData.data.SoundPosition = 0;
  719. savedData.data.damageTaken = 0;
  720. savedData.data.difficultly = 2;
  721. savedData.flush();
  722. getLevelData();
  723. pausePosition = 0;
  724. currentLevel = 1;
  725. }
  726. private function onCreditsBack(event:CreditsPageEvent)
  727. {
  728. removeChild(Credit);
  729. loadMenu();
  730. }
  731. //Couldn't get preloader to work.
  732. static function onEnterFrame(event : Event)
  733. {
  734. LoadingBar.graphics.beginFill(0x0000FF);
  735. LoadingBar.graphics.drawRect(1,1,(Lib.current.root.loaderInfo.bytesLoaded/Lib.current.root.loaderInfo.bytesTotal)*498,48);
  736. LoadingBar.graphics.endFill();
  737. if (Lib.current.root.loaderInfo.bytesLoaded >= Lib.current.root.loaderInfo.bytesTotal)
  738. {
  739. Lib.current.root.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
  740. // Lib.current.gotoAndStop("start");
  741. // new Images();
  742. removeLoadingBar();
  743. try
  744. {
  745. var mainInstance:Main = new Main();
  746. }
  747. catch (err:flash.Error)
  748. {
  749. trace(err.message);
  750. }
  751. }
  752. }
  753. private static var LoadingBar:Sprite;
  754. public static function removeLoadingBar()
  755. {
  756. flash.Lib.current.removeChild(LoadingBar);
  757. }
  758. public static function addLoadingBar()
  759. {
  760. LoadingBar = new Sprite();
  761. LoadingBar.graphics.beginFill(0x000000);
  762. LoadingBar.graphics.drawRect(0,0,500,50);
  763. LoadingBar.graphics.endFill();
  764. flash.Lib.current.addChild(LoadingBar);
  765. LoadingBar.x = 50; LoadingBar.y = 225;
  766. }
  767. static function main() {
  768. // Log.trace("Starting preloader");
  769. addLoadingBar();
  770. Lib.current.root.addEventListener(Event.ENTER_FRAME, onEnterFrame);
  771. // Create the request object...
  772. // var loader = new flash.display.Loader();
  773. // // When the image is ready, instanciate the game class...
  774. // loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE,
  775. // function(_) { new Main(untyped loader.content.bitmapData); });
  776. // // Fire off the request and wait...
  777. // loader.load(new flash.net.URLRequest("img/file.gif"));
  778. //new Main();
  779. }
  780. }