/Flash project/src/com/danta/radialFortress/components/ShieldMeter.as

https://github.com/just-granada/RadialFortress
ActionScript | 137 lines | 46 code | 21 blank | 70 comment | 3 complexity | 6f42c0459a5db5ee7c0958f43d1956b1 MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Zemoga Inc
  4. // Copyright 2011 Zemoga Inc
  5. // All Rights Reserved.
  6. //
  7. ////////////////////////////////////////////////////////////////////////////////
  8. package com.danta.radialFortress.components
  9. {
  10. import flash.display.Sprite;
  11. /**
  12. * Class description here
  13. *
  14. * @author camilosoto <email>
  15. */
  16. public class ShieldMeter extends Sprite
  17. {
  18. //------------------------------------------------------------------------------
  19. //
  20. // Constants
  21. //
  22. //------------------------------------------------------------------------------
  23. //--------------------------------------
  24. // Public
  25. //--------------------------------------
  26. //--------------------------------------
  27. // Private
  28. //--------------------------------------
  29. //------------------------------------------------------------------------------
  30. //
  31. // Static Methods
  32. //
  33. //------------------------------------------------------------------------------
  34. ////////////////////////////////////////////////////////////////////////////////
  35. //
  36. // Constructor
  37. //
  38. ////////////////////////////////////////////////////////////////////////////////
  39. public function ShieldMeter()
  40. {
  41. shieldLabel=new ShieldLabel();
  42. this.addChild(shieldLabel);
  43. piecesContainer = new Sprite();
  44. piecesContainer.x = shieldLabel.width+10;
  45. this.addChild(piecesContainer);
  46. createPieces();
  47. }
  48. //------------------------------------------------------------------------------
  49. //
  50. // Variables
  51. //
  52. //------------------------------------------------------------------------------
  53. private var shieldLabel:ShieldLabel;
  54. private var piecesContainer:Sprite;
  55. private var pieces:Array;
  56. //--------------------------------------
  57. // Public
  58. //--------------------------------------
  59. //--------------------------------------
  60. // Private
  61. //--------------------------------------
  62. //------------------------------------------------------------------------------
  63. //
  64. // Properties (getters/setters)
  65. //
  66. //------------------------------------------------------------------------------
  67. //------------------------------------------------------------------------------
  68. //
  69. // Overriden methods
  70. //
  71. //------------------------------------------------------------------------------
  72. //------------------------------------------------------------------------------
  73. //
  74. // Methods
  75. //
  76. //------------------------------------------------------------------------------
  77. //--------------------------------------
  78. // Public
  79. //--------------------------------------
  80. public function setHealth(health:int):void
  81. {
  82. for(var i:int=0; i<Ship.MAX_HEALTH;i++)
  83. {
  84. if(i<health)
  85. {
  86. pieces[i].visible=true;
  87. }
  88. else
  89. {
  90. pieces[i].visible=false;
  91. }
  92. }
  93. }
  94. //--------------------------------------
  95. // Private
  96. //--------------------------------------
  97. private function createPieces():void
  98. {
  99. pieces=[];
  100. var piece:ShieldPiece;
  101. for(var i:int=0; i<Ship.MAX_HEALTH;i++)
  102. {
  103. piece=new ShieldPiece();
  104. piece.x=i*(piece.width-5);
  105. piece.y=5;
  106. piecesContainer.addChild(piece);
  107. pieces.push(piece);
  108. }
  109. }
  110. //------------------------------------------------------------------------------
  111. //
  112. // Event Handlers
  113. //
  114. //------------------------------------------------------------------------------
  115. }
  116. }