PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Scene.hx

http://save-the-princess.googlecode.com/
Haxe | 1205 lines | 1025 code | 135 blank | 45 comment | 149 complexity | dc53da077b4905c57b054d5aed881d6c 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.display.Shape;
  16. import flash.events.MouseEvent;
  17. import flash.events.EventDispatcher;
  18. import flash.events.Event;
  19. import TextArea;
  20. import PauseMenu;
  21. import FadingText;
  22. import CustomSprite;
  23. import GenericMenu;
  24. import PopUp;
  25. import PopUpText;
  26. import flash.utils.Timer;
  27. import flash.events.TimerEvent;
  28. import flash.net.SharedObject;
  29. import haxe.remoting.AMFConnection;
  30. //import haxe.Timer;
  31. import HelperMethods;
  32. import Images;
  33. import Blob;
  34. import Sounds;
  35. import Button;
  36. import KidnapList;
  37. import Kongregate;
  38. class Scene extends CustomSprite
  39. {
  40. public var Speed : Float;
  41. public var PrincessPosition:Array<Array<Bool>>;
  42. public var Player : CharacterStat;
  43. public var currentBackground : CustomSprite;
  44. private var BackButton:Sprite;
  45. public var MenuBar:CustomSprite;
  46. public var KidnapPrincess : CustomSprite;
  47. public var ActionButton : CustomSprite;
  48. public var ActionMenuItem : ActionMenu;
  49. public var ResourceButton : CustomSprite;
  50. public var ResourceMenuItem : ResourceMenu;
  51. public var LeftButton : CustomSprite;
  52. public var SpeedText : TextField;
  53. public var RightButton : CustomSprite;
  54. public var SuspicionBar:CustomSprite;
  55. public var SuspicionBarText:TextField;
  56. public var SuspicionBarInner:CustomSprite;
  57. public var SuspicionBarOuter:CustomSprite;
  58. public var SuspicionText:TextField;
  59. public var FearBar:CustomSprite;
  60. public var FearBarText:TextField;
  61. public var FearText:TextField;
  62. public var FearBarInner:CustomSprite;
  63. public var FearBarOuter:CustomSprite;
  64. public var PopulationText:TextField;
  65. public var PrincessStatus:CustomSprite;
  66. public var PrincessStatusImage1:CustomSprite;
  67. public var PrincessStatusImage2:CustomSprite;
  68. public var PrincessStatusImage3:CustomSprite;
  69. public var PrincessStatusImage4:CustomSprite;
  70. public var PrincessStatusImage5:CustomSprite;
  71. public var PrincessStatusImage6:CustomSprite;
  72. public var PrincessStatusCurrentImage:String;
  73. public var CurrentMenu:String;
  74. public var Castle:CustomSprite;
  75. public var OkPopUp : PopUp;
  76. public var OkPopUpText : PopUpText;
  77. private var ignoreKeyPress : String;
  78. public var text : String;
  79. var mKeyDown:Array<Bool>;
  80. var lastUp:Int;
  81. var Pause:String;
  82. public var volume:Bool;
  83. public var sound:Bool;
  84. public var running:Bool;
  85. public var victory:String;
  86. public var TurnLeft:TextField;
  87. private var myTimer:Timer;
  88. private static inline var FRAME_RATE:Int = 40;
  89. private var _period:Float;
  90. private var _beforeTime:Int;
  91. private var _afterTime:Int;
  92. private var _timeDiff:Int;
  93. private var _sleepTime:Int;
  94. private var _overSleepTime:Int;
  95. private var _excess:Int;
  96. var State:String;
  97. var PauseTillKeyPressed:Bool;
  98. public var Intro:CustomSprite;
  99. public var IntroText:TextField;
  100. public var IntroOK:CustomSprite;
  101. public var Loss:CustomSprite;
  102. public var LossText:TextField;
  103. public var LossQuit:CustomSprite;
  104. public var LossRetry:CustomSprite;
  105. public var Win:CustomSprite;
  106. public var WinText:TextField;
  107. public var WinQuit:CustomSprite;
  108. public var WinContinue:CustomSprite;
  109. public var pauseMenu:PauseMenu;
  110. var pauseMenuPoint:Point;
  111. public var saveGame:Int;
  112. //public var savedData:flash.net.SharedObject;
  113. private var player:SoundPlayer;
  114. var kongVar : CKongregate;
  115. public function new(inBackground:BitmapData)
  116. {
  117. //Need to RegisterMethods inOrder to Save
  118. haxe.remoting.AMFConnection.registerClassAlias("CharacterStatAlias",CharacterStat);
  119. haxe.remoting.AMFConnection.registerClassAlias("KidnapingAlias",Kidnaping);
  120. haxe.remoting.AMFConnection.registerClassAlias("KidnapListAlias",KidnapList);
  121. haxe.remoting.AMFConnection.registerClassAlias("CustomSpriteAlias",CustomSprite);
  122. haxe.remoting.AMFConnection.registerClassAlias("HeroAlias", Hero);
  123. super();
  124. //
  125. try
  126. {
  127. kongVar = new CKongregate();
  128. }
  129. catch (msg:Dynamic)
  130. {
  131. }
  132. Speed = 1;
  133. saveGame = 0;
  134. PrincessStatusCurrentImage = "";
  135. PrincessPosition = [[]];
  136. //old determine what to use
  137. pauseMenu = new PauseMenu();
  138. pauseMenuPoint = new Point(0,370);
  139. running = false;
  140. victory = "None";
  141. Pause = "UnPaused";
  142. volume = true;
  143. sound = true;
  144. State = "Wait";
  145. ignoreKeyPress = "";
  146. PauseTillKeyPressed = false;
  147. currentBackground = new CustomSprite();
  148. currentBackground.graphics.beginBitmapFill(inBackground.clone());
  149. currentBackground.graphics.drawRect(0, 0, inBackground.width,inBackground.height);
  150. currentBackground.graphics.endFill();
  151. currentBackground.resize(Constants.flashWidth,Constants.flashHeight);
  152. var grass= new CustomSprite();
  153. grass.graphics.beginBitmapFill(new Grass());
  154. grass.graphics.drawRect(10, 10, 780,580);
  155. grass.graphics.endFill();
  156. currentBackground.addChild(grass);
  157. MenuBar = new CustomSprite();
  158. MenuBar.graphics.beginFill(0xFFFFFF);
  159. MenuBar.graphics.drawRect(0,0,780,75);
  160. MenuBar.graphics.endFill();
  161. MenuBar.x=10; MenuBar.y=10;
  162. KidnapPrincess = new CustomSprite();
  163. KidnapPrincess.graphics.beginBitmapFill(inBackground.clone());
  164. KidnapPrincess.graphics.drawRect(0, 0, inBackground.width,inBackground.height);
  165. KidnapPrincess.resize(50,50);
  166. KidnapPrincess.buttonMode = true;
  167. KidnapPrincess.x = 240; KidnapPrincess.y = 20;
  168. ActionButton = new CustomSprite();
  169. ActionButton.graphics.beginBitmapFill(new Bombs());
  170. ActionButton.graphics.drawRect(0, 0, 100,100);
  171. ActionButton.resize(50,50);
  172. ActionButton.isHover = true;
  173. ActionButton.setHoverText( "<font='14'><b>Command<b></font>");
  174. ActionButton.buttonMode = true;
  175. ActionButton.x = 300; ActionButton.y = 20;
  176. ResourceButton = new CustomSprite();
  177. // ResourceButton.graphics.beginBitmapFill(inBackground.clone());
  178. // ResourceButton.graphics.drawRect(0, 0, inBackground.width,inBackground.height);
  179. // ResourceButton.resize(51,51);
  180. ResourceButton.graphics.beginBitmapFill(new ResourceImage());
  181. ResourceButton.graphics.drawRect(0, 0, 50,50);
  182. ResourceButton.isHover = true;
  183. ResourceButton.setHoverText( "<font='14'><b>Resources<b></font>");
  184. ResourceButton.buttonMode = true;
  185. ResourceButton.x = 230; ResourceButton.y = 20;
  186. SuspicionBar = new CustomSprite();
  187. SuspicionBarText = new TextField();
  188. SuspicionBarText.htmlText = "Suspicion: ";
  189. SuspicionBar.addChild(SuspicionBarText);
  190. SuspicionBarText.y = -5;
  191. SuspicionBarOuter = new CustomSprite();
  192. SuspicionBarOuter.graphics.beginFill(0x000000);
  193. SuspicionBarOuter.graphics.drawRect(0,0,100,10);
  194. SuspicionBarOuter.graphics.endFill();
  195. SuspicionBar.addChild(SuspicionBarOuter);
  196. SuspicionBarOuter.x = 60;
  197. SuspicionBarInner = new CustomSprite();
  198. SuspicionBarInner.graphics.beginFill(0x0000FF);
  199. SuspicionBarInner.graphics.drawRect(1,1,0,8);
  200. SuspicionBarInner.graphics.endFill();
  201. SuspicionBar.addChild(SuspicionBarInner);
  202. SuspicionBarInner.x = 60;
  203. SuspicionBar.x = 600; SuspicionBar.y =40;
  204. // public var FearBar:CustomSprite;
  205. // public var FearBarText:TextField;
  206. // public var FearBarInner:CustomSprite;
  207. // public var FearBarOuter:CustomSprite;
  208. FearBar = new CustomSprite();
  209. FearBarText = new TextField();
  210. FearBarText.htmlText = "Fear: ";
  211. FearBar.addChild(FearBarText);
  212. FearBarText.y = -5;
  213. FearBarOuter = new CustomSprite();
  214. FearBarOuter.graphics.beginFill(0x000000);
  215. FearBarOuter.graphics.drawRect(0,0,100,10);
  216. FearBarOuter.graphics.endFill();
  217. FearBar.addChild(FearBarOuter);
  218. FearBarOuter.x = 60;
  219. FearBarInner = new CustomSprite();
  220. FearBarInner.graphics.beginFill(0xFF0000);
  221. FearBarInner.graphics.drawRect(1,1,0,8);
  222. FearBarInner.graphics.endFill();
  223. FearBar.addChild(FearBarInner);
  224. FearBarInner.x = 60;
  225. FearBar.x = 600; FearBar.y =60;
  226. OkPopUp = new PopUp(inBackground.clone(),"Test Message");
  227. OkPopUpText = new PopUpText(inBackground.clone(),"Test Message");
  228. mKeyDown = [];
  229. lastUp = Keyboard.RIGHT;
  230. TurnLeft = new TextField();
  231. Player = new CharacterStat();
  232. Player.Money = 0;
  233. Player.addEventListener("updateValues",updateValues);
  234. LeftButton = new CustomSprite();
  235. LeftButton.graphics.beginBitmapFill(new LeftArrow());
  236. LeftButton.graphics.drawRect(0, 0, 30,50);
  237. LeftButton.x = 420;LeftButton.y =20;
  238. LeftButton.buttonMode = true;
  239. SpeedText = new TextField();
  240. RightButton = new CustomSprite();
  241. RightButton.graphics.beginBitmapFill(new RightArrow());
  242. RightButton.graphics.drawRect(20, 0, 30,50);
  243. RightButton.x = 480;RightButton.y =20;
  244. RightButton.buttonMode = true;
  245. Castle = new CustomSprite();
  246. Castle.graphics.beginBitmapFill(new CastleImage());
  247. Castle.graphics.drawRect(0, 0, 530,500);
  248. // Castle.graphics.beginFill(0xFFFFFF);
  249. // Castle.graphics.lineStyle(1);
  250. // Castle.graphics.drawRect(0,0,530,500);
  251. Castle.graphics.endFill();
  252. Castle.x = 150;Castle.y= 100;
  253. addChild(currentBackground);
  254. addChild(Castle);
  255. addChild(MenuBar);
  256. addChild(SuspicionBar);
  257. addChild(FearBar);
  258. //addChild(KidnapPrincess);
  259. addChild(ResourceButton);
  260. addChild(ActionButton);
  261. addChild(LeftButton);
  262. addChild(RightButton);
  263. LeftButton.addEventListener(MouseEvent.CLICK, onLeftArrowButtonClick);
  264. RightButton.addEventListener(MouseEvent.CLICK, onRightArrowButtonClick);
  265. ResourceButton.addEventListener(MouseEvent.CLICK, onResourceButtonClick);
  266. ActionButton.addEventListener(MouseEvent.CLICK, onActionButtonClick);
  267. addChild(SpeedText);
  268. SpeedText.x = 425;
  269. SpeedText.autoSize = TextFieldAutoSize.CENTER;
  270. SpeedText.y = 20;
  271. SpeedText.htmlText = "<Font size = '15'><u>Speed</u>\n "+ Speed + "</font>";
  272. SpeedText.selectable = false;
  273. PopulationText = new TextField();
  274. addChild(PopulationText);
  275. PopulationText.x = 600;
  276. PopulationText.autoSize = TextFieldAutoSize.LEFT;
  277. PopulationText.y = 10;
  278. var Population = 1000 * Math.pow(10,Player.PopulationLevel);
  279. var suffix = "";
  280. if(Player.PopulationLevel >= 6)
  281. {
  282. Population = 1 * Math.pow(10,Player.PopulationLevel-6);
  283. suffix = " Mil";
  284. }
  285. PopulationText.htmlText = "Population: " + HelperMethods.format(Population,0) + suffix;
  286. FearText = new TextField();
  287. addChild(FearText);
  288. FearText.x = 660;
  289. FearText.autoSize = TextFieldAutoSize.RIGHT;
  290. FearText.y = 56;
  291. FearText.htmlText = "<font color='#FFFFFF' size='10'>"+Player.Fear+"</font>";
  292. SuspicionText= new TextField();
  293. addChild(SuspicionText);
  294. SuspicionText.x = 660;
  295. SuspicionText.autoSize = TextFieldAutoSize.RIGHT;
  296. SuspicionText.y = 36;
  297. SuspicionText.htmlText = "<font color='#FFFFFF' size='10'>"+Player.Suspicion+"</font>";
  298. addChild(TurnLeft);
  299. TurnLeft.x = 540;
  300. TurnLeft.y = 40;
  301. PrincessStatus = new CustomSprite();
  302. PrincessStatus.graphics.beginFill(0xFFFFFF);
  303. PrincessStatus.graphics.lineStyle(1);
  304. PrincessStatus.graphics.drawRect(0,0,75,75);
  305. PrincessStatus.x =10;PrincessStatus.y=10;
  306. addChild(PrincessStatus);
  307. PrincessStatusImage1 = new CustomSprite();
  308. PrincessStatusImage1.graphics.beginBitmapFill(new PrincessStatus1());
  309. PrincessStatusImage1.graphics.drawRect(0, 0, 75,75);
  310. PrincessStatusImage1.graphics.endFill();
  311. PrincessStatusImage2 = new CustomSprite();
  312. PrincessStatusImage2.graphics.beginBitmapFill(new PrincessStatus2());
  313. PrincessStatusImage2.graphics.drawRect(0, 0, 75,75);
  314. PrincessStatusImage2.graphics.endFill();
  315. PrincessStatusImage3 = new CustomSprite();
  316. PrincessStatusImage3.graphics.beginBitmapFill(new PrincessStatus3());
  317. PrincessStatusImage3.graphics.drawRect(0, 0, 75,75);
  318. PrincessStatusImage3.graphics.endFill();
  319. PrincessStatusImage4 = new CustomSprite();
  320. PrincessStatusImage4.graphics.beginBitmapFill(new PrincessStatus4());
  321. PrincessStatusImage4.graphics.drawRect(0, 0, 75,75);
  322. PrincessStatusImage4.graphics.endFill();
  323. PrincessStatusImage5 = new CustomSprite();
  324. PrincessStatusImage5.graphics.beginBitmapFill(new PrincessStatus5());
  325. PrincessStatusImage5.graphics.drawRect(0, 0, 75,75);
  326. PrincessStatusImage5.graphics.endFill();
  327. PrincessStatusImage6 = new CustomSprite();
  328. PrincessStatusImage6.graphics.beginBitmapFill(new PrincessStatus6());
  329. PrincessStatusImage6.graphics.drawRect(0, 0, 75,75);
  330. PrincessStatusImage6.graphics.endFill();
  331. Intro = new CustomSprite();
  332. Intro.graphics.beginFill(0xFFFFFF);
  333. Intro.graphics.lineStyle(1);
  334. Intro.graphics.drawRect(0,0,400,400);
  335. Intro.x =200;Intro.y=150;
  336. Intro.graphics.endFill();
  337. IntroText = new TextField();
  338. IntroText.width = 400;
  339. IntroText.htmlText = "<font size='20'><b><u>Welcome</u></b>\nYou're responsible for a small kingdom, but your ambitions aren't satisfied with that. You want so much more. Of course, since its your kingdom is blessed with peace, there is no need to wage war with neighboring kingdoms. Until you come up with your own threat. You must constantly stage kidnapping, until you take over the world. But be careful, it's only a matter time before people figure out your plan.</font>";
  340. IntroText.autoSize = TextFieldAutoSize.CENTER;
  341. IntroText.wordWrap = true;
  342. IntroText.selectable = false;
  343. Intro.addChild(IntroText);
  344. IntroOK = new Button(200,50,"Start Already!");
  345. IntroOK.addEventListener(MouseEvent.CLICK, onIntroOKClick);
  346. IntroOK.y = 300;IntroOK.x = 100;
  347. Intro.addChild(IntroOK);
  348. Loss= new CustomSprite();
  349. Loss.graphics.beginFill(0xFFFFFF);
  350. Loss.graphics.lineStyle(1);
  351. Loss.graphics.drawRect(0,0,400,400);
  352. Loss.x =200;Loss.y=150;
  353. Loss.graphics.endFill();
  354. LossText = new TextField();
  355. LossText.width = 400;
  356. LossText.htmlText = "<font size='20'><b><u>Too bad.</u></b>\nYou're kingdom got too suspicious and staged a coup d'etat. Looks like you've been sentenced to the guillotine, with no chance of appeal.</font>";
  357. LossText.autoSize = TextFieldAutoSize.CENTER;
  358. LossText.wordWrap = true;
  359. LossText.selectable = false;
  360. Loss.addChild(LossText);
  361. LossRetry = new Button(200,50,"Retry");
  362. LossRetry.addEventListener(MouseEvent.CLICK, onLossRetryClick);
  363. LossRetry.y = 200;LossRetry.x = 100;
  364. Loss.addChild(LossRetry);
  365. LossQuit = new Button(200,50,"Quit");
  366. LossQuit.addEventListener(MouseEvent.CLICK, onLossQuitClick);
  367. LossQuit.y = 300;LossQuit.x = 100;
  368. Loss.addChild(LossQuit);
  369. Win= new CustomSprite();
  370. Win.graphics.beginFill(0xFFFFFF);
  371. Win.graphics.lineStyle(1);
  372. Win.graphics.drawRect(0,0,400,400);
  373. Win.x =200;Win.y=150;
  374. Win.graphics.endFill();
  375. WinText = new TextField();
  376. WinText.width = 400;
  377. WinText.htmlText = "<font size='20'><b><u>Hooray!</u></b>\nYou've Suppressed the Entire World! Not bad for an innocent looking princess. But think you can keep going? See how you'd do with a larger population.</font>";
  378. WinText.autoSize = TextFieldAutoSize.CENTER;
  379. WinText.wordWrap = true;
  380. WinText.selectable = false;
  381. Win.addChild(WinText);
  382. WinContinue = new Button(200,50,"Continue");
  383. WinContinue.addEventListener(MouseEvent.CLICK, onWinContinueClick);
  384. WinContinue.y = 200;WinContinue.x = 100;
  385. Win.addChild(WinContinue);
  386. WinQuit = new Button(200,50,"Quit");
  387. WinQuit.addEventListener(MouseEvent.CLICK, onWinQuitClick);
  388. WinQuit.y = 300;WinQuit.x = 100;
  389. Win.addChild(WinQuit);
  390. CurrentMenu = "";
  391. pauseMenu.addEventListener("Quit",onQuit);
  392. pauseMenu.addEventListener("Save",onSave);
  393. }
  394. public function onQuit(event:Event)
  395. {
  396. removeChild(pauseMenu);
  397. //this.removeEventListener(Event.ENTER_FRAME, OnEnter);
  398. State = "EndGame";
  399. dispatchEvent(new Event("LevelQuit"));
  400. }
  401. public function onSave(event:Event)
  402. {
  403. var savedData = SharedObject.getLocal("GameData");
  404. savedData.data.Player = Player;
  405. savedData.data.PrincessPosition = PrincessPosition;
  406. savedData.flush();
  407. }
  408. public function PurchasePrincess(event:Event)
  409. {
  410. Player.PrincessTotal+=1;
  411. Player.Fear -=10;
  412. }
  413. //Load Level, so that it isn't automatically loaded automatically.
  414. public function Load(inVolume:Bool,inSound:Bool,inContinue:Bool)
  415. {
  416. CurrentMenu = "";
  417. volume = inVolume;
  418. sound = inSound;
  419. running = true;
  420. flash.Lib.current.addChild(this);
  421. //addhild(OkPopUp);
  422. //OkPopUpText.Load();
  423. //this.addEventListener(Event.ENTER_FRAME, OnEnter)
  424. //On Enter Was very slow on my computer. So I'm using the timer event so it doesn't render as much.
  425. myTimer = new Timer(20);
  426. myTimer.addEventListener("timer", timerHandler);
  427. myTimer.start();
  428. stage.addEventListener(KeyboardEvent.KEY_DOWN, OnKeyDown );
  429. stage.addEventListener(KeyboardEvent.KEY_UP, OnKeyUp );
  430. this.addEventListener("PopUpTextEvent",onPopUpTextEvent);
  431. if(!inContinue)
  432. {
  433. addChild(Intro);
  434. try
  435. {
  436. kongVar.SubmitStat("StartGame",1);
  437. }
  438. catch(msg: Dynamic)
  439. {
  440. }
  441. }
  442. State = "Intro";
  443. if(inContinue)
  444. {
  445. try
  446. {
  447. kongVar.SubmitStat("ContinueGame",1);
  448. }
  449. catch(msg: Dynamic)
  450. {
  451. }
  452. try
  453. {
  454. var savedData = SharedObject.getLocal("GameData");
  455. if(savedData.data.Player != null)
  456. {
  457. Player = savedData.data.Player;
  458. PrincessPosition = savedData.data.PrincessPosition;
  459. }
  460. State = "Playing";
  461. }
  462. catch(err:Dynamic)
  463. {trace(err);}
  464. }
  465. for(Kidnap in Player.Kidnapings)
  466. {
  467. Kidnap.draw();
  468. if(Kidnap.addedPrincess)
  469. {currentBackground.addChild(Kidnap.PrincessAvatar);}
  470. if(Kidnap.addedVillian)
  471. {currentBackground.addChild(Kidnap.VillianAvatar);}
  472. if(Kidnap.addedHero)
  473. {currentBackground.addChild(Kidnap.HeroAvatar);}
  474. }
  475. player = new SoundPlayer(Player.PopulationLevel+1);
  476. ResourceMenuItem = new ResourceMenu(new Background(),Player);
  477. ResourceMenuItem.x = 100;
  478. ActionMenuItem = new ActionMenu(new Background(),Player);
  479. ActionMenuItem.x = 100;
  480. ActionMenuItem.addEventListener("ExpandedCastle",onExpandedCastle);
  481. GetPrincessStatusImage();
  482. }
  483. private function isPaused():Bool{
  484. if(Pause != "UnPaused")
  485. {
  486. if(Pause == "Paused" || Pause == "Pausing")
  487. {
  488. addPauseMenu();
  489. }
  490. else if(Pause == "UnPausing")
  491. {
  492. removePauseMenu();
  493. }
  494. return true;
  495. }
  496. return false;
  497. }
  498. public function drawScreen()
  499. {
  500. SuspicionBar.removeChild(SuspicionBarInner);
  501. SuspicionBarInner.graphics.clear();
  502. SuspicionBarInner.graphics.beginFill(0x0000FF);
  503. SuspicionBarInner.graphics.drawRect(1,1,98*(Player.Suspicion/10000),8);
  504. SuspicionBarInner.graphics.endFill();
  505. SuspicionBar.addChild(SuspicionBarInner);
  506. FearBar.removeChild(FearBarInner);
  507. FearBarInner.graphics.clear();
  508. FearBarInner.graphics.beginFill(0xFF0000);
  509. FearBarInner.graphics.drawRect(1,1,98*(Player.Fear/Player.MaxFear),8);
  510. FearBarInner.graphics.endFill();
  511. FearBar.addChild(FearBarInner);
  512. var Population = 1000 * Math.pow(10,Player.PopulationLevel);
  513. var suffix = "";
  514. if(Player.PopulationLevel >= 6)
  515. {
  516. Population = 1 * Math.pow(10,Player.PopulationLevel-6);
  517. suffix = " Billion";
  518. }
  519. PopulationText.htmlText = "Population: " + HelperMethods.format(Population,0) + suffix;
  520. FearText.htmlText = "<font color='#FFFFFF' size='10'>"+Player.Fear+"</font>";
  521. SuspicionText.htmlText = "<font color='#FFFFFF' size='10'>"+Math.round(Player.Suspicion)+"</font>";
  522. ActionMenuItem.ExpandCastle.setHoverText("<u>Level " + (Player.PopulationLevel+1) + " - " + 5000 * Math.pow(2,Player.PopulationLevel) + "</u>\n"+"With enough fear, you'll be able to mobilize your army to expand your empire.");
  523. ActionMenuItem.Propaganda.setHoverText("<u>Level " + (Player.Propaganda+1) + " - " + 1000 * Math.pow(2,Player.Propaganda) + "</u>\n" + "Nothing like acquiring some newpaper and schools, to educate the public properly. Decrease Suspicion a small percent each turn.");
  524. SpeedText.htmlText = "<Font size = '15'><u>Speed</u>\n "+ Speed + "</font>";
  525. ResourceMenuItem.PurchasePrincessText.htmlText = ResourceMenuItem.getPurchasePrincessText();
  526. }
  527. public function GetPrincessStatusImage()
  528. {
  529. if(Player.PopulationLevel <= 0)
  530. {
  531. if(PrincessStatusCurrentImage != "1")
  532. {
  533. while(PrincessStatus.numChildren != 0)
  534. {
  535. PrincessStatus.removeChildAt(0);
  536. }
  537. PrincessStatus.addChild(PrincessStatusImage1);
  538. PrincessStatusCurrentImage = "1";
  539. }
  540. }
  541. else if(Player.PopulationLevel == 1)
  542. {
  543. if(PrincessStatusCurrentImage != "2")
  544. {
  545. while(PrincessStatus.numChildren != 0)
  546. {
  547. PrincessStatus.removeChildAt(0);
  548. }
  549. PrincessStatus.addChild(PrincessStatusImage2);
  550. PrincessStatusCurrentImage = "2";
  551. }
  552. }
  553. else if(Player.PopulationLevel == 2)
  554. {
  555. if(PrincessStatusCurrentImage != "3")
  556. {
  557. while(PrincessStatus.numChildren != 0)
  558. {
  559. PrincessStatus.removeChildAt(0);
  560. }
  561. PrincessStatus.addChild(PrincessStatusImage3);
  562. PrincessStatusCurrentImage = "3";
  563. }
  564. }
  565. else if(Player.PopulationLevel == 3)
  566. {
  567. if(PrincessStatusCurrentImage != "4")
  568. {
  569. while(PrincessStatus.numChildren != 0)
  570. {
  571. PrincessStatus.removeChildAt(0);
  572. }
  573. PrincessStatus.addChild(PrincessStatusImage4);
  574. PrincessStatusCurrentImage = "4";
  575. }
  576. }
  577. else if(Player.PopulationLevel == 4)
  578. {
  579. if(PrincessStatusCurrentImage != "5")
  580. {
  581. while(PrincessStatus.numChildren != 0)
  582. {
  583. PrincessStatus.removeChildAt(0);
  584. }
  585. PrincessStatus.addChild(PrincessStatusImage5);
  586. PrincessStatusCurrentImage = "5";
  587. }
  588. }
  589. else if(Player.PopulationLevel >= 5)
  590. {
  591. if(PrincessStatusCurrentImage != "6")
  592. {
  593. while(PrincessStatus.numChildren != 0)
  594. {
  595. PrincessStatus.removeChildAt(0);
  596. }
  597. PrincessStatus.addChild(PrincessStatusImage6);
  598. PrincessStatusCurrentImage = "6";
  599. }
  600. }
  601. }
  602. private function StartKidnapPrincess()
  603. {
  604. if(Player.PrincessTotal > Player.PrincessUsed)
  605. {
  606. Player.PrincessUsed++;
  607. var kidnap = new Kidnaping();
  608. kidnap.HasPrincess = true;
  609. kidnap.currentState = "addPrincess";
  610. kidnap.FramesLeft = Player.KidnapTime;
  611. Player.Kidnapings.add(kidnap);
  612. }
  613. }
  614. private function onExpandedCastle(event:Event)
  615. {
  616. try
  617. {
  618. kongVar.SubmitStat("LevelBeaten",Player.PopulationLevel+1);
  619. }
  620. catch(msg: Dynamic)
  621. {
  622. }
  623. player.increaseState();
  624. GetPrincessStatusImage();
  625. if(Player.PopulationLevel == 5)
  626. {
  627. addChild(Win);
  628. State = "Won";
  629. }
  630. }
  631. private function onLeftArrowButtonClick(event:MouseEvent) {
  632. DecreaseSpeed();
  633. }
  634. private function onRightArrowButtonClick(event:MouseEvent) {
  635. IncreaseSpeed();
  636. }
  637. private function onIntroOKClick(event:MouseEvent) {
  638. removeChild(Intro);
  639. State = "Playing";
  640. }
  641. private function onLossRetryClick(event:MouseEvent) {
  642. removeChild(Loss);
  643. dispatchEvent(new Event("LevelRetry"));
  644. }
  645. private function onLossQuitClick(event:MouseEvent) {
  646. removeChild(Loss);
  647. State = "EndGame";
  648. dispatchEvent(new Event("LevelQuit"));
  649. }
  650. private function onWinContinueClick(event:MouseEvent) {
  651. removeChild(Win);
  652. State="Playing";
  653. }
  654. private function onWinQuitClick(event:MouseEvent) {
  655. removeChild(Win);
  656. State = "EndGame";
  657. dispatchEvent(new Event("LevelQuit"));
  658. }
  659. public function DecreaseSpeed()
  660. {
  661. var decreaseAmount = 0.5 * Speed;
  662. if(decreaseAmount >= 0.25)
  663. {Speed = decreaseAmount;}
  664. }
  665. public function IncreaseSpeed()
  666. {
  667. var increaseAmount = 2 * Speed;
  668. if(increaseAmount <= 4)
  669. {Speed = increaseAmount;}
  670. }
  671. private function onResourceButtonClick(event:MouseEvent) {
  672. if(State!= "Playing"){return;}
  673. if(CurrentMenu == "Action")
  674. {
  675. ActionMenuItem.removeEventListener("Back",onActionMenuItemBack);
  676. removeChild(ActionMenuItem);
  677. }
  678. CurrentMenu = "Resource";
  679. addChild(ResourceMenuItem);
  680. ResourceMenuItem.addEventListener("Back",onResourceMenuItemBack);
  681. }
  682. private function onResourceMenuItemBack(event:GenericMenuEvent){
  683. ResourceMenuItem.removeEventListener("Back",onResourceMenuItemBack);
  684. removeChild(ResourceMenuItem);
  685. CurrentMenu = "";
  686. }
  687. private function onActionButtonClick(event:MouseEvent) {
  688. if(State!= "Playing"){return;}
  689. if(CurrentMenu == "Resource")
  690. {
  691. ResourceMenuItem.removeEventListener("Back",onResourceMenuItemBack);
  692. removeChild(ResourceMenuItem);
  693. }
  694. CurrentMenu = "Action";
  695. addChild(ActionMenuItem);
  696. ActionMenuItem.addEventListener("Back",onActionMenuItemBack);
  697. }
  698. private function onActionMenuItemBack(event:GenericMenuEvent){
  699. ActionMenuItem.removeEventListener("Back",onActionMenuItemBack);
  700. removeChild(ActionMenuItem);
  701. CurrentMenu = "";
  702. }
  703. public function checkLose()
  704. {
  705. if(Player.Suspicion >= 10000)
  706. {
  707. State="Loss";
  708. }
  709. }
  710. public function timerHandler(event:TimerEvent) {
  711. if(!volume)
  712. {
  713. //pausePosition = player.getPosition();
  714. player.stop();
  715. }
  716. else
  717. {
  718. player.play(0);
  719. }
  720. if(State == "Wait")
  721. {
  722. }
  723. if(State == "Loss")
  724. {
  725. addChild(Loss);
  726. }
  727. else if(State == "Playing")
  728. {
  729. if(isPaused())
  730. {return;}
  731. //Player.Money += (Player.TaxRate*Player.Population)/1000;
  732. try
  733. {
  734. incrementPhase();
  735. }
  736. catch(msg:Dynamic)
  737. {
  738. trace(msg);
  739. }
  740. drawScreen();
  741. checkLose();
  742. }
  743. _afterTime = flash.Lib.getTimer();
  744. _timeDiff = _afterTime - _beforeTime;
  745. _sleepTime = (Std.int(_period) - _timeDiff) - _overSleepTime;
  746. if(_sleepTime <= 0) {
  747. _excess -= Std.int(_sleepTime);
  748. _sleepTime = 2;
  749. }
  750. myTimer.reset();
  751. myTimer.delay = _sleepTime;
  752. myTimer.start();
  753. event.updateAfterEvent;
  754. if(State == "EndGame")
  755. {
  756. //Show score
  757. //unLoad();
  758. }
  759. }
  760. public function incrementPhase()
  761. {
  762. StartKidnapPrincess();
  763. Player.Suspicion += (Player.getSuspicionPerTurn())*Speed;
  764. var stopPostion = 50;
  765. for(Kidnap in Player.Kidnapings)
  766. {
  767. if(Kidnap.FramesLeft <= 0)
  768. {
  769. Player.Kidnapings.remove(Kidnap);
  770. Player.PrincessUsed--;
  771. Player.VillianUsed--;
  772. Player.HeroUsed--;
  773. }
  774. else
  775. {
  776. if(Kidnap.currentState == "addPrincess")
  777. {
  778. var found = false;
  779. for(xPos in 0...4)
  780. {
  781. for(yPos in 0...14)
  782. {
  783. try
  784. {
  785. if(PrincessPosition[xPos] == null)
  786. {PrincessPosition[xPos] = [];}
  787. if(PrincessPosition[xPos][yPos] == false)
  788. {
  789. PrincessPosition[xPos][yPos] = true;
  790. Kidnap.PostionX = xPos;
  791. Kidnap.PostionY = yPos;
  792. found = true;
  793. break;
  794. }
  795. }
  796. catch (msg:Dynamic)
  797. {trace(msg);}
  798. }
  799. if(found){break;}
  800. }
  801. if(!found)
  802. {
  803. Kidnap.addAvatars = false;
  804. Kidnap.PostionX = 5;
  805. Kidnap.PostionY = 0;
  806. }
  807. Kidnap.PrincessAvatar.y = 125+Kidnap.PostionY*30;
  808. Kidnap.PrincessAvatar.x = 100-Kidnap.PostionX*30;
  809. if(Kidnap.addAvatars)
  810. {
  811. try
  812. {
  813. currentBackground.addChild(Kidnap.PrincessAvatar);
  814. Kidnap.addedPrincess = true;
  815. }
  816. catch(ex:Dynamic)
  817. {
  818. }
  819. }
  820. Kidnap.currentState = "addVillian";
  821. }
  822. try
  823. {
  824. if(Kidnap.HasPrincess && !Kidnap.HasVillian)
  825. {
  826. if(Player.VillianTotal > Player.VillianUsed)
  827. {
  828. Player.VillianUsed++;
  829. Kidnap.HasVillian = true;
  830. Player.Fear += (10 * (Player.WriterTotal+1));
  831. }
  832. }
  833. if(Kidnap.HasPrincess && Kidnap.HasVillian && !Kidnap.HasHero)
  834. {
  835. if(Player.HeroTotal > Player.HeroUsed)
  836. {
  837. Player.HeroUsed++;
  838. Kidnap.HasHero = true;
  839. }
  840. }
  841. }
  842. catch (msg:Dynamic)
  843. {trace(msg);}
  844. try
  845. {
  846. if(Kidnap.HasPrincess && Kidnap.HasVillian)
  847. {
  848. if(Kidnap.currentState == "addVillian")
  849. {
  850. // trace("add Villian");
  851. Kidnap.VillianAvatar.x=-35;Kidnap.VillianAvatar.y=Kidnap.PrincessAvatar.y-20;
  852. if(Kidnap.addAvatars)
  853. {
  854. try
  855. {
  856. currentBackground.addChild(Kidnap.VillianAvatar);
  857. Kidnap.addedVillian = true;
  858. }
  859. catch(ex:Dynamic)
  860. {
  861. }
  862. }
  863. // trace("PRincess");
  864. Kidnap.currentState = "getPrincess";
  865. }
  866. if(Kidnap.currentState == "getPrincess")
  867. {
  868. Kidnap.VillianAvatar.x += 3*Speed;
  869. if(Kidnap.VillianAvatar.x >= Kidnap.PrincessAvatar.x-15)
  870. {
  871. Kidnap.currentState = "exit";
  872. Kidnap.HeroAvatar.x = Kidnap.PrincessAvatar.x; Kidnap.HeroAvatar.y = 550;
  873. if(Kidnap.addAvatars)
  874. {
  875. try
  876. {
  877. currentBackground.addChild(Kidnap.HeroAvatar);
  878. Kidnap.addedHero = true;
  879. }
  880. catch(ex:Dynamic)
  881. {
  882. }
  883. }
  884. }
  885. }
  886. if(Kidnap.currentState == "exit")
  887. {
  888. Kidnap.PrincessAvatar.y -= 10*Speed;
  889. Kidnap.VillianAvatar.y -= 10*Speed;
  890. if(Kidnap.PrincessAvatar.y <= stopPostion)
  891. {
  892. if(Kidnap.addAvatars)
  893. {
  894. try
  895. {
  896. currentBackground.removeChild(Kidnap.PrincessAvatar);
  897. currentBackground.removeChild(Kidnap.VillianAvatar);
  898. Kidnap.addedPrincess = false;
  899. Kidnap.addedVillian = false;
  900. }
  901. catch(ex:Dynamic)
  902. {
  903. }
  904. }
  905. if(Kidnap.PostionX < 5)
  906. {
  907. PrincessPosition[Kidnap.PostionX][Kidnap.PostionY] = false;
  908. }
  909. Kidnap.currentState = "HeroAdded";
  910. }
  911. }
  912. }
  913. }
  914. catch (msg:Dynamic)
  915. {trace(msg);}
  916. try
  917. {
  918. if(Kidnap.HasPrincess && Kidnap.HasVillian && Kidnap.HasHero)
  919. {
  920. if(Kidnap.currentState == "HeroAdded")
  921. {
  922. Kidnap.currentState = "HeroExits";
  923. }
  924. if(Kidnap.currentState == "HeroExits")
  925. {
  926. Kidnap.HeroAvatar.y -= 10*Speed;
  927. if(Kidnap.HeroAvatar.y < stopPostion)
  928. {
  929. if(Kidnap.addAvatars)
  930. {
  931. try
  932. {
  933. currentBackground.removeChild(Kidnap.HeroAvatar);
  934. Kidnap.addedHero = false;
  935. }
  936. catch(ex:Dynamic)
  937. {}
  938. }
  939. Kidnap.currentState = "Wait";
  940. }
  941. }
  942. if(Kidnap.currentState == "Wait")
  943. {
  944. Kidnap.FramesLeft -= 1*Speed;
  945. if(Kidnap.FramesLeft< 0 )
  946. {
  947. }
  948. }
  949. }
  950. }
  951. catch (msg:Dynamic)
  952. {trace(msg);}
  953. }
  954. }
  955. }
  956. public function updateValues(e:Event)
  957. {
  958. }
  959. private function onPopUpTextEvent(event:PopUpTextEvent)
  960. {
  961. removeChild(OkPopUpText);
  962. }
  963. //Define Win
  964. public function checkEnd() : Bool
  965. {
  966. //End if won or if overthrown.
  967. return false;
  968. }
  969. //When we're done with the level, we'll unload in.
  970. public function unLoad()
  971. {
  972. running = false;
  973. //removeChild(new Bitmap(currentBackground));
  974. for(Kidnap in Player.Kidnapings)
  975. {
  976. if(Kidnap.addedPrincess)
  977. {currentBackground.removeChild(Kidnap.PrincessAvatar);}
  978. if(Kidnap.addedVillian)
  979. {currentBackground.removeChild(Kidnap.VillianAvatar);}
  980. if(Kidnap.addedHero)
  981. {currentBackground.removeChild(Kidnap.HeroAvatar);}
  982. }
  983. if(CurrentMenu == "Action")
  984. {
  985. ActionMenuItem.removeEventListener("Back",onActionMenuItemBack);
  986. removeChild(ActionMenuItem);
  987. }
  988. if(CurrentMenu == "Resource")
  989. {
  990. ResourceMenuItem.removeEventListener("Back",onResourceMenuItemBack);
  991. removeChild(ResourceMenuItem);
  992. }
  993. //Player = new CharacterStat();
  994. player.stop();
  995. myTimer.stop();
  996. //Player = new CharacterStat();
  997. flash.Lib.current.removeChild(this);
  998. }
  999. public function OnKeyDown(event:KeyboardEvent)
  1000. {
  1001. // When a key is held down, multiple KeyDown events are generated.
  1002. // This check means we only pick up the first one.
  1003. if (!mKeyDown[event.keyCode])
  1004. {
  1005. if(ignoreKeyPress != "")
  1006. {return;}
  1007. //Press any key to continue scence
  1008. PauseTillKeyPressed = false;
  1009. // Store for use in game
  1010. mKeyDown[event.keyCode] = true;
  1011. if(State == "Playing")
  1012. {
  1013. //I do this here, because if they hold down P,
  1014. // it won't pause and unpause constantly.
  1015. if(mKeyDown[ 80 ] == true)
  1016. {
  1017. if(Pause == "Paused" || Pause == "Pausing")
  1018. {
  1019. Pause = "UnPausing";
  1020. }
  1021. else
  1022. {
  1023. Pause = "Pausing";
  1024. pauseMenu.x = pauseMenuPoint.x;
  1025. pauseMenu.y = pauseMenuPoint.y;
  1026. addChild(pauseMenu);
  1027. }
  1028. }
  1029. if(isPaused()){return;}
  1030. }
  1031. // if(mKeyDown[ 77 ] == true)
  1032. // {
  1033. // Mute = !Mute;
  1034. // }
  1035. }
  1036. }
  1037. public function OnKeyUp (event:KeyboardEvent)
  1038. {
  1039. mKeyDown[event.keyCode] = false;
  1040. lastUp = event.keyCode;
  1041. }
  1042. //Pause Menu
  1043. public function addPauseMenu()
  1044. {
  1045. pauseMenu.x = pauseMenuPoint.x;
  1046. pauseMenu.y = pauseMenuPoint.y;
  1047. if(pauseMenuPoint.y <= 0)
  1048. {
  1049. Pause = "Paused";
  1050. }
  1051. if(Pause == "Pausing")
  1052. {
  1053. pauseMenuPoint.y = pauseMenuPoint.y - 20;
  1054. }
  1055. }
  1056. public function removePauseMenu()
  1057. {
  1058. pauseMenu.x = pauseMenuPoint.x;
  1059. pauseMenu.y = pauseMenuPoint.y;
  1060. if(pauseMenuPoint.y >= 380)
  1061. {
  1062. Pause = "UnPaused";
  1063. removeChild(pauseMenu);
  1064. }
  1065. if(Pause == "UnPausing")
  1066. {
  1067. pauseMenuPoint.y = pauseMenuPoint.y + 20;
  1068. }
  1069. }
  1070. }