import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class BMPSprite
{
    private String filename;
    private BufferedImage img;
    
    public BMPSprite(int id)
    {
        if (id == 0)
        {
//            filename = "person.bmp";
//            filename = "person.png";
            filename = "Character.png";
        }
        else if (id == 1)
        {
            filename = "Obstacle.png";
        }
        else if (id == 2)
        {
            filename = "Cloud.png";
        }
        else if (id == 3)
        {
            filename = "Grass2.png";
        }
        else if (id == 4)
        {
            filename = "Obstacle2.png";
        }
        else if (id == 5)
        {
            filename = "CharacterAlt.png";
        }
        else if (id == 6)
        {
            filename = "Flame.png";
        }
        else if (id == 7)
        {
            filename = "FlameWeak.png";
        }
        else if (id == 8)
        {
            filename = "Grass.png";
        }
        
        load();
    }
    
    private void load()
    {
        img = null;
        try
        {
            img = ImageIO.read(new File(filename));
            System.out.println("loaded " + filename);
        }
        catch (IOException e)
        {
            System.out.println(e);
        }
    }
    
    public int getHeight()
    {
        if (img == null)
            return 0;
        return img.getHeight(null);
    }
    
    public int getWidth()
    {
        if (img == null)
            return 0;
        return img.getWidth(null);
    }
    
    public void draw(Graphics2D g2d, int x, int y)
    {
        if (img == null)
        {
            return;
        }
        g2d.drawImage(img, x - getWidth()/2, y - getHeight(), null);
    }
}
