Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.isartdigital.shmup.ui.hud
- {
- import com.isartdigital.shmup.controller.Controller;
- import com.isartdigital.utils.Config;
- import com.isartdigital.utils.ui.Screen;
- import com.isartdigital.shmup.ui.UIManager;
- import com.isartdigital.utils.ui.UIPosition;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.display.DisplayObject;
- import flash.text.TextField;
- import com.isartdigital.shmup.game.GameManager;
- /**
- * Classe en charge de gérer les informations du Hud
- * @author Mathieu ANTHOINE
- */
- public class Hud extends Screen
- {
- /**
- * instance unique de la classe Hud
- */
- protected static var instance: Hud;
- public var mcTopLeft:Sprite;
- public var mcTopCenter:Sprite;
- public var mcTopRight:Sprite;
- public var mcBottomRight:Sprite;
- public var SPbar = DisplayObject;
- public var bar = DisplayObject;
- public var HUDscore:TextField;
- protected var life0;
- protected var life1;
- protected var life2;
- protected var life3;
- protected var life4;
- protected var bomb0;
- protected var bomb1;
- protected var bomb2;
- protected var bomb3;
- protected var bomb4;
- protected var mcBar;
- public function Hud()
- {
- super();
- addEventListener(Event.ADDED_TO_STAGE, Init);
- if (!Config.debug && Controller.type != Controller.TOUCH) {
- removeChild(mcBottomRight);
- mcBottomRight = null;
- }
- }
- /**
- * Retourne l'instance unique de la classe, et la crée si elle n'existait pas au préalable
- * @return instance unique
- */
- public static function getInstance (): Hud {
- if (instance == null) instance = new Hud();
- return instance;
- }
- /**
- * repositionne les éléments du Hud
- * @param pEvent
- */
- override protected function onResize (pEvent:Event=null): void {
- UIManager.getInstance().setPosition(mcTopLeft, UIPosition.TOP_LEFT);
- UIManager.getInstance().setPosition(mcTopCenter, UIPosition.TOP);
- UIManager.getInstance().setPosition(mcTopRight, UIPosition.TOP_RIGHT);
- if (mcBottomRight!=null) UIManager.getInstance().setPosition(mcBottomRight, UIPosition.BOTTOM_RIGHT);
- }
- /**
- * Ajoute, graphiquement, une vie(Change alpha des MovieClips)
- */
- public function addLife() : void {
- if (life0.alpha < 1) life0.alpha = 1;
- else if (life1.alpha < 1) life1.alpha = 1;
- else if (life2.alpha < 1) life2.alpha = 1;
- else if (life3.alpha < 1) life3.alpha = 1;
- else if (life4.alpha < 1) life4.alpha = 1;
- }
- /**
- * Ajoute, graphiquement, une Bombe(Change alpha des MovieClips)
- */
- public function addBomb() : void {
- if (bomb0.alpha < 1) bomb0.alpha = 1;
- else if (bomb1.alpha < 1) bomb1.alpha = 1;
- else if (bomb2.alpha < 1) bomb2.alpha = 1;
- else if (bomb3.alpha < 1) bomb3.alpha = 1;
- }
- /**
- * Enleve, graphiquement, une vie(Change alpha des MovieClips)
- */
- public function removeLife() : void {
- if (life4.alpha == 1) life4.alpha = 0.5;
- else if (life3.alpha == 1) life3.alpha = 0.5;
- else if (life2.alpha == 1) life2.alpha = 0.5;
- else if (life1.alpha == 1) life1.alpha = 0.5;
- else if (life0.alpha == 1) life0.alpha = 0.5;
- }
- /**
- * Enleve, graphiquement, une Bombe(Change alpha des MovieClips)
- */
- public function removeBomb() : void {
- if (bomb3.alpha == 1) bomb3.alpha = 0.5;
- else if (bomb2.alpha == 1) bomb2.alpha = 0.5;
- else if (bomb1.alpha == 1) bomb1.alpha = 0.5;
- else if (bomb0.alpha == 1) bomb0.alpha = 0.5;
- }
- public function increaseSpecial():void {
- bar.x += 30;
- }
- public function decreaseSpecial():void {
- bar.x -= 300;
- }
- protected function Init(e:Event):void {
- HUDscore = TextField(mcTopCenter.getChildByName("txtScore"));
- life0 = mcTopRight.getChildByName("mcLife0");
- life1 = mcTopRight.getChildByName("mcLife1");
- life2 = mcTopRight.getChildByName("mcLife2");
- life3 = mcTopRight.getChildByName("mcLife3");
- life4 = mcTopRight.getChildByName("mcLife4");
- bomb0 = mcTopLeft.getChildByName("mcBomb0");
- bomb1 = mcTopLeft.getChildByName("mcBomb1");
- bomb2 = mcTopLeft.getChildByName("mcBomb2");
- bomb3 = mcTopLeft.getChildByName("mcBomb3");
- bomb4 = mcTopLeft.getChildByName("mcBomb4");
- SPbar = mcTopLeft.getChildByName("mcSpecialBar");
- bar = SPbar.getChildByName("mcBar");
- }
- /**
- * détruit l'instance unique et met sa référence interne à null
- */
- override public function destroy (): void {
- instance = null;
- super.destroy();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement