package finale;

import javax.media.opengl.GL;

import devUtil.Vector3;

import object.Model;
import util.MP3;
import world.GameObject;

public class Gun extends GameObject {
	
	Model gun;
	
	public Gun() {
		
		gun = new Model();
		
		gun.setMode(true, false);
		gun.parseObjectFile(ClassLoader.getSystemResourceAsStream(
						"visual/models/AK-74M.obj"));
		
		gun.setSize(20, 100, 70);
		gun.setXRotation(-90);
		gun.setColor(.25f, .25f, .25f);
		
		gun.setPosition(100, -500, 100);
		
		new MP3("/audio/FX/Bell.mp3").play(2);
	}
	
	public void update() {
		
		if(gun.getYPosition() < 50)
			gun.setYPosition(gun.getYPosition() + 1);
		
		gun.setZRotation(gun.getZRotation() + .25f);
	}
	
	public void render(GL gl) {
		gun.render(gl);
	}
	
	public void interact(GameObject object) {
		
		if(object instanceof Player) {
			
			Vector3 space = gun.getPosition();
			space.subtract(camera.getPosition());
			
			if(space.getMagnitude() <= 50) {
				
				((Player) object).equip("Gun");
				new MP3("/audio/FX/Gun Load.mp3").play(1);
				
				destroy();
			}
		}
	}
}