using UnityEngine;
using System.Collections;

public class PeoPlePoint : MonoBehaviour {

	// Use this for initialization
	void Start () {
	    
	}

    public float XMoveSpeed = 1.0f;
    public float YPos = -1.0f;
    public GameObject Manager;
    public float Point = 100;
    int pattern = 0;
    private float Rota = 0.0f;
	// おぼれている人の挙動
	void Update () {
        switch (pattern) {
            case 0:
                // 溺れている状態
                transform.position = new Vector3(
                    transform.position.x - XMoveSpeed * Time.deltaTime,
                    YPos + Manager.GetComponent<PlayerMove>().YPosition(transform.position.x),
                    transform.position.z+ YPos * 0.01f);
                Point -= Time.deltaTime * 20;
                // 左端まで移動しきったら削除
                if (transform.position.x < -20) {
                    Destroy(gameObject);
                }
                break;
            case 1:
                // 救助された状態
                Rota += Time.deltaTime * 360 * 50;
                transform.rotation = Quaternion.Euler(0.0f, 0.0f, Rota);
                transform.position += new Vector3(-100.0f * Time.deltaTime, 30 * Time.deltaTime);
                if(transform.position.y > 30) {
                    Destroy(gameObject);
                }
                break;
        }
	}

    // プレイヤーに触れたら救助状態
    void OnTriggerEnter2D(Collider2D col) {
        // Debug.Log("接触");
        if (col.gameObject.tag == "Play") {
            if (pattern == 0) {
                Manager.GetComponent<MainManager>().ScoreAdd(Mathf.Max(20, Mathf.RoundToInt(Point)));
                pattern++;
            }
        }
    }
}
