示例#1
0
 public PlayState(GameObject r)
 {
     zeroVector  = new Vector2(0, 0);
     robot       = r;
     robotScript = robot.GetComponent <RobotBehaviour>();
     anim        = robot.GetComponent <Animator>();
 }
    public void SetBehaviour(BehaviourType b)
    {
        switch (b)
        {
        case BehaviourType.Boids1:
            behaviour = new RobotBehaviourBoids(this);
            break;

        case BehaviourType.Boids2:
            behaviour = new RobotBehaviourBoidsAdvanced(this);
            break;

        case BehaviourType.Net:
            behaviour = new RobotBehaviourNetAdvanced(this);
            break;

        case BehaviourType.SoloCoop:
            behaviour = new RobotBehaviourSoloCooperation(this);
            break;

        case BehaviourType.MinCheating:
            behaviour = new RobotBehaviourSoloCheating(this);
            break;

        default:
            Debug.LogError("Invalid Behaviour name");
            break;
        }
    }
示例#3
0
    //Estructuras de control

    public virtual IEnumerator repetir()
    {
        Transform      theRobot     = (Transform)Init.robotInstance;
        RobotBehaviour behaviour    = (RobotBehaviour)theRobot.GetComponent <RobotBehaviour>();
        int            i            = 0;
        Type           type         = behaviour.GetType();
        int            n            = int.Parse((string)arguments[0]);
        string         sentenceName = (string)arguments[1];

        if (n > i)
        {
            for (i = 0; i < n; i++)
            {
                MethodInfo methodInfo = type.GetMethod(sentenceName);
                behaviour.StartCoroutine(methodInfo.Name, 0);
            }
        }
        else
        {
            UI.runtimeErrorMsg = I18N.getValue("the_number_of_repetitions_was_not_specified");
        }
        yield return(new WaitForSeconds(0));

        //Fin de ejecucion
        UI.executingCurrentLine = false;
    }
示例#4
0
 private void OnTriggerExit(Collider other)
 {
     if (other.CompareTag("Robot"))
     {
         _currentState = DoorState.IDLE; //This resets the door after a robot comes through
     }
     _tempTriggerBot = null;
 }
示例#5
0
 private void OnTriggerStay(Collider other)
 {
     //allowBridgeExit = false;
     // Debug.Log("ontrigger");
     if (other.gameObject.CompareTag("Robot"))
     {
         _tempTriggerBot = other.gameObject.GetComponent <RobotBehaviour>();
     }
 }
 private void Start()
 {
     UI             = Canvas.GetComponent <InterfaceElements>();
     gameData       = Canvas.GetComponent <GameData>();
     sceneIndex     = gameData.SceneIndex;
     padBehaviour   = UI.Pad.GetComponent <PadBehaviour>();
     robotBehaviour = gameData.Player.GetComponent <RobotBehaviour>();
     UI.NextLevelButton.gameObject.SetActive(false);
     tasksCount = gameData.TaskTexts.Length;
 }
 public void PauseGame()
 {
     foreach (GameObject robot in robots)          //put all robots into pausestate
     {
         RobotBehaviour robotBehaviour = robot.GetComponent <RobotBehaviour>();
         robotBehaviour.CurrentState.EnterPauseState();
         robotBehaviour.freeTime = roundTime;
     }
     DisableMovingPreviews();
 }
 public void RevertToOldCommands()
 {
     foreach (GameObject robot in robots)
     {
         if (robot.GetComponent <RobotBehaviour>().oldCommands.Count > 0)
         {
             RobotBehaviour robotBehaviour = robot.GetComponent <RobotBehaviour>();
             robotBehaviour.Commands = robotBehaviour.oldCommands;
             robotBehaviour.oldCommands.Clear();
         }
     }
 }
示例#9
0
 public void SetBotInDropZone(RobotBehaviour rb, PointsDrop pd)
 {
     WaitingList.RemoveAt(0);
     if (pd == PointsDrop.DROPRIGHT)
     {
         CorrectBot = rb;
     }
     else
     {
         IncorrectBot = rb;
     }
 }
示例#10
0
    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.layer != LayerMask.NameToLayer("SwarmRobot"))
        {
            return;
        }

        var neighbour = other.gameObject.GetComponentInParent <RobotBehaviour>();

        if (neighbourClosest == neighbour)
        {
            neighbourClosest = null;
        }
    }
    //####
    // Utility functions
    //####
    Dictionary <int, List <Command> > GetCommandDict(List <GameObject> robotList)
    {
        Dictionary <int, List <Command> > dict = new Dictionary <int, List <Command> >();

        for (int i = 0; i < robotList.Count; i++)
        {
            RobotBehaviour rb = robotList[i].GetComponent <RobotBehaviour>();
            if (rb.Commands.Count > 0)
            {
                dict.Add(i, rb.Commands);
                //for(int j = 0; j < rb.Commands.Count;j++ ){
                //Debug.Log("x: " + rb.Commands[j].targetPosition.x + " y:" + rb.Commands[j].targetPosition.y);
                //}
            }
        }
        return(dict);
    }
示例#12
0
 /// <summary>
 /// Instantiates a random robot.
 /// </summary>
 IEnumerator InstantiateRandomRobot()
 {
     while (true)
     {
         GameObject robot = (GameObject)Instantiate(robotPrefab);
         robot.transform.position = SpawnFromTheCenter();
         BoxColor       r  = RandomBoxColor();
         RobotBehaviour rb = robot.GetComponent <RobotBehaviour>();
         if (rb == null)
         {
             Debug.LogError("Error, no robot behaviour available");
         }
         waitSecondsForRobotSpawn -= timeSubstractorRobot;
         waitSecondsForRobotSpawn  = Mathf.Clamp(waitSecondsForRobotSpawn, minimumRobotSpawn, 100);
         yield return(new WaitForSeconds(waitSecondsForRobotSpawn));
     }
 }
示例#13
0
    /** Efectiviza la animacion de la instruccion */
    void executeLine(int lineNo)
    {
        // FIXME: Aqui deberia delegarse al robot a fin de que realice la animacion
        string status = I18N.getValue("exec_line") + (currentLine + 1) + ": " + sentences[lineNo];

        statusText = status;

        // Invocar ejecucion visual via reflection
        try
        {
            object result = null;
            // Recuperar el BigBang, y a partir de alli el Robot que se tenga configurado
            Transform      theRobot  = (Transform)Init.robotInstance;
            RobotBehaviour behaviour = (RobotBehaviour)theRobot.GetComponent <RobotBehaviour>();
            Type           type      = behaviour.GetType();

            // Pruebas para argumentos.  Esto igualmente se recibe desde libreria
            string sentence     = (string)sentences[lineNo];
            string sentenceName = sentence.Substring(0, sentence.Contains("(") ? sentence.IndexOf("(") : sentence.Length);
            // Cargar los parametros segun la instruccion que sea.  FIXME: Deshardcode
            if (sentence.Contains("("))
            {
                behaviour.resetArguments();
                string sentenceArgs = sentence.Substring(sentence.IndexOf("("), sentence.Length - sentence.IndexOf("("));
                sentenceArgs = sentenceArgs.Replace("(", "").Replace(")", "").Replace(" ", "");
                string[] args = sentenceArgs.Split(","[0]);
                for (int i = 0; i < args.Length; i++)
                {
                    behaviour.addArgument(args[i]);
                }
            }

            MethodInfo methodInfo = type.GetMethod(sentenceName);
            // ParameterInfo[] parameters = methodInfo.GetParameters();

            // Invocar a la corutina encargada de ejecutar la visualizacion
            behaviour.StartCoroutine(methodInfo.Name, 0);
        }
        catch (Exception e)
        {
            Debug.Log("Exception!! " + e.ToString());
            statusText = I18N.getValue("unknown_line") + (currentLine + 1) + ": " + sentences[currentLine];
            run        = false;
        }
    }
 bool RevertCommand()
 {
     if (Input.GetKeyDown(KeyCode.V))
     {
         if (robotMovingTrails[selectedRobotIndex].Count > 0)
         {
             robotMovingTrails[selectedRobotIndex].Last().DestroyTrail();
             robotMovingTrails[selectedRobotIndex].RemoveAt(robotMovingTrails[selectedRobotIndex].Count - 1);
         }
         RobotBehaviour selectedRobotBehaviour = robots[selectedRobotIndex].GetComponent <RobotBehaviour>();
         if (selectedRobotBehaviour.Commands.Count > 0)
         {
             selectedRobotBehaviour.freeTime += selectedRobotBehaviour.Commands.Last().lifeDuration;
             selectedRobotBehaviour.Commands.RemoveAt(selectedRobotBehaviour.Commands.Count - 1);
         }
         return(true);
     }
     return(false);
 }
示例#15
0
    private void UpdateClosest(RobotBehaviour neighbourCandidate)
    {
        if (neighbourClosest == null)
        {
            neighbourClosest = neighbourCandidate;
            return;
        }
        if (neighbourCandidate == null)
        {
            return;
        }

        var distanceCandidate = Vector3.Distance(transform.position, neighbourCandidate.transform.position);
        var distanceCurrent   = Vector3.Distance(transform.position, neighbourClosest.transform.position);

        if (distanceCandidate < distanceCurrent)
        {
            neighbourClosest = neighbourCandidate;
        }
    }
示例#16
0
    void Start()
    {
        // PickableUpObject
        PickedUp = false;
        disposed = false;

        wander   = GetComponent <WanderBehaviour>();
        seek     = GetComponent <SeekBehaviour>();
        avoid    = GetComponent <AvoidBehaviour>();
        steering = GetComponent <DelegatedSteering>();

        behaviour = new RobotBehaviour(this);
        board     = UnityEngine.Object.FindObjectsOfType <BlackBoard>()[0];

        CurrentBattery = FullBattery;

        CurrentTrash   = null;
        PickedUpObject = null;

        behaviour.Start();
    }
示例#17
0
 private void ManageQueues()
 {
     if (waitZone)
     {
         // Debug.Log("uwu");
         if (_currentState == DoorState.IDLE && _correctPath && !CorrectBot)
         {
             //Debug.LogWarning("Yes");
             allowDropPointEntrance = true;
             CorrectBot             = _tempTriggerBot;
             _currentState          = DoorState.ROBOT_PASSING;
         }
         else if (_currentState == DoorState.IDLE && !_correctPath && !IncorrectBot)
         {
             // Debug.LogWarning("No");
             allowDropPointEntrance = true;
             IncorrectBot           = _tempTriggerBot;
             _currentState          = DoorState.ROBOT_PASSING;
         }
     }
 }
示例#18
0
    /** Ejecucion de una instruccion */
    IEnumerator executeStep()
    {
        step = true;
        currentLine++;

        if (currentLine == sentences.Count - 1)
        {
            statusText  = I18N.getValue("finished");
            currentLine = -1;
            run         = false;
            ended       = true;
            // Invocar a la corutina encargada de ejecutar la visualizacion
            Transform      theRobot  = (Transform)Init.robotInstance;
            RobotBehaviour behaviour = (RobotBehaviour)theRobot.GetComponent <RobotBehaviour>();
            behaviour.StartCoroutine("finalizar", 0);
        }
        else if (sentences[currentLine] != null && sentences[currentLine].ToString().Length > 0)
        {
            executingCurrentLine = true;
            executeLine(currentLine);
        }

        // Mientras que este ejecutando, esperar
        while (executingCurrentLine)
        {
            yield return(new WaitForSeconds(1 - currentRunningSpeed));
        }

        step = false;

        // Hubo un error?
        if (runtimeErrorMsg != null)
        {
            angry       = true;
            statusText  = "Error ejecutando linea " + (currentLine + 1) + ": " + sentences[currentLine] + ". " + runtimeErrorMsg;
            run         = false;
            ended       = true;
            currentLine = -1;
        }
    }
示例#19
0
    void OnGUI()
    {
        timeAffiche.GetComponent <TextMesh>().text    = "" + (int)TreeTimer.timer;
        garbageAffiche.GetComponent <TextMesh>().text = HoleBehaviour.plantedTrees.ToString();

        if (TreeTimer.win)
        {
            HoleBehaviour.normalTexture = true;
            GUI.DrawTexture(new Rect(Event.current.mousePosition.x - cursorSizeX / 2, Event.current.mousePosition.y - cursorSizeY / 2, cursorSizeX, cursorSizeY), myCursor);
            timeMesh.GetComponent <TextMesh>().text    = "" + (int)TreeTimer.timer;
            garbageMesh.GetComponent <TextMesh>().text = HoleBehaviour.plantedTrees.ToString();
            stars[0].SetActive(true);
            if (HoleBehaviour.plantedTrees > 10)
            {
                stars[1].SetActive(true);
            }
            if (HoleBehaviour.plantedTrees > 20)
            {
                stars[2].SetActive(true);
            }

            winLayer.SetActive(true);
            s1         = gameManager.GetComponent <RobotBehaviour>();
            s1.enabled = false;
        }

        if (HoleBehaviour.normalTexture)
        {
            GUI.DrawTexture(new Rect(Event.current.mousePosition.x - cursorSizeX / 2, Event.current.mousePosition.y - cursorSizeY / 2, cursorSizeX, cursorSizeY), myCursor);
        }
        else if (HoleBehaviour.plantTexture)
        {
            GUI.DrawTexture(new Rect(Event.current.mousePosition.x - cursorSizeX / 2, Event.current.mousePosition.y - cursorSizeY / 2, cursorSizeX, cursorSizeY), plantCursor);
        }
        else
        {
            GUI.DrawTexture(new Rect(Event.current.mousePosition.x - cursorSizeX / 2, Event.current.mousePosition.y - cursorSizeY / 2, cursorSizeX, cursorSizeY), shovelCursor);
        }
    }
示例#20
0
 public void AddToQueue(RobotBehaviour robotiyo)
 {
     WaitingList.Add(robotiyo);
 }
示例#21
0
 private void Awake()
 {
     robotBehaviour = Canvas.GetComponent <GameData>().Player.GetComponent <RobotBehaviour>();
 }
示例#22
0
 void Awake()
 {
     _rm = Robot.GetComponent <RobotBehaviour>();
     _ra = Robot.GetComponent <RobotAI>();
 }
示例#23
0
 public PauseState(GameObject r)
 {
     robot       = r;
     robotScript = robot.GetComponent <RobotBehaviour>();
 }