Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.64 KB | None | 0 0
  1. package;
  2. import flixel.FlxG;
  3. import flixel.FlxSprite;
  4. import flixel.math.FlxPoint;
  5. import flixel.util.FlxColor;
  6. import states.StateGameplay;
  7.  
  8. /**
  9.  * ...
  10.  * @author ORL
  11.  */
  12. class Light extends FlxSprite
  13. {
  14.     private var _follow:FlxSprite;
  15.     public var enabled:Bool;
  16.     public var switchable:Bool = false;
  17.     public var _scale:Float = 1;
  18.  
  19.  
  20.     public function new(x:Float, y:Float, ?img:String, ?follow:FlxSprite, ?Switchable:Bool = false, ?Scale:Float = 1)
  21.     {
  22.         super(x, y);
  23.        
  24.        
  25.        
  26.         _follow = follow;
  27.         switchable = Switchable;
  28.         _scale = Scale;
  29.        
  30.         loadGraphic(img);
  31.  
  32.         this.blend = openfl.display.BlendMode.SCREEN;
  33.         antialiasing = false;
  34.        
  35.         width = width *LightManager.RESOLUTION;
  36.         height = height * LightManager.RESOLUTION;
  37.        
  38.         scale.x =   scale.x /2* Scale;
  39.         scale.y = scale.y / 2*Scale;
  40.        
  41.         centerOffsets();
  42.     }
  43.  
  44.     public function getXY():FlxPoint
  45.     {
  46.         if (_follow != null)
  47.         {
  48.             var pscreenXY:FlxPoint = _follow.getScreenPosition();
  49.            
  50.             return new FlxPoint(pscreenXY.x - width / 2  + _follow.width / 2, pscreenXY.y - height / 2  + _follow.height / 2);
  51.         }
  52.         else
  53.         {
  54.             return getScreenPosition();
  55.         }
  56.     }
  57.    
  58.     override public function update(elapsed:Float):Void
  59.     {
  60.         super.update(elapsed);
  61.            
  62.         //enabled = _follow.isOnScreen();
  63.    
  64.        
  65.         enabled = false;
  66.         if ( Utils.getDistance(StateGameplay.instance.player.getMidpoint(), _follow.getMidpoint()) <= 900)
  67.         {
  68.             enabled = true;
  69.         }  
  70.        
  71.         if (!switchable)
  72.         enabled = true;
  73.        
  74.         if(switchable)
  75.         if (FlxG.keys.justPressed.M)
  76.         {
  77.             alive = !alive;
  78.         }
  79.  
  80.         alpha = StateGameplay.instance.darkness.alpha*1.4;//1.8
  81.         //alpha = 1;//1.8
  82.     }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement