示例#1
0
    /* Players every frame */
    void FixedUpdate()
    {
        movePlayer(this.moveToObstacle);


        // shininegh color
        if (this.sameColor)
        {
            this.fixedUpdate++;
        }
        if (this.sameColor && fixedUpdate == fixUpdateInterval)
        {
            fixedUpdate = 0;
            for (int i = 0; i < sameColorList.Count; i++)
            {
                if (moveableObs.ContainsKey(sameColorList[i].getTag()))
                {
                    moveableObs[sameColorList[i].getTag()].disHighlight();
                    sameColorList[i].highlight();
                    obstacle temp = moveableObs[sameColorList[i].getTag()];
                    moveableObs[sameColorList[i].getTag()] = sameColorList[i];
                    sameColorList[i] = temp;
                }
            }
        }
    }
示例#2
0
    private float axisZ = 1.7f;     //Controller of the hieght of the ship.

    void Start()
    {
        this.statementList  = new List <Statement> ();
        this.sameColorList  = new List <obstacle> ();
        this.loopPath       = new List <obstacle> ();
        this.moveableObs    = new Dictionary <string, obstacle> ();
        this.moveToObstacle = firstObstacle;
        this.targetObatacle = firstObstacle;

        lr = gameObject.AddComponent <LineRenderer>();
        lr.SetWidth((float)0.05, (float)0.05);
        lr.material = new Material(Shader.Find("Sprites/Default"));
        lr.SetColors(Color.black, Color.white);
        lr.SetVertexCount(2);

        drawline(firstObstacle.transform.position);

        this.transform.LookAt(firstObstacle.transform.position - new Vector3(0f, 0f, axisZ));
        if (transform.position.x > moveToObstacle.transform.position.x)
        {
            this.transform.Rotate(transform.rotation.x, transform.rotation.y, 180);
        }
        //this.transform.Rotate (transform.rotation.x, transform.rotation.y, 150);
        //this.transform.Rotate (transform.rotation.x, transform.rotation.y, 20);
    }
    IEnumerator SpawnRandomObstacles()
    {
        yield return(new WaitForSeconds(Random.Range(0.5f, 5f)));

        int index = Random.Range(0, obstaclesToSpawn.Count);

        while (true)
        {
            obstacle obstacles = obstaclesToSpawn[index];

            if (!obstacles.gameObject.activeInHierarchy)
            {
                obstacles.gameObject.SetActive(true);
                obstacles.transform.position = transform.position;
                break;
            }
            else
            {
                index = Random.Range(0, obstaclesToSpawn.Count);
            }
        }


        StartCoroutine(SpawnRandomObstacles());
    }
示例#4
0
    /*
     * Calculate the movement base on where the character is.
     */
    private void calMovement(obstacle obs)
    {
        IEnumerable <char> c      = "";
        string             result = "";

        obstacle[] connObs = obs.getConnection();

        foreach (Statement s in statementList)
        {
            if (s.getType().Equals("I"))
            {
                string temp = s.getCondtion();
                if (temp.Contains(obs.getTag()))
                {
                    c = c.Union(s.getResult());
                }
            }
            else if (s.getType().Equals("L"))
            {
                string   str     = s.getCondtion() + s.getResult();
                obstacle lresult = checkLoop(0, 0, str, obs, null);
                if (lresult != null)
                {
                    moveableObs.Add("L", lresult);
                    lresult.highlight();
                    send("L");

                    this.loopPath.IndexOf(lresult);
                }
            }
        }

        foreach (char ch in c)
        {
            result += ch;
        }

        foreach (obstacle o in connObs)
        {
            //print ("oname:" + o.getName());
            if (result.Contains(o.getTag()))
            {
                if (moveableObs.ContainsKey(o.getTag()))
                {
                    //print ("test" + o.getTag());
                    print(this.sameColor);
                    this.sameColorList.Add(o);
                    this.sameColor = true;
                }
                else
                {
                    moveableObs.Add(o.getTag(), o);
                    o.highlight();
                    send(o.getTag());
                }
            }
        }
    }
示例#5
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (!_grounded && other.gameObject.tag == "Terrain")
        {
            MapController map = other.gameObject.GetComponent <MapController>();
            if (!map.leftMap(transform.position.x))
            {
                bool isMain = map == Camera.main.GetComponent <followPlayer>()._mainMap;

                if (!map.badCollision(transform.right, transform.position.x, _badCollisionAngle))
                {
                    _grounded = true;
                    if (achievedRotation)
                    {
                        _rotationBoostTime = maxRotationBoostTime;
                    }
                    achievedRotation = false;
                    _rotation        = 0;

                    _currentMap = map;
                    adjustRotationToMap(true);

                    if (isMain)
                    {
                        _sp.land();
                    }
                    else
                    {
                        _sp.startGrind();
                    }
                }
                else if (isMain)
                {
                    _rotationBoostTime = 0;
                    blink();
                }
            }
        }
        else if (other.gameObject.tag == "Obstacle")
        {
            _obstacleTime      = maxObstaclePenaltyTime;
            _rotationBoostTime = 0;
            obstacle o = other.gameObject.GetComponent <obstacle>();
            _velocity = _velocity.normalized * 0;
            _sp.trash();
            o.destroy();
        }
        else if (other.gameObject.tag == "ramp")
        {
            if (_grounded && _currentMap == _mainMap)
            {
                weakJump();
            }
        }
    }
示例#6
0
 /*
  * Get data from user
  */
 public void input(string command)
 {
     if (inputAble)
     {
         print(this.name + " get command: " + command);
         print(command.Length);
         if (!gameStart)
         {
             newStatement += command;
             if (newStatement.Contains("E"))
             {
                 print(newStatement);
                 addStatement(newStatement);
                 newStatement = "";
             }
         }
         else
         {
             foreach (string s in moveableObs.Keys)
             {
                 print(s);
             }
             if (moveableObs.ContainsKey(command))
             {
                 if (command.Contains("L"))
                 {
                     this.moveToObstacle = this.loopPath.ElementAt(1);
                     this.targetObatacle = moveableObs[command];
                     this.speed          = 8f;
                 }
                 else
                 {
                     this.moveToObstacle = moveableObs[command];
                     this.targetObatacle = this.moveToObstacle;
                 }
                 this.moveObject = true;
                 this.inputAble  = false;
                 foreach (obstacle o in moveableObs.Values)
                 {
                     o.disHighlight();
                 }
                 this.sameColorList.Clear();
                 this.sameColor = false;
                 this.moveableObs.Clear();
             }
         }
     }
 }
示例#7
0
    /*
     * Check if the obstacle be able to use LOOP
     */
    private obstacle checkLoop(int x, int y, string str, obstacle obs, obstacle final)
    {
        obstacle finalObstacle = final;
        int      current       = x;
        int      next          = 0;

        if (current == str.Length - 1)
        {
            next = 0;
        }
        else
        {
            next = current + 1;
        }
        if (y > 0 && current == str.Length - 1)
        {
            finalObstacle = obs;
        }
        //print (str + ": " + current);
        if (obs.getTag().Contains(str.ElementAt(current)))
        {
            this.loopPath.Add(obs);

            foreach (obstacle o in obs.getConnection())
            {
                if (o.getTag().Contains(str.ElementAt(next)) && !loopPath.Contains(o))
                {
                    if (current == str.Length - 1)
                    {
                        return(checkLoop(next, y + 1, str, o, finalObstacle));
                    }
                    else
                    {
                        return(checkLoop(next, y, str, o, finalObstacle));
                    }
                }
            }

            if (y > 0)
            {
                return(finalObstacle);
            }
        }
        return(null);
    }
示例#8
0
    /* Moves player based on provided next position */
    void movePlayer(obstacle obs)
    {
        //gets next objects possition
        float   xPos   = obs.transform.position.x;
        float   yPos   = obs.transform.position.y;
        Vector3 newPos = new Vector3(xPos, yPos, -1.7f);

        float step = this.speed * Time.deltaTime;

        if (moveObject == true)
        {
            this.planetTrigger = false;
            transform.position = Vector3.MoveTowards(transform.position, newPos, step);
            transform.LookAt(this.moveToObstacle.transform.position - new Vector3(0f, 0f, axisZ));
            if (transform.position.x > moveToObstacle.transform.position.x)
            {
                this.transform.Rotate(transform.rotation.x, transform.rotation.y, 180);
            }
            this.speed += 0.05f;
        }

        if (this.planetTrigger)
        {
            this.transform.position = this.moveToObstacle.transform.position - new Vector3(0f, 0f, axisZ);
        }

        if (transform.position.x == newPos.x && transform.position.y == newPos.y)
        {
            this.moveObject    = false;
            this.planetTrigger = true;
            this.speed         = 2.5f;


            //this.transform.position.x = this.moveToObstacle.transform.position.x;
            //this.transform.position.y = this.moveToObstacle.transform.position.y;
        }
    }
示例#9
0
文件: Player.cs 项目: Dripper7/GGJ18
    // Update is called once per frame
    void FixedUpdate()
    {
        PlayerInput();

        if (speedfactor > speedlimit)
        {
            speedfactor = speedlimit;
        }
        if (speed < minspeed)
        {
            speed = minspeed * SpeedPercentage;
        }
        speed = speedfactor * SpeedPercentage;


        zAxis   = transform.localPosition;
        zAxis.z = 0;
        transform.localPosition = zAxis;

        if (timer > 2)
        {
            speedblocker = false;
            timer        = 0;
        }
        if (speedblocker)
        {
            speedlimit = 0.5f;
            timer     += Time.deltaTime;
        }

        this.transform.rotation = new Quaternion(0, 0, 0, 0);

        if (SA_AttachedKugeln.Count > 0)
        {
            GetComponentInChildren <Image>().fillAmount = 0;

            var v3 = Input.mousePosition;
            v3.z = 10.0f;
            v3   = Camera.main.ScreenToWorldPoint(v3);
            //this.GetComponent<LineRenderer>().enabled = true;
            //this.GetComponent<LineRenderer>().SetPosition(0, this.transform.position);
            //this.GetComponent<LineRenderer>().SetPosition(1, Camera.main.ScreenToWorldPoint(Input.mousePosition));

            foreach (Kugel Kugel in SA_AttachedKugeln)
            {
                Kugel.kugelstate = KugelState.Loaded;

                Physics.IgnoreCollision(Kugel.GetComponent <Collider>(), GetComponent <Collider>(), true);
                this.GetComponent <LineRenderer>().SetPosition(0, Vector3.zero);
                Kugel.GetComponent <LineRenderer>().SetPosition(1, this.transform.position - Kugel.transform.position);
                if (Vector3.Distance(Kugel.transform.position, this.transform.position) > 0.1f)
                {
                    Kugel.delta += Time.deltaTime * 2;
                }
                Kugel.transform.position = Vector3.MoveTowards(Kugel.transform.position, this.transform.position, Kugel.delta);
            }
            if (singleplayer)
            {
                foreach (Kugel Kugel in SA_AttachedKugeln)
                {
                    if (Input.GetKeyDown(KeyCode.Space) && !Shoot && Vector3.Distance(this.transform.position, Kugel.transform.position) < 0.5f)
                    {
                        //Shoot = true;
                        foreach (obstacle obstacl in obstacle.All)
                        {
                            if (obstacl.obstaclestate == ObstacleState.DestructableWall)
                            {
                                if (Vector3.Distance(obstacl.transform.position, this.transform.position) < oldDistance)
                                {
                                    oldDistance    = Vector3.Distance(obstacl.transform.position, this.transform.position);
                                    current_target = obstacl;
                                }
                            }
                            //foreach (obstacle obstacl in obstacle.All)
                            //{
                            //    Vector3 screenPoint = Camera.main.WorldToViewportPoint(obstacl.transform.position);
                            //    bool onScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
                            //}
                        }
                        if (current_target.obstaclestate == ObstacleState.DestructableWall)
                        {
                            Debug.Log("works");
                            GetComponent <AudioSource>().clip = aShot;
                            GetComponent <AudioSource>().Play();
                            Kugel.kugelstate = KugelState.Shot;
                            SA_AttachedKugeln.Remove(Kugel);
                            Kugel.GetComponent <Rigidbody>().AddForce((current_target.transform.position - this.transform.position).normalized * 55, ForceMode.Impulse);
                            Kugel.EnableCollider(this, Kugel);
                            current_target = null;
                            oldDistance    = 10000;
                            break;
                        }
                    }
                }
            }
            if (!singleplayer)
            {
                if (this == All[0])
                {
                    foreach (Kugel Kugel in SA_AttachedKugeln)
                    {
                        if (Input.GetKeyDown(KeyCode.Space) && !Shoot && Vector3.Distance(this.transform.position, Kugel.transform.position) < 0.5f)
                        {
                            //Shoot = true;

                            {
                                {
                                    GetComponent <AudioSource>().clip = aShot;
                                    GetComponent <AudioSource>().Play();
                                    Kugel.kugelstate = KugelState.Shot;
                                    SA_AttachedKugeln.Remove(Kugel);
                                    Kugel.GetComponent <Rigidbody>().AddForce((All[1].transform.position - this.transform.position).normalized * 55, ForceMode.Impulse);
                                    Kugel.EnableCollider(this, Kugel);
                                    break;
                                }
                            }
                        }
                    }
                }
                if (this == All[1])
                {
                    foreach (Kugel kugel in SA_AttachedKugeln)
                    {
                        if (Input.GetKeyDown(KeyCode.M) && !Shoot && Vector3.Distance(this.transform.position, kugel.transform.position) < 0.5f)
                        {
                            {
                                {
                                    GetComponent <AudioSource>().clip = aShot;
                                    GetComponent <AudioSource>().Play();
                                    kugel.kugelstate = KugelState.Shot;
                                    SA_AttachedKugeln.Remove(kugel);
                                    kugel.GetComponent <Rigidbody>().AddForce((All[0].transform.position - this.transform.position).normalized * 55, ForceMode.Impulse);
                                    kugel.EnableCollider(this, kugel);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }

        if (SA_AttachedKugeln.Count == 0 && !SpecialAttackReady)
        {
            this.GetComponent <LineRenderer>().enabled = false;
            SAtimer += Time.deltaTime * 2;
            GetComponentInChildren <Image>().fillAmount = SAtimer;
            if (SAtimer > 1)
            {
                SAtimer            = 0;
                SpecialAttackReady = true;
            }
        }
    }
    public void Save()
    {
        // 1. Get the SaveName;
        string scenarioName = ScenarioName.text;

        // 2. Get all the existing scenes from gamemanager.
        List <GameObject> AllScenes = null;

        if (gamemanager.name == "DesignSceneGameManager")
        {
            AllScenes = gamemanager.GetComponent <DesignSceneGameManager>().AllScenes;
        }

        // 3. Create a folder named with savename.
        WorkingDirectory = Application.persistentDataPath + "/" + scenarioName;
        // If there already exists a scenario with scenarioName, replace it with the new one. Therefore,
        // users should make sure not to use the same scenario name
        if (Directory.Exists(WorkingDirectory))
        {
            Directory.Delete(WorkingDirectory, true);
        }
        Directory.CreateDirectory(WorkingDirectory);

        // 4. For each scene, do the followings
        foreach (GameObject Scene in AllScenes)
        {
            // 4.1 create a sub-folder with the scenarioName name
            WorkingDirectory = Application.persistentDataPath + "/" + scenarioName + "/" + Scene.name;
            Directory.CreateDirectory(WorkingDirectory);

            // 4.2 create a list to store all the names of the objects
            List <string> AllObjectNames = new List <string>();

            // 4.3 Fill in the class SceneDetails according to the design of the scene
            SceneDetails sceneDetails = new SceneDetails();
            sceneDetails.Walls       = new List <wall>();
            sceneDetails.Floors      = new List <floor>();
            sceneDetails.Ceilings    = new List <ceiling>();
            sceneDetails.Obstacles   = new List <obstacle>();
            sceneDetails.Doors       = new List <door>();
            sceneDetails.Fires       = new List <fire>();
            sceneDetails.Pedestrians = new List <pedestrian>();
            sceneDetails.Players     = new List <player>();
            // 4.3.1 Fill in the simulation info
            sceneDetails.SimTime = Scene.GetComponent <SceneInfo>().SimulationTime;
            sceneDetails.Width   = Scene.GetComponent <SceneInfo>().Width;
            sceneDetails.Length  = Scene.GetComponent <SceneInfo>().Length;
            sceneDetails.Height  = Scene.GetComponent <SceneInfo>().Height;
            sceneDetails.PlayerX = Scene.GetComponent <SceneInfo>().PlayerX;
            sceneDetails.PlayerY = Scene.GetComponent <SceneInfo>().PlayerY;
            // 4.3.2 fill in the info of different objects into sceneDetails
            foreach (Transform ChildObjectTransform in Scene.transform)
            {
                // Wall and its doors
                if (ChildObjectTransform.tag == "Wall")
                {
                    wall WallInfo = new wall();
                    Wall wallinfo = ChildObjectTransform.gameObject.GetComponent <Wall>();
                    AllObjectNames.Add(wallinfo.Name);
                    WallInfo.NameIndex = AllObjectNames.Count - 1;
                    WallInfo.xpos      = wallinfo.x_pos;
                    WallInfo.ypos      = wallinfo.y_pos;
                    WallInfo.zrot      = wallinfo.z_rot;
                    WallInfo.Width     = wallinfo.Width;
                    WallInfo.Height    = wallinfo.Height;
                    WallInfo.Opacity   = wallinfo.Opacity;
                    sceneDetails.Walls.Add(WallInfo);

                    // doors that are attached to it
                    foreach (Transform doorTransform in ChildObjectTransform)
                    {
                        if (doorTransform.tag == "Door")
                        {
                            door DoorInfo = new door();
                            Door doorinfo = doorTransform.gameObject.GetComponent <Door>();
                            AllObjectNames.Add(doorinfo.Name);
                            DoorInfo.NameIndex        = AllObjectNames.Count - 1;
                            DoorInfo.RelativePosition = doorinfo.RelativePosition;
                            DoorInfo.Width            = doorinfo.Width;
                            DoorInfo.Height           = doorinfo.Height;
                            if (doorinfo.Open)
                            {
                                DoorInfo.Open = 1;
                            }
                            else
                            {
                                DoorInfo.Open = 0;
                            }
                            DoorInfo.WallNameIndex = WallInfo.NameIndex;
                            AllObjectNames.Add(doorinfo.NextScene.name);
                            DoorInfo.SceneNameIndex = AllObjectNames.Count - 1;
                            sceneDetails.Doors.Add(DoorInfo);
                        }
                    }
                }
                // Floor
                else if (ChildObjectTransform.tag == "Floor")
                {
                    floor FloorInfo = new floor();
                    Floor floorinfo = ChildObjectTransform.gameObject.GetComponent <Floor>();
                    AllObjectNames.Add(floorinfo.Name);
                    FloorInfo.NameIndex = AllObjectNames.Count - 1;
                    FloorInfo.xpos      = floorinfo.x_pos;
                    FloorInfo.ypos      = floorinfo.y_pos;
                    FloorInfo.Width     = floorinfo.Width;
                    FloorInfo.Length    = floorinfo.Length;
                    sceneDetails.Floors.Add(FloorInfo);
                }
                // Ceiling
                else if (ChildObjectTransform.tag == "Ceiling")
                {
                    ceiling CeilingInfo = new ceiling();
                    Ceiling ceilinginfo = ChildObjectTransform.gameObject.GetComponent <Ceiling>();
                    AllObjectNames.Add(ceilinginfo.Name);
                    CeilingInfo.NameIndex = AllObjectNames.Count - 1;
                    CeilingInfo.xpos      = ceilinginfo.x_pos;
                    CeilingInfo.ypos      = ceilinginfo.y_pos;
                    CeilingInfo.zpos      = ceilinginfo.z_pos;
                    CeilingInfo.Width     = ceilinginfo.Width;
                    CeilingInfo.Length    = ceilinginfo.Length;
                    CeilingInfo.Opacity   = ceilinginfo.Opacity;
                    sceneDetails.Ceilings.Add(CeilingInfo);
                }
                // Obstacle
                else if (ChildObjectTransform.tag == "Obstacle")
                {
                    obstacle ObstacleInfo = new obstacle();
                    Obstacle obstacleinfo = ChildObjectTransform.gameObject.GetComponent <Obstacle>();
                    AllObjectNames.Add(obstacleinfo.Name);
                    ObstacleInfo.NameIndex = AllObjectNames.Count - 1;
                    ObstacleInfo.xpos      = obstacleinfo.x_pos;
                    ObstacleInfo.ypos      = obstacleinfo.y_pos;
                    ObstacleInfo.Width     = obstacleinfo.Width;
                    ObstacleInfo.Length    = obstacleinfo.Length;
                    ObstacleInfo.Height    = obstacleinfo.Height;
                    ObstacleInfo.Opacity   = obstacleinfo.Opacity;
                    sceneDetails.Obstacles.Add(ObstacleInfo);
                }
                // Fire
                else if (ChildObjectTransform.tag == "Fire")
                {
                    fire FireInfo = new fire();
                    Fire fireinfo = ChildObjectTransform.gameObject.GetComponent <Fire>();
                    AllObjectNames.Add(fireinfo.Name);
                    FireInfo.NameIndex  = AllObjectNames.Count - 1;
                    FireInfo.xpos       = fireinfo.x_pos;
                    FireInfo.ypos       = fireinfo.y_pos;
                    FireInfo.zpos       = fireinfo.z_pos;
                    FireInfo.Width      = fireinfo.Width;
                    FireInfo.Length     = fireinfo.Length;
                    FireInfo.HRRPUA     = fireinfo.HRRPUA;
                    FireInfo.CO_YIELD   = fireinfo.CO_YIELD;
                    FireInfo.SOOT_YIELD = fireinfo.SOOT_YIELD;
                    FireInfo.Fuel       = Array.IndexOf(fireinfo.Fuels,
                                                        fireinfo.FUEL);
                    sceneDetails.Fires.Add(FireInfo);
                }
                // Pedestrian
                else if (ChildObjectTransform.tag == "Pedestrian")
                {
                    pedestrian PedestrianInfo = new pedestrian();
                    Pedestrian pedestrianinfo = ChildObjectTransform.gameObject.GetComponent <Pedestrian>();
                    AllObjectNames.Add(pedestrianinfo.Name);
                    PedestrianInfo.NameIndex = AllObjectNames.Count - 1;
                    PedestrianInfo.xpos      = pedestrianinfo.x_pos;
                    PedestrianInfo.ypos      = pedestrianinfo.y_pos;
                    PedestrianInfo.Speed     = pedestrianinfo.Speed;
                    PedestrianInfo.Health    = pedestrianinfo.Health;
                    AllObjectNames.Add(pedestrianinfo.Exit.name);
                    PedestrianInfo.ExitNameIndex = AllObjectNames.Count - 1;
                    sceneDetails.Pedestrians.Add(PedestrianInfo);
                }
                else if (ChildObjectTransform.tag == "Player")
                {
                    player PlayerInfo = new player();
                    Player playerinfo = ChildObjectTransform.gameObject.GetComponent <Player>();
                    AllObjectNames.Add(playerinfo.Name);
                    PlayerInfo.NameIndex = AllObjectNames.Count - 1;
                    PlayerInfo.xpos      = playerinfo.x_pos;
                    PlayerInfo.ypos      = playerinfo.y_pos;
                    PlayerInfo.Speed     = playerinfo.Speed;
                    PlayerInfo.Health    = playerinfo.Health;
                    sceneDetails.Players.Add(PlayerInfo);
                }
            }

            // 4.4 Save AllObjectNames into a text file
            StreamWriter NamesTxtFile = new StreamWriter(WorkingDirectory + "/AllNames.txt");
            foreach (string name in AllObjectNames)
            {
                NamesTxtFile.WriteLine(name);
            }
            NamesTxtFile.Close();

            // 4.5 Save sceneDetails into a binary file, SceneDetails.dat
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(WorkingDirectory + "/SceneDetails.dat", FileMode.OpenOrCreate);
            bf.Serialize(file, sceneDetails);
            file.Close();
        }
    }
示例#11
0
        private void stateMachine_Tick(object sender, EventArgs e)
        {
            obstacle positionObstacle = obstacle.PAS_D_OBSTACLE;

            if (stateMachineActivated)
            {
                //Détermination de la position des obstacles en fonction des télémètres
                if (TelemetreC < distanceCentre ||
                    ((TelemetreG < distanceSecurite || TelemetreEG < distanceSecurite) &&
                     (TelemetreD < distanceSecurite || TelemetreED < distanceSecurite)))
                {
                    positionObstacle = obstacle.OBSTACLE_EN_FACE;
                }
                else if (TelemetreD < distanceCotes)
                {
                    //            (TelemetreD > 500 &&
                    //            TelemetreED < distanceSecurite && TelemetreC < distanceSecurite)) //Obstacle à droite
                    positionObstacle = obstacle.OBSTACLE_CRITIQUE_DROITE;
                }
                else if (TelemetreG < distanceCotes)
                {
                    positionObstacle = obstacle.OBSTACLE_CRITIQUE_GAUCHE;
                }
                else if (TelemetreD < distanceCotes &&
                         TelemetreED < distanceECotes)
                {
                    positionObstacle = obstacle.OBSTACLE_A_DROITE;
                }
                else if (TelemetreG < distanceCotes &&
                         TelemetreEG < distanceECotes)
                {
                    positionObstacle = obstacle.OBSTACLE_A_GAUCHE;
                }
                else if (TelemetreG > distanceCotes &&
                         TelemetreC > distanceCentre &&
                         TelemetreEG < distanceECotes)
                {
                    positionObstacle = obstacle.OBSTACLE_E_GAUCHE;
                }
                else if (TelemetreD > distanceCotes &&
                         TelemetreC > distanceCentre &&
                         TelemetreED < distanceECotes)
                {
                    positionObstacle = obstacle.OBSTACLE_E_DROIT;
                }
                else if (TelemetreC < distanceCentreEloigne ||
                         TelemetreD < distanceCotesEloigne ||
                         TelemetreG < distanceCotesEloigne ||
                         TelemetreED < distanceECotesEloigne ||
                         TelemetreEG < distanceECotesEloigne)
                {
                    positionObstacle = obstacle.OBSTACLE_ELOIGNE;
                }
                else if (TelemetreD > distanceCotes &&
                         TelemetreC > distanceCentre &&
                         TelemetreG > distanceCotes &&
                         TelemetreEG > distanceECotes &&
                         TelemetreED > distanceECotes) //pas d?obstacle
                {
                    positionObstacle = obstacle.PAS_D_OBSTACLE;
                }

                //Détermination de l?état à venir du robot
                if (positionObstacle == obstacle.PAS_D_OBSTACLE)
                {
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_AVANCE });
                    stateChanged = (int)stateRobot.STATE_AVANCE;
                    if (timestamp_1 - timestamp > 20)
                    {
                        coteChoisi  = 0;
                        nombreTours = 0;
                    }
                }
                else if (positionObstacle == obstacle.OBSTACLE_EN_FACE || nombreTours > 20)
                {
                    timestamp_1 = timestamp;
                    if (Math.Abs(TelemetreG - TelemetreD) > 1 && coteChoisi == 0)
                    {
                        if (TelemetreG > TelemetreD)
                        {
                            UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_SUR_PLACE_GAUCHE });
                            stateChanged = (int)stateRobot.STATE_TOURNE_SUR_PLACE_GAUCHE;
                            coteChoisi   = 1;
                        }
                        else
                        {
                            UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_SUR_PLACE_DROITE });
                            stateChanged = (int)stateRobot.STATE_TOURNE_SUR_PLACE_DROITE;
                            coteChoisi   = 2;
                        }
                    }
                    else
                    {
                        if (coteChoisi != 0)
                        {
                            UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)(6 + coteChoisi * 2) });
                            stateChanged = 6 + coteChoisi * 2;
                        }
                    }
                }
                else if (positionObstacle == obstacle.OBSTACLE_A_DROITE)
                {
                    nombreTours++;
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_GAUCHE });
                    stateChanged = (int)stateRobot.STATE_TOURNE_GAUCHE;
                }
                else if (positionObstacle == obstacle.OBSTACLE_A_GAUCHE)
                {
                    nombreTours++;
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_DROITE });
                    stateChanged = (int)stateRobot.STATE_TOURNE_DROITE;
                }
                else if (positionObstacle == obstacle.OBSTACLE_ELOIGNE)
                {
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_AVANCE_LENTEMENT });
                    stateChanged = (int)stateRobot.STATE_AVANCE_LENTEMENT;
                    if (timestamp_1 - timestamp > 20)
                    {
                        coteChoisi  = 0;
                        nombreTours = 0;
                    }
                }
                else if (positionObstacle == obstacle.OBSTACLE_CENTRE_DROIT)
                {
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_SUR_PLACE_GAUCHE });
                    stateChanged = (int)stateRobot.STATE_TOURNE_SUR_PLACE_GAUCHE;
                }
                else if (positionObstacle == obstacle.OBSTACLE_CENTRE_GAUCHE)
                {
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_SUR_PLACE_DROITE });
                    stateChanged = (int)stateRobot.STATE_TOURNE_SUR_PLACE_DROITE;
                }
                else if (positionObstacle == obstacle.OBSTACLE_E_DROIT)
                {
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_LENTEMENT_GAUCHE });
                    stateChanged = (int)stateRobot.STATE_TOURNE_LENTEMENT_GAUCHE;
                    nombreTours++;
                }
                else if (positionObstacle == obstacle.OBSTACLE_E_GAUCHE)
                {
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_LENTEMENT_DROITE });
                    stateChanged = (int)stateRobot.STATE_TOURNE_LENTEMENT_DROITE;
                    nombreTours++;
                }
                else if (positionObstacle == obstacle.OBSTACLE_CRITIQUE_DROITE)
                {
                    nombreTours++;
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_SUR_PLACE_GAUCHE });
                    stateChanged = (int)stateRobot.STATE_TOURNE_SUR_PLACE_GAUCHE;
                }
                else if (positionObstacle == obstacle.OBSTACLE_CRITIQUE_GAUCHE)
                {
                    nombreTours++;
                    UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateRobot.STATE_TOURNE_SUR_PLACE_DROITE });
                    stateChanged = (int)stateRobot.STATE_TOURNE_SUR_PLACE_DROITE;
                }
            }
        }
示例#12
0
    /* Finds out when the next object is reached and gives movement options */
    void OnTriggerEnter(Collider coll)
    {
        if (!coll.name.StartsWith("C"))
        {
            print("hit the ship");
            if (coll.name == this.targetObatacle.getName())
            {
                if (coll.gameObject.name == this.finishObstacle.getName())
                {
                    this.inputAble      = false;
                    this.moveToObstacle = goal;
                    this.moveObject     = true;
                    print("Ready to finish");
                }
                else if (coll.gameObject.name == this.goal.getName())
                {
                    send("GameFin");
                }
                else
                {
                    this.loopPath.Clear();
                    //this.speed = 2.5f;
                    this.inputAble = true;
                    calMovement(moveToObstacle);
                }
            }
            else
            {
                int index = this.loopPath.IndexOf(this.moveToObstacle) + 1;
                if (index < this.loopPath.Count)
                {
                    this.moveToObstacle = this.loopPath.ElementAt(index);
                }
            }
            //this.planetTrigger = true;
            //this.transform.position = this.moveToObstacle.transform.position - new Vector3(0f,0f,1.5f);
            //this.transform.position.x = this.moveToObstacle.transform.position.x;
            //this.transform.position.y = this.moveToObstacle.transform.position.y;
        }

        /*
         * if (!coll.name.StartsWith ("C")) {
         *      if (coll.gameObject.name == "FINISH") {
         *              this.inputAble = false;
         *              send("GameFin");
         *      } else {
         *              if(coll.name == this.targetObatacle.getName()){
         *                      //this.travling = false;
         *                      this.loopPath.Clear();
         *                      this.speed = 2f;
         *                      this.inputAble = true;
         *                      calMovement(moveToObstacle);
         *              }else{
         *                      int index = this.loopPath.IndexOf(this.moveToObstacle) + 1;
         *                      if(index < this.loopPath.Count){
         *                              this.moveToObstacle = this.loopPath.ElementAt(index);
         *                      }
         *              }
         *      }
         * }
         */
    }