Ejemplo n.º 1
0
    private void FixedUpdate()
    {
        int currentAction = -1;

        // we want to check the game conditions each physics cycle?

        // ---------------------------------------------------------------------------------------
        // NOBODY HAS BALL
        // ---------------------------------------------------------------------------------------
        if (condition.GetTeamWithBall() == "None")
        {
            currentAction = LocationConditions(0, 1, 2);
        }

        // ---------------------------------------------------------------------------------------
        // PLAYER'S TEAM HAS BALL
        // ---------------------------------------------------------------------------------------
        if (condition.GetTeamWithBall() == team)
        {
            currentAction = LocationConditions(3, 4, 5);
        }

        // ---------------------------------------------------------------------------------------
        // ENEMY TEAM HAS BALL
        // ---------------------------------------------------------------------------------------
        else
        {
            currentAction = LocationConditions(6, 7, 8);
        }

        Debug.Log(this.transform.name + ": " + currentAction);

        switch (currentAction)
        {
        case 0:
            // move between ball and top goal line
            SetNewTarget(Refs.FindFractionalPointBetween(game.ball.transform.position,
                                                         new Vector3(
                                                             game.ball.transform.position.x,
                                                             Refs.ARENA_HEIGHT / 2,
                                                             game.ball.transform.position.z),
                                                         traitWeights[0]));
            hasTarget = !actions.MoveTo(this, moveTarget, speed);
            break;

        case 1:
            // move between ball and bottom goal line
            SetNewTarget(Refs.FindFractionalPointBetween(game.ball.transform.position,
                                                         new Vector3(
                                                             game.ball.transform.position.x,
                                                             -Refs.ARENA_HEIGHT / 2,
                                                             game.ball.transform.position.z),
                                                         traitWeights[1]));
            hasTarget = !actions.MoveTo(this, moveTarget, speed);
            break;

        case 2:
            // move to ball
            hasTarget = !actions.MoveTo(this, game.ball.transform.position, speed);
            break;

        case 3:
            actions.ThrowBall(game.ball, moveTarget);
            break;

        case 4:
            // move between ball and right line
            SetNewTarget(Refs.FindFractionalPointBetween(game.ball.transform.position,
                                                         new Vector3(
                                                             Refs.ARENA_WIDTH / 2,
                                                             game.ball.transform.position.y,
                                                             game.ball.transform.position.z),
                                                         traitWeights[2]));
            hasTarget = !actions.MoveTo(this, moveTarget, speed);
            break;

        case 5:
            // move between ball and left line
            SetNewTarget(Refs.FindFractionalPointBetween(game.ball.transform.position,
                                                         new Vector3(
                                                             -Refs.ARENA_WIDTH / 2,
                                                             game.ball.transform.position.y,
                                                             game.ball.transform.position.z),
                                                         traitWeights[3]));
            hasTarget = !actions.MoveTo(this, moveTarget, speed);
            break;

        case 6:
        case 7:
        case 8:
        case 9:
            break;

        default:
            Debug.LogError("Player: current action switch made it to default - is current action not set");
            break;
        }
    }