using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Hover
{
    class Star
    {
        Vector2 pos;
        byte strength;
        byte strBase;

        float xvel;

        public Star()
        {
            Spawn();
            pos.X = Engine.Rnd.Next((int)Engine.GameRes.X);
        }

        public void Spawn()
        {
            xvel = (float)Engine.Rnd.NextDouble() * 0.05f;
            strBase = (byte)(Engine.Rnd.Next(100) + 150 + xvel * 200);
            strength = strBase;
            pos = new Vector2(Engine.GameRes.X, (float)Engine.Rnd.Next((int)Engine.GameRes.Y * 3) - Engine.GameRes.Y * 2 - 30);
        }

        public void Update()
        {
            if (Engine.Rnd.NextDouble() > 0.99f)
                strength = 255;

            if (strength >= strBase)
                strength -= 10;

            pos.X -= xvel;
            if (pos.X < 0)
                Spawn();
        }

        public void Draw(SpriteBatch sb)
        {
            var drawPos = pos;
            //drawPos = new Vector2(pos.X, pos.Y - Engine.CamPos.Y * (1- xvel) * 0.4f)
            sb.Draw(Engine.Pixel, drawPos, new Color(strength, strength, strength));
        }
    }
}
