package edu.wisc.cs.games10.chrononaut;

import processing.core.*;

public class Taser extends SimpleMovable {
	
	boolean playerFacingRight;

	public Taser(Player p, PApplet canvas) {
		imageToDraw = canvas.loadImage("player/taser/test_taser.png");
		tileHeight = imageToDraw.height / 32.0f;
		tileWidth = imageToDraw.width / 32.0f;
		
		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() - .2f;
		else
			loc.x -= tileWidth - .2f;
		
		loc.y += (p.tileHeight - tileHeight) - 1.2f;
	}

	public void kill() {
		// TODO Auto-generated method stub
	}
	
	public void render(PApplet canvas) {
		canvas.pushMatrix();
		
			/*
			canvas.beginShape(PConstants.QUADS);
				canvas.texture(lower);
				canvas.vertex(0, 0, 0, 0);
				canvas.vertex(1, 0, 32,0);
				canvas.vertex(1, 1, 32,32);
				canvas.vertex(0, 1, 0,32);
			canvas.endShape();
			*/
			
			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();
	}
	
	private PImage imageToDraw;
}
