using Otter;
using System;

namespace KellysMarvelousAdventure.entities
{
    class Leaves : Entity
    {
        private Spritemap<string> _spriteMap;
        private int _deathTimer = 200;
        private float _x = Rand.Float(570, 650);
        private float _y = 70;
        private double variance = 1;

        public Leaves(float x, float y)
        {
            X = x; Y = y;
            _spriteMap = new Spritemap<string>(Assets.LEAVES, 20, 20);
            _spriteMap.Add("main1", new int[] { 0 }, new float[] { 3, 3 });
            _spriteMap.Add("main2", new int[] { 1 }, new float[] { 3, 3 });
            _spriteMap.Add("main3", new int[] { 2 }, new float[] { 3, 3 });
            _spriteMap.Add("main4", new int[] { 3 }, new float[] { 3, 3 });
            _spriteMap.Add("main5", new int[] { 4 }, new float[] { 3, 3 });
            _spriteMap.Add("main6", new int[] { 5 }, new float[] { 3, 3 });
            var anim = "main" + Rand.Int(1, 6);//i hope this is 0 through 5
            _spriteMap.Play(anim);//random leaf
            Graphic = _spriteMap;
            Layer = -3;
        }
        public override void Update()
        {
            base.Update();
            X = Scene.CameraX + _x;
            Y = Scene.CameraY + _y;
            _y += Rand.Float(.2f, .5f);//(float)Math.Cos(variance);
            _x += (float)Math.Sin(variance);
            variance = Rand.Float(1,100);
            if (_deathTimer <= 0) RemoveSelf();
            if (_deathTimer > 0) _deathTimer--;
        }
    }
}
