using System;
using System.Collections.Generic;
using System.Text;
using HumanLikeBattleRobots.Graphic;

namespace HumanLikeBattleRobots.Logic
{
    abstract class Bullet
    {
        protected Vec2f position;
        protected float radius;
        private Vec2f speed;
        protected Sprite bulletSprite;
        protected float zPosition = 1f;
        protected float zSpeed = 0f;
        private bool onAir = true;
        private bool enemyBullet;
        protected int stage;

        public int Stage { get { return stage; } }

        public Bullet(Vec2f position, Vec2f speed, bool enemyBullet)
        {
            this.position = position;
            this.speed = speed;
            this.enemyBullet = enemyBullet;
            GameManager.bullets.Add(this);
            stage = 3;
        }

        public virtual void Proceed(double delta)
        {
            zPosition -= zSpeed * (float)delta;

            if (zPosition <= 0)
            {
                onAir = false;
                stage = 0;
                zPosition = 0;
            }

            if (onAir)
            {
                position += speed * (float)delta;
                bulletSprite.Position = position;

                if (GameManager.CheckBulletCollision(this, this.enemyBullet))
                    Bang();

            }
        }

        private void Bang()
        {
            GameManager.bullets.Remove(this);
        }

        public abstract void Draw();

        public Vec2f Position
        {
            get { return position; }
        }

        public float Radius
        {
            get { return radius; }
        }

        public float HitRadius
        {
            get { return radius; }
        }
    }
}
