package com.ady.timerunner;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

import com.badlogic.gdx.graphics.Color;


/**
 * Created by ADY on 27.1.2018.
 */

public class Particle {

    public float size;
    public Vector2 position = new Vector2();
    public Vector2 position2 = new Vector2();
    public Color color= new Color(1,1,1,1);
    private float randfloat=MathUtils.random();
    private float change=0.03f;

    public Particle() {
        position.set(5, 5);
        position2.set(5, 5);
        size= MathUtils.random(0.5f,1.2f);
        color.set(color.fromHsv(00f,0.5f,1f    ));
        if(MathUtils.randomBoolean())
        {
            change*=-1;
        }
    }


    public void act(float angle, float size, float height, Vector2 center) {
        position.set(center);

        Vector2 added = new Vector2(5, 5);
        added.setLength(size / 2f);
        added.setAngle(angle);
        position.add(added);
        position2.set(position);
        added.setLength(height);
        added.setAngle(angle);
        position2.add(added);


        color.set(color.fromHsv(MathUtils.random(180,320),0.8f,1f    ));
        randfloat+=change;
        if(randfloat>1f)
        {
            randfloat=0f;
        }
        if(randfloat<0f)
        {
            randfloat=1f;
        }
        this.size-=0.01;
        if(this.size<=0.2f)
        {
            this.size=1f;
        }

    }

    public Vector2 getposition() {

        return position.cpy().lerp(position2, randfloat);
    }
}
