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

/BuildingHome.hx

http://portable-monsters.googlecode.com/
Haxe | 493 lines | 455 code | 33 blank | 5 comment | 94 complexity | 37b2b2b819e4e38c73bc699639d1d2b5 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 BuildingHome extends Building{
  13. public static inline var MAX_TILE_SIZE:Int = 32;
  14. public var Tristan:Character;
  15. public var Paul:Character;
  16. public var ZakI:Character;
  17. public function new(){
  18. super();
  19. ExitLocation.x = 4;ExitLocation.y = 4;
  20. MapDoorLocation.x = 4;MapDoorLocation.y = 3;
  21. //flash.Lib.current.addChild(this);
  22. // myTimer = new Timer(12);
  23. // myTimer.addEventListener("timer", OnEnter);
  24. // myTimer.start();
  25. }
  26. override public function initializeCharacters()
  27. {
  28. var tileSheetColumn:Int = 3;
  29. var tileSheetRow:Int = 4;
  30. var Row = 1; var Column = 1;
  31. ZakI = new Character
  32. (
  33. MAX_TILE_SIZE,
  34. tileSheetColumn, tileSheetRow,
  35. Row, Column,
  36. MAX_TILE_SIZE, MAX_TILE_SIZE
  37. );
  38. Characters.add(ZakI);
  39. ZakI.ID = 1;
  40. _characterMap[ZakI.centerY][ZakI.centerX] = ZakI.ID;
  41. var tileSheetColumn:Int = 3;
  42. var tileSheetRow:Int = 5;
  43. Row = 5; Column = 9;
  44. var Chris = new Character
  45. (
  46. MAX_TILE_SIZE,
  47. tileSheetColumn, tileSheetRow,
  48. Row, Column,
  49. MAX_TILE_SIZE, MAX_TILE_SIZE
  50. );
  51. Characters.add(Chris);
  52. Chris.ID = 2;
  53. _characterMap[Chris.centerY][Chris.centerX] = Chris.ID;
  54. var tileSheetColumn:Int = 2;
  55. var tileSheetRow:Int = 5;
  56. var Row = 3; var Column = 6;
  57. Paul = new Character
  58. (
  59. MAX_TILE_SIZE,
  60. tileSheetColumn, tileSheetRow,
  61. Row, Column,
  62. MAX_TILE_SIZE, MAX_TILE_SIZE
  63. );
  64. Characters.add(Paul);
  65. Paul.ID = 3;
  66. _characterMap[Paul.centerY][Paul.centerX] = Paul.ID;
  67. var tileSheetColumn:Int = 2;
  68. var tileSheetRow:Int = 12;
  69. var Row = 1; var Column = 5;
  70. Tristan = new Character
  71. (
  72. MAX_TILE_SIZE,
  73. tileSheetColumn, tileSheetRow,
  74. Row, Column,
  75. MAX_TILE_SIZE, MAX_TILE_SIZE
  76. );
  77. Characters.add(Tristan);
  78. Tristan.ID = 4;
  79. _characterMap[Tristan.centerY][Tristan.centerX] = Tristan.ID;
  80. }
  81. public override function checkBoundaries()
  82. {
  83. var maxX = (MAP_COLUMNS * MAX_TILE_SIZE);
  84. var minX = 0;
  85. if (_MainCharacterModel.xPos + (_MainCharacterModel.width) > maxX)
  86. {
  87. _MainCharacterModel.setX = maxX - (_MainCharacterModel.width);
  88. _MainCharacterModel.vx = 0;
  89. }
  90. else if (_MainCharacterModel.xPos < minX)
  91. {
  92. _MainCharacterModel.setX = minX;
  93. _MainCharacterModel.vx = 0;
  94. }
  95. var maxY = (MAP_ROWS * MAX_TILE_SIZE);
  96. var minY = 0;
  97. if (_MainCharacterModel.yPos <= minY )
  98. {
  99. _MainCharacterModel.setY = minY;
  100. _MainCharacterModel.vy = 0;
  101. }
  102. else if (_MainCharacterModel.yPos + _MainCharacterModel.height >= maxY)
  103. {
  104. _MainCharacterModel.setY = maxY - _MainCharacterModel.height;
  105. _MainCharacterModel.vy = 0;
  106. }
  107. }
  108. override public function getObjectText(y:Int,x:Int)
  109. {
  110. if(x == 14 && y == 9)
  111. {
  112. Text.htmlText = "<font size='16'>Lying in this bed somehow heals your monsters.</font>";
  113. HealMonsters();
  114. State = "addText";
  115. }
  116. }
  117. override public function getNextLine()
  118. {
  119. currentTalkingStep++;
  120. if(currentTalkingCharacter.ID == 1)
  121. {
  122. if(currentTalkingCharacter.TalkedTo == 0)
  123. {
  124. if(currentTalkingStep == 0)
  125. {
  126. Text.htmlText = "<font size='16'>Zaki: I got the groceries and they're all put away.</font>";
  127. }
  128. else if(currentTalkingStep == 1)
  129. {
  130. Text.htmlText = "<font size='16'>Corliss: I think its time for a break.</font>";
  131. }
  132. else
  133. {
  134. currentTalkingCharacter.TalkedTo += 3;
  135. currentPlot.State = "Step Outside";
  136. currentTalkingStep = -1;
  137. WorldMap.removeChild(TextBox);
  138. State = "Playing";
  139. }
  140. }
  141. else if(currentTalkingCharacter.TalkedTo >= 1)
  142. {
  143. if(currentTalkingStep == 0)
  144. {
  145. Text.htmlText = "<font size='16'>...</font>";
  146. }
  147. else
  148. {
  149. currentTalkingStep = -1;
  150. WorldMap.removeChild(TextBox);
  151. currentTalkingCharacter.TalkedTo += 1;
  152. State = "Playing";
  153. }
  154. }
  155. }
  156. else if(currentTalkingCharacter.ID == 2)
  157. {
  158. if(currentTalkingCharacter.TalkedTo <= 3)
  159. {
  160. if(currentTalkingStep == 0)
  161. {
  162. Text.htmlText = "<font size='16'>I understand. It's for the best.</font>";
  163. }
  164. else
  165. {
  166. currentTalkingStep = -1;
  167. WorldMap.removeChild(TextBox);
  168. currentTalkingCharacter.TalkedTo += 1;
  169. State = "Playing";
  170. }
  171. }
  172. else if(currentTalkingCharacter.TalkedTo == 4)
  173. {
  174. if(currentTalkingStep == 0)
  175. {
  176. Text.htmlText = "<font size='16'>Just GO already!</font>";
  177. }
  178. else
  179. {
  180. currentTalkingStep = -1;
  181. WorldMap.removeChild(TextBox);
  182. currentTalkingCharacter.TalkedTo += 1;
  183. State = "Playing";
  184. }
  185. }
  186. else
  187. {
  188. if(currentTalkingStep == 0)
  189. {
  190. Text.htmlText = "<font size='16'>...</font>";
  191. }
  192. else
  193. {
  194. currentTalkingStep = -1;
  195. WorldMap.removeChild(TextBox);
  196. currentTalkingCharacter.TalkedTo += 1;
  197. State = "Playing";
  198. }
  199. }
  200. }
  201. if(currentTalkingCharacter.ID == 3)
  202. {
  203. if(currentTalkingCharacter.TalkedTo >= 0)
  204. {
  205. if(currentTalkingStep == 0)
  206. {
  207. Text.htmlText = "<font size='16'>Why are you going?</font>";
  208. }
  209. else
  210. {
  211. currentTalkingStep = -1;
  212. WorldMap.removeChild(TextBox);
  213. currentTalkingCharacter.TalkedTo += 1;
  214. State = "Playing";
  215. }
  216. }
  217. else
  218. {
  219. if(currentTalkingStep == 0)
  220. {
  221. Text.htmlText = "<font size='16'>...</font>";
  222. }
  223. else
  224. {
  225. currentTalkingStep = -1;
  226. WorldMap.removeChild(TextBox);
  227. currentTalkingCharacter.TalkedTo += 1;
  228. State = "Playing";
  229. }
  230. }
  231. }
  232. if(currentTalkingCharacter.ID == 4)
  233. {
  234. if(currentTalkingCharacter.TalkedTo == 0)
  235. {
  236. if(currentTalkingStep == 0)
  237. {
  238. Text.htmlText = "<font size='16'>Paul: Eve!!!</font>";
  239. Paul.setX = 4 * MAX_TILE_SIZE;
  240. Paul.setY = 8 * MAX_TILE_SIZE;
  241. }
  242. else if(currentTalkingStep == 1)
  243. {
  244. redraw();
  245. for(char in Characters)
  246. {
  247. drawGameObject(char, _foregroundBitmapData);
  248. }
  249. for(trainer in Trainers)
  250. {
  251. drawGameObject(trainer.Model, _foregroundBitmapData);
  252. }
  253. drawGameObject(_MainCharacterModel, _foregroundBitmapData);
  254. Text.htmlText = "<font size='16'>*hugs*</font>";
  255. }
  256. else if(currentTalkingStep == 2)
  257. {
  258. Text.htmlText = "<font size='16'>Paul: I missed you so much. Don't ever leave again, okay?</font>";
  259. }
  260. else if(currentTalkingStep == 3)
  261. {
  262. Text.htmlText = "<font size='16'>Chris: You should see this Vine Cat I got. I've been training really hard. I can't wait to get my badge.</font>";
  263. }
  264. else if(currentTalkingStep == 4)
  265. {
  266. Text.htmlText = "<font size='16'>Zaki: Didn't expect you back so soon.</font>";
  267. ZakI.setX = 2 * MAX_TILE_SIZE;
  268. ZakI.setY = 8 * MAX_TILE_SIZE;
  269. }
  270. else if(currentTalkingStep == 5)
  271. {
  272. redraw();
  273. for(char in Characters)
  274. {
  275. drawGameObject(char, _foregroundBitmapData);
  276. }
  277. for(trainer in Trainers)
  278. {
  279. drawGameObject(trainer.Model, _foregroundBitmapData);
  280. }
  281. drawGameObject(_MainCharacterModel, _foregroundBitmapData);
  282. Text.htmlText = "<font size='16'>Eve: You Should be old enough to train Zak, are you heading out pretty soon?</font>";
  283. }
  284. else if(currentTalkingStep == 6)
  285. {
  286. Text.htmlText = "<font size='16'>Zaki: No way! I'm no trainer. Besides, I'm more intereseted in studying science.</font>";
  287. }
  288. else if(currentTalkingStep == 7)
  289. {
  290. Text.htmlText = "<font size='16'>Zaki: I'm glad you're back though. You should stay awhile.</font>";
  291. }
  292. else if(currentTalkingStep == 8)
  293. {
  294. TextBox.y = 412;
  295. Text.htmlText = "<font size='16'>Tristan: Hey...</font>";
  296. }
  297. else if(currentTalkingStep == 9)
  298. {
  299. TextBox.y = 412;
  300. Text.htmlText = "<font size='16'>Eve: Hey...</font>";
  301. }
  302. else if(currentTalkingStep == 10)
  303. {
  304. TextBox.y = 0;
  305. Text.htmlText = "<font size='16'>Eve: It's good to be home.</font>";
  306. }
  307. else
  308. {
  309. currentTalkingStep = -1;
  310. WorldMap.removeChild(TextBox);
  311. currentTalkingCharacter.TalkedTo += 1;
  312. getInsideBuilding(5,9);
  313. }
  314. }
  315. if(currentTalkingCharacter.TalkedTo >= 1)
  316. {
  317. if(currentTalkingStep == 0)
  318. {
  319. Text.htmlText = "<font size='16'>Hey.</font>";
  320. }
  321. else
  322. {
  323. currentTalkingStep = -1;
  324. WorldMap.removeChild(TextBox);
  325. currentTalkingCharacter.TalkedTo += 1;
  326. State = "Playing";
  327. }
  328. }
  329. }
  330. }
  331. override public function LoadBuilding(inVolume:Bool,inKongVar:CKongregate,inTrainer:Trainer,inPlot:Plot)
  332. {
  333. for(char in Characters)
  334. {
  335. if(char.ID == Tristan.ID)
  336. {
  337. Characters.remove(char);
  338. }
  339. }
  340. if(inPlot.TristanHome)
  341. {
  342. Characters.add(Tristan);
  343. }
  344. updateCharacterMap();
  345. super.LoadBuilding(inVolume,inKongVar,inTrainer,inPlot);
  346. }
  347. override public function LoadMapData()
  348. {
  349. MAP_COLUMNS = 15;
  350. MAP_ROWS = 10;
  351. MAP_WIDTH = 15;
  352. MAP_HEIGHT = 10;
  353. _terrainBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  354. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  355. _terrainBitmap = new Bitmap(_terrainBitmapData);
  356. _backgroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  357. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  358. _backgroundBitmap = new Bitmap(_backgroundBitmapData);
  359. _frontBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  360. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  361. _frontBitmap = new Bitmap(_frontBitmapData);
  362. _doorsBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  363. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  364. _doorsBitmap = new Bitmap(_doorsBitmapData);
  365. _itemsBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  366. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  367. _itemsBitmap = new Bitmap(_itemsBitmapData);
  368. _foregroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  369. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  370. _foregroundBitmap = new Bitmap(_foregroundBitmapData);
  371. _backgroundMap =
  372. [
  373. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  374. [-1,-1,-1,-1,-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],
  394. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  395. [-1,-1,-1,EXIT,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
  396. ];
  397. _frontMap =
  398. [
  399. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  400. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  401. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  402. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  403. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  404. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  405. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  406. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  407. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  408. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
  409. ];
  410. _terrainMap =
  411. [
  412. // 01 02 03 04 05 06 07 08 09 10
  413. /*01*/[KTIL,KTIL,KTIL,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE],
  414. /*02*/[KTIL,KTIL,KTIL,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE],
  415. /*03*/[KTIL,KTIL,KTIL,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE],
  416. /*04*/[TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE],
  417. /*05*/[TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE],
  418. /*06*/[TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE],
  419. /*07*/[TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE],
  420. /*08*/[TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE],
  421. /*09*/[TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE],
  422. /*10*/[TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE,TILE]
  423. ];
  424. _gameObjectMap =
  425. [
  426. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  427. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  428. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  429. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  430. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  431. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  432. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  433. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  434. [-1,-1,-1,MAIN,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  435. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
  436. ];
  437. buildItems();
  438. initBlankArrays();
  439. }
  440. override function OnEnter(e:flash.events.Event)
  441. {
  442. try
  443. {
  444. if(currentPlot.State == "Home End")
  445. {
  446. _MainCharacterModel.direction = "up";
  447. }
  448. super.OnEnter(e);
  449. if(currentPlot.State == "Home End")
  450. {
  451. getCharacterText(4);
  452. currentPlot.State = "Home Talk";
  453. }
  454. }
  455. catch(err:flash.Error)
  456. {
  457. trace(err.message);
  458. }
  459. }
  460. }