package edu.wisc.cs.games10.chrononaut;

import processing.core.*;

public class Bullet extends SimpleMovable {
	
	PImage image;
	float timeLeft;		// in milliseconds
	int width;			// in pixels
	int height;			// in pixels
	
	public Bullet(float lifetime, Vector2D l, Vector2D initialVel, int w, int h) {
		timeLeft = lifetime;
		loc = l;
		vel = initialVel;
		width = w;
		height = h;
		tileWidth = ((float)width/32);
		tileHeight = ((float)height/32);
	}
	
	public Bullet(float lifetime, Vector2D l, Vector2D initialVel, PImage pic) {
		timeLeft = lifetime;
		loc = l;
		image = pic;
		width = pic.width;
		height = pic.height;
		vel = initialVel;
		tileWidth = ((float)width/32);
		tileHeight = ((float)height/32);
	}
	
	public void moveBulletTo(Vector2D l) {
		loc = l;
	}
	
	public float getTimeLeft() {
		return timeLeft;
	}

	public float getTileHeight() {
		return tileHeight;
	}

	public float getTileWidth() {
		return tileWidth;
	}

	public void update(float time) {
		timeLeft-=time;
		loc.x += vel.x;
		loc.y += vel.y;
	}
	
	public void kill() {
		timeLeft = 0;
	}
	
	public void render(PApplet canvas) {
		if(image != null) {
			canvas.pushMatrix();
			canvas.translate(loc.x, loc.y);
			canvas.beginShape(PConstants.QUADS);
				canvas.texture(image);
				canvas.vertex(0, 0, 0, 0);
				canvas.vertex(tileWidth, 0, width,0);
				canvas.vertex(tileWidth, tileHeight, width,height);
				canvas.vertex(0, tileHeight, 0,height);
			canvas.endShape();
			canvas.popMatrix();
		}
	}
	
}
