package ;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import flixel.*;
import openfl.Assets;
import flixel.group.*;
import flixel.util.FlxTimer;
import flixel.util.FlxRandom;
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;

class Timer extends flixel.group.FlxGroup
{	
	public inline static var HEIGHT = 120;
	var itemBoxes:FlxGroup = new FlxGroup();
	var time:Float;
	var timer:FlxTimer;
	var text:FlxText;
	private var player:Player;

    public function new(X:Int=0, Y:Int=0, time:Float, _player:Player)
    {
    	super();
    	player = _player;

    	var fill = new FlxSprite( player.x, player.startY + 4 );
    	fill.loadGraphic(Reg.assets_dir + "player_load_fill.png");
    	add(fill);

    	var outline = new FlxSprite( player.x, player.startY + 4 );
    	outline.loadGraphic(Reg.assets_dir + "player_load_mask.png");
    	add(outline);

    	fill.origin.y = fill.height;
    	fill.scale.y = 0.0;
    	FlxTween.tween(fill.scale, { y:1 }, time, { ease: FlxEase.quadOut, complete: timerComplete });

		// timer = new FlxTimer(time, timerComplete);

		// text = new FlxText(X, Y + 40, 500); // x, y, width
		// text.text = "" + time;
		// text.setFormat("assets/GOTHIC.TTF", 40, 0x5b103c, "center");
		// add(text);


	}

	override public function update():Void 
	{		
		//text.text = "" + Math.round(timer.timeLeft);

		super.update();
	}

	private function timerComplete(tween:FlxTween) 
	{		
		player.revive();
		this.destroy();
	}	
}