package de.frajul.endlessroll.entities.particles;

import java.util.Random;

import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.particles.Particle;
import de.frajul.endlessroll.entities.particles.ParticleEffect;
import de.frajul.endlessroll.entities.particles.ParticleSource;
import de.frajul.endlessroll.main.game.Camera;

/**
 * Created by Julian on 15.07.2017.
 */

public class Firework {

    private ParticleEffect effect;
    private Camera camera;
    private Random random;

    public Firework(ParticleEffect effect, Camera camera){
        this.effect = effect;
        this.camera = camera;
        this.random = new Random();
    }

    public void start(){
        randomExplosion(500);
        randomExplosion(1000);
        randomExplosion(2000);
        randomExplosion(3500);
        randomExplosion(3590);
        randomExplosion(4800);
        randomExplosion(5600);
        randomExplosion(6900);
        randomExplosion(7000);
    }

    private void randomExplosion(float delay){
        ParticleSource explosion = new ParticleSource(randomPosition(), effect);
        explosion.setDelayMS(delay);
        explosion.start();
    }

    private Vector randomPosition(){
        float x = camera.getX() + (random.nextFloat() - 0.5f) * 2.5f;
        float y = camera.getY() + (random.nextFloat() * 0.5f) - 1f;
        return new Vector(x, y);
    }



}
