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

/BossLevel.hx

http://boxyboxumber.googlecode.com/
Haxe | 675 lines | 579 code | 60 blank | 36 comment | 124 complexity | f8ae6097f061cc027eeaed17ad26a93a 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.geom.Point;
  6. import flash.geom.Rectangle;
  7. import flash.geom.Matrix;
  8. import flash.utils.Timer;
  9. import haxe.FastList;
  10. import haxe.Timer;
  11. import Images;
  12. import TileModel;
  13. import HealthBarView;
  14. import BaseLevel;
  15. import Kongregate;
  16. class BossLevel extends BaseLevel
  17. {
  18. private var whiteMask:Sprite;
  19. private var won:Int;
  20. private var mult:Int;
  21. private var _pinkMap:Array<Array<Int>>;
  22. private static inline var MAX_TILE_SIZE:Int = 64;
  23. private static inline var MAP_COLUMNS:Int = 10;
  24. private static inline var MAP_ROWS:Int = 8;
  25. //tile ID s in tile sheet
  26. private static inline var BOX:Int = 00;
  27. private static inline var PLATFORM:Int = 11;
  28. private static inline var BOSS:Int = 12;
  29. private static inline var SKY_:Int = 10;
  30. private static inline var PLAT:Int = 11;
  31. private static inline var MACHINE_GUN:Int = 01;
  32. private static inline var PISTOL:Int = 02;
  33. private static inline var SHOTGUN:Int = 03;
  34. private static inline var PINK:Int = 21;
  35. private static inline var BLUE:Int = 20;
  36. private static inline var FAIRY:Int = 30;
  37. private static inline var PINK_FAIRY:Int = 22;
  38. private static inline var FLOWER:Int = 31;
  39. private static inline var HEART:Int = 32;
  40. private static inline var KITTY:Int = 33;
  41. private static inline var PinkRadius:Float = 20.5;
  42. private static inline var BlueRadius:Float = 20.5;
  43. public function new(stage:Dynamic){
  44. super(stage);
  45. MAP_COLUMNS = 70;
  46. removeChild(_staticBackgroundBitmap);
  47. removeChild(_backgroundBitmap);
  48. removeChild(_foregroundBitmap);
  49. removeChild(shotVectorView);
  50. won = 0;
  51. mult = 1;
  52. _staticBackgroundBitmapData = new CardboardBackground();
  53. _staticBackgroundBitmap = new Bitmap(_staticBackgroundBitmapData);
  54. _backgroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  55. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  56. _backgroundBitmap = new Bitmap(_backgroundBitmapData);
  57. _foregroundBitmapData = new BitmapData(MAP_COLUMNS * MAX_TILE_SIZE,
  58. MAP_ROWS * MAX_TILE_SIZE, true, 0);
  59. _foregroundBitmap = new Bitmap(_foregroundBitmapData);
  60. _camera = new Rectangle (0, 0, stage.stageWidth, stage.stageHeight);
  61. addChild(_staticBackgroundBitmap);
  62. addChild(_backgroundBitmap);
  63. addChild(_foregroundBitmap);
  64. whiteMask = new Sprite();
  65. whiteMask.graphics.beginFill(0xFFFFFF);
  66. whiteMask.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
  67. whiteMask.graphics.endFill();
  68. whiteMask.alpha = 0.5;
  69. shotVector = new VectorModel();
  70. shotVectorView = new VectorView(shotVector,_camera, 1);
  71. addChild(shotVectorView);
  72. _platformMap =
  73. [
  74. // Level 1 Level 2 Level 3 Level 4 Level 5 Level 6 Level 7
  75. // 0 , 1 , 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
  76. [SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_,SKY_, SKY_,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,-1,-1,-1,-1,-1],
  94. [-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,-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],
  95. ] ;
  96. maxEnemiesOnScreen = 10;
  97. // myTimer = new Timer(12);
  98. // myTimer.addEventListener("timer", OnEnter);
  99. // myTimer.start();
  100. //Add the game bitmaps
  101. }
  102. public override function Load(inVolume:Bool,inSound:Bool,inKongVar:CKongregate,inDifficulty:Int)
  103. {
  104. super.Load(inVolume,inSound,inKongVar,inDifficulty);
  105. //Run the buildMap method to convert the
  106. //map array data into a visual display
  107. won = 0;
  108. buildMap(_platformMap);
  109. buildMap(_gameObjectMap);
  110. if(_bossModel != null)
  111. {
  112. addChild(_bossHealth);
  113. }
  114. minX = stage.stageWidth*0;
  115. maxX = stage.stageWidth*1;
  116. _bossModel.setX = stage.stageWidth-64;
  117. if(Difficulty >= 3)
  118. {
  119. mult = 2;
  120. }
  121. //buildReserveEnemies();
  122. }
  123. public override function checkWin()
  124. {
  125. if(won > 50)
  126. {removeChild(whiteMask);}
  127. return (won > 50);
  128. }
  129. public override function buildReserveEnemies()
  130. {
  131. }
  132. override function OnEnter(e:flash.events.Event)
  133. {
  134. try
  135. {
  136. if(won > 0)
  137. {
  138. won++;
  139. if(won%2 == 0)
  140. {
  141. super.OnEnter(e);
  142. }
  143. return;
  144. }
  145. super.OnEnter(e);
  146. var enemyModelCount = 0;
  147. //_bossModel.hit();
  148. for(enemyModel in _enemies)
  149. {
  150. enemyModelCount++;
  151. }
  152. if(_bossModel.health > 90 * mult)
  153. {
  154. if(enemyModelCount == 0)
  155. {
  156. //addEnemyReserve(PINK,"Pink",6,9);
  157. addEnemyReserve(PINK,"Pink",6,8);
  158. addEnemyReserve(PINK,"Pink",6,7);
  159. addEnemyReserve(PINK,"Pink",6,6);
  160. addEnemyReserve(PINK,"Pink",6,4);
  161. addEnemyReserve(PINK,"Pink",6,3);
  162. addEnemyReserve(PINK,"Pink",6,2);
  163. }
  164. else if(enemyModelCount < 6)
  165. {
  166. addEnemyReserve(PINK,"Pink",6,8);
  167. }
  168. }
  169. else if(_bossModel.health > 75 * mult)
  170. {
  171. if(_bossModel.xPos < 640)
  172. {
  173. _bossModel.CanHit = false;
  174. clearEnemies();
  175. _bossModel.vx = 5;
  176. }
  177. else
  178. {
  179. maxX = stage.stageWidth*2;
  180. if(_boxModel.xPos >= stage.stageWidth)
  181. {minX = stage.stageWidth;}
  182. _bossModel.CanHit = true;
  183. _bossModel.setX = 1216;
  184. if(minX >= stage.stageWidth)
  185. {
  186. if(enemyModelCount == 0)
  187. {
  188. //addEnemyReserve(PINK,"Pink",6,9);
  189. addEnemyReserve(BLUE,"Blue",6,16);
  190. addEnemyReserve(BLUE,"Blue",6,15);
  191. addEnemyReserve(BLUE,"Blue",6,14);
  192. }
  193. else if(enemyModelCount < 3)
  194. {
  195. addEnemyReserve(BLUE,"Blue`",6,16);
  196. }
  197. }
  198. }
  199. }
  200. else if(_bossModel.health > 60 * mult)
  201. {
  202. if(_bossModel.xPos < stage.stageWidth*2)
  203. {
  204. _bossModel.CanHit = false;
  205. clearEnemies();
  206. _bossModel.vx = 5;
  207. }
  208. else
  209. {
  210. maxX = stage.stageWidth*3;
  211. if(_boxModel.xPos >= stage.stageWidth*2)
  212. {minX = stage.stageWidth*2;}
  213. _bossModel.CanHit = true;
  214. _bossModel.setX = stage.stageWidth*3-64;
  215. if(minX >= stage.stageWidth*2)
  216. {
  217. if(enemyModelCount == 0)
  218. {
  219. //addEnemyReserve(PINK,"Pink",6,9);
  220. // addEnemyReserve(FAIRY,"Fairy",6,26);
  221. addEnemyReserve(FAIRY,"Fairy",6,25);
  222. addEnemyReserve(FAIRY,"Fairy",6,24);
  223. addEnemyReserve(FAIRY,"Fairy",6,23);
  224. // addEnemyReserve(FAIRY,"Fairy",6,22);
  225. // addEnemyReserve(FAIRY,"Fairy",6,21);
  226. // addEnemyReserve(FAIRY,"Fairy",5,26);
  227. addEnemyReserve(FAIRY,"Fairy",5,25);
  228. addEnemyReserve(FAIRY,"Fairy",5,24);
  229. addEnemyReserve(FAIRY,"Fairy",5,23);
  230. // addEnemyReserve(FAIRY,"Fairy",5,22);
  231. // addEnemyReserve(FAIRY,"Fairy",5,21);
  232. addEnemyReserve(FAIRY,"Fairy",2,20);
  233. addEnemyReserve(FAIRY,"Fairy",2,21);
  234. addEnemyReserve(FAIRY,"Fairy",2,22);
  235. addEnemyReserve(FAIRY,"Fairy",1,20);
  236. addEnemyReserve(FAIRY,"Fairy",1,21);
  237. addEnemyReserve(FAIRY,"Fairy",1,22);
  238. addEnemyReserve(FAIRY,"Fairy",2,29);
  239. addEnemyReserve(FAIRY,"Fairy",2,28);
  240. addEnemyReserve(FAIRY,"Fairy",2,27);
  241. addEnemyReserve(FAIRY,"Fairy",1,29);
  242. addEnemyReserve(FAIRY,"Fairy",1,28);
  243. addEnemyReserve(FAIRY,"Fairy",1,27);
  244. }
  245. else if(enemyModelCount < 18)
  246. {
  247. addEnemyReserve(FAIRY,"Fairy",6,25);
  248. }
  249. }
  250. }
  251. }
  252. else if(_bossModel.health > 45 * mult)
  253. {
  254. if(_bossModel.xPos < stage.stageWidth*3)
  255. {
  256. _bossModel.CanHit = false;
  257. clearEnemies();
  258. _bossModel.vx = 5;
  259. }
  260. else if(_bossModel.xPos >= stage.stageWidth*3 && _bossModel.xPos < stage.stageWidth*3+4*MAX_TILE_SIZE )
  261. {
  262. _bossModel.setX = stage.stageWidth*3+4*MAX_TILE_SIZE+5;
  263. _bossModel.setY = 3*MAX_TILE_SIZE;
  264. _bossModel.vx = 0;
  265. }
  266. else
  267. {
  268. maxX = stage.stageWidth*4;
  269. if(_boxModel.xPos >= stage.stageWidth*3)
  270. {minX = stage.stageWidth*3;}
  271. _bossModel.CanHit = true;
  272. if(minX >= stage.stageWidth*3)
  273. {
  274. if(enemyModelCount == 0)
  275. {
  276. //addEnemyReserve(PINK,"Pink",6,9);
  277. // addEnemyReserve(FAIRY,"Fairy",6,26);
  278. addEnemyReserve(PINK_FAIRY,"PinkFairy",6,39);
  279. addEnemyReserve(PINK_FAIRY,"PinkFairy",6,38);
  280. addEnemyReserve(PINK_FAIRY,"PinkFairy",6,37);
  281. }
  282. else if(enemyModelCount < 3)
  283. {
  284. addEnemyReserve(PINK_FAIRY,"PinkFairy",6,39);
  285. }
  286. }
  287. }
  288. }
  289. else if(_bossModel.health > 30 * mult)
  290. {
  291. if(_bossModel.xPos < stage.stageWidth*4)
  292. {
  293. _bossModel.CanHit = false;
  294. clearEnemies();
  295. _bossModel.vx = 5;
  296. }
  297. else if(_bossModel.xPos >= stage.stageWidth*4 && _bossModel.xPos < stage.stageWidth*5-64 )
  298. {
  299. _bossModel.setX = stage.stageWidth*5-64;
  300. _bossModel.setY = 5*MAX_TILE_SIZE;
  301. _bossModel.vx = 0;
  302. }
  303. else
  304. {
  305. maxX = stage.stageWidth*5;
  306. if(_boxModel.xPos >= stage.stageWidth*4)
  307. {minX = stage.stageWidth*4;}
  308. _bossModel.CanHit = true;
  309. if(minX >= stage.stageWidth*4)
  310. {
  311. if(enemyModelCount == 0)
  312. {
  313. //addEnemyReserve(PINK,"Pink",6,9);
  314. // addEnemyReserve(FAIRY,"Fairy",6,26);
  315. addEnemyReserve(FLOWER,"Flower",4,47);
  316. var tempModel = _enemiesReserve.pop();
  317. while (tempModel != null)
  318. {
  319. addChild(tempModel.HealthBar);
  320. tempModel.model.health = 100;
  321. tempModel.model.MaxHealth = 100;
  322. tempModel.model.Clockwise = false;
  323. tempModel.model.setX = tempModel.model.xPos+(MAX_TILE_SIZE-tempModel.model.width);
  324. tempModel.model.vy = -5;
  325. tempModel.model.vx = 0;
  326. tempModel.model.update();
  327. _enemies.add(tempModel);
  328. enemyModelCount++;
  329. tempModel = _enemiesReserve.pop();
  330. }
  331. addEnemyReserve(FLOWER,"Flower",4,46);
  332. var tempModel = _enemiesReserve.pop();
  333. while (tempModel != null)
  334. {
  335. addChild(tempModel.HealthBar);
  336. tempModel.model.health = 100;
  337. tempModel.model.MaxHealth = 100;
  338. tempModel.model.update();
  339. tempModel.model.Clockwise = false;
  340. tempModel.model.setX = tempModel.model.xPos+(MAX_TILE_SIZE-tempModel.model.width);
  341. tempModel.model.vy = 5;
  342. tempModel.model.vx = 0;
  343. _enemies.add(tempModel);
  344. enemyModelCount++;
  345. tempModel = _enemiesReserve.pop();
  346. }
  347. }
  348. else if(enemyModelCount < 2)
  349. {
  350. addEnemyReserve(PINK_FAIRY,"PinkFairy",6,39);
  351. }
  352. }
  353. }
  354. }
  355. else if(_bossModel.health > 15* mult)
  356. {
  357. if(_bossModel.xPos < stage.stageWidth*5)
  358. {
  359. _bossModel.CanHit = false;
  360. clearEnemies();
  361. _bossModel.vx = 5;
  362. }
  363. else if(_bossModel.xPos >= stage.stageWidth*5 && _bossModel.xPos < stage.stageWidth*5+MAX_TILE_SIZE )
  364. {
  365. _bossModel.setX = stage.stageWidth*5+6*MAX_TILE_SIZE;
  366. _bossModel.setY = 4*MAX_TILE_SIZE;
  367. _bossModel.vx = 0;
  368. }
  369. else
  370. {
  371. maxX = stage.stageWidth*6;
  372. if(_boxModel.xPos >= stage.stageWidth*5)
  373. {minX = stage.stageWidth*5;}
  374. _bossModel.CanHit = true;
  375. if(minX >= stage.stageWidth*5)
  376. {
  377. if(enemyModelCount == 0)
  378. {
  379. //addEnemyReserve(PINK,"Pink",6,9);
  380. // addEnemyReserve(FAIRY,"Fairy",6,26);
  381. addEnemyReserve(HEART,"Heart",4,57);
  382. addEnemyReserve(HEART,"Heart",6,57);
  383. addEnemyReserve(HEART,"Heart",4,56);
  384. addEnemyReserve(HEART,"Heart",6,56);
  385. }
  386. else if(enemyModelCount < 4)
  387. {
  388. addEnemyReserve(HEART,"Heart",6,57);
  389. }
  390. }
  391. }
  392. }
  393. else if(_bossModel.health > 0* mult)
  394. {
  395. if(_bossModel.xPos < stage.stageWidth*6)
  396. {
  397. _bossModel.CanHit = false;
  398. clearEnemies();
  399. _bossModel.vx = 5;
  400. }
  401. else if(_bossModel.xPos >= stage.stageWidth*6 && _bossModel.xPos < stage.stageWidth*6+MAX_TILE_SIZE )
  402. {
  403. _bossModel.setX = stage.stageWidth*7-MAX_TILE_SIZE;
  404. _bossModel.setY = 0*MAX_TILE_SIZE;
  405. _bossModel.vx = 0;
  406. }
  407. else
  408. {
  409. maxX = stage.stageWidth*7;
  410. if(_boxModel.xPos >= stage.stageWidth*6)
  411. {minX = stage.stageWidth*6;}
  412. _bossModel.CanHit = true;
  413. if(minX >= stage.stageWidth*6)
  414. {
  415. if(enemyModelCount == 0)
  416. {
  417. //addEnemyReserve(PINK,"Pink",6,9);
  418. // addEnemyReserve(FAIRY,"Fairy",6,26);
  419. addEnemyReserve(KITTY,"Kitty",0,67);
  420. addEnemyReserve(KITTY,"Kitty",0,66);
  421. addEnemyReserve(KITTY,"Kitty",0,65);
  422. addEnemyReserve(KITTY,"Kitty",0,64);
  423. }
  424. else if(enemyModelCount < 4)
  425. {
  426. addEnemyReserve(KITTY,"Kitty",0,67);
  427. }
  428. }
  429. }
  430. }
  431. else if(_bossModel.health < 0 * mult)
  432. {
  433. clearEnemies();
  434. addChild(whiteMask);
  435. if(won <= 0)
  436. {won = 1;}
  437. }
  438. var tempModel = _enemiesReserve.pop();
  439. while (tempModel != null)
  440. {
  441. addChild(tempModel.HealthBar);
  442. tempModel.model.health = 100;
  443. tempModel.model.MaxHealth = 100;
  444. tempModel.model.update();
  445. _enemies.add(tempModel);
  446. enemyModelCount++;
  447. tempModel = _enemiesReserve.pop();
  448. }
  449. }
  450. catch(err:flash.Error)
  451. {
  452. trace(err.message);
  453. }
  454. }
  455. public override function findNewDirection(gameObject:TileModel)
  456. {
  457. var newDirection:String = "";
  458. //A random number between 1 and 4
  459. if(gameObject.changeDirection == "down")
  460. {
  461. if((gameObject.centerX*MAX_TILE_SIZE) <stage.stageWidth*5+5*MAX_TILE_SIZE)
  462. {newDirection = "left";}
  463. else
  464. {newDirection = "right";}
  465. }
  466. else if(gameObject.changeDirection == "up")
  467. {
  468. if((gameObject.centerX*MAX_TILE_SIZE) <stage.stageWidth*5+5*MAX_TILE_SIZE)
  469. {newDirection = "left";}
  470. else
  471. {newDirection = "right";}
  472. }
  473. else if(gameObject.changeDirection == "left")
  474. {
  475. newDirection = "up";
  476. }
  477. else if(gameObject.changeDirection == "right")
  478. {
  479. newDirection = "up";
  480. }
  481. //Test the new direction and call this method recursively
  482. //if the direction runs the object into a wall
  483. switch(newDirection)
  484. {
  485. case "left":
  486. if(_platformMap[gameObject.mapRow][gameObject.mapColumn - 1]
  487. != PLATFORM)
  488. {
  489. gameObject.direction = newDirection;
  490. gameObject.vx = -5;
  491. gameObject.vy = 0;
  492. }
  493. else
  494. {
  495. //If the test hits a wall, assign this direction as
  496. //the object's new direction and test again.
  497. //(Assigning the new direction prevents the objects
  498. //from accidentally getting stuck in cul-de-sacs)
  499. gameObject.direction = newDirection;
  500. findRandomDirection(gameObject);
  501. }
  502. case "right":
  503. if(_platformMap[gameObject.mapRow][gameObject.mapColumn + 1]
  504. != PLATFORM)
  505. {
  506. gameObject.direction = newDirection;
  507. gameObject.vx = 5;
  508. gameObject.vy = 0;
  509. }
  510. else
  511. {
  512. gameObject.direction = newDirection;
  513. findRandomDirection(gameObject);
  514. }
  515. case "up":
  516. if(_platformMap[gameObject.mapRow - 1][gameObject.mapColumn]
  517. != PLATFORM)
  518. {
  519. gameObject.direction = newDirection;
  520. gameObject.vx = 0;
  521. gameObject.vy = -5;
  522. }
  523. else
  524. {
  525. gameObject.direction = newDirection;
  526. findRandomDirection(gameObject);
  527. }
  528. case "down":
  529. if(_platformMap[gameObject.mapRow + 1][gameObject.mapColumn]
  530. != PLATFORM)
  531. {
  532. gameObject.direction = newDirection;
  533. gameObject.vx = 0;
  534. gameObject.vy = 5;
  535. }
  536. else
  537. {
  538. gameObject.direction = newDirection;
  539. findRandomDirection(gameObject);
  540. }
  541. default:
  542. gameObject.direction = newDirection;
  543. findRandomDirection(gameObject);
  544. }
  545. }
  546. public function addEnemyReserve(TileNumber:Int,characterType:String,row:Int,column:Int)
  547. {
  548. var tileSheetColumn:Int = Std.int(TileNumber / 10);
  549. var tileSheetRow:Int = Std.int(TileNumber % 10);
  550. var enemyModel = new TileModel
  551. (
  552. MAX_TILE_SIZE,
  553. tileSheetColumn, tileSheetRow,
  554. row, column,
  555. 41, 41,false, MAX_TILE_SIZE, MAX_TILE_SIZE
  556. );
  557. if(characterType == "Pink" || characterType == "Blue")
  558. {
  559. enemyModel.gravity_Vy = 0.98;
  560. enemyModel.vx = -5;
  561. enemyModel.ImageX = 11;
  562. enemyModel.ImageY = 11;
  563. enemyModel.ImageWidth = 41;
  564. enemyModel.ImageHeight= 41;
  565. }
  566. else if(characterType == "Fairy")
  567. {
  568. enemyModel.vx = -5;
  569. enemyModel.vy = -5;
  570. enemyModel.ImageX = 0;
  571. enemyModel.ImageY = 0;
  572. enemyModel.ImageXOffset = 11;
  573. enemyModel.ImageYOffset = 11;
  574. enemyModel.ImageWidth = 64;
  575. enemyModel.ImageHeight= 64;
  576. }
  577. else if(characterType == "Flower")
  578. {
  579. enemyModel.vx = -5;
  580. enemyModel.vy = 0;
  581. enemyModel.ImageX = 0;
  582. enemyModel.ImageY = 0;
  583. enemyModel.ImageXOffset = 11;
  584. enemyModel.ImageYOffset = 11;
  585. enemyModel.ImageWidth = 64;
  586. enemyModel.ImageHeight= 64;
  587. }
  588. else if(characterType == "Kitty")
  589. {
  590. enemyModel.gravity_Vy = 0.98;
  591. enemyModel.ImageX = 0;
  592. enemyModel.ImageY = 0;
  593. enemyModel.ImageXOffset = 11;
  594. enemyModel.ImageYOffset = 11;
  595. enemyModel.ImageWidth = 64;
  596. enemyModel.ImageHeight= 64;
  597. }
  598. else
  599. {
  600. enemyModel.ImageX = 0;
  601. enemyModel.ImageY = 0;
  602. enemyModel.ImageXOffset = 11;
  603. enemyModel.ImageYOffset = 11;
  604. enemyModel.ImageWidth = 64;
  605. enemyModel.ImageHeight= 64;
  606. }
  607. enemyModel.friction = 1;
  608. //addChild(Circle);
  609. enemyModel.setY = enemyModel.yPos +PinkRadius;
  610. enemyModel.setX = enemyModel.xPos +PinkRadius;
  611. enemyModel.CharacterType = characterType;
  612. var enemyModelContainer = new TileModelContainer(enemyModel,_camera);
  613. _enemiesReserve.add(enemyModelContainer);
  614. }
  615. }