using UnityEngine;
using System.Collections;

public class PlayerStampShapeScript : MonoBehaviour 
{
	public PlayerLearnShapeScript learnShape;

	private Transform myTransform;

	private GameObject currentStamped;

	private bool axisPressed = false;

	// Use this for initialization
	void Start () 
	{
		myTransform = transform;
	}
	
	// Update is called once per frame
	void Update () 
	{
		// We are currently mimicing a shape
		if (PlayerStateManager.instance.currentPlayerState == Enums.PlayerState.Morphing)
		{
			// We have learned a shape
			if (learnShape.currentShape != null)
			{
				// We are pressing the stamp key
				if (Input.GetAxis("Stamp") != 0)
				{
					// If we have previously created an object destroy it
					if (currentStamped != null)
					{
						GameObject.Destroy(currentStamped);
						currentStamped = null;
					}

					// Create the new object
					currentStamped = GameObject.Instantiate(learnShape.currentShape, myTransform.position, Quaternion.identity) as GameObject;
					currentStamped.GetComponent<SetupInteractableScript>().enabled = true;
					/*currentStamped.collider2D.isTrigger = true;
					currentStamped.GetComponent<Rigidbody2D>().isKinematic = true;*/

					// we were facing left, flip the sprite
					if (myTransform.localScale.x < 0)
					{
						Vector3 newScale = currentStamped.transform.localScale;
						newScale.x *= -1;
						currentStamped.transform.localScale = newScale;
					}

					axisPressed = false;
				}
			}
		}
	}
}
