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

/BuildingGym4.hx

http://portable-monsters.googlecode.com/
Haxe | 313 lines | 249 code | 30 blank | 34 comment | 23 complexity | 9fea35c45da0355c634cc5c691d9a986 MD5 | raw file
  1. import flash.display.Sprite;
  2. import flash.display.Bitmap;
  3. import flash.display.BitmapData;
  4. import flash.events.Event;
  5. import flash.events.KeyboardEvent;
  6. import flash.geom.Point;
  7. import flash.geom.Rectangle;
  8. import flash.utils.Timer;
  9. import haxe.Timer;
  10. import Images;
  11. import Kongregate;
  12. class BuildingGym4 extends Building{
  13. public static inline var MAX_TILE_SIZE:Int = 32;
  14. public function new(){
  15. super();
  16. Cost = 1500;
  17. ExitLocation.x = 71;ExitLocation.y = 49;
  18. MapDoorLocation.x = 71;MapDoorLocation.y = 48;
  19. //flash.Lib.current.addChild(this);
  20. // myTimer = new Timer(12);
  21. // myTimer.addEventListener("timer", OnEnter);
  22. // myTimer.start();
  23. }
  24. override public function getNextLine()
  25. {
  26. currentTalkingStep++;
  27. if(currentTalkingCharacter.ID == 1)
  28. {
  29. if(currentTalkingCharacter.TalkedTo >= 0)
  30. {
  31. if(currentTalkingStep == 0)
  32. {
  33. Text.htmlText = "<font size='16'>It's a statue.</font>";
  34. }
  35. else
  36. {
  37. currentTalkingStep = -1;
  38. WorldMap.removeChild(TextBox);
  39. currentTalkingCharacter.TalkedTo += 1;
  40. State = "Playing";
  41. }
  42. }
  43. else
  44. {
  45. if(currentTalkingStep == 0)
  46. {
  47. Text.htmlText = "<font size='16'>It's a statue.</font>";
  48. }
  49. else
  50. {
  51. currentTalkingStep = -1;
  52. WorldMap.removeChild(TextBox);
  53. currentTalkingCharacter.TalkedTo += 1;
  54. State = "Playing";
  55. }
  56. }
  57. }
  58. }
  59. override public function initializeCharacters()
  60. {
  61. }
  62. override public function getTrainerNextLine()
  63. {
  64. currentTalkingStep++;
  65. if(currentTrainer.ID == 1)
  66. {
  67. if(!currentTrainer.Battled)
  68. {
  69. if(currentTalkingStep == 0)
  70. {
  71. Text.htmlText = "<font size='16'>Ready?</font>";
  72. }
  73. else
  74. {
  75. WorldMap.removeChild(TextBox);
  76. State = "BattleFlash1";
  77. currentTalkingStep = -1;
  78. }
  79. }
  80. else
  81. {
  82. if(currentTalkingStep == 0)
  83. {
  84. Text.htmlText = "<font size='16'>That's it. Was it all that you expected?</font>";
  85. }
  86. else if(currentTalkingStep == 1)
  87. {
  88. Text.htmlText = "<font size='16'>You recieved the Empty Badge.</font>";
  89. currentPlot.BlankBadge = true;
  90. }
  91. else
  92. {
  93. WorldMap.removeChild(TextBox);
  94. State = "Playing";
  95. currentTalkingStep = -1;
  96. currentTrainer = null;
  97. }
  98. }
  99. }
  100. }
  101. // override public function startTrainerBattle(trainer:EnemyTrainer)
  102. // {
  103. //
  104. // if(trainer.ID == 1)
  105. // {
  106. // _backgroundMap[5][6] = -1;
  107. // }
  108. // if(trainer.ID == 2)
  109. // {
  110. // _backgroundMap[4][7] = -1;
  111. // }
  112. // if(trainer.ID == 3)
  113. // {
  114. // _backgroundMap[5][8] = -1;
  115. // }
  116. //
  117. // redraw();
  118. // for(char in Characters)
  119. // {
  120. // drawGameObject(char, _foregroundBitmapData);
  121. // }
  122. // for(trainer in Trainers)
  123. // {
  124. // drawGameObject(trainer.Model, _foregroundBitmapData);
  125. // }
  126. // drawGameObject(_MainCharacterModel, _foregroundBitmapData);
  127. // super.startTrainerBattle(trainer);
  128. // }
  129. override public function initializeTrainers()
  130. {
  131. var tileSheetColumn:Int = 2;
  132. var tileSheetRow:Int = 13;
  133. var Row = 1; var Column = 7;
  134. var TrainerModel = new TileModel
  135. (
  136. MAX_TILE_SIZE,
  137. tileSheetColumn, tileSheetRow,
  138. Row, Column,
  139. MAX_TILE_SIZE, MAX_TILE_SIZE
  140. );
  141. var GymLeader = new EnemyTrainer(TrainerModel);
  142. GymLeader.ID = 1;
  143. GymLeader.AvatarTile = 0003;
  144. Trainers.add(GymLeader);
  145. GymLeader.CurrentMonster = new Monster();
  146. GymLeader.CurrentMonster.Character = "Mini Elephant";
  147. GymLeader.CurrentMonster.XP = 2450;
  148. GymLeader.CurrentMonster.LevelUp();
  149. GymLeader.addNewMonster(GymLeader.CurrentMonster);
  150. var newMonster = new Monster();
  151. newMonster.Character = "Hippo";
  152. newMonster.XP = 2550;
  153. newMonster.LevelUp();
  154. GymLeader.addNewMonster(newMonster);
  155. var newMonster = new Monster();
  156. newMonster.Character = "Unicorn";
  157. newMonster.XP = 2650;
  158. newMonster.LevelUp();
  159. GymLeader.addNewMonster(newMonster);
  160. _trainerMap[GymLeader.Model.centerY][GymLeader.Model.centerX] = GymLeader.ID;
  161. // GymLeader.SightMap.add(new Point(GymLeader.Model.centerX-1,GymLeader.Model.centerY));
  162. }
  163. public override function checkBoundaries()
  164. {
  165. var maxX = (MAP_COLUMNS * MAX_TILE_SIZE);
  166. var minX = 0;
  167. if (_MainCharacterModel.xPos + (_MainCharacterModel.width) > maxX)
  168. {
  169. _MainCharacterModel.setX = maxX - (_MainCharacterModel.width);
  170. _MainCharacterModel.vx = 0;
  171. }
  172. else if (_MainCharacterModel.xPos < minX)
  173. {
  174. _MainCharacterModel.setX = minX;
  175. _MainCharacterModel.vx = 0;
  176. }
  177. var maxY = (MAP_ROWS * MAX_TILE_SIZE);
  178. var minY = 0;
  179. if (_MainCharacterModel.yPos <= minY )
  180. {
  181. _MainCharacterModel.setY = minY;
  182. _MainCharacterModel.vy = 0;
  183. }
  184. else if (_MainCharacterModel.yPos + _MainCharacterModel.height >= maxY)
  185. {
  186. _MainCharacterModel.setY = maxY - _MainCharacterModel.height;
  187. _MainCharacterModel.vy = 0;
  188. }
  189. }
  190. override public function LoadMapData()
  191. {
  192. MAP_COLUMNS = 20;
  193. MAP_ROWS = 10;
  194. MAP_WIDTH = 20;
  195. MAP_HEIGHT = 10;
  196. _terrainBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  197. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  198. _terrainBitmap = new Bitmap(_terrainBitmapData);
  199. _frontBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  200. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  201. _frontBitmap = new Bitmap(_frontBitmapData);
  202. _backgroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  203. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  204. _backgroundBitmap = new Bitmap(_backgroundBitmapData);
  205. _doorsBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  206. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  207. _doorsBitmap = new Bitmap(_doorsBitmapData);
  208. _itemsBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  209. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  210. _itemsBitmap = new Bitmap(_itemsBitmapData);
  211. _foregroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  212. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  213. _foregroundBitmap = new Bitmap(_foregroundBitmapData);
  214. _backgroundMap =
  215. [
  216. [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100],
  217. [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100],
  218. [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100],
  219. [-100,-100,-100,-100,-100,-100,-100,-100,-199,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100],
  220. [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100],
  221. [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100],
  222. [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100],
  223. [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100],
  224. [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100],
  225. [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100]
  226. ];
  227. _doorsMap =
  228. [
  229. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  230. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  231. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  232. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  233. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  234. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  235. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  236. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  237. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  238. [-1,-1,-1,-1,-1,-1,-1,EXIT,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
  239. ];
  240. _frontMap =
  241. [
  242. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  243. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-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,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  272. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  273. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  274. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  275. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  276. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  277. [-1,-1,-1,-1,-1,-1,-1,MAIN,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  278. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
  279. ];
  280. buildItems();
  281. initBlankArrays();
  282. }
  283. }