package de.frajul.endlessroll.main.game;

import java.util.Random;

import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.particles.ParticleSource;
import de.frajul.endlessroll.entities.particles.ParticleSystem;
import de.frajul.endlessroll.entities.shapes.PlayerShape;
import de.frajul.endlessroll.entities.textures.TexturePack;
import de.frajul.endlessroll.levels.worlds.World;
import de.frajul.endlessroll.main.GameActivity;

public class StartScene extends Scene {

    private final float TERRAIN_EDGE = -0.8f;
    private Random random;
    private World currentWorld = World.GRASSLANDS;

    public StartScene(GameActivity gameActivity, TexturePack texturePack, ParticleSystem particleSystem) {
        super(gameActivity, texturePack, particleSystem);
        player.init(PlayerShape.BALL, TERRAIN_EDGE, 0.5f, 0.5f, null);
        uncategorizedEntities.add(player);

        random = new Random();
        randomizeWorld();
        loadTexturesForCurrentWorld();
    }

    public void randomizeWorld() {
        int worldId = random.nextInt(World.values().length);
        currentWorld = World.values()[worldId];
        if (currentWorld == World.ICY_MOUNTAINS) {
            enviromentParticles = new ParticleSource(new Vector(), particleSystem.snow);
            enviromentParticles.start();
        } else {
            if (enviromentParticles != null)
                enviromentParticles.kill();
            particleSystem.deleteAllSources();
        }
    }

    public void loadTexturesForCurrentWorld() {
        terrain.clear();
        terrain.createEndless(currentWorld, TERRAIN_EDGE);
        background.changeTexture(currentWorld.getBackgroundTexture());
    }

}