package ru.cdmlex.jtest;

import java.awt.*;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.net.URL;

public class Sprite {
	private Image img;
	private int h;
	public Sprite(String path) {
		BufferedImage srcImg = null;
		try {
			URL url = getClass().getClassLoader().getResource(path);
			srcImg = ImageIO.read(url);
			img = Toolkit.getDefaultToolkit().createImage(srcImg.getSource());
			h = img.getHeight(null);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void draw(Graphics2D g,int x,int y) {
		g.drawImage(img,x,y,null);
	}
	public void draw_a(Graphics2D g,int x,int y, int s) {
		s = s * 8;
		g.drawImage(img,x,y,x+8,y+h,s,0,s+8,h,null);
	}	
	public void draw_a_sl(Graphics2D g,int x,int y, int s, int dx, int dy) {
		s = s * 8;
		g.drawImage(img,x,y,x+dx,y+dy,s+8-dx,h-dy,s+8,h,null);
	}
	public void draw_a_sl2(Graphics2D g,int x,int y, int s, int dy) {
		s = s * 8;
		dy = h - dy;
		g.drawImage(img,x,y+dy,x+8,y+h,s,0,s+8,h-dy,null);
		//g.drawImage(img,x,y+h-dy,x+8,y+h,s+8,h-dy,s+8,h,null);
	}		
}