Advertisement
Guest User

Untitled

a guest
May 25th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.03 KB | None | 0 0
  1. package {
  2.  
  3. import flash.display.Loader;
  4. import flash.display.MovieClip;
  5. import flash.display.SimpleButton;
  6. import flash.display.Sprite;
  7. import flash.events.MouseEvent;
  8. import flash.events.Event;
  9. import flash.text.TextField;
  10. import flash.text.TextFormat;
  11. import flash.events.KeyboardEvent;
  12. import flash.filesystem.*;
  13. import flash.net.*;
  14.  
  15. public class Map extends MovieClip {
  16. var game : Main;
  17. var walkableMap : Vector.<Vector.<int>>;
  18. var objects : Vector.<SimpleButton>;
  19. var zombies : Vector.<Zombie>;
  20. var soldiers : Vector.<Soldier>;
  21. var scientist : Scientist;
  22. var imageLoader : Loader;
  23. var mapWidth;
  24. var mapHeight;
  25. var verdanaBoldFont ;
  26.  
  27. var menuOpen : Boolean = false;
  28. var backgroundExit;
  29. var nameField;
  30. var exitBtn;
  31. var saveBtn;
  32. var username;
  33. var building;
  34. var confirm;
  35. var cancel;
  36. var info;
  37. var background;
  38. var nPersons;
  39. var probSucess;
  40. var probEspecial;
  41. var score = 0;
  42.  
  43. var linhas : Array = new Array();
  44.  
  45. public function Map(game : Main, imageLoader : Loader) {
  46. this.game = game;
  47. this.imageLoader = imageLoader;
  48. verdanaBoldFont = new Font2();
  49. this.objects = new Vector.<SimpleButton>;
  50. this.zombies = new Vector.<Zombie>;
  51. this.soldiers = new Vector.<Soldier>;
  52. }
  53.  
  54. public function generateMap(level : Level) {
  55. trace("generating map: " + level.id + " " + level.mapWidth + " " + level.mapHeight);
  56.  
  57. trace((game.stage.stageWidth - level.mapWidth) * 0.5 + " " + (game.stage.stageHeight - level.mapHeight) * 0.5);
  58.  
  59. game.x = (game.stage.stageWidth - level.mapWidth) * 0.5;
  60. game.y = (game.stage.stageHeight - level.mapHeight) * 0.5;
  61.  
  62. walkableMap = new Vector.<Vector.<int>>(level.mapWidth);
  63. for (var i = 0; i < level.mapWidth; i++) {
  64. walkableMap[i] = new Vector.<int>(level.mapHeight);
  65. }
  66.  
  67. for(i = 0; i < level.objects.length; i++) {
  68. setWalkable(level.objects[i]);
  69. drawInMap(level.objects[i]);
  70. }
  71.  
  72. game.stage.addEventListener(KeyboardEvent.KEY_UP, exit);
  73.  
  74. }
  75.  
  76. public function exit(evt : KeyboardEvent) {
  77. if(evt.keyCode == 81) {
  78. if(!menuOpen) {
  79. backgroundExit = addBackground(scientist.x - 250, scientist.y - 150);
  80. saveBtn = addButtonSpecial(scientist.x - 200, scientist.y -100 , 400, 50, "Save Game", 25);
  81. saveBtn.addEventListener(MouseEvent.CLICK, saveGame);
  82. exitBtn = addButtonSpecial(scientist.x - 200, scientist.y +50 , 400, 50, "Return to Main Menu", 25);
  83. exitBtn.addEventListener(MouseEvent.CLICK, pressedExit);
  84. game.stage.frameRate = 0;
  85.  
  86. menuOpen = true;
  87. } else {
  88. resumeGame();
  89. menuOpen = false;
  90. }
  91. }
  92. }
  93.  
  94. public function saveGame(evt : Event) {
  95.  
  96. game.saveDataObject = SharedObject.getLocal("save");
  97. game.saveDataObject.data.game = game;
  98. game.saveDataObject.data.map = this;
  99.  
  100. game.saveDataObject.flush();
  101.  
  102. resumeGame();
  103. }
  104.  
  105. public function pressedExit(evt : Event) {
  106. exitGame();
  107. }
  108.  
  109. public function resumeGame() {
  110. game.removeChild(backgroundExit);
  111. game.removeChild(saveBtn);
  112. game.removeChild(exitBtn);
  113.  
  114. game.stage.frameRate = 60;
  115. }
  116.  
  117. public function exitGame() {
  118. trace("eliminando");
  119. if(menuOpen) {
  120. game.removeChild(backgroundExit);
  121. game.removeChild(saveBtn);
  122. game.removeChild(exitBtn);
  123. trace("menu eliminado");
  124. }
  125. scientist.removeListeners();
  126. game.removeChild(scientist);
  127. trace("scientist eliminado");
  128. for(var i = 0; i < this.zombies.length; i++) {
  129. game.removeChild(this.zombies[i]);
  130. }
  131. trace("zombies eliminado");
  132. for(i = 0; i < this.soldiers.length; i++) {
  133. this.soldiers[i].removeListeners();
  134. for(var k = 0; k < this.soldiers[i].bulletList.length; k++) {
  135. game.removeChild(this.soldiers[i].bulletList[k]);
  136. }
  137. trace("balas eliminado");
  138. game.removeChild(this.soldiers[i]);
  139. }
  140. trace("soldiers eliminado");
  141.  
  142. game.clean();
  143. this.clean();
  144.  
  145. trace("all eliminado");
  146. var intro : Intro = new Intro(game, true);
  147. game.x = 0;
  148. game.y = 0;
  149. game.stage.frameRate = 60;
  150.  
  151. }
  152.  
  153. public function getName() {
  154. backgroundExit = addBackground(scientist.x - 250, scientist.y - 150);
  155. nameField = addTField(scientist.x - 200, scientist.y -100 , 400, 100, true, false, null, 40);
  156. exitBtn = addButtonSpecial(scientist.x - 200, scientist.y +50 , 400, 50, "Exit", 25);
  157. exitBtn.addEventListener(MouseEvent.CLICK, pressedExitUserName);
  158. }
  159.  
  160. public function pressedExitUserName(evt : Event) {
  161. username = nameField.text;
  162.  
  163. trace("Username mothafocka: " + username);
  164.  
  165. readHighscores();
  166.  
  167. linhas[linhas.length] = score + " " + username + "\n";
  168.  
  169. writeHighscoresToFile();
  170.  
  171. endGameRemovers();
  172.  
  173.  
  174. }
  175.  
  176. function readHighscores(){
  177. var myFile:File = File.documentsDirectory.resolvePath("highscores.txt");
  178. var fileStream:FileStream = new FileStream(); // Create our file stream
  179. fileStream.open(myFile, FileMode.READ);
  180.  
  181. linhas= fileStream.readUTFBytes(fileStream.bytesAvailable).split("\n");
  182.  
  183. for(var i = 0; i < linhas.length; i++) {
  184. linhas[i] += "\n";
  185. }
  186.  
  187. fileStream.close();
  188. }
  189.  
  190. function writeHighscoresToFile(){
  191. var file : File = File.documentsDirectory.resolvePath("highscores.txt");
  192. var stream: FileStream = new FileStream();
  193. stream.open(file, FileMode.WRITE);
  194. linhas.sort();
  195. for(var i = 0; i < linhas.length; i++){
  196. stream.writeUTFBytes(linhas[i]);
  197. }
  198.  
  199. stream.close();
  200. }
  201.  
  202. public function addTField(x:Number, y:Number, width:Number, height:Number, input:Boolean, pass:Boolean, text : String, size:Number):TextField
  203. {
  204. var textF : TextField = new TextField();
  205. var textboxFormat : TextFormat = new TextFormat();
  206. textF.x = x - 20;
  207. textF.y = y;
  208. textF.width = width;
  209. textF.height = height;
  210. textF.embedFonts = false;
  211. textF.wordWrap = true;
  212. textF.defaultTextFormat = new TextFormat(verdanaBoldFont.fontName);
  213.  
  214. if (input==true)
  215. {
  216. textF.type = "input";
  217. textF.border = true;
  218. textF.restrict = "@A-Za-z0-9._-";
  219. textF.maxChars = 30;
  220.  
  221. textF.multiline = false;
  222. if (pass ==true)
  223. {
  224. textF.displayAsPassword = true;
  225. }
  226. }
  227. else
  228. {
  229. textF.text = text;
  230. }
  231. textboxFormat.align = "center";
  232. textboxFormat.font = verdanaBoldFont.fontName;
  233. textboxFormat.size = size;
  234. textF.setTextFormat(textboxFormat);
  235.  
  236. game.addChild(textF);
  237. return textF;
  238. }
  239.  
  240. public function endGame() {
  241. trace("lost");
  242. scientist.removeListeners();
  243.  
  244. for(var i = 0; i < this.soldiers.length; i++) {
  245. this.soldiers[i].removeListeners();
  246. }
  247.  
  248. getName();
  249. }
  250.  
  251. public function endGameRemovers() {
  252. game.stage.frameRate = 0;
  253.  
  254. if(menuOpen) {
  255. game.removeChild(backgroundExit);
  256. game.removeChild(nameField);
  257. game.removeChild(exitBtn);
  258. trace("menu eliminado");
  259. }
  260.  
  261. game.removeChild(scientist);
  262. trace("scientist eliminado");
  263. for(var i = 0; i < this.zombies.length; i++) {
  264. game.removeChild(this.zombies[i]);
  265. }
  266. trace("zombies eliminado");
  267. for(i = 0; i < this.soldiers.length; i++) {
  268.  
  269. for(var k = 0; k < this.soldiers[i].bulletList.length; k++) {
  270. game.removeChild(this.soldiers[i].bulletList[k]);
  271. }
  272. trace("balas eliminado");
  273. game.removeChild(this.soldiers[i]);
  274. }
  275. trace("soldiers eliminado");
  276.  
  277. game.clean();
  278. this.clean();
  279.  
  280. trace("all eliminado");
  281. var intro : Intro = new Intro(game, true);
  282. game.x = 0;
  283. game.y = 0;
  284. game.stage.frameRate = 60;
  285.  
  286. }
  287.  
  288. public function addBackground(auxX, auxY) : Sprite {
  289. var buttonSprite : Sprite = new Sprite();
  290. buttonSprite.graphics.beginFill(0x291500);
  291. buttonSprite.graphics.drawRect(auxX, auxY,500,300);
  292. buttonSprite.graphics.endFill();
  293. buttonSprite.buttonMode = false;
  294. buttonSprite.alpha = 0.7;
  295. game.addChild(buttonSprite);
  296. return buttonSprite;
  297. }
  298.  
  299. public function isOpenBackground() : Boolean {
  300. return backgroundExit.open;
  301. }
  302.  
  303. public function setWalkable(object : MapObjects) {
  304. for(var i = 0; i < object.sizeX; i++) {
  305. walkableMap[object.posX + i][object.posY] = object.walkable;
  306. }
  307.  
  308. for(i = 0; i < object.sizeY; i++) {
  309. walkableMap[object.posX][object.posY + i] = object.walkable;
  310. }
  311. }
  312.  
  313. public function drawInMap(object : MapObjects) {
  314. createMapObject(object.imageSrc, object.posX, object.posY, object.sizeX, object.sizeY, object.walkable, object.info, object.nPersons, object.probSucess, object.probEspecial);
  315. }
  316.  
  317. public function createMapObject(src : String, x : int, y : int, width : int, height : int, walkable : int, info : String, nPersons : int, probSucess : int, probEspecial : int) {
  318. trace("drawing: " + x + " " + y + " " + width + " " + height);
  319. switch (src) {
  320. case "edificio1":
  321. var ed1 : edificio1 = new edificio1();
  322. ed1.width = width;
  323. ed1.height = height;
  324. ed1.x = x;
  325. ed1.y = y;
  326. ed1.mouseEnabled = walkable;
  327. ed1.addEventListener(MouseEvent.CLICK, pressBuilding);
  328.  
  329. ed1.info = info;
  330. ed1.nPersons = nPersons;
  331. ed1.probSucess = probSucess;
  332. ed1.probEspecial = probEspecial;
  333.  
  334. game.addChild(ed1);
  335. this.objects.push(ed1);
  336. break;
  337. case "edificio3":
  338. var ed3 : edificio3 = new edificio3();
  339. ed3.width = width;
  340. ed3.height = height;
  341. ed3.x = x;
  342. ed3.y = y;
  343. ed3.mouseEnabled = walkable;
  344. ed3.addEventListener(MouseEvent.CLICK, pressBuilding);
  345.  
  346. ed3.info = info;
  347. ed3.nPersons = nPersons;
  348. ed3.probSucess = probSucess;
  349. ed3.probEspecial = probEspecial;
  350.  
  351. game.addChild(ed3);
  352. this.objects.push(ed3);
  353. break;
  354. case "labEdificio":
  355. var lab : labEdificio = new labEdificio();
  356. lab.width = width;
  357. lab.height = height;
  358. lab.x = x;
  359. lab.y = y;
  360. lab.mouseEnabled = walkable;
  361. lab.addEventListener(MouseEvent.CLICK, pressBuilding);
  362.  
  363. lab.info = info;
  364. lab.nPersons = nPersons;
  365. lab.probSucess = probSucess;
  366. lab.probEspecial = probEspecial;
  367.  
  368. game.addChild(lab);
  369. this.objects.push(lab);
  370. break;
  371. case "heloEdificio":
  372. var helo : heloEdificio = new heloEdificio();
  373. helo.width = width;
  374. helo.height = height;
  375. helo.x = x;
  376. helo.y = y;
  377. helo.mouseEnabled = walkable;
  378. helo.addEventListener(MouseEvent.CLICK, pressBuilding);
  379.  
  380. helo.info = info;
  381. helo.nPersons = nPersons;
  382. helo.probSucess = probSucess;
  383. helo.probEspecial = probEspecial;
  384.  
  385. game.addChild(helo);
  386. this.objects.push(helo);
  387. break;
  388. case "uniEdificio":
  389. var uni : uniEdificio = new uniEdificio();
  390. uni.width = width;
  391. uni.height = height;
  392. uni.x = x;
  393. uni.y = y;
  394. uni.mouseEnabled = walkable;
  395. uni.addEventListener(MouseEvent.CLICK, pressBuilding);
  396.  
  397. uni.info = info;
  398. uni.nPersons = nPersons;
  399. uni.probSucess = probSucess;
  400. uni.probEspecial = probEspecial;
  401.  
  402. game.addChild(uni);
  403. this.objects.push(uni);
  404. break;
  405. case "armazemEdificio":
  406. var arm : armazemEdificio = new armazemEdificio();
  407. arm.width = width;
  408. arm.height = height;
  409. arm.x = x;
  410. arm.y = y;
  411. arm.mouseEnabled = walkable;
  412. arm.addEventListener(MouseEvent.CLICK, pressBuilding);
  413.  
  414. arm.info = info;
  415. arm.nPersons = nPersons;
  416. arm.probSucess = probSucess;
  417. arm.probEspecial = probEspecial;
  418.  
  419. game.addChild(arm);
  420. this.objects.push(arm);
  421. break;
  422. case "apartEdificio":
  423. var apart : apartEdificio = new apartEdificio();
  424. apart.width = width;
  425. apart.height = height;
  426. apart.x = x;
  427. apart.y = y;
  428. apart.mouseEnabled = walkable;
  429. apart.addEventListener(MouseEvent.CLICK, pressBuilding);
  430.  
  431. apart.info = info;
  432. apart.nPersons = nPersons;
  433. apart.probSucess = probSucess;
  434. apart.probEspecial = probEspecial;
  435.  
  436. game.addChild(apart);
  437. this.objects.push(apart);
  438. break;
  439. case "militarEdificio":
  440. var militar : militarEdificio = new militarEdificio();
  441. militar.width = width;
  442. militar.height = height;
  443. militar.x = x;
  444. militar.y = y;
  445. militar.mouseEnabled = walkable;
  446. militar.addEventListener(MouseEvent.CLICK, pressBuilding);
  447.  
  448. militar.info = info;
  449. militar.nPersons = nPersons;
  450. militar.probSucess = probSucess;
  451. militar.probEspecial = probEspecial;
  452.  
  453. game.addChild(militar);
  454. this.objects.push(militar);
  455. break;
  456. case "estradah":
  457. var esh : estradah = new estradah();
  458. esh.width = width;
  459. esh.height = height;
  460. esh.x = x;
  461. esh.y = y;
  462. esh.mouseEnabled = walkable;
  463. game.addChild(esh);
  464. break;
  465. case "estradav":
  466. var esv : estradav = new estradav();
  467. esv.width = width;
  468. esv.height = height;
  469. esv.x = x;
  470. esv.y = y;
  471. esv.mouseEnabled = walkable;
  472. game.addChild(esv);
  473. break;
  474. case "interseccao":
  475. var inte : interseccao = new interseccao();
  476. inte.width = width;
  477. inte.height = height;
  478. inte.x = x;
  479. inte.y = y;
  480. inte.mouseEnabled = walkable;
  481. game.addChild(inte);
  482. break;
  483. case "erva":
  484. var erv : erva = new erva();
  485. erv.width = width;
  486. erv.height = height;
  487. erv.x = x;
  488. erv.y = y;
  489. erv.mouseEnabled = walkable;
  490. game.addChild(erv);
  491. break;
  492. case "arvore1":
  493. var arv : arvore1 = new arvore1();
  494. arv.width = width;
  495. arv.height = height;
  496. arv.x = x;
  497. arv.y = y;
  498. arv.mouseEnabled = walkable;
  499. game.addChild(arv);
  500. break;
  501. case "arvore2":
  502. var arvo : arvore2 = new arvore2();
  503. arvo.width = width;
  504. arvo.height = height;
  505. arvo.x = x;
  506. arvo.y = y;
  507. arvo.mouseEnabled = walkable;
  508. game.addChild(arvo);
  509. break;
  510. case "arvore3":
  511. var arvor : arvore3 = new arvore3();
  512. arvor.width = width;
  513. arvor.height = height;
  514. arvor.x = x;
  515. arvor.y = y;
  516. arvor.mouseEnabled = walkable;
  517. game.addChild(arvor);
  518. break;
  519. case "linhah":
  520. var lh : linhah = new linhah();
  521. lh.width = width;
  522. lh.height = height;
  523. lh.x = x;
  524. lh.y = y;
  525. lh.mouseEnabled = walkable;
  526. game.addChild(lh);
  527. this.objects.push(lh);
  528. break;
  529. default:
  530. trace("error");
  531. }
  532.  
  533. }
  534.  
  535. public function createSoldier(x : int, y : int, width : int, height : int) {
  536. trace("Soldier: " + x + " " + y + " " + width + " " + height);
  537. var type = generateRandomInt(10, 0);
  538. trace("soldier type " + type);
  539. var soldier;
  540.  
  541. if (type < 5) {
  542. soldier = new DefaultSoldier(game, this);
  543. } else {
  544. if (Math.pow(-1, soldiers.length) == -1) {
  545. soldier = new Pro(game, this);
  546. } else {
  547. soldier = new Rambo(game, this);
  548. }
  549. }
  550.  
  551. soldier.x = x;
  552. soldier.y = y;
  553. soldier.width = width;
  554. soldier.height = height;
  555. this.game.addChild(soldier);
  556.  
  557. this.soldiers.push(soldier);
  558. }
  559.  
  560. public function createZombie(x : int, y : int, width : int, height : int) {
  561. var zombie;
  562. var type = generateRandomInt(10, 0);
  563. var auxX = generateRandomInt(70, 30);
  564. var auxY = generateRandomInt(70, 30);
  565.  
  566. trace("zombie type: " + type);
  567.  
  568. if (type < 6) {
  569. zombie = new Default(game, this);
  570. } else {
  571. if (Math.pow(-1, zombies.length) == -1) {
  572. zombie = new Roger(game, this);
  573. } else {
  574. zombie = new Tank(game, this);
  575. }
  576. }
  577.  
  578. if(generateRandomInt(0, 10) <= 5) {
  579. zombie.x = x + auxX;
  580. zombie.constX = auxX;
  581. } else {
  582. zombie.x = x + auxX * -1;
  583. zombie.constX = auxX * -1;
  584. }
  585. if(generateRandomInt(0, 10) <= 5) {
  586. zombie.y = y + auxY;
  587. zombie.constY = auxY;
  588. } else {
  589. zombie.y = y + auxY * -1;
  590. zombie.constY = auxY * -1;
  591. }
  592.  
  593. trace("Zombie: " + zombie.x + " " + zombie.y + " " + zombie.width + " " + zombie.height);
  594. zombie.width = width;
  595. zombie.height = height;
  596. this.game.addChild(zombie);
  597.  
  598. this.zombies.push(zombie);
  599. }
  600.  
  601. public function createTank(x: int, y:int, width: int, height:int){
  602. var zombie = new Tank(game, this);
  603. var auxX = generateRandomInt(70, 30);
  604. var auxY = generateRandomInt(70, 30);
  605.  
  606. if(generateRandomInt(0, 10) <= 5) {
  607. zombie.x = x + auxX;
  608. zombie.constX = auxX;
  609. } else {
  610. zombie.x = x + auxX * -1;
  611. zombie.constX = auxX * -1;
  612. }
  613. if(generateRandomInt(0, 10) <= 5) {
  614. zombie.y = y + auxY;
  615. zombie.constY = auxY;
  616. } else {
  617. zombie.y = y + auxY * -1;
  618. zombie.constY = auxY * -1;
  619. }
  620.  
  621. trace("Zombie: " + zombie.x + " " + zombie.y + " " + zombie.width + " " + zombie.height);
  622. zombie.width = width;
  623. zombie.height = height;
  624. this.game.addChild(zombie);
  625.  
  626. this.zombies.push(zombie);
  627. }
  628.  
  629. public function createRoger(x: int, y:int, width: int, height:int){
  630. var zombie = new Roger(game, this);
  631. var auxX = generateRandomInt(70, 30);
  632. var auxY = generateRandomInt(70, 30);
  633.  
  634. if(generateRandomInt(0, 10) <= 5) {
  635. zombie.x = x + auxX;
  636. zombie.constX = auxX;
  637. } else {
  638. zombie.x = x + auxX * -1;
  639. zombie.constX = auxX * -1;
  640. }
  641. if(generateRandomInt(0, 10) <= 5) {
  642. zombie.y = y + auxY;
  643. zombie.constY = auxY;
  644. } else {
  645. zombie.y = y + auxY * -1;
  646. zombie.constY = auxY * -1;
  647. }
  648.  
  649. trace("Zombie: " + zombie.x + " " + zombie.y + " " + zombie.width + " " + zombie.height);
  650. zombie.width = width;
  651. zombie.height = height;
  652. this.game.addChild(zombie);
  653.  
  654. this.zombies.push(zombie);
  655. }
  656.  
  657. public function pressBuilding(evt : Event) {
  658. trace(evt.target.info);
  659. game.stage.frameRate = 0;
  660. building = evt.target;
  661.  
  662. background = addBackgroundAlert(evt.target.x, evt.target.y);
  663. info = addInfo(evt.target.x, evt.target.y, evt.target.info);
  664.  
  665. if(!building.rapped) {
  666. confirm = addConfirmBtn(evt.target.x, evt.target.y);
  667. nPersons = evt.target.nPersons;
  668. probSucess = evt.target.probSucess;
  669. probEspecial = evt.target.probEspecial;
  670. confirm.addEventListener(MouseEvent.CLICK, alertConfirm);
  671. }
  672.  
  673. cancel = addCancelBtn(evt.target.x, evt.target.y);
  674. cancel.addEventListener(MouseEvent.CLICK, alertCancel);
  675. }
  676.  
  677. public function alertConfirm(evt : Event) {
  678. trace(nPersons + " " + probSucess + " " + probEspecial);
  679. if (generateRandomInt(100,0) < probSucess){
  680. for (var i = 0; i < nPersons; i++){
  681. if (generateRandomInt(100,0) < 50){
  682. createZombie(scientist.x,scientist.y,35,25);
  683. }
  684. if(generateRandomInt(100,0) < 10) {
  685. if(probEspecial == 1) {
  686. createTank(scientist.x, scientist.y, 35, 25);
  687. } else if (probEspecial == 2) {
  688. createRoger(scientist.x, scientist.y, 35, 25);
  689. }
  690. }
  691. }
  692. }
  693.  
  694. building.info += "\nSaqueado";
  695.  
  696. cleanAlert();
  697.  
  698. building.rapped = true;
  699. }
  700.  
  701. public function alertCancel(evt : Event) {
  702. cleanAlert();
  703. }
  704.  
  705. public function cleanAlert() {
  706. //confirm.removeListener(MouseEvent.CLICK, alertConfirm);
  707. game.removeChild(background);
  708. game.removeChild(info);
  709. if (!building.rapped) {
  710. game.removeChild(confirm);
  711. }
  712. game.removeChild(cancel);
  713. game.stage.frameRate = 60;
  714. }
  715.  
  716. public function addBackgroundAlert (auxX, auxY) : Sprite {
  717. var buttonSprite : Sprite = new Sprite();
  718. buttonSprite.graphics.beginFill(0x291500);
  719. buttonSprite.graphics.drawRect(auxX - 75, auxY - 75,150,150);
  720. buttonSprite.graphics.endFill();
  721. buttonSprite.buttonMode = false;
  722. buttonSprite.alpha = 0.7;
  723. game.addChild(buttonSprite);
  724. return buttonSprite;
  725. }
  726.  
  727. public function addInfo (auxX : int, auxY : int, info : String) : TextField {
  728. var titleText : TextField = new TextField();
  729. titleText.text = info;
  730. titleText.textColor = 0xDBCDAB;// Cor
  731. titleText.embedFonts = true;
  732. titleText.antiAliasType = "advanced";
  733. titleText.border = false;
  734. titleText.wordWrap = true;
  735. titleText.width = 360;
  736.  
  737. titleText.x = auxX - 60;
  738. titleText.y = auxY - 50;
  739. titleText.selectable = false;
  740. var titleTextFormat : TextFormat = new TextFormat();
  741. titleTextFormat.size = 10;
  742. titleTextFormat.font = verdanaBoldFont.fontName;
  743. titleTextFormat.bold = true;
  744. titleTextFormat.align = "left";
  745. titleText.setTextFormat(titleTextFormat);
  746. game.addChild(titleText);
  747. return titleText;
  748. }
  749.  
  750. public function addConfirmBtn(auxX, auxY) : Sprite {
  751. return addButtonSpecial(auxX - 65, auxY + 25, 50, 25, "Confirm", 10);
  752. }
  753.  
  754. public function addCancelBtn(auxX, auxY) : Sprite {
  755. return addButtonSpecial(auxX + 15, auxY + 25, 50, 25, "Cancel", 10);
  756. }
  757.  
  758. public function addButtonSpecial(x:Number,y:Number, width:Number, height:Number, text:String, size : int):Sprite
  759. {
  760. var textbox : TextField = new TextField();
  761. textbox.mouseEnabled = false;
  762. textbox.text = text;
  763. textbox.x = x;
  764. textbox.y = y;
  765. textbox.width = width;
  766. textbox.height = height;
  767. textbox.textColor = 0xFFFFFF;
  768. textbox.embedFonts = true;
  769. textbox.border = false;
  770. textbox.wordWrap = true;
  771. textbox.antiAliasType = "advanced";
  772. var textboxFormat : TextFormat = new TextFormat();
  773. textboxFormat.align = "center";
  774. textboxFormat.font = verdanaBoldFont.fontName;
  775. textboxFormat.bold = true;
  776. textboxFormat.size = size;
  777. textbox.setTextFormat(textboxFormat);
  778.  
  779. var buttonSprite : Sprite = new Sprite();
  780. buttonSprite.graphics.beginFill(0x291500);
  781. buttonSprite.graphics.drawRect(x,y,width,height);
  782. buttonSprite.graphics.endFill();
  783. buttonSprite.buttonMode = true;
  784. buttonSprite.alpha = 0.8;
  785. buttonSprite.addChild(textbox);
  786. game.addChild(buttonSprite);
  787. return buttonSprite;
  788. }
  789.  
  790. public function generateRandomInt(max : int, min : int) : int {
  791. return min + (max - min) * Math.random();
  792. }
  793.  
  794. public function clean()
  795. {
  796. while(this.numChildren>0)
  797. {
  798. this.removeChildAt(0);
  799. }
  800. }
  801. }
  802.  
  803. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement