package edu.stuy.starlorn.entities;

import edu.stuy.starlorn.upgrades.GunUpgrade;

import java.io.IOException;
import java.util.LinkedList;

import org.lwjgl.input.Keyboard;

public class Ship extends Entity {
    protected LinkedList<GunUpgrade> _gunupgrades;
    protected int _baseDamage, _baseShotSpeed, _health, _fullCooldown, _cooldown, _cooldownRate;
    protected double _baseAim;

    public Ship() {
        super();
        _gunupgrades = new LinkedList<GunUpgrade>();
        _baseDamage = 1;
        _baseShotSpeed = 1;
        _health = 10;
        _baseAim = 0; //Aim up by default
        _cooldown = 10;
        _fullCooldown = _cooldown+1;
        _cooldownRate = 1;
		try {
			_texture = TextureLoader.getTexture("PNG",
					ResourceLoader.getResourceAsStream("res/spaceship.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
    }

	public void draw() {
		render();
	}

	public void render() {
		int x = 1;
		int y = 2;
		if (Keyboard.isKeyDown(KEYBOARD.KEY_UP)){
			y = 1;
			_ycor--;
		}
		if (Keyboard.isKeyDown(KEYBOARD.KEY_RIGHT)){
			x = 2;
			_ycor++;
		}
		if (Keyboard.isKeyDown(KEYBOARD.KEY_DOWN)){
			y = 0;
			_ycor++;
		}
		if (Keyboard.isKeyDown(KEYBOARD.KEY_LEFT)){
			x = 0;
			_xcor--;
		}
		
	}

	public void ihopethisworks(int tx, int ty) {
		Color.white.bind();

		_texture.bind();

		GL11.glBegin(GL11.GL_QUADS);
		GL11.glTexCoord2d(tx * 0.078125, ty * 0.078125);
		GL11.glVertex2d(_xcor, y);
		GL11.glTexCoord2d((tx + 1) * 0.078125, ty * 0.078125);
		GL11.glVertex2d(_xcor + 64, _ycor);
		GL11.glTexCoord2d((tx + 1) * 0.078125, (ty + 1) * 0.078125);
		GL11.glVertex2d(_xcor + 64, _ycor + 64);
		GL11.glTexCoord2d(tx * 0.078125, (ty + 1) * 0.078125);
		GL11.glVertex2d(_xcor, _ycor + 64);
		GL11.glEnd();
	}

    public void addUpgrade(GunUpgrade upgrade) {
        _gunupgrades.add(upgrade);
    }

    @Override
    public void step() {
        //Only cooldown if we're below the rate, otherwise the ship hasn't tried to shoot
        if (_fullCooldown <= _cooldown) {
            if (_fullCooldown < 0) {
                this.shoot();
                _fullCooldown = _cooldown+1;
            } else {
                _fullCooldown -= _cooldownRate;
            }
        }
        super.step();
    }

    /*
     * Create the shots based on the available GunUpgrades
     */
    public void shoot() {
        GunUpgrade topShot = _gunupgrades.get(0);
        int damage = _baseDamage;
        int shotSpeed = _baseShotSpeed;
        for (GunUpgrade up : _gunupgrades) {
            if (up.getNumShots() > topShot.getNumShots())
                topShot = up;
            damage = up.getDamage(damage);
            shotSpeed = up.getShotSpeed(shotSpeed);
        }
        // Create new shots, based on dem vars
        int numShots = topShot.getNumShots();
        for (int i = 0; i < numShots; i++) {
            Bullet b = new Bullet(_baseAim + topShot.getAimAngle(), damage, shotSpeed);
            b.setWorld(this.getWorld());
        }
    }
}

@@ -169,16 +169,47 @@
 board;%0A%0A
+import org.lwjgl.opengl.GL11;%0A%0A
 public c
@@ -413,16 +413,50 @@
 baseAim;
+%0A    //protected Texture _texture;
 %0A%0A    pu
@@ -744,16 +744,27 @@
 te = 1;%0A
+        /*%0A
 %09%09try %7B%0A
@@ -928,16 +928,27 @@
 ();%0A%09%09%7D%0A
+        */%0A
     %7D%0A%0A%09
@@ -1056,31 +1056,31 @@
 .isKeyDown(K
-EYBOARD
+eyboard
 .KEY_UP))%7B%0A%09
@@ -1126,31 +1126,31 @@
 .isKeyDown(K
-EYBOARD
+eyboard
 .KEY_RIGHT))
@@ -1199,31 +1199,31 @@
 .isKeyDown(K
-EYBOARD
+eyboard
 .KEY_DOWN))%7B
@@ -1279,15 +1279,15 @@
 wn(K
-EYBOARD
+eyboard
 .KEY
@@ -1324,24 +1324,31 @@
 %0A%09%09%7D%0A%09%09%0A%09%7D%0A%0A
+    /*%0A
 %09public void
@@ -1849,16 +1849,23 @@
 nd();%0A%09%7D
+%0A    */
 %0A%0A    pu

Fix the build, textures need to work