package edu.wisc.cs.games10.chrononaut;

import processing.core.*;

public class EquippedItem extends SimpleMovable {
	
	PImage imageToDraw;
	boolean playerFacingRight;
	Vector2D offset;

	public EquippedItem(Player p, PApplet canvas, PImage image, Vector2D Offset) {
		imageToDraw = image; //canvas.loadImage("player/taser/test_taser.png"); /* CHANGE THIS */
		tileHeight = imageToDraw.height / 32.0f;
		tileWidth = imageToDraw.width / 32.0f;
		offset = Offset;
		move(p);
		vel = new Vector2D(0, 0);
	}
	
	public void move(Player p) {
		// create extractor relative to player 'p' position
		loc = p.loc.copy();
		if (p.faceRight)
			loc.x += p.getTileWidth() - offset.x;//.2f;
		else
			loc.x -= tileWidth - offset.x;//.2f;
		
		loc.y += (p.tileHeight - tileHeight) - offset.y; //1.2f;
	}

	public void kill() {
		// TODO Auto-generated method stub
	}
	
	public void render(PApplet canvas) {
		canvas.pushMatrix();
					
			int firstVertexTexCoord;
			int secondVertexTexCoord;
			int thirdVertexTexCoord;
			int fourthVertexTexCoord;

			if(playerFacingRight) {
				firstVertexTexCoord = 0;
				secondVertexTexCoord = imageToDraw.width;
				thirdVertexTexCoord = imageToDraw.width;
				fourthVertexTexCoord = 0;
			} else {
				firstVertexTexCoord = imageToDraw.width;
				secondVertexTexCoord = 0;
				thirdVertexTexCoord = 0;
				fourthVertexTexCoord = imageToDraw.width;
			}

			
			canvas.translate(loc.x, loc.y);
			
			canvas.beginShape(PConstants.QUADS);
				canvas.texture(imageToDraw);
				canvas.vertex(0, 0, firstVertexTexCoord, 0);
				canvas.vertex(tileWidth, 0, secondVertexTexCoord,0);
				canvas.vertex(tileWidth, tileHeight, thirdVertexTexCoord, 40);
				canvas.vertex(0, tileHeight, fourthVertexTexCoord, 40);
			canvas.endShape();
		
		canvas.popMatrix();
	}
	
	
}
