package com.ady.timerunner;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;

/**
 * Created by ADY on 26.1.2018.
 */

public class Bullet {

    public float height;
    public Vector2 center;
    public Vector2 position;
    public float worldradius;
    public World world;
    public float angle;
    public float speed = 0.01f;
    public float acc = 0.01f;
    public float deadtimer=0;
    Circle body = new Circle(5,5,5);
    public boolean dead = false;
    private int time = 0;

    public Bullet(World world, float angle, float height) {
        this.angle = angle -1.5f;
        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));
        body.set(position.x+25,position.y+25,20);
    }

    public void act(Array<Bubble> bubbles) {
        angle -= speed;
        deadtimer++;
        if (speed < 1.2f) {
            speed += acc;
            acc += 0.001f;
        } else {
            speed += 0.0001f;
        }
        height -=world.projectileg ;
        position = center.cpy().add(MathUtils.cosDeg(angle) * (worldradius  + height +50), MathUtils.sinDeg(angle) * (worldradius  + height +50));

        if(deadtimer>3000)
        {
            dead=true;
        }

        if (time < 30) {
            height -= 1 / (speed * 4);
        }
        if (time++ < 60) {
            height += 1f;

        }
        if (MathUtils.random() + 0.3f > speed) {
            bubbles.add(new Bubble(position.x+25, position.y+25, speed, center, angle, worldradius, height));
            bubbles.add(new Bubble(position.x+25, position.y+25, speed, center, angle, worldradius, height));
            bubbles.add(new Bubble(position.x+25, position.y+25, speed, center, angle, worldradius, height));
        }
        System.out.println(speed + "   ---");
        if (height < -30) {
            dead = true;
        }
        if (speed > 1.0f) {
            speed = 1.0f;
        }
        body.set(position.x+25,position.y+25,20);
    }
}
