Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        mainHand = controller.Frame().Hands[0];

        objInLastFrame = objInCurrFrame;
        objInCurrFrame = null;

        //testing purposes
        if (Input.GetKeyDown(KeyCode.I))
        {
            objInCurrFrame = CreateObject(MagicType.IceWall);
        }
        if (Input.GetKeyDown(KeyCode.F))
        {
            objInCurrFrame = CreateObject(MagicType.Fireball);
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            Application.LoadLevel(MagicConstant.TUTORIAL_LEVEL);
        }
        if (Input.GetKeyDown(KeyCode.G))
        {
            Application.LoadLevel(MagicConstant.GAME_LEVEL);
        }
        if (Input.GetKey(KeyCode.J) || Input.GetKey(KeyCode.Q))
        {
            player.transform.Rotate(new Vector3(0, -TURN_DIST, 0));
            //pivot left
        }
        if (Input.GetKey(KeyCode.K) || Input.GetKey(KeyCode.E))
        {
            //pivot right
            player.transform.Rotate(new Vector3(0, TURN_DIST, 0));
        }

        //Debug.Log (HandHelper.isFaceForward(mainHand, controller.Frame()) + " " + mainHand.Direction + ":" + mainHand.PalmNormal);

        //cooling down, don't do anything else
        if (cd.coolingDown(nc))
        {
            neutralize();
            //hand stuff
        }
        else if (HandHelper.isValidHand(mainHand))
        {
            if (HandHelper.isClosedFist(mainHand))
            {
                //nc.resetBottomServo();
                canCharge = true;
            }
            else if (HandHelper.isFaceUp(mainHand, controller.Frame()) && canCharge)
            {
                Debug.Log(chargeCounter);

                if (chargeCounter <= LONG_THRESHOLD)
                {
                    if (chargeCounter > SHORT_THRESHOLD && chargeCounter <= MEDIUM_THRESHOLD)
                    {
                        objInCurrFrame = CreateObject(MagicType.FireCharge, Size.Medium);
                    }
                    else if (chargeCounter > MEDIUM_THRESHOLD)
                    {
                        objInCurrFrame = CreateObject(MagicType.FireCharge, Size.Large);
                    }
                    else
                    {
                        objInCurrFrame = CreateObject(MagicType.FireCharge, Size.Small);
                    }

                    //Debug.Log ("Charging: " + chargeCounter);

                    nc.heatPeltier(lastSize);
                    chargeCounter++;
                    //overloaded, go into cooldown
                }
                else
                {
                    Debug.Log("Charged too long, in cooldown mode");
                    neutralize();
                    cd.startCooldown();
                }
                //shoot charged object
            }
            else if (HandHelper.isFaceForward(mainHand, controller.Frame()) && chargeCounter > MIN_THRESHOLD)
            {
                objInCurrFrame = CreateObject(MagicType.Fireball);

                neutralize();
                //charge ice wall
            }
            else if (HandHelper.isFaceForward(mainHand, controller.Frame()))
            {
                Vector3    palmPos      = mainHand.PalmPosition.ToUnityScaled();
                Collider[] hitColliders = Physics.OverlapSphere(transform.TransformPoint(palmPos), CLOSEST_ICEWALL_DIST);

                bool collided = false;

                for (int i = 0; i < hitColliders.Length; i++)
                {
                    if (hitColliders[i].tag == MagicConstant.ICEWALL_TAG)
                    {
                        hitColliders[i].SendMessage(MagicConstant.ICEWALL_CHARGE_SPELLNAME);
                        collided = true;
                    }
                }



                //create an ice wall if there isn't a nearby one and a circle gesture was performed
                if (!collided && GameObject.FindWithTag(MagicConstant.FIREBALL_TAG) == null)
                {
                    iceCounter++;

                    if (iceCounter > ICE_THRESHOLD)
                    {
                        objInCurrFrame = CreateObject(MagicType.IceWall);
                        canIce         = false;
                        iceCounter     = 0;
                    }
                }
            }
            else
            {
                idling();
            }
        }
        else
        {
            idling();
        }
    }
        public override bool ReadyForNextInstr(float deltaTime, Frame frame, Hand hand)
        {
            Texture texture;

            //do this only at start of new instruction
            if (deltaTime < 0.5f)
            {
                switch (gestureType)
                {
                case "fist":
                    texture = Resources.Load("Images/fist-close") as Texture;
                    renderer.material.mainTexture = texture;
                    break;

                case "fire":
                    texture = Resources.Load("Images/fist-open") as Texture;
                    renderer.material.mainTexture = texture;
                    break;

                case "fireball":
                    texture = Resources.Load("Images/open-shoot") as Texture;
                    renderer.material.mainTexture = texture;
                    break;

                case "forward":
                    texture = Resources.Load("Images/hand-open") as Texture;
                    renderer.material.mainTexture = texture;
                    break;

                case "ice":
                    texture = Resources.Load("Images/spin-hand") as Texture;
                    renderer.material.mainTexture = texture;
                    break;

                default:
                    Debug.Log("unrecognized gesture");
                    break;
                }
            }

            if (deltaTime >= thresholdTime)
            {
                switch (gestureType)
                {
                case "fist":
                    return(HandHelper.isClosedFist(hand));

                case "fire":
                    return(GameObject.FindGameObjectsWithTag(MagicConstant.FIRECHARGE_TAG).Length > 0);

                case "fireball":
                    //shoot two before continuing
                    return(GameObject.FindGameObjectsWithTag(MagicConstant.FIREBALL_TAG).Length > 1);

                case "forward":
                    return(HandHelper.isFaceForward(hand, frame));

                case "ice":
                    return(GameObject.FindGameObjectsWithTag(MagicConstant.ICEWALL_TAG).Length > 0);

                default:
                    Debug.Log("unrecognized gesture");
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }