package com.hexabeast.lasermonster;

import com.badlogic.gdx.graphics.Texture;

public class Button {

	float x;
	float y;
	float w;
	float h;
	
	Texture tex;
	float alpha = 1;
	
	boolean fadeout = false;
	
	public Button(int x,int y,Texture tex)
	{
		this.x = x;
		this.y = y;
		w = tex.getWidth();
		h = tex.getHeight();
		
		this.tex = tex;
	}
	
	public boolean isTouched()
	{
		if(Inputs.instance.mousedown && contained(GameScreen.getAbsolutePos().x, x, x+w) && contained(GameScreen.getAbsolutePos().y, y, y+h))
		{
			return true;
		}
		return false;
	}
	
	public boolean contained(float x, float y, float z)
	{
		if(x<=z && x>= y)return true;
		return false;
	}
	
	public void draw(boolean transparent)
	{
		
		;
		
		if(fadeout)alpha-=Main.delta;
		
		if(alpha>0)
		{
			float a = alpha;
			if(transparent)a/=2;
			
			GameScreen.batch.setColor(1, 1, 1, a);
			
			GameScreen.batch.draw(tex, x, y);
			
			GameScreen.batch.setColor(1, 1, 1, 1);
		}
		else alpha = 0;
		
	}
	
}
