PageRenderTime 59ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/Screen.hx

http://portable-monsters.googlecode.com/
Haxe | 817 lines | 656 code | 107 blank | 54 comment | 85 complexity | d750448004eecb52c7f15066319d55b1 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.text.TextField;
  9. import flash.text.TextFieldAutoSize;
  10. import flash.text.TextFormat;
  11. import flash.text.TextFormatAlign;
  12. import flash.utils.Timer;
  13. import haxe.Timer;
  14. import Images;
  15. import Kongregate;
  16. import Monster;
  17. class Screen extends Sprite{
  18. private var myTimer:Timer;
  19. public var volume:Bool;
  20. var kongVar : CKongregate;
  21. public var Items:List<Item>;
  22. public var Characters:List<Trainer>;
  23. private var _terrainBitmapData:BitmapData;
  24. private var _terrainBitmap:Bitmap;
  25. private var _backgroundBitmapData:BitmapData;
  26. private var _backgroundBitmap:Bitmap;
  27. private var _doorsBitmapData:BitmapData;
  28. private var _doorsBitmap:Bitmap;
  29. private var _itemsBitmapData:BitmapData;
  30. private var _itemsBitmap:Bitmap;
  31. private var _foregroundBitmapData:BitmapData;
  32. private var _foregroundBitmap:Bitmap;
  33. private var _tileSheetBitmapData:TileSheet;
  34. private var _collisionController:TileCollisionController;
  35. private var _MainCharacterModel:TileModel;
  36. private var _MainCharacterController:MainCharacterController;
  37. private var _MainCharacterView:MainCharacterView;
  38. public static inline var MAX_TILE_SIZE:Int = 32;
  39. private var MAP_COLUMNS:Int;
  40. private var MAP_ROWS:Int;
  41. private var _terrainMap:Array<Array<Int>>;
  42. private var _backgroundMap:Array<Array<Int>>;
  43. private var _doorsMap:Array<Array<Int>>;
  44. private var _itemsMap:Array<Array<Int>>;
  45. private var _gameObjectMap:Array<Array<Int>>;
  46. private var MAIN:Int;
  47. //Objects
  48. private var ITEM:Int;
  49. private var TOMB:Int;
  50. //House
  51. private var HUPL:Int;
  52. private var HUPC:Int;
  53. private var HUPR:Int;
  54. private var HLOL:Int;
  55. private var DOOR:Int;
  56. private var HLOR:Int;
  57. public var TNHL:Int;
  58. //Terrian
  59. private var GRAS:Int;
  60. private var GGRA:Int;
  61. private var MONT:Int;
  62. //Roads
  63. //Regular
  64. private var ROAD:Int;
  65. //up
  66. private var ROUP:Int;
  67. //Corners
  68. private var RURC:Int;
  69. //1 openings
  70. private var RD1O:Int;
  71. //Fence
  72. private var FEUP:Int;
  73. private var FERT:Int;
  74. private var FEDN:Int;
  75. private var FELT:Int;
  76. public var EXIT:Int;
  77. public var EXRI:Int;
  78. public var EXUP:Int;
  79. public var EXLE:Int;
  80. public var TILE:Int;
  81. public var WorldMap:Sprite;
  82. public var TextBox:Sprite;
  83. public var Text:TextField;
  84. public var RandomBattleImage:Sprite;
  85. public var BattleField:Sprite;
  86. public var CurrentBattle:BattleScreen;
  87. public var BattleWait:Int;
  88. public var State:String;
  89. public var MainTrainer:Trainer;
  90. private var mKeyDown:Array<Bool>;
  91. private var Pause:String;
  92. public var pauseMenu:PauseMenu;
  93. private var _camera:Rectangle;
  94. public function new(){
  95. super();
  96. LoadConstants();
  97. volume = false;
  98. WorldMap = new Sprite();
  99. Items = new List<Item>();
  100. addChild(WorldMap);
  101. State = "Playing";
  102. mKeyDown = [];
  103. Pause = "UnPaused";
  104. pauseMenu = new PauseMenu();
  105. pauseMenu.addEventListener("Quit",onQuit);
  106. initializeNewData();
  107. // myTimer = new Timer(12);
  108. // myTimer.addEventListener("timer", OnEnter);
  109. // myTimer.start();
  110. RandomBattleImage = new Sprite();
  111. RandomBattleImage.graphics.beginFill(0x000000);
  112. RandomBattleImage.graphics.drawRect(0,0,640,512);
  113. RandomBattleImage.graphics.endFill();
  114. TextBox = new Sprite();
  115. TextBox.graphics.beginFill(0xFFFFFF);
  116. TextBox.graphics.lineStyle(10);
  117. TextBox.graphics.drawRect(5,5,630,100);
  118. TextBox.graphics.endFill();
  119. Text = new TextField();
  120. Text.htmlText = "";
  121. Text.x = 10;
  122. Text.y = 10;
  123. Text.width = 620;
  124. Text.wordWrap = true;
  125. Text.selectable = false;
  126. TextBox.addChild(Text);
  127. _tileSheetBitmapData = new TileSheet();
  128. _collisionController = new TileCollisionController();
  129. LoadMapData();
  130. buildMap(_terrainMap,_terrainBitmapData);
  131. buildMap(_backgroundMap,_backgroundBitmapData);
  132. buildMap(_doorsMap,_doorsBitmapData);
  133. drawItems();
  134. WorldMap.addChild(_terrainBitmap);
  135. WorldMap.addChild(_backgroundBitmap);
  136. WorldMap.addChild(_doorsBitmap);
  137. WorldMap.addChild(_itemsBitmap);
  138. WorldMap.addChild(_foregroundBitmap);
  139. //Buildings
  140. }
  141. public function LoadConstants()
  142. {
  143. MAIN = Constants.MAIN;
  144. //Objects
  145. ITEM = Constants.ITEM;
  146. TOMB = Constants.TOMB;
  147. //House
  148. HUPL = Constants.HUPL;
  149. HUPC = Constants.HUPC;
  150. HUPR = Constants.HUPR;
  151. HLOL = Constants.HLOL;
  152. DOOR = Constants.DOOR;
  153. HLOR = Constants.HLOR;
  154. //Terrian
  155. GRAS = Constants.GRAS;
  156. GGRA = Constants.GGRA;
  157. MONT = Constants.MONT;
  158. //Roads
  159. //Regular
  160. ROAD = Constants.ROAD;
  161. //up
  162. ROUP = Constants.ROUP;
  163. //Corners
  164. RURC = Constants.RURC;
  165. //1 openings
  166. RD1O = Constants.RD1O;
  167. //Fence
  168. FEUP = Constants.FEUP;
  169. FERT = Constants.FERT;
  170. FEDN = Constants.FEDN;
  171. FELT = Constants.FELT;
  172. EXIT= Constants.EXIT;
  173. EXRI= Constants.EXRI;
  174. EXUP= Constants.EXUP;
  175. EXLE= Constants.EXLE;
  176. TILE = Constants.TILE;
  177. }
  178. public function LoadMapData()
  179. {
  180. MAP_COLUMNS = 40;
  181. MAP_ROWS = 16;
  182. _terrainBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  183. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  184. _terrainBitmap = new Bitmap(_terrainBitmapData);
  185. _backgroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  186. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  187. _backgroundBitmap = new Bitmap(_backgroundBitmapData);
  188. _doorsBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  189. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  190. _doorsBitmap = new Bitmap(_doorsBitmapData);
  191. _itemsBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  192. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  193. _itemsBitmap = new Bitmap(_itemsBitmapData);
  194. _foregroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  195. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  196. _foregroundBitmap = new Bitmap(_foregroundBitmapData);
  197. _backgroundMap =
  198. [
  199. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  200. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  201. [-1,-1,-1,HUPL,HUPC,HUPR,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  202. [-1,-1,-1,HLOL,-1,HLOR,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  203. [-1,-1,-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1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  267. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  268. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  269. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  270. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  271. [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-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,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
  273. ] ;
  274. buildItems();
  275. }
  276. public function initializeNewData()
  277. {
  278. MainTrainer = new Trainer();
  279. MainTrainer.CurrentMonster = new Monster();
  280. MainTrainer.CurrentMonster.XP =10;
  281. MainTrainer.CurrentMonster.LevelUp();
  282. MainTrainer.addNewMonster(MainTrainer.CurrentMonster);
  283. MainTrainer.addNewMonster(new Monster());
  284. building = new Building();
  285. }
  286. public function onQuit(event:Event)
  287. {
  288. removeChild(pauseMenu);
  289. this.removeEventListener(Event.ENTER_FRAME, OnEnter);
  290. UnLoad();
  291. dispatchEvent(new Event("LevelQuit"));
  292. }
  293. public function UnLoad()
  294. {
  295. flash.Lib.current.removeChild(this);
  296. //_MainCharacterController = null;
  297. stage.removeEventListener(KeyboardEvent.KEY_DOWN, OnKeyDown );
  298. stage.removeEventListener(KeyboardEvent.KEY_UP, OnKeyUp );
  299. }
  300. public function Load(inVolume:Bool,inKongVar:CKongregate)
  301. {
  302. initializeNewData();
  303. flash.Lib.current.addChild(this);
  304. this.addEventListener(Event.ENTER_FRAME, OnEnter);
  305. volume = inVolume;
  306. kongVar = inKongVar;
  307. buildMap(_gameObjectMap,_foregroundBitmapData);
  308. stage.addEventListener(KeyboardEvent.KEY_DOWN, OnKeyDown );
  309. stage.addEventListener(KeyboardEvent.KEY_UP, OnKeyUp );
  310. _camera = new Rectangle (0, 0, stage.stageWidth, stage.stageHeight);
  311. building.addEventListener("Exit",onBuildingExit);
  312. }
  313. public function buildItems()
  314. {
  315. //Column then Row
  316. Items.add(new Item(new Point(0,2),"Potion",false));
  317. Items.add(new Item(new Point(0,2),"Potion",false));
  318. Items.add(new Item(new Point(10,2),"Nothing",false));
  319. }
  320. public function drawItems()
  321. {
  322. _itemsMap = [[]];
  323. for(mapRow in 0...MAP_ROWS)
  324. {
  325. _itemsMap[mapRow] = [];
  326. }
  327. for(mapColumn in 0...MAP_COLUMNS)
  328. {
  329. for(mapRow in 0...MAP_ROWS)
  330. {
  331. _itemsMap[mapRow][mapColumn] = -1;
  332. }
  333. }
  334. for (item in Items)
  335. {
  336. _itemsMap[Std.int(item.Location.y)][Std.int(item.Location.x)] = 20;
  337. }
  338. _itemsBitmapData.fillRect(_itemsBitmapData.rect, 0);
  339. buildMap(_itemsMap,_itemsBitmapData);
  340. }
  341. //Create tile Models and map them to the
  342. //correct positions on the tile sheet
  343. private function buildMap(map:Array<Array<Int>>,mapBitmapData:BitmapData)
  344. {
  345. for(mapColumn in 0...MAP_COLUMNS)
  346. {
  347. for(mapRow in 0...MAP_ROWS)
  348. {
  349. var currentTile:Int = map[mapRow][mapColumn];
  350. if(currentTile > -1)
  351. {
  352. //Find the tile's column and row position
  353. //on the tile sheet
  354. var tileSheetColumn:Int = Std.int(currentTile / 10);
  355. var tileSheetRow:Int = Std.int(currentTile % 10);
  356. switch(currentTile)
  357. {
  358. case MAIN:
  359. _MainCharacterModel
  360. = new TileModel
  361. (
  362. MAX_TILE_SIZE,
  363. tileSheetColumn, tileSheetRow,
  364. mapRow, mapColumn,
  365. MAX_TILE_SIZE, MAX_TILE_SIZE
  366. );
  367. //Add the UIView and UIController
  368. _MainCharacterController
  369. = new MainCharacterController(_MainCharacterModel);
  370. _MainCharacterView
  371. = new MainCharacterView
  372. (_MainCharacterModel, _MainCharacterController, stage);
  373. drawGameObject(_MainCharacterModel, mapBitmapData);
  374. var Grass:TileModel
  375. = new TileModel
  376. (
  377. MAX_TILE_SIZE,
  378. tileSheetColumn, tileSheetRow,
  379. mapRow, mapColumn,
  380. MAX_TILE_SIZE, MAX_TILE_SIZE
  381. );
  382. drawGameObject(Grass, mapBitmapData);
  383. default:
  384. var Blank:TileModel
  385. = new TileModel
  386. (
  387. MAX_TILE_SIZE,
  388. tileSheetColumn, tileSheetRow,
  389. mapRow, mapColumn,
  390. MAX_TILE_SIZE, MAX_TILE_SIZE
  391. );
  392. drawGameObject(Blank, mapBitmapData);
  393. }
  394. }
  395. }
  396. }
  397. }
  398. function getInsideBuilding()
  399. {
  400. removeChild(WorldMap);
  401. building.LoadBuilding(volume,kongVar,MainTrainer);
  402. addChild(building);
  403. State = "InsideBuilding";
  404. trace("HERE");
  405. }
  406. public function checkItem()
  407. {
  408. var x = _MainCharacterModel.centerX;
  409. var y = _MainCharacterModel.centerY;
  410. if(_MainCharacterModel.direction == "left")
  411. {
  412. x--;
  413. }
  414. if(_MainCharacterModel.direction == "right")
  415. {
  416. x++;
  417. }
  418. if(_MainCharacterModel.direction == "up")
  419. {
  420. y--;
  421. }
  422. if(_MainCharacterModel.direction == "down")
  423. {
  424. y++;
  425. }
  426. if(_backgroundMap[y][x] >= 0)
  427. {
  428. getObjectText(y,x);
  429. }
  430. if(_itemsMap[y][x] >= 0)
  431. {
  432. removeItem(y,x);
  433. }
  434. }
  435. public function getObjectText(y:Int,x:Int)
  436. {
  437. if(x == 21 && y == 8)
  438. {
  439. Text.htmlText = "<font size='16'><u>Jacob</u>\nDied age 33.\nTook his life a year after his wife died.\nSurviving is his oldest of 10, eve and 5 sons.</font>";
  440. State = "addText";
  441. }
  442. else if(x == 23 && y== 8)
  443. {
  444. Text.htmlText = "<font size='16'><u>Amanda</u>\nDied age 31 during a boating accident.\nWife and Mother of 6.</font>";
  445. State = "addText";
  446. }
  447. }
  448. public function removeItem(y:Int,x:Int)
  449. {
  450. for(item in Items)
  451. {
  452. if(item.Location.x == x && item.Location.y == y)
  453. {
  454. TryToPickUpItem(item);
  455. break;
  456. }
  457. }
  458. drawItems();
  459. }
  460. public function TryToPickUpItem(item:Item)
  461. {
  462. switch(item.ID)
  463. {
  464. case "Nothing":
  465. Text.htmlText = "<font size='16'>You got Nothing...Well, that's disappointing.<font size='16'>";
  466. State = "addText";
  467. Items.remove(item);
  468. case "Potion":
  469. Text.htmlText = "<font size='16'>You got a Potion!<font size='16'>";
  470. MainTrainer.CurrentInventory.Items.add(item);
  471. State = "addText";
  472. Items.remove(item);
  473. default:
  474. State = "Playing";
  475. }
  476. }
  477. public function onBuildingExit(event:Event)
  478. {
  479. building.UnLoad();
  480. //removeChild(building);
  481. _MainCharacterModel.setY = _MainCharacterModel.yPos + 64;
  482. State = "Playing";
  483. addChild(WorldMap);
  484. trace("HERE5");
  485. }
  486. public function OnKeyDown(event:KeyboardEvent)
  487. {
  488. // When a key is held down, multiple KeyDown events are generated.
  489. // This check means we only pick up the first one.
  490. if (!mKeyDown[event.keyCode])
  491. {
  492. // if(ignoreKeyPress != "")
  493. // {return;}
  494. //
  495. //
  496. //
  497. // //Press any key to continue scence
  498. // PauseTillKeyPressed = false;
  499. // Store for use in game
  500. mKeyDown[event.keyCode] = true;
  501. if(State == "Playing")
  502. {
  503. //I do this here, because if they hold down P,
  504. // it won't pause and unpause constantly.
  505. if(mKeyDown[ 80 ] == true)
  506. {
  507. if(Pause == "Paused")
  508. {
  509. Pause = "UnPaused";
  510. removeChild(pauseMenu);
  511. }
  512. else
  513. {
  514. Pause = "Paused";
  515. addChild(pauseMenu);
  516. }
  517. }
  518. if(Pause == "Paused")
  519. {return;}
  520. BattleWait += 50;
  521. if(event.keyCode == 65 || event.keyCode == 13)
  522. {
  523. checkItem();
  524. }
  525. }
  526. else if(State == "Text")
  527. {
  528. WorldMap.removeChild(TextBox);
  529. State = "Playing";
  530. }
  531. // if(mKeyDown[ 77 ] == true)
  532. // {
  533. // Mute = !Mute;
  534. // }
  535. }
  536. }
  537. public function OnKeyUp (event:KeyboardEvent)
  538. {
  539. mKeyDown[event.keyCode] = false;
  540. }
  541. function OnEnter(e:flash.events.Event)
  542. {
  543. try
  544. {
  545. if(State == "addText")
  546. {
  547. WorldMap.addChild(TextBox);
  548. State = "Text";
  549. }
  550. if(State == "BattleFlash1")
  551. {
  552. WorldMap.addChild(RandomBattleImage);
  553. RandomBattleImage.alpha = 1;
  554. State = "BattleFlash2";
  555. }
  556. if(State == "BattleFlash2")
  557. {
  558. RandomBattleImage.alpha = 0;
  559. State = "BattleFlash3";
  560. }
  561. if(State == "BattleFlash3")
  562. {
  563. RandomBattleImage.alpha = 1;
  564. State = "BattleFlash4";
  565. }
  566. if(State == "BattleFlash4")
  567. {
  568. RandomBattleImage.alpha = 0;
  569. State = "BattleFade";
  570. }
  571. if(State == "BattleFade")
  572. {
  573. RandomBattleImage.alpha += 0.1;
  574. if( RandomBattleImage.alpha >= 1)
  575. {State="InitBattle";}
  576. }
  577. if(State == "InitBattle")
  578. {
  579. State = "Battle";
  580. CurrentBattle = new BattleScreen(stage,true,MainTrainer,null);
  581. CurrentBattle.addEventListener("BattleFinished",onBattleFinished);
  582. //addnew
  583. }
  584. trace("PLATING");
  585. if(State != "Playing")
  586. {trace("Ereturn");return;}
  587. trace("EAE");
  588. if(Pause == "Paused")
  589. {return;}
  590. _foregroundBitmapData.fillRect(_foregroundBitmapData.rect, 0);
  591. _MainCharacterModel.update();
  592. checkBoundaries();
  593. _collisionController.platformCollisionAnything(_MainCharacterModel, _backgroundMap, MAX_TILE_SIZE);
  594. _collisionController.platformCollisionAnything(_MainCharacterModel, _itemsMap, MAX_TILE_SIZE);
  595. if(_doorsMap[_MainCharacterModel.top][_MainCharacterModel.left] != -1 && _MainCharacterModel.moving <= 1)
  596. {getInsideBuilding();}
  597. if(WaitForNextRandomBattle())
  598. {
  599. if(_terrainMap[_MainCharacterModel.top][_MainCharacterModel.left] == MONT && _MainCharacterModel.moving <= 1)
  600. {checkRandomEncouter();}
  601. }
  602. drawGameObject(_MainCharacterModel, _foregroundBitmapData);
  603. _camera.x = _MainCharacterModel.xPos - stage.stageHeight * 0.5;
  604. _camera.y = _MainCharacterModel.yPos - stage.stageHeight * 0.5;
  605. //Check the camera's game world boundaries
  606. //Left
  607. if(_camera.x < 0)
  608. {
  609. _camera.x = 0;
  610. }
  611. //Right
  612. if(_camera.x > (MAP_COLUMNS * MAX_TILE_SIZE)
  613. - stage.stageWidth)
  614. {
  615. _camera.x = (MAP_COLUMNS * MAX_TILE_SIZE) - stage.stageWidth;
  616. }
  617. //Bottom
  618. if(_camera.y > (MAP_ROWS * MAX_TILE_SIZE) - stage.stageHeight)
  619. {
  620. _camera.y = (MAP_ROWS * MAX_TILE_SIZE) - stage.stageHeight;
  621. }
  622. //Top
  623. if(_camera.y < 0)
  624. {
  625. _camera.y = 0;
  626. }
  627. //Scroll the game world
  628. _terrainBitmap.scrollRect = _camera;
  629. _foregroundBitmap.scrollRect = _camera;
  630. _backgroundBitmap.scrollRect = _camera;
  631. _doorsBitmap.scrollRect = _camera;
  632. _itemsBitmap.scrollRect = _camera;
  633. }
  634. catch(err:flash.Error)
  635. {
  636. trace(err.message);
  637. }
  638. }
  639. public function WaitForNextRandomBattle()
  640. {
  641. BattleWait++;
  642. return(BattleWait > 50);
  643. }
  644. public function onBattleFinished(e:Event)
  645. {
  646. CurrentBattle = null;
  647. BattleWait = 0;
  648. WorldMap.removeChild(RandomBattleImage);
  649. State = "Playing";
  650. }
  651. public function checkRandomEncouter()
  652. {
  653. var randomNumber = Std.random(50);
  654. if(randomNumber == 1)
  655. {
  656. State="BattleFlash1";
  657. }
  658. }
  659. public function checkBoundaries()
  660. {
  661. var maxX = (MAP_COLUMNS * MAX_TILE_SIZE);
  662. var minX = 0;
  663. if (_MainCharacterModel.xPos + (_MainCharacterModel.width) > maxX)
  664. {
  665. _MainCharacterModel.setX = maxX - (_MainCharacterModel.width);
  666. _MainCharacterModel.vx = 0;
  667. }
  668. else if (_MainCharacterModel.xPos < minX)
  669. {
  670. _MainCharacterModel.setX = minX;
  671. _MainCharacterModel.vx = 0;
  672. }
  673. if (_MainCharacterModel.yPos <= 0)
  674. {
  675. _MainCharacterModel.setY = 0;
  676. _MainCharacterModel.vy = 0;
  677. }
  678. else if (_MainCharacterModel.yPos + _MainCharacterModel.height >= stage.stageHeight)
  679. {
  680. _MainCharacterModel.setY = stage.stageHeight - _MainCharacterModel.height;
  681. _MainCharacterModel.vy = 0;
  682. }
  683. }
  684. private function drawGameObject
  685. (
  686. tileModel:TileModel,
  687. screen:BitmapData
  688. )
  689. {
  690. var sourceRectangle:Rectangle = new Rectangle
  691. (
  692. tileModel.tileSheetColumn * MAX_TILE_SIZE+ tileModel.ImageX,
  693. tileModel.tileSheetRow * MAX_TILE_SIZE+ tileModel.ImageY,
  694. tileModel.ImageWidth,
  695. tileModel.ImageHeight
  696. );
  697. var destinationPoint:Point = new Point
  698. (
  699. tileModel.xPos-(tileModel.ImageXOffset),
  700. tileModel.yPos-(tileModel.ImageYOffset)
  701. );
  702. screen.copyPixels
  703. (
  704. _tileSheetBitmapData,
  705. sourceRectangle,
  706. destinationPoint,
  707. null, null, true
  708. );
  709. }
  710. }