class Renderer {
	constructor(spriteX, spriteY, canvasX, canvasY, rotation=0) {
		this.spriteX = spriteX
		this.spriteY = spriteY
		this.canvasX = canvasX
		this.canvasY = canvasY
		this.rotation = rotation

		if (this.rotation === 0) {
			this.render()
		} else {
			this.rotateRender()
		}
	}

	render() {
		ctx.drawImage(
			spriteMap, 
			spriteSize * this.spriteX, 
			spriteSize * this.spriteY, 
			spriteSize, 
			spriteSize, 
			spriteSize * this.canvasX, 
			spriteSize * this.canvasY, 
			spriteSize, 
			spriteSize
		)
	}

	rotateRender() {
		ctx.save()

		ctx.translate(
			spriteSize * this.canvasX + (spriteSize / 2),
			spriteSize * this.canvasY + (spriteSize / 2)
		)
		ctx.rotate(this.rotation * TO_RADIANS)

		ctx.drawImage(
			spriteMap, 
			spriteSize * this.spriteX, 
			spriteSize * this.spriteY, 
			spriteSize, 
			spriteSize, 
			-(spriteSize/2), 
			-(spriteSize/2),
			spriteSize, 
			spriteSize)

		ctx.restore()
	}
} 
