Advertisement
JuiceBoxx

tile.hx

May 27th, 2016
1,756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.59 KB | None | 0 0
  1. package effects;
  2.  
  3. import flixel.FlxSprite;
  4. import flixel.system.FlxAssets.FlxGraphicAsset;
  5. import flixel.util.FlxColor;
  6. import flixel.tweens.FlxTween;
  7. import flixel.tweens.FlxEase;
  8. import flixel.math.FlxPoint;
  9. import registry.REG;
  10.  
  11. /**
  12.  * ...
  13.  * @author Justin Cruz
  14.  */
  15. class Tile extends FlxSprite{
  16.    
  17.     var floating:Bool = true;
  18.     var state:GameState;
  19.     var startPoint:FlxPoint;
  20.    
  21.     public var aY:Float = 4;
  22.  
  23.     public function new(?X:Float = 0, ?Y:Float = 0, State:GameState, ?Sprite:FlxSprite, ?Floating:Bool = true)
  24.     {
  25.         super(X, Y);
  26.        
  27.         floating = Floating;
  28.         state = State;
  29.        
  30.         if (Sprite != null)
  31.         {
  32.             loadGraphicFromSprite(Sprite);
  33.             angle = Sprite.angle;
  34.             x = Sprite.x;
  35.             y = Sprite.y;
  36.             alpha = Sprite.alpha;
  37.             alive = Sprite.alive;
  38.         }
  39.        
  40.         startPoint = new FlxPoint(x, y);
  41.        
  42.     }
  43.    
  44.     override public function update(e:Float)
  45.     {
  46.         super.update(e);
  47.        
  48.         if (y > startPoint.y + aY)
  49.         {
  50.             velocity.y = 0;
  51.             y = startPoint.y + aY;
  52.         }
  53.        
  54.         if (y < startPoint.y)
  55.         {
  56.             velocity.y = 0;
  57.             y = startPoint.y;
  58.         }
  59.        
  60.     }
  61.    
  62.     //Sink
  63.     public function startSink()
  64.     {
  65.         if (!alive)
  66.         {
  67.             FlxTween.manager.clear();
  68.             velocity.y = REG.sinkSpeed;
  69.             state.ripples.add(new Ripple(x - 48, y + 16, 2));
  70.             FlxTween.color(this, 1 - ((y - startPoint.y) / 8), color, FlxColor.fromRGB(242, 242, 242, 255));
  71.             alive = true;
  72.         }
  73.     }
  74.    
  75.     //Unskink
  76.     public function floatUp()
  77.     {
  78.         if (alive)
  79.         {
  80.             FlxTween.manager.clear();
  81.             velocity.y = -REG.sinkSpeed;
  82.             FlxTween.color(this,((y - startPoint.y) / 8), color, FlxColor.WHITE);
  83.             alive = false;
  84.         }
  85.     }
  86.    
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement