package player;

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

import animations.PlayerAnimations;
import engine.Game;
import utils.Utils;

/**  ------------- Nihilne ------------
    *** @author Mitch Weaver - 2016 ***
      ~~~~ All Rights Reserved ~~~~ */

public final class PlayerDeath {
	
	private static int DEATH_ANIMATION_DELAY;
	public static boolean RUNNING;
	
	public static final void START() {
		RUNNING = true;
		final int seconds = 60;
		DEATH_ANIMATION_DELAY = seconds * 5;
	}
	
	public static void tick() {
		PlayerAnimations.deaths[Player.facing - 1].playAnimationOnce();
		if(--DEATH_ANIMATION_DELAY < 0) END_DEATH();
	}
	
	private static Graphics2D copy; private static final AffineTransform transform = new AffineTransform();
	public static void render(final Graphics2D g2d) {
		transform.setToRotation(-Utils._45 * (Game.rotation - 1), Player.center.x, Player.center.y); copy = (Graphics2D) g2d.create(); copy.transform(transform);
		PlayerAnimations.deaths[Player.facing - 1].drawAnimation(copy, Player.pos.x - Player.width/2, Player.pos.y - Player.height/2);
		copy.dispose(); copy = null;
	}
	
	private static final void END_DEATH()  {
		RUNNING = false;
		//display message, delete save, etc etc.
		System.out.println("YOU DIED!");
	}
	
}
