package Sprites;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * Created by sagi on 23/01/2016.
 */
public class SideScollerBackground extends Sprite {

    private int locXCopy;

    public SideScollerBackground(int w, int h, int acc, String imgName, int sWidth, int sHeight) {
        super(0, 0, w, h, acc, imgName, 0, sWidth, sHeight);

        locXCopy = pWidth;
        if(sHeight != pHeight){
            locY = pHeight-sHeight;
        }



    }


    //if a bg element moves pass the screen, it returns to the begining
    @Override
    public void update() {
        locX -= acceleration;
        locXCopy -= acceleration;
        if(locX+pWidth < 0)
            locX = pWidth;
        if(locXCopy+pWidth < 0)
            locXCopy = pWidth;
    }

    //draws 2 bg instances that follow each other
    @Override
    public void drawSprite(Graphics g, JPanel p){
        super.drawSprite(g,p);
        g.drawImage(bImage, locXCopy, locY, p);
    }


}
