package spaceinvaders.objects;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

public abstract class Ship{
	private BufferedImage ship, subimage;
	public Rectangle border;	
	private int offset;
	
	public Ship(BufferedImage image, int x, int y){
		ship = image;
		subimage = image.getSubimage(0, 0, 32, ship.getHeight());
		border = new Rectangle(0, 0, 32, image.getHeight());
		setLocation(x, y);
	}
	public void draw(Graphics2D g2){
		g2.drawImage(subimage, (int)border.getX(), (int)border.getY(), (int)border.getWidth(), (int)border.getHeight(), null);
		g2.setStroke(new BasicStroke(1));
	}
	public void setLocation(int x, int y){
		border.setLocation(x, y);
		subimage = ship.getSubimage(offset, 0, 32, ship.getHeight());
		if(offset == 32){
			offset = 0;
		}else {
			offset = 32;
		}
	}
	public int getX(){
		return (int) border.getX();
	}
	public int getY(){
		return (int) border.getY();
	}
	public int getWidth(){
		return (int) border.getWidth();
	}
	public int getHeight(){
		return (int) border.getHeight();
	}
	public Rectangle getBorder() {
		return border;
	}	
}
