Ejemplo n.º 1
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;
        }
    }
Ejemplo n.º 2
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;
    }