package com.hyperling.apps.games;

import android.graphics.Bitmap;
import android.graphics.Canvas;

/**
 * Created by ling on 12/17/16.
 */

public class GameBackground {

    private Bitmap image;
    private int x, y;

    public GameBackground(Bitmap i){
        image = i;
    }

    public void update(int gameSpeed){
        // Move the background
        x += gameSpeed;

        // If the image is completely off the screen, put it back to the middle.
        if (x <= -GameView.WIDTH || x >= GameView.WIDTH){
            x = 0;
        }
    }

    public void draw(Canvas canvas){
        // Draw the current image
        canvas.drawBitmap(image, x, y, null);

        // Place two more to the right since we are to the left
        if (x < 0){
            canvas.drawBitmap(image, x + GameView.WIDTH, y, null);
            //canvas.drawBitmap(image, x + (2 * GameView.WIDTH), y, null);
        }
        // Place two more to the left since we are to the right
        else if (x > 0){
            canvas.drawBitmap(image, x - GameView.WIDTH, y, null);
            //canvas.drawBitmap(image, x - (2 * GameView.WIDTH), y, null);
        }
    }
}
