using UnityEngine;
using System;

public class HeadBangDetector : UniqueMonoBehaviour<HeadBangDetector> {

    private Boolean _lastHeadUp;
    private Boolean _headUp;
    private Boolean _bangDown;
    private Boolean _bangUp;
	
	// Update is called once per frame
	void Update () {
        _lastHeadUp = _headUp;
        if(_headUp){
            _headUp = Math.Abs(Input.acceleration.z) < 0.6f;
        } else {
            _headUp = Math.Abs(Input.acceleration.z) < 0.4f;
        }

        _bangDown = _lastHeadUp && !_headUp;
        _bangUp = !_lastHeadUp && _headUp;
    }

    /**
     * Remains true while head is up, false otherwise
     */
    public Boolean HeadUp {
        get
        {
            return _headUp;
        }
    }

    /**
     * Remains true while head is down, false otherwise
     */
    public Boolean HeadDown
    {
        get
        {
            return !_headUp;
        }
    }

    /**
     * Signals when head is banged down
     */
    public Boolean BangDown
    {
        get
        {
            return _bangDown;
        }
    }

    /**
     * Signals when head is banged up
     */
    public Boolean BangUp
    {
        get
        {
            return _bangUp;
        }
    }
}
