package finale;

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 finale.boss.Xyrux;

import util.MP3;
import world.GameObject;

public class Skybox extends GameObject {
	
	Texture sky;
	
	double rotation;
	float gold;
	
	MP3 music;
	
	public Skybox() {
		sky = TextureLoader.getTexture("/visual/textures/Space.png");
	}
	
	int time = 0;
	
	public void update() {
		
		time += 2;
		
		if(time > 3000) {
			
			//rotation += .1;
			
			gold += .001;
			
			if(gold > 1)
				gold = 1;
		}
		
		if(time == 4000) {
			
			spawn.add(new Xyrux());
			
			music = new MP3("/audio/BGM/Dragon Slayer.mp3");
			music.play();
		}
	}
	
	public void render(GL gl) {
		
		if(gold > 0)
			gl.glColor3f(1, (float) (.5 - gold / 2), 1 - gold);
		
		gl.glRotated(rotation, 0, 1, 0);
		
		sky.enable();
		sky.bind();
		
		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 float radius = 12500f;
		final int slices = 16;
		final int stacks = 16;
		
		glu.gluSphere(skybox, radius, slices, stacks);
		glu.gluDeleteQuadric(skybox);
		
		sky.disable();
		
		gl.glRotated(rotation, 0, -1, 0);
		gl.glColor3f(1, 1, 1);
	}
	
	public void onEnd() {
		music.stop();
	}
}