package com.ady.timerunner;

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


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

public class Star {

    private final float height;
    private final World world;
    private final Vector2 center;
    private float angle;
    public float worldradius;
    public Vector2 position = new Vector2(5, 5);
    public float choose = MathUtils.random(359f);
    public float fakesize = MathUtils.random(0.1f, 0.45f);
    public float size = MathUtils.random(0.1f, 0.45f);
    public float alpha = 1f;
    private boolean blink = false;
    public Color color = new Color(Color.WHITE);


    public Star(World world, float angle, float height) {
        this.angle = angle - 2f;
        this.height = height;
        this.world = world;
        center = world.center;
        worldradius = world.size / 2f;
        position = center.cpy().add(MathUtils.cosDeg(this.angle) * (worldradius + 50 + height), MathUtils.sinDeg(this.angle) * (worldradius + 50 + height));
        color.set(color.fromHsv(MathUtils.random(180f, 359f), 0.7f, 1f));
    }


    public void act(float globalclock,float zoom) {
        angle += fakesize / 10;
        size=fakesize*MathUtils.log2(zoom);
        position = center.cpy().add(MathUtils.cosDeg(angle) * (worldradius + height + 50), MathUtils.sinDeg(angle) * (worldradius + height + 50));

        if (MathUtils.randomBoolean(0.001f)) {
            blink = true;
            choose = MathUtils.random(180, 359.9f);

        }
        if (blink) {

            color.set(color.fromHsv(choose, MathUtils.random(0.2f, 0.4f), 1f));

            //  color.set(MathUtils.random(),0,MathUtils.random(),alpha);
            alpha -= 0.01f;
            if (alpha < 0.4f) {
                alpha = 1f;
                blink = false;
            }

        }
        Color newcolor=new Color(color.r, color.g, color.b, MathUtils.clamp((globalclock - 7f) , 0f, 1f));
        color.set(newcolor);
    }

}
