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

public class BossStateMachine : MonoBehaviour {

	public GameObject waypoint;
	public Transform player;
	public GameObject bullet;
	public Transform enemyPos;
	
	public float moveTime;
	private float startTime;
	private float moveSpeed = 2;
	private int cooldown;
	public enum States{	Move, Attack };
	private States currentState = new States ();

	// Use this for initialization
	void Start () {
		startTime = Time.time;
		currentState = States.Move;
		cooldown = 300;
	}

	// Update is called once per frame
	void Update () {
		switch (currentState) {
		case States.Move:
			Move ();
			break;
		case States.Attack:
			Attack ();
			break;
		default:
			break;
		}

		moveSpeed = (Time.time - startTime) / moveTime;
		cooldown -= 1;
		if (cooldown <= 0) {
			Attack ();
			cooldown = 300;
		}
	}

	void Move () {
		this.transform.position = Vector2.LerpUnclamped (this.transform.position, waypoint.transform.position, moveSpeed * Time.deltaTime);
	}

	void Attack() {
		int roll = Random.Range (1, 100);
//		if (roll <91)
			Shoot ();
//		else
//			Charge ();
		
	}

	void Shoot () {
		GameObject instanceBullet = Instantiate (bullet, this.transform.position, Quaternion.identity);
		//instanceBullet.transform.LookAt (player.position);

		//instanceBullet.transform.rotation = Quaternion.FromToRotation (this.transform.position, player.position);
		//instanceBullet.transform.rotaation = Quaternion.;
	}

//	void Charge () {
//		float chargeSpeed = (Time.time - startTime) / 1;
//		this.transform.position = Vector2.Lerp (this.transform.position, player.transform.position, chargeSpeed * Time.deltaTime);
//	}

}
