package coolbot;

import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;

import com.sun.opengl.util.texture.Texture;

import devUtil.TextureLoader;
import devUtil.Vector3;

import util.MP3;
import world.GameObject;

public class Explosion extends GameObject {
	
	private Vector3 position;
	
	private Texture surface;
	
	private double radius;
	
	private int time;
	
	public Explosion() {
		
	}
	
	public void update() {
		
		time--;
		radius++;
		
		if(time == 0)
			destroy();
	}
	
	public void setExplosion(Vector3 position, double radius, int time) {
		
		this.radius = radius;
		this.position = position;
		this.time = time;
		
		new MP3("/audio/FX/Grenade.mp3").play(1);
	}
	
	public void render(GL gl) {
		
		if(surface == null)
			surface = TextureLoader.getTexture("/visual/textures/Sun.jpg");

		surface.enable();
		surface.bind();

		gl.glTranslated(position.getX(), position.getY(), position.getZ());

		GLUquadric skybox = glu.gluNewQuadric();

		glu.gluQuadricTexture(skybox, true);
		glu.gluQuadricDrawStyle(skybox, GLU.GLU_FILL);
		glu.gluQuadricNormals(skybox, GLU.GLU_FLAT);
		glu.gluQuadricOrientation(skybox, GLU.GLU_OUTSIDE);

		final int slices = 16;
		final int stacks = 16;

		glu.gluSphere(skybox, radius, slices, stacks);
		glu.gluDeleteQuadric(skybox);
		
		gl.glTranslated(-position.getX(), -position.getY(), -position.getZ());

		surface.disable();
	}
}