コード例 #1
0
ファイル: LevelGeneratorSystem.cs プロジェクト: Valars95/Spy
    private GameObject createEntity(int i, int j, Direction.Dir direction, int type, List <Action> script = null, bool repeat = false)
    {
        GameObject entity = null;

        switch (type)
        {
        case 0:
            entity = Object.Instantiate <GameObject>(Resources.Load("Prefabs/Robot Kyle") as GameObject, gameData.Level.transform.position + new Vector3(i * 3, 1.5f, j * 3), Quaternion.Euler(0, 0, 0), gameData.Level.transform);
            break;

        case 1:
            entity = Object.Instantiate <GameObject>(Resources.Load("Prefabs/Ennemy") as GameObject, gameData.Level.transform.position + new Vector3(i * 3, 3, j * 3), Quaternion.Euler(0, 0, 0), gameData.Level.transform);
            break;

        case 2:
            entity = Object.Instantiate <GameObject>(Resources.Load("Prefabs/Drone") as GameObject, gameData.Level.transform.position + new Vector3(i * 3, 5f, j * 3), Quaternion.Euler(0, 0, 0), gameData.Level.transform);
            break;
        }

        entity.GetComponent <Position>().x          = i;
        entity.GetComponent <Position>().z          = j;
        entity.GetComponent <Direction>().direction = direction;

        ActionManipulator.resetScript(entity.GetComponent <Script>());
        if (script != null)
        {
            entity.GetComponent <Script>().actions = script;
        }

        entity.GetComponent <Script>().repeat = repeat;

        GameObjectManager.bind(entity);

        return(entity);
    }
コード例 #2
0
ファイル: ApplyScriptSystem.cs プロジェクト: Valars95/Spy
    public void applyScriptToPlayer()
    {
        foreach (GameObject go in playerGO)
        {
            ActionManipulator.resetScript(go.GetComponent <Script>());
            go.GetComponent <Script>().actions = ActionManipulator.ScriptContainerToActionList(scriptComposer);
            gameData.nbStep = ActionManipulator.getNbStep(go.GetComponent <Script>());
        }

        //Check if If actions are valid
        int nbStepToAdd = 0;

        foreach (GameObject scripted in controllableGO)
        {
            int nbStepPlayer = 0;
            ActionManipulator.invalidAllIf(scripted.GetComponent <Script>());
            Action nextIf = ActionManipulator.getCurrentIf(scripted);

            while (nextIf != null && !ActionManipulator.endOfScript(scripted))
            {
                //Check if ok
                bool    ifok = nextIf.ifNot;
                Vector2 vec  = new Vector2();
                switch (ActionManipulator.getDirection(scripted.GetComponent <Direction>().direction, nextIf.ifDirection))
                {
                case Direction.Dir.North:
                    vec = new Vector2(0, 1);
                    break;

                case Direction.Dir.South:
                    vec = new Vector2(0, -1);
                    break;

                case Direction.Dir.East:
                    vec = new Vector2(1, 0);
                    break;

                case Direction.Dir.West:
                    vec = new Vector2(-1, 0);
                    break;
                }

                switch (nextIf.ifEntityType)
                {
                case 0:
                    for (int i = 1; i <= nextIf.range; i++)
                    {
                        foreach (GameObject go in wallGO)
                        {
                            if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i)
                            {
                                ifok = !nextIf.ifNot;
                            }
                        }
                    }
                    break;

                case 1:
                    for (int i = 1; i <= nextIf.range; i++)
                    {
                        foreach (GameObject go in controllableGO)
                        {
                            if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i &&
                                go.tag == "Ennemy")
                            {
                                ifok = !nextIf.ifNot;
                            }
                        }
                    }
                    break;

                case 2:
                    for (int i = 1; i <= nextIf.range; i++)
                    {
                        foreach (GameObject go in controllableGO)
                        {
                            if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i &&
                                go.tag == "Player")
                            {
                                ifok = !nextIf.ifNot;
                            }
                        }
                    }
                    break;
                }

                if (ifok)
                {
                    nextIf.ifValid = true;
                    if (scripted.tag == "Player")
                    {
                        nbStepPlayer += ActionManipulator.getNbStep(nextIf, true);
                    }
                }
                else
                {
                    nextIf.currentAction = nextIf.actions.Count - 1;
                    ActionManipulator.incrementActionScript(scripted.GetComponent <Script>());
                }
                nextIf = ActionManipulator.getCurrentIf(scripted);
            }

            if (nbStepPlayer > nbStepToAdd)
            {
                nbStepToAdd = nbStepPlayer;
            }
        }
        gameData.nbStep += nbStepToAdd;

        if (gameData.nbStep > 0)
        {
            gameData.totalExecute++;
        }
    }