// Runs once per frame
    void Update()
    {
        // If it hasn't been half a second since the last action, don't do anything
        if ((DateTime.Now - last).TotalSeconds < 0.5f)
        {
            return;
        }

        // If a fish has already been clicked,
        if (turnState == turn.LEFT || turnState == turn.RIGHT)
        {
            // set grower to be the fish whose turn it is to grow
            ActionObject grower = (turnState == turn.LEFT) ? left.GetComponent <ActionObject> () : right.GetComponent <ActionObject> ();
            // set shrinker to be the fish whose turn it isn't to grow (it will shrink if clicked)
            ActionObject shrinker = (turnState == turn.RIGHT) ? left.GetComponent <ActionObject> () : right.GetComponent <ActionObject> ();

            // If the proper fish is clicked on, grow it
            if (grower.ClickedOn(clickedPos))
            {
                Grow(grower, (turnState == turn.LEFT) ? turn.RIGHT : turn.LEFT);
            }

            // If the improper whale is clicked on, shrink both whales
            else if (shrinker.ClickedOn(clickedPos))
            {
                Shrink(grower, shrinker);
            }

            // If both of the fish are of the winning scale, the user wins!
            if (WinningScale(grower) && WinningScale(shrinker))
            {
                turnState = turn.END;
                MoveOffScreen();
            }
        }

        // No fish has been clicked yet
        else if (turnState == turn.START)
        {
            // Get the ActionObject components of each of the fish
            ActionObject left_ob  = left.GetComponent <ActionObject> ();
            ActionObject right_ob = right.GetComponent <ActionObject> ();

            // Grow a fish if it is clicked on
            if (left_ob.ClickedOn(clickedPos))
            {
                Grow(left_ob, turn.RIGHT);
            }
            else if (right_ob.ClickedOn(clickedPos))
            {
                Grow(right_ob, turn.LEFT);
            }
        }
        else if (turnState == turn.END)
        {
        }
    }
Esempio n. 2
0
    void Update()
    {
        bool attackersRemaining = false;

        for (int i = 0; i < attackers.Length; ++i)
        {
            if (!attackers [i].attacker)
            {
                continue;
            }
            else
            {
                attackersRemaining = true;
            }

            GameObject attacker = attackers [i].attacker;

            ActionObject script = attacker.GetComponent <ActionObject> ();

            if (Utility.V3Equal(script.pos, attackers [i].target))
            {
                if (Utility.V3Equal(script.pos, targetPos))
                {
                    --health;
                    print(string.Format("Hit! {0} health remaining.", health));
                    Destroy(attacker);
                    attackers [i].attacker = null;
                }
                else
                {
                    attackers [i].target = targetPos;
                }
            }
            else
            {
                if (script.ClickedOn(clickedPos) && Utility.V3Equal(attackers [i].target, targetPos))
                {
                    attackers [i].target = GetNewTarget(script);
                }
                script.MoveTowardsTarget(attackers [i].target);
            }
        }

        if (!attackersRemaining)
        {
            enabled = false;
        }

        if (health == 0)
        {
            print("Game over, attackers win!");
            Destroy(defender);
            foreach (AttackerWithTarget g in attackers)
            {
                if (g.attacker)
                {
                    Destroy(g.attacker);
                }
            }
            enabled = false;
        }
    }
Esempio n. 3
0
    void Update()
    {
        if (end)
        {
            Debug.Log("Moving offscreen");
            foreach (whaleWithState w in whaleList)
            {
                w.whale.GetComponent <ActionObject>().MoveTowardsTarget(offscreenPos);
            }
            GetComponent <LineGame>().enabled = false;
            GetComponent <Main>().enabled     = true;
        }
        else
        {
            //			audioIsPlaying = false;
            foreach (whaleWithState w in whaleList)
            {
                ActionObject script = w.whale.GetComponent <ActionObject>();
                switch (w.state)
                {
                case objectState.NORMAL:
                    /*kinectClickedOn, clickedPos*/
                    if (script.ClickedOn())
                    {
                        w.state = objectState.MOVINGTO;
                        script.MoveTowardsTarget(w.targetPos);
                        break;
                    }
                    break;

                case objectState.MOVINGTO:
                    //print ("MOVING TO");
                    if (Utility.V3Equal(script.pos, w.targetPos))
                    {
                        lineCount++;
                        if (lineCount == numObjects)
                        {
                            //all objects must dive
                            music.PlayFeedback(music.neg);
                            foreach (whaleWithState item in whaleList)
                            {
                                item.state = objectState.SHOULD_DIVE;
                            }
                        }
                        else
                        {
                            w.state = objectState.DONE;
                        }
                    }
                    break;

                case objectState.SHOULD_DIVE:
                    //print ("DIVING");
                    w.diveTargetPos.x = w.targetPos.x - 0.5f;
                    w.diveTargetPos.y = w.targetPos.y - 1;
                    script.MoveTowardsTarget(w.diveTargetPos);
                    w.state = objectState.DIVING;
                    lineCount--;
                    break;

                case objectState.DIVING:
                    //print ("IS DIVING");
                    if (Utility.V3Equal(script.pos, w.diveTargetPos))
                    {
                        lineCount++;
                        if (lineCount == numObjects)
                        {
                            //all objects must dive
                            foreach (whaleWithState item in whaleList)
                            {
                                item.state = objectState.RESTART;
                            }
                        }
                        else
                        {
                            w.state = objectState.DONE;
                        }
                    }
                    break;

                case objectState.DONE:
                    break;

                case objectState.RESTART:
                    Debug.Log("RESTART");
                    foreach (whaleWithState item in whaleList)
                    {
                        item.state = objectState.DONE;
                        lineCount--;
                    }
                    end = true;

                    /*
                     * whalePos = script.GetRandomVector(8);
                     * script.pos = whalePos;
                     * script.targetLocation = whalePos;
                     * w.state = objectState.NORMAL;
                     * w.targetPos.y = 0;
                     * lineCount--;
                     * audioIsPlaying = false;
                     */
                    break;
                }
            }
        }
        //kinectClickedOn = false;
    }