package de.frajul.endlessroll.entities;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.textures.Texture;

/**
 * Created by Julian on 20.07.2016.
 */
public class Background {

    private List<BackgroundLayer> layers = Collections
            .synchronizedList(new ArrayList<BackgroundLayer>());

    public Background(List<Texture> textures) {
        changeTextures(textures);
    }

    public void changeTextures(List<Texture> textures) {
        layers.clear();
        for (int i = 0; i < textures.size(); i++) {
            Texture texture = textures.get(i);
            float speed = (float) Math.pow(0.95f, Math.pow(i + 1, Math.sqrt(i + 1)));
            layers.add(new BackgroundLayer(texture, speed));
        }
    }

    public void move(float playerMoveX, float cameraX) {
        synchronized (layers){
            for(BackgroundLayer layer : layers){
                layer.move(playerMoveX, cameraX);
            }
        }
    }

    public void resetPosition() {
        synchronized (layers){
            for(BackgroundLayer layer : layers)
                layer.resetPosition();
        }
    }

    public List<BackgroundLayer> getLayers() {
        return layers;
    }
}
