package MapItem;

import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.jln.ld.GameEntity;
import com.jln.ld.Shared;

import menus.GameMenu;

public class Powerup implements GameEntity{

	private float x, y;
	private int type;
	private boolean destroy = false;
	private TextureRegion region;
	
	public static final int POWERUP_INCREASESHOOT = 0;
	public static final int POWERUP_SHIELD = 2;
	public static final int POWERUP_50 = 3;
	public static final int POWERUP_100 = 4;
	
	public Powerup(float x, float y, int type, GameMenu game){
		if(type == POWERUP_INCREASESHOOT){
			// Pour eviter d'avoir trop de shoot trop tot
			int nbUp = game.getHunter01().getShootLevel()+game.getHunter02().getShootLevel()+game.getSupplyShip().getShootLevel();
			if( (game.getTimer()/35) > (nbUp+1)){
				type = POWERUP_100;
			}
		}
		this.type = type;
		this.x = x;
		this.y = y;
		destroy = false;
		if(type == POWERUP_INCREASESHOOT){
			region = Shared.POWERUP[0][0];
		}else if(type == POWERUP_SHIELD){
			region = Shared.POWERUP[1][0];
		}else if(type == POWERUP_50){
			region = Shared.POWERUP[2][0];
		}else if(type == POWERUP_100){
			region = Shared.POWERUP[2][1];
		}
	}
	
	@Override
	public void update(GameMenu game) {
		if(x<-16){
			destroy = true;
		}else{
			x-=0.5f;
			if(game.getHunter01().onItemContact(game, this)){
				destroy = true;
			}else if(game.getHunter02().onItemContact(game, this)){
				destroy = true;
			}else if(game.getSupplyShip().onItemContact(game, this)){
				destroy = true;
			}
		}
		
	}

	@Override
	public void render(GameMenu game) {
		if(!destroy){
			Shared.GAME_BATCH.draw(region, x-8+Shared.DECAL_X, y-8+Shared.DECAL_Y);
		}
		
	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	public int getType() {
		return type;
	}

	public boolean isDestroy() {
		return destroy;
	}
	
	

}
