package de.frajul.endlessroll.entities.particles;

import java.util.Random;

import de.frajul.endlessroll.data.Vector;
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(0);
        randomExplosion(100);
        randomExplosion(300);
    }

    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);
    }


}
