﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

using TeamBOS.GSDD.Sources.Input;

namespace TeamBOS.GSDD.Sources.Mob.Components
{
    public class UserInputController : Component
    {
        public const float JumpHeight = 1.1f;
        public const float Speed = 0.4f;

        public override void Update(GameObject obj, GameTime time, CustomInput input)
        { 
            if(input.IsKeyPressed(Keys.Space))
            {
                obj.Emit((JumpController c) => { c.Jump(obj, JumpHeight); });
            }
            KeyboardState keyboard = Keyboard.GetState();
            if (keyboard.IsKeyDown(Keys.D))
            {
                obj.Emit<RigidBody>(r => r.Velocity = new Vector2(Speed, r.Velocity.Y));
            }
            else if (keyboard.IsKeyDown(Keys.A))
            {
                obj.Emit<RigidBody>(r => r.Velocity = new Vector2(-Speed, r.Velocity.Y));
            } else
            {
                obj.Emit<RigidBody>(r => r.Velocity = new Vector2(0, r.Velocity.Y));
            }
        }
    }
}
