package coolbot;

import java.awt.event.KeyEvent;

import javax.media.opengl.GL;

import object.Model;

import world.GameObject;

public class Rocket extends GameObject {
	
	Model rocket;
	
	double height;
	
	public Rocket() {
		
		rocket = new Model();
		
		rocket.setMode(true, false);
		rocket.parseObjectFile(ClassLoader.getSystemResourceAsStream(
						"visual/models/Rocket.obj"));

		rocket.setPosition(2500, 0, 2500);
		rocket.setRotation(-90, 0, 0);
		rocket.setSize(1000, 1000, 2000);
		
		rocket.setColor(0, 0, 1);
	}
	
	public void update() {
		
		if(Math.sqrt(Math.pow(rocket.getXPosition() - camera.getXPosition(), 2) +
				Math.pow(rocket.getZPosition() - camera.getZPosition(), 2)) < 300)
			
			for(int i = 0; i < input.getKeysDown().size(); i++)
				
				if(input.getKeysDown().get(i) == KeyEvent.VK_SPACE) {
					
					triggeredGameState = "Level, Space";
					endScene();
				}
		
		rocket.setYPosition((float) height);
	}
	
	public void render(GL gl) {
		rocket.render(gl);
	}
	
	public void interact(GameObject object) {
		
		 if(object instanceof Map) {
			 
			 height = ((Map) object).getHeightAt(2500, 2500) + 1000;
		 }
	}
}