Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. package com.isartdigital.shmup.ui.hud
  2. {
  3. import com.isartdigital.shmup.controller.Controller;
  4. import com.isartdigital.utils.Config;
  5. import com.isartdigital.utils.ui.Screen;
  6. import com.isartdigital.shmup.ui.UIManager;
  7. import com.isartdigital.utils.ui.UIPosition;
  8. import flash.display.Sprite;
  9. import flash.events.Event;
  10. import flash.display.DisplayObject;
  11. import flash.text.TextField;
  12. import com.isartdigital.shmup.game.GameManager;
  13. /**
  14. * Classe en charge de gérer les informations du Hud
  15. * @author Mathieu ANTHOINE
  16. */
  17. public class Hud extends Screen
  18. {
  19.  
  20. /**
  21. * instance unique de la classe Hud
  22. */
  23. protected static var instance: Hud;
  24.  
  25. public var mcTopLeft:Sprite;
  26. public var mcTopCenter:Sprite;
  27. public var mcTopRight:Sprite;
  28. public var mcBottomRight:Sprite;
  29. public var SPbar = DisplayObject;
  30. public var bar = DisplayObject;
  31. public var HUDscore:TextField;
  32. protected var life0;
  33. protected var life1;
  34. protected var life2;
  35. protected var life3;
  36. protected var life4;
  37. protected var bomb0;
  38. protected var bomb1;
  39. protected var bomb2;
  40. protected var bomb3;
  41. protected var bomb4;
  42. protected var mcBar;
  43. public function Hud()
  44. {
  45. super();
  46. addEventListener(Event.ADDED_TO_STAGE, Init);
  47. if (!Config.debug && Controller.type != Controller.TOUCH) {
  48. removeChild(mcBottomRight);
  49. mcBottomRight = null;
  50. }
  51. }
  52.  
  53. /**
  54. * Retourne l'instance unique de la classe, et la crée si elle n'existait pas au préalable
  55. * @return instance unique
  56. */
  57. public static function getInstance (): Hud {
  58. if (instance == null) instance = new Hud();
  59. return instance;
  60. }
  61.  
  62. /**
  63. * repositionne les éléments du Hud
  64. * @param pEvent
  65. */
  66. override protected function onResize (pEvent:Event=null): void {
  67. UIManager.getInstance().setPosition(mcTopLeft, UIPosition.TOP_LEFT);
  68. UIManager.getInstance().setPosition(mcTopCenter, UIPosition.TOP);
  69. UIManager.getInstance().setPosition(mcTopRight, UIPosition.TOP_RIGHT);
  70. if (mcBottomRight!=null) UIManager.getInstance().setPosition(mcBottomRight, UIPosition.BOTTOM_RIGHT);
  71. }
  72. /**
  73. * Ajoute, graphiquement, une vie(Change alpha des MovieClips)
  74. */
  75. public function addLife() : void {
  76. if (life0.alpha < 1) life0.alpha = 1;
  77. else if (life1.alpha < 1) life1.alpha = 1;
  78. else if (life2.alpha < 1) life2.alpha = 1;
  79. else if (life3.alpha < 1) life3.alpha = 1;
  80. else if (life4.alpha < 1) life4.alpha = 1;
  81. }
  82.  
  83. /**
  84. * Ajoute, graphiquement, une Bombe(Change alpha des MovieClips)
  85. */
  86. public function addBomb() : void {
  87. if (bomb0.alpha < 1) bomb0.alpha = 1;
  88. else if (bomb1.alpha < 1) bomb1.alpha = 1;
  89. else if (bomb2.alpha < 1) bomb2.alpha = 1;
  90. else if (bomb3.alpha < 1) bomb3.alpha = 1;
  91. }
  92.  
  93. /**
  94. * Enleve, graphiquement, une vie(Change alpha des MovieClips)
  95. */
  96. public function removeLife() : void {
  97. if (life4.alpha == 1) life4.alpha = 0.5;
  98. else if (life3.alpha == 1) life3.alpha = 0.5;
  99. else if (life2.alpha == 1) life2.alpha = 0.5;
  100. else if (life1.alpha == 1) life1.alpha = 0.5;
  101. else if (life0.alpha == 1) life0.alpha = 0.5;
  102. }
  103.  
  104. /**
  105. * Enleve, graphiquement, une Bombe(Change alpha des MovieClips)
  106. */
  107. public function removeBomb() : void {
  108. if (bomb3.alpha == 1) bomb3.alpha = 0.5;
  109. else if (bomb2.alpha == 1) bomb2.alpha = 0.5;
  110. else if (bomb1.alpha == 1) bomb1.alpha = 0.5;
  111. else if (bomb0.alpha == 1) bomb0.alpha = 0.5;
  112. }
  113. public function increaseSpecial():void {
  114. bar.x += 30;
  115. }
  116. public function decreaseSpecial():void {
  117. bar.x -= 300;
  118. }
  119. protected function Init(e:Event):void {
  120. HUDscore = TextField(mcTopCenter.getChildByName("txtScore"));
  121. life0 = mcTopRight.getChildByName("mcLife0");
  122. life1 = mcTopRight.getChildByName("mcLife1");
  123. life2 = mcTopRight.getChildByName("mcLife2");
  124. life3 = mcTopRight.getChildByName("mcLife3");
  125. life4 = mcTopRight.getChildByName("mcLife4");
  126. bomb0 = mcTopLeft.getChildByName("mcBomb0");
  127. bomb1 = mcTopLeft.getChildByName("mcBomb1");
  128. bomb2 = mcTopLeft.getChildByName("mcBomb2");
  129. bomb3 = mcTopLeft.getChildByName("mcBomb3");
  130. bomb4 = mcTopLeft.getChildByName("mcBomb4");
  131. SPbar = mcTopLeft.getChildByName("mcSpecialBar");
  132. bar = SPbar.getChildByName("mcBar");
  133. }
  134. /**
  135. * détruit l'instance unique et met sa référence interne à null
  136. */
  137. override public function destroy (): void {
  138. instance = null;
  139. super.destroy();
  140. }
  141.  
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement