Example #1
0
    public void fixLayer(PersonBrain self, bool isPlayer)
    {
        int init;

        switch (self.type) {
            case PersonBrain.enType.boss:     init = 10; break;
            case PersonBrain.enType.follower: init = 20; break;
            case PersonBrain.enType.level_0:  init = 30; break;
            case PersonBrain.enType.level_1:  init = 40; break;
            case PersonBrain.enType.level_2:  init = 50; break;
            default: init = -20; break;
        }

        if (isPlayer) {
            init = 60;
        }

        this.head.sortingOrder = init - 2;
        if (this.neck != null) {
            this.neck.sortingOrder = init - 2;
        }
        this.rfarm.sortingOrder = init + 0;
        this.rarm.sortingOrder  = init + 0;
        this.lfarm.sortingOrder = init - 2;
        this.larm.sortingOrder  = init - 2;
        this.body.sortingOrder  = init - 1;
        this.rfoot.sortingOrder = init - 2;
        this.rleg.sortingOrder  = init - 2;
        this.rcalf.sortingOrder = init - 2;
        this.lfoot.sortingOrder = init - 3;
        this.lleg.sortingOrder  = init - 3;
        this.lcalf.sortingOrder = init - 3;
    }
    public int countFreeWithColor(PersonBrain.enColor color, PersonBrain.enType type)
    {
        int count;

        count = 0;
        foreach (Transform item in this.personsInUse) {
            PersonBrain brain;

            brain = item.GetComponent<PersonBrain>();
            if (brain && brain.state == PersonBrain.enState.free &&
                    brain.type <= type && brain.sufferInfluence(color)) {
                count++;
            }
        }

        return count;
    }
    /**
     * Spawn a new level
     *
     * @param [in]width           The width of the level in "scene chunks"
     * @param [in]targetFollowers How many follower the player must have to
     *                            advance
     * @param [in]people          Array of people's colors
     */
    private void spawnLevel(int width, int targetFollowers,
            PersonBrain.enColor[] people)
    {
        int i;

        // Temporarially store this width so it can be returned
        this.width = width * 9 - 4.5f;

        // Store how many followers are required to finish this level
        this.targetFollowers = targetFollowers;
        this.currentFollowers = 0;

        // Set the limits for the RNG
        PersonBrain.minHorPosition = -4.4f;
        PersonBrain.maxHorPosition = this.width - 4.5f;
        // Spawn everything
        i = 0;
        while (i < people.Length) {
            PersonBrain.enColor color;
            PersonBrain.enType type;

            color = people[i];
            switch (color) {
                case PersonBrain.enColor.magenta: type = PersonBrain.enType.level_0; break;
                case PersonBrain.enColor.cyan: type = PersonBrain.enType.level_0; break;
                case PersonBrain.enColor.yellow: type = PersonBrain.enType.level_0; break;
                case PersonBrain.enColor.red: type = PersonBrain.enType.level_1; break;
                case PersonBrain.enColor.green: type = PersonBrain.enType.level_1; break;
                case PersonBrain.enColor.blue: type = PersonBrain.enType.level_1; break;
                case PersonBrain.enColor.black: type = PersonBrain.enType.level_2; break;
                case PersonBrain.enColor.white: type = PersonBrain.enType.level_2; break;
                default: type = PersonBrain.enType.level_0; break;
            }
            spawnNewPerson(type, color);

            i++;
        }
    }
    /**
     * Spawn (either recycled or instantiated) a new person of the desired type
     * and color
     */
    private bool spawnNewPerson(PersonBrain.enType type, PersonBrain.enColor color)
    {
        Transform newPerson;
        PersonBrain personScript;

        newPerson = getNewPerson();
        personScript = newPerson.GetComponent<PersonBrain>();

        if (personScript) {
            personScript.initInstance(type, color, false);

            personsInUse.Add(newPerson);
        }
        else {
            Destroy(newPerson);
            return false;
        }

        return true;
    }
    public PersonBrain getNextInfluentiable(PersonBrain.enColor color, PersonBrain.enType type)
    {
        foreach (Transform item in this.personsInUse) {
            PersonBrain brain;

            brain = item.GetComponent<PersonBrain>();
            if (brain && brain.state == PersonBrain.enState.free &&
                    brain.type <= type && brain.sufferInfluence(color)) {
                return brain;
            }
        }
        return null;
    }