using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HumanLikeBattleRobots.Graphic;
using HumanLikeBattleRobots.Data;
using Bass;

namespace HumanLikeBattleRobots.Logic
{
    class Explosion: IFX
    {
        private float timer = 0;
        private ExplosionSprite sprite = new ExplosionSprite(1);
        private bool isOver = false;

        public bool IsOver { get { return isOver; } }

        public Explosion(Vec2f position)
        {
            UInt16 volume;
            UInt16 pan;
            volume = (UInt16)(25000 / GameManager.myRobot.Position.Distance(position));
            //pan = (UInt16)(position.X - GameManager.myRobot.Position.X);
            sprite.Position = position;
            GameManager.FX.Add(this);
            new Crater(position);

            if (!GameManager.Mute)
                Bass.Bass.BASS_SamplePlayEx(SoundResources.Explosion[GameManager.MainRandom.Next(2)], 
                    0, 0, volume, 0, false);
        }

        public void Proceed(double delta)
        {
            int frame = (int)(timer/0.5*16);
            timer += (float)delta;
            sprite.Frame = frame;
            if (timer >= 0.5)
            {
                isOver = true;
            }
        }

        public void Draw()
        {
            sprite.Draw();
        }
    }
}
