using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HaiDan : Creature
{
    [SerializeField] private float moveCDMax = 1f;
    [SerializeField] private float speedValue = 50f;

    private Vector3 direction;
    private bool moveLeft;
    private bool upLast;
    private float moveCDTimer;

    protected override void Start()
    {
        base.Start();

        moveLeft = GameApp.Instance.GetRandomBool();
    }

    protected override void Update()
    {
        base.Update();

        HandleMovement();
    }

    private void HandleMovement()
    {
        moveCDTimer -= Time.deltaTime;
        if (moveCDTimer < 0)
        {
            moveCDTimer = moveCDMax;
            direction = GetNextDir();
        }

        Vector3 curPos = transform.position;
        curPos += direction * speedValue * Time.deltaTime;
        transform.position = curPos;
    }

    private Vector3 GetNextDir()
    {
        if (upLast)
        {
            upLast = !upLast;
            if (moveLeft)
            {
                return Vector3.left;
            }
            else
            {
                return Vector3.right;
            }
        }
        else
        {
            upLast = !upLast;
            return new Vector3(0,1,0);
        }
    }
}
