using UnityEngine;
using System.Collections;

public class SparkMotion : MonoBehaviour {

    public Transform startPosition;
    public AudioGetter aGetter;
    public float[] moveRange;
    public float[] pitchRange;

    private float pitchSpan;
    private float moveSpan;

	// Use this for initialization
	void Start () {
        pitchSpan = pitchRange[1] - pitchRange[0];
        moveSpan = moveRange[1] - moveRange[0];
	}

    void ResetPosition()
    {
        this.transform.position = startPosition.position;
        this.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, 0f);
    }

    void BeginPlay()
    {
        this.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 120f));
       // this.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, 2f);
    }
	
	// Update is called once per frame
	void Update () {
        float spanPosition = ( aGetter.pitchAvg - pitchRange[0] ) / pitchSpan;

        Vector2 newPos = new Vector2(this.transform.position.x, this.transform.position.y);
        newPos.x = (spanPosition * moveSpan) + moveRange[0];
        newPos.x = Mathf.Clamp(newPos.x, moveRange[0], moveRange[1]);

        this.transform.position = newPos;
	}
}
