Advertisement
Guest User

Untitled

a guest
Oct 5th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.07 KB | None | 0 0
  1. package;
  2.  
  3. import flash.display.Sprite;
  4. import flash.geom.ColorTransform;
  5. import flixel.util.FlxPath;
  6. import openfl.Assets;
  7. import flash.display.BlendMode;
  8. import flixel.FlxObject;
  9. import flixel.FlxG;
  10. import flixel.tile.FlxTile;
  11. import flixel.FlxSprite;
  12. import flixel.FlxState;
  13. import flixel.group.FlxGroup;
  14. import flixel.text.FlxText;
  15. import flixel.tile.FlxTilemap;
  16. import flixel.tweens.FlxTween;
  17. import flixel.tweens.FlxEase;
  18. import flixel.util.FlxColor;
  19. import flixel.math.FlxMath;
  20. import flixel.math.FlxPoint;
  21.  
  22. import flixel.addons.editors.ogmo.FlxOgmoLoader;
  23.  
  24. import flixel.system.FlxSound;
  25.  
  26. import zerolib.ZSpotLight;
  27.  
  28.  
  29. import crashdumper.CrashDumper;
  30. import crashdumper.SessionData;
  31.  
  32. import haxe.CallStack;
  33.  
  34. import flixel.addons.weapon.FlxWeapon;
  35.  
  36. import flixel.util.FlxTimer;
  37.  
  38. import flixel.util.FlxAxes;
  39.  
  40. /**
  41. * Atari 2600 Breakout
  42. *
  43. * @author Davey, Photon Storm
  44. * @link http://www.photonstorm.com/archives/1290/video-of-me-coding-breakout-in-flixel-in-20-mins
  45. */
  46. class PlayState extends FlxState
  47. {
  48.  
  49.  
  50. private var _bat:Bat;
  51. private var _ball:Ball;
  52. private var Border:FlxSprite;
  53. private var BackScreen:FlxSprite;
  54.  
  55. private var _walls:FlxGroup;
  56. private var _leftWall:FlxSprite;
  57. private var _leftWallB:FlxSprite;
  58. private var _rightWall:FlxSprite;
  59. private var _topWall:FlxSprite;
  60. private var _topWallB:FlxSprite;
  61. private var _bottomWall:FlxSprite;
  62.  
  63. private var Bricks:FlxGroup;
  64.  
  65. private var Scene:FlxOgmoLoader;
  66.  
  67. private var Base:FlxTilemap;
  68.  
  69. private var Screen:FlxTilemap;
  70.  
  71.  
  72. private var _scoreText:FlxText;
  73. private var _scoreDisplay:FlxText;
  74.  
  75. private var _levelText:FlxText;
  76. private var _levelDisplay:FlxText;
  77.  
  78. private var _livesText:FlxText;
  79. private var _liveDisplay:FlxText;
  80.  
  81.  
  82.  
  83. private var _score:Int = 0;
  84. private var _lives:Int = 5;
  85. private var _extralife:Int = 500;
  86.  
  87. //Liquids
  88. public static var lava1 : Liquid;
  89. public static var lavas1 : FlxTypedGroup<Liquid>;
  90. public static var lava2 : Liquid;
  91. public static var lavas2 : FlxTypedGroup<Liquid>;
  92.  
  93. public var ScreenNumber:Int;
  94.  
  95. public var playerBullets:FlxTypedGroup<Bullet>;
  96. public var BallGroup:FlxTypedGroup<Ball>;
  97. public var PowerGroup:FlxTypedGroup<PowerBrick>;
  98.  
  99. public var Streamer:FlxWeapon;
  100. //private var weapon:FlxWeapon = new FlxWeapon("arma", null, Bullet);
  101.  
  102.  
  103. private var _sndCoin:FlxSound;
  104.  
  105. public var EndClock:FlxTimer;
  106. public var EndNum:Float = 4;
  107. public var EndTag:FlxText;
  108. public var Title:FlxText;
  109. public var NextGame:FlxText;
  110.  
  111. private var GameEndText:FlxText;
  112.  
  113. public var ExitDoor:Exit;
  114.  
  115. public var isGameOver:Bool;
  116.  
  117.  
  118. private var _paused:Bool = false;
  119.  
  120. override public function create():Void
  121. {
  122.  
  123. FlxG.sound.playMusic("Action", 1, true);
  124.  
  125.  
  126. BackScreen = new FlxSprite(16, 16, "images/BackDropA.png");
  127. add(BackScreen);
  128.  
  129.  
  130. #if !android
  131. FlxG.mouse.visible = false;
  132. #end
  133.  
  134. ScreenNumber = 1;
  135.  
  136.  
  137. _bat = new Bat(268, 426);
  138.  
  139. _ball = new Ball(320, 240);
  140.  
  141.  
  142. _walls = new FlxGroup();
  143. BallGroup = new FlxTypedGroup<Ball>();
  144. PowerGroup = new FlxTypedGroup<PowerBrick>();
  145. Bricks = new FlxGroup();
  146.  
  147.  
  148.  
  149. createWalls();
  150. LoadLevel(ScreenNumber);
  151.  
  152. add(PowerGroup);
  153. add(Bricks);
  154.  
  155. //Streamer = new FlxWeapon("arma");
  156. //Streamer.fireFrom = _bat;
  157.  
  158. add(_bat);
  159.  
  160. playerBullets = new FlxTypedGroup<Bullet>();
  161. add(playerBullets);
  162.  
  163. add(BallGroup);
  164. BallGroup.add(_ball);
  165.  
  166. //GUI
  167. ////////////////////////////////////////////////////////////////////////
  168. createGui();
  169. /////////////////////////////////////////////////////////////////////////
  170.  
  171. _sndCoin = FlxG.sound.load("sounds/Coin01.mp3");
  172.  
  173. //EndClock = new FlxTimer().time = EndNum;
  174.  
  175. isGameOver = false;
  176. }
  177.  
  178. function createText(x:Float, y:Float, ?text:String, FontSize:Int, W:Float)
  179. {
  180. var text = new FlxText(x, y, W, text);
  181. text.setFormat(null, FontSize, FlxColor.BLACK,CENTER);
  182. text.setBorderStyle(OUTLINE, FlxColor.WHITE, 2);
  183. return text;
  184. }
  185.  
  186. private function createGui():Void
  187. {
  188. // A text to display the score
  189. var format6 = new FlxTextFormat(0xFF0000, false, false, 0xFFFFFF);
  190.  
  191. _scoreText = createText(368, 32, "Score: ", 16, 400);
  192. _scoreText.addFormat(format6, -1, -1);
  193. add(_scoreText);
  194.  
  195. _scoreDisplay = new FlxText(364, 52, 400, "" + 0);
  196. _scoreDisplay.setFormat(null, 16, FlxColor.WHITE, CENTER, OUTLINE);
  197. add(_scoreDisplay);
  198.  
  199.  
  200. _levelText = createText(368, 132, "Level: ", 16, 400);
  201. _levelText.addFormat(format6, -1, -1);
  202. add(_levelText);
  203.  
  204. _levelDisplay = new FlxText(364, 164, 400, "" + 0);
  205. _levelDisplay.setFormat(null, 16, FlxColor.WHITE, CENTER, OUTLINE);
  206. add(_levelDisplay);
  207.  
  208. _livesText = createText(368, 194, "Lives: ", 16, 400);
  209. _livesText.addFormat(format6, -1, -1);
  210. add(_livesText);
  211.  
  212. _liveDisplay = new FlxText(364, 218, 400, "" + _lives);
  213. _liveDisplay.setFormat(null, 16, FlxColor.WHITE, CENTER, OUTLINE);
  214. add(_liveDisplay);
  215.  
  216. EndTag = createText(-32, FlxG.height / 2, "Ready in: " + EndNum, 16, FlxG.width);
  217. EndTag.addFormat(format6, -1, -1);
  218. EndTag.visible = false;
  219. add(EndTag);
  220.  
  221. GameEndText = createText(-64,240, "Game Over!",48,FlxG.width);
  222. GameEndText.addFormat(format6, -1, -1);
  223. GameEndText.visible = false;
  224. add(GameEndText);
  225. GameEndText.screenCenter(FlxAxes.Y);
  226.  
  227. NextGame = createText(-64,340, "Press X To Restart!",16,FlxG.width);
  228. NextGame.addFormat(format6, -1, -1);
  229. NextGame.visible = false;
  230. add(NextGame);
  231. //NextGame.screenCenter(FlxAxes.X);
  232. }
  233.  
  234. private function createWalls():Void
  235. {
  236. _leftWall = new FlxSprite(0, 256, "images/LeftPipeA.png");
  237. _leftWall.immovable = true;
  238. _walls.add(_leftWall);
  239.  
  240. _leftWallB = new FlxSprite(0, 32, "images/LeftPipeB.png");
  241. _leftWallB.immovable = true;
  242. _walls.add(_leftWallB);
  243.  
  244.  
  245.  
  246. _rightWall = new FlxSprite(482, 0,"images/RightPipe.png");
  247. _rightWall.immovable = true;
  248. _walls.add(_rightWall);
  249.  
  250. _topWall = new FlxSprite(0, 0,"images/TopPipeA.png");
  251. _topWall.immovable = true;
  252. _walls.add(_topWall);
  253.  
  254. _topWallB = new FlxSprite(256, 0,"images/TopPipeB.png");
  255. _topWallB.immovable = true;
  256. _walls.add(_topWallB);
  257.  
  258.  
  259.  
  260. _bottomWall = new FlxSprite(0, 464);
  261. _bottomWall.makeGraphic(640, 16, FlxColor.GRAY);
  262. _bottomWall.immovable = true;
  263. _bottomWall.visible = false;
  264. //_walls.add(_bottomWall);
  265. add(_bottomWall);
  266.  
  267.  
  268.  
  269.  
  270. add(_walls);
  271. }
  272.  
  273. //Clean Out Everything
  274. private function CleanScreen():Void
  275. {
  276. remove(Bricks);
  277. remove(Screen);
  278. remove(playerBullets);
  279. remove(lavas1);
  280. remove(EndTag);
  281. remove(ExitDoor);
  282. remove(BallGroup);
  283. remove(PowerGroup);
  284. }
  285.  
  286. private function LoadLevel(Screen:Int):Void
  287. {
  288. if(ScreenNumber!=1) CleanScreen();
  289.  
  290. //Each screen is a ogmo level now
  291. Scene = new FlxOgmoLoader("data/Screen"+ Std.string(ScreenNumber) + ".oel");
  292. Base = Scene.loadTilemap("images/TileSet.png", 32, 16, "Bricks");
  293. for (i in 1...31) Base.setTileProperties(i, FlxObject.ANY, leftHit);
  294. add(Base);
  295.  
  296.  
  297. Scene.loadEntities(placeEntities, "Squares"); //Layering issue
  298.  
  299. add(Bricks);
  300. add(playerBullets);
  301.  
  302. lavas1 = new FlxTypedGroup<Liquid>();
  303. var delta = 0;
  304. var r : Bool = false;
  305. for (i in 0 ... 20)
  306. {
  307. if (!r) delta ++;
  308. else delta --;
  309.  
  310. if (delta == 10) r = true;
  311. if (delta == 0) r = false;
  312.  
  313. lava1 = new Liquid(0 + (i * 32), 472 - (delta-delta/2) * 2, delta/50,0xBBFC0C12,0xBB10A9FC,true,false ); // 2500 pour pas les voir au start. lower for this game
  314. lavas1.add(lava1);
  315. }
  316. add(lavas1);
  317.  
  318. _ball.reset(_bat.getMidpoint().x, _bat.getMidpoint().y - 16);
  319. _ball.elasticity = 1;
  320. _ball.maxVelocity.set(200, 430);
  321. _ball.velocity.y = 200;
  322.  
  323. add(BallGroup);
  324. add(PowerGroup);
  325.  
  326. BallGroup.add(_ball);
  327.  
  328. add(EndTag);
  329. }
  330.  
  331. private function placeEntities(entityName:String, entityData:Xml):Void
  332. {
  333. var x:Int = Std.parseInt(entityData.get("x"));
  334. var y:Int = Std.parseInt(entityData.get("y"));
  335. var eType:Int = Std.parseInt(entityData.get("eType"));
  336. var isPow:Int = Std.parseInt(entityData.get("isPow"));
  337. var pCast:Int = Std.parseInt(entityData.get("PowType"));
  338.  
  339. if (entityName == "Brick1") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  340. if (entityName == "Brick2") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  341. if (entityName == "Brick3") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  342. if (entityName == "Brick4") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  343. if (entityName == "Brick5") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  344. if (entityName == "Brick6") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  345. if (entityName == "Brick7") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  346. if (entityName == "Brick8") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  347. if (entityName == "Brick9") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  348. if (entityName == "Brick10") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  349. if (entityName == "Brick11") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  350. if (entityName == "Brick12") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  351. if (entityName == "Brick13") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  352. if (entityName == "Brick14") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  353. if (entityName == "Brick15") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  354. if (entityName == "Brick16") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  355. if (entityName == "Brick17") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  356. if (entityName == "Brick18") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  357. if (entityName == "Brick19") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  358. if (entityName == "Brick20") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  359. if (entityName == "Brick21") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  360. if (entityName == "Brick22") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  361. if (entityName == "Brick23") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  362. if (entityName == "Brick24") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  363. if (entityName == "Brick25") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  364. if (entityName == "Brick26") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  365. if (entityName == "Brick27") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  366. if (entityName == "Brick28") Bricks.add(new Brick(x, y, eType,isPow,pCast));
  367. //if (entityName == "PowerUp") PowerGroup.add(new PowerBrick(x, y, eType));
  368. }
  369.  
  370.  
  371.  
  372. private function onVictory():Void
  373. {
  374. if (isGameOver == false)
  375. {
  376. for (all in BallGroup) all.halt();
  377.  
  378.  
  379. EndNum = 4;
  380. ScreenNumber += 1;
  381. EndTag.visible = false;
  382. if (ScreenNumber <= 10) LoadLevel(ScreenNumber);
  383. }
  384. }
  385.  
  386. private function GameOver():Void
  387. {
  388. _ball.kill();
  389. _bat.kill();
  390.  
  391. GameEndText.visible = true;
  392. NextGame.visible = true;
  393. }
  394.  
  395. private function onLostLife():Void
  396. {
  397. if (isGameOver == false)
  398. {
  399. EndNum = 4;
  400. EndTag.visible = false;
  401.  
  402. _bat.revive();
  403. _bat.reset(268, 426);
  404.  
  405. _ball.revive();
  406. _ball.reset(_bat.getMidpoint().x, _bat.getMidpoint().y - 16);
  407. _ball.init();
  408. BallGroup.add(_ball);
  409. add(_ball);
  410. }
  411. }
  412.  
  413. override public function update(elapsed:Float):Void
  414. {
  415. if (FlxG.keys.justPressed.P)
  416. {
  417. _paused = !_paused;
  418. }
  419. /*
  420. if (!_paused)
  421. {
  422. _ball.velocity.x = 200;
  423. _ball.velocity.y = 200;
  424. }*/
  425.  
  426. if (_paused)
  427. {
  428.  
  429. //_ball.velocity.x = 0;
  430. //_ball.velocity.y = 0;
  431.  
  432. return;
  433. }
  434.  
  435.  
  436. FlxG.watch.add(this, "ScreenNumber", "ScreenIs");
  437.  
  438.  
  439. //End State
  440. #if !android
  441. if (FlxG.keys.justReleased.R)
  442. {
  443. FlxG.resetState();
  444. }
  445.  
  446. if (FlxG.keys.justReleased.X && isGameOver == true)
  447. {
  448. FlxG.camera.fade(FlxColor.BLACK, 1, false, FadeOut, false);
  449. }
  450.  
  451. #end
  452.  
  453. FlxG.collide(BallGroup, Base,leftHit);
  454. FlxG.collide(BallGroup, Screen);
  455.  
  456.  
  457. if (FlxG.overlap(BallGroup, _walls))
  458. {
  459. FlxG.collide(BallGroup, _walls);
  460. FlxG.sound.play("Smack", 1, false);
  461. }
  462. /*
  463. if (_ball.overlaps(_walls))
  464. {
  465. FlxG.collide(BallGroup, _walls);
  466. FlxG.sound.play("Smack", 1, false);
  467. }*/
  468.  
  469.  
  470.  
  471. FlxG.collide(_bat, BallGroup, ping);
  472.  
  473.  
  474. FlxG.collide(BallGroup, Bricks, scoreBricks);
  475. FlxG.collide(BallGroup, PowerGroup, PowerBricks);
  476.  
  477. //Bullets
  478. FlxG.collide(playerBullets, Bricks);
  479. FlxG.overlap(playerBullets, Bricks,scoreBricksShot);
  480. //FlxG.overlap(_ball, Bricks, scoreBricks);
  481.  
  482.  
  483. _scoreDisplay.text = "" + _score;
  484. _levelDisplay.text = "" + ScreenNumber;
  485. _liveDisplay.text = "" + _lives;
  486.  
  487.  
  488. //Game Over
  489. if (_lives < 0)
  490. {
  491. isGameOver = true;
  492. GameOver();
  493. }
  494.  
  495.  
  496. //Bricks clear
  497. // Fade out to victory screen stuffs
  498.  
  499. if (Bricks.countLiving() <= 0)
  500. {
  501. if (isGameOver == false)
  502. {
  503. _ball.velocity.x = 0;
  504. _ball.velocity.y = 0;
  505.  
  506. if (EndNum == 4) FlxG.sound.play("RoundEnd", 1, false);
  507.  
  508. if (EndNum > 0) EndNum -= elapsed;
  509.  
  510. EndTag.visible = true;
  511. EndTag.text = "Ready in: " + Std.int(EndNum);
  512.  
  513. if (EndNum <= 0)
  514. {
  515. EndNum = 4;
  516. onVictory();
  517. }
  518. }
  519. }
  520.  
  521. //Lose Ball at bottom
  522. //FlxG.overlap(BallGroup, _walls)
  523. //if (_ball.overlaps(_bottomWall)) -Original
  524.  
  525. FlxG.overlap(BallGroup, _bottomWall, ExtraLoss);
  526.  
  527. if (isGameOver == false)
  528. {
  529. if (BallGroup.countLiving() <= 0)
  530. {
  531. BallGroup.kill();
  532.  
  533. _bat.kill();
  534.  
  535. if (EndNum == 4) FlxG.sound.play("Death", 1, false);
  536.  
  537. if (EndNum > 0) EndNum -= elapsed;
  538.  
  539. EndTag.visible = true;
  540. if (_lives > 0) EndTag.text = "Ready in: " + Std.int(EndNum);
  541. else
  542. {
  543. EndTag.text = ("Waiting...");
  544. EndNum = 0;
  545. }
  546.  
  547.  
  548. if (EndNum <= 0 && isGameOver == false)
  549. {
  550. _lives -= 1;
  551. EndNum = 4;
  552. onLostLife();
  553. }
  554. }
  555.  
  556.  
  557. } else
  558. {
  559. EndNum = 0;
  560. EndTag.visible = false;
  561. EndTag.text = ("Waiting...");
  562.  
  563.  
  564. isGameOver = true;
  565. GameOver();
  566.  
  567. }
  568.  
  569.  
  570.  
  571. /*
  572. if (FlxG.overlap(BallGroup, _bottomWall))
  573. {
  574. if (isGameOver == false)
  575. {
  576.  
  577. for (single in BallGroup)
  578. {
  579. if (single.overlaps(_bottomWall)) single.kill();
  580.  
  581. }
  582.  
  583. if (BallGroup.countLiving() <= 0)
  584. {
  585. BallGroup.kill();
  586.  
  587. _bat.kill();
  588.  
  589. if (EndNum == 4) FlxG.sound.play("Death", 1, false);
  590.  
  591. if (EndNum > 0) EndNum -= elapsed;
  592.  
  593. EndTag.visible = true;
  594. if (_lives > 0) EndTag.text = "Ready in: " + Std.int(EndNum);
  595. else
  596. {
  597. EndTag.text = ("Waiting...");
  598. EndNum = 0;
  599. }
  600.  
  601.  
  602. if (EndNum <= 0 && isGameOver == false)
  603. {
  604. _lives -= 1;
  605. EndNum = 4;
  606. onLostLife();
  607. }
  608. }
  609.  
  610.  
  611. } else
  612. {
  613. EndNum = 0;
  614. EndTag.visible = false;
  615. EndTag.text = ("Waiting...");
  616.  
  617.  
  618. isGameOver = true;
  619. GameOver();
  620.  
  621. }
  622.  
  623.  
  624. }
  625. */
  626. //1 up
  627. while (_score >= _extralife)
  628. {
  629. FlxG.sound.play("RoundEnd",1);
  630. _score += 7;
  631. _extralife += 500;
  632. _lives++;
  633. }
  634.  
  635. if (_lives < 0) _liveDisplay.text = ("0");
  636.  
  637.  
  638. if (FlxG.keys.pressed.SPACE)
  639. {
  640. var pB = new Bullet(_bat.getMidpoint().x, _bat.getMidpoint().y);
  641. playerBullets.add(pB);
  642. }
  643.  
  644. if (FlxG.keys.justPressed.E)
  645. {
  646. var pB2 = new Ball(_ball.getMidpoint().x, _ball.getMidpoint().y);
  647. BallGroup.add(pB2);
  648. }
  649.  
  650.  
  651.  
  652.  
  653. if (FlxG.keys.justPressed.S)
  654. {
  655. _lives--;
  656. }
  657.  
  658.  
  659. super.update(elapsed);
  660.  
  661.  
  662.  
  663. }
  664.  
  665.  
  666.  
  667. public function ExtraLoss(life:FlxObject,impact:FlxObject):Void
  668. {
  669. if (Std.is(life, Ball))
  670. {
  671. life.kill();
  672. }
  673.  
  674.  
  675. }
  676.  
  677. private function FadeOut():Void
  678. {
  679. FlxG.switchState(new MenuState());
  680. }
  681.  
  682.  
  683. private function PowerBricks(Ba:Ball,B:PowerBrick):Void
  684. {
  685.  
  686. for (i in 0...3)
  687. {
  688. if (B.eType == i)
  689. {
  690. var B1 = new Ball(Ba.x + 16, Ba.y);
  691. BallGroup.add(B1);
  692. var B2 = new Ball(Ba.x - 16, Ba.y);
  693. BallGroup.add(B2);
  694. var B3 = new Ball(Ba.x, Ba.y + 16);
  695. BallGroup.add(B3);
  696.  
  697. B1.init();
  698. B2.init();
  699. B3.init();
  700. }
  701. }
  702.  
  703. B.kill();
  704.  
  705. }
  706.  
  707. private function scoreBricksShot(Shot:Bullet, B:Brick):Void
  708. {
  709.  
  710.  
  711.  
  712. if (B.alive && B.exists && Shot.alive && Shot.exists )
  713. {
  714. /*
  715. _sndCoin.play(true);
  716. _money++;
  717. _hud.updateHUD(_health, _money);
  718. */
  719. _score += 7;
  720.  
  721. Shot.kill();
  722. B.kill();
  723. }
  724. }
  725.  
  726. private function scoreBricks(Ba:Ball,B:Brick):Void
  727. {
  728. if (B.alive && B.exists)
  729. {
  730.  
  731. //Power Up Bricks
  732. if (B.isPower == 1 && B.eType == 1)
  733. {
  734. var B1 = new Ball(Ba.x + 16, Ba.y);
  735. BallGroup.add(B1);
  736. var B2 = new Ball(Ba.x - 16, Ba.y);
  737. BallGroup.add(B2);
  738. var B3 = new Ball(Ba.x, Ba.y + 16);
  739. BallGroup.add(B3);
  740.  
  741. B1.init();
  742. B2.init();
  743. B3.init();
  744. }
  745.  
  746.  
  747. /*
  748. _sndCoin.play(true);
  749. _money++;
  750. _hud.updateHUD(_health, _money);
  751. */
  752. _score += 7;
  753.  
  754. B.kill();
  755. }
  756. }
  757.  
  758.  
  759. private function leftHit(Tile:FlxObject, Particle:FlxObject):Void
  760. {
  761. removeTile(cast Tile);
  762. }
  763.  
  764. private function hit(Ball:FlxObject, Brick:FlxObject):Void
  765. {
  766. Brick.exists = false;
  767. }
  768.  
  769. private function removeTile(Tile:FlxTile):Void
  770. {
  771. //Screen.setTileByIndex(Tile.mapIndex, 0, true);
  772. Base.setTileByIndex(Tile.mapIndex, 0, true);
  773. }
  774.  
  775. private function ping(BatZ:Bat, BallZ:Ball):Void
  776. {
  777. FlxG.sound.play("Smack", 1, false);
  778.  
  779. var batmid:Int = Std.int(BatZ.x) + 20;
  780. var ballmid:Int = Std.int(BallZ.x) + 3;
  781. var diff:Int;
  782.  
  783. if (ballmid < batmid)
  784. {
  785. // Ball is on the left of the bat
  786. diff = batmid - ballmid;
  787. BallZ.velocity.x = ( -10 * diff);
  788. }
  789. else if (ballmid > batmid)
  790. {
  791. // Ball on the right of the bat
  792. diff = ballmid - batmid;
  793. BallZ.velocity.x = (10 * diff);
  794. }
  795. else
  796. {
  797. // Ball is perfectly in the middle
  798. // A little random X to stop it bouncing up!
  799. BallZ.velocity.x = 2 + FlxG.random.int(0, 8);
  800. }
  801. }
  802. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement