Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //        m_Agent.destination = TragetPos;
        if (!updated_env)
        {
            myMapInfo = FindObjectOfType<CreateMap>();
            mPlayerInfo = FindObjectOfType<PlayerController>();
            myGridSize = myMapInfo.getGridSize();
            myLocationOfFirstCube = myMapInfo.getFirstLocationOfCube();
            myMap = myMakeCopyOf(myMapInfo.GetMyMap());
            int rand_col = UnityEngine.Random.Range((int)0, (int)2);
            transform.position = myFindFirstRandomPlace(myMap, myLocationOfFirstCube, myGridSize, mPlayerInfo.transform.position, rand_col) + new Vector3(0f, transform.position[1], 0f);
            setTargetPos(transform.position - new Vector3(0f, this.transform.position[1], 0f), false);
            updated_env = true;

        }
        flag_hit_player = false;
        if (EnemyType == myEnemyType.NotFollowingPlayer)
        {
            float threshold = Mathf.Abs(EnemySpeed);
            bool flag_find_new_target = false;
            if ((this.transform.position - new Vector3(0.0f, transform.position[1], 0.0f) - TragetPos).magnitude < threshold)
            {
                flag_find_new_target = true;
            }
            else if (myUpdatedPath != null)
            {
                if (myUpdatedPath.Count == 0)
                {
                    flag_find_new_target = true;
                }
            }
            if (flag_find_new_target)
            {
                int rand_pos = UnityEngine.Random.Range((int)0, (int)2);
                if (rand_pos == 0)
                    TragetPos = myFindRandomPlace(myMap, myLocationOfFirstCube, myGridSize, true) + new Vector3(0f, transform.position[1], 0f);
                else
                    TragetPos = myFindRandomPlace(myMap, myLocationOfFirstCube, myGridSize, false) + new Vector3(0f, transform.position[1], 0f);
                flag_update_path = true;
            }
        }

        if (flag_update_path)
        {
            if (EnemyType == myEnemyType.FollowingPlayer)
            {
                setTargetPos(FindObjectOfType<PlayerController>().transform.position, true);//get position of the agent
            }
            else
            {
                setTargetPos(TragetPos, false);
            }
            Vector3 pos1 = mPosToMapIndex(transform.position, myLocationOfFirstCube, myGridSize);
            pos1[0] = Mathf.Round(pos1[0]);
            pos1[2] = Mathf.Round(pos1[2]);
            Vector3 pos2 = TragetPos;
            myUpdatedPath = mFindPath(pos1, pos2, myUpdatedPath);
            flag_update_path = false;
        }

        if (EscapeTileBombPos[1] >= 0)
        {
            Vector3 dis_player_bomb = transform.position - EscapeTileBombPos;
            if (!(Mathf.Abs(dis_player_bomb[0]) < myGridSize[0] && Mathf.Abs(dis_player_bomb[2]) < myGridSize[2]))
            {
                EscapeTileBombPos[1] = -1;
            }
        }

        mMoveOnThePath(myUpdatedPath, myLocationOfFirstCube, myGridSize);
        checkBombHitEnemy();
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (!updated_env)
        {
            myMapInfo             = FindObjectOfType <CreateMap>();
            myGridSize            = myMapInfo.getGridSize();
            myLocationOfFirstCube = myMapInfo.getFirstLocationOfCube();
            myMap = myMakeCopyOf(myMapInfo.GetMyMap());
            int rand_col = UnityEngine.Random.Range((int)0, (int)2);
            this.transform.localScale = new Vector3(myGridSize[0] / 2, this.transform.localScale[1], myGridSize[2] / 2);
            transform.position        = myFindFirstRandomPlace(myMap, myLocationOfFirstCube, myGridSize, rand_col) + new Vector3(0f, transform.position[1], 0f);
            setTargetPos(transform.position - new Vector3(0f, this.transform.position[1], 0f), false);
            updated_env = true;
        }

        if (EnemyType == myEnemyType.NotFollowingPlayer)
        {
            float threshold            = Mathf.Abs(EnemySpeed);
            bool  flag_find_new_target = false;
            if ((this.transform.position - new Vector3(0.0f, transform.position[1], 0.0f) - TragetPos).magnitude < threshold)
            {
                flag_find_new_target = true;
            }
            else if (myUpdatedPath != null)
            {
                if (myUpdatedPath.Count == 0)
                {
                    flag_find_new_target = true;
                }
            }
            if (flag_find_new_target)
            {
                int rand_pos = UnityEngine.Random.Range((int)0, (int)2);
                if (rand_pos == 0)
                {
                    TragetPos = myFindRandomPlace(myMap, myLocationOfFirstCube, myGridSize, true) + new Vector3(0f, transform.position[1], 0f);
                }
                else
                {
                    TragetPos = myFindRandomPlace(myMap, myLocationOfFirstCube, myGridSize, false) + new Vector3(0f, transform.position[1], 0f);
                }
                flag_update_path = true;
            }
        }

        if (flag_update_path)
        {
            if (EnemyType == myEnemyType.FollowingPlayer)
            {
            }
            else
            {
                setTargetPos(TragetPos, false);
            }
            Vector3 pos1 = mPosToMapIndex(transform.position, myLocationOfFirstCube, myGridSize);
            pos1[0] = Mathf.Round(pos1[0]);
            pos1[2] = Mathf.Round(pos1[2]);
            Vector3 pos2 = TragetPos;
            myUpdatedPath    = mFindPath(pos1, pos2, myUpdatedPath);
            flag_update_path = false;
        }

        mMoveOnThePath(myUpdatedPath, myLocationOfFirstCube, myGridSize);
    }
Exemplo n.º 3
0
    private void PlacePlayerOnMapAndGetInfo()
    {
        if (!flag_got_map_info)
        {
            planeInfo = FindObjectOfType<Playground>().gameObject;
            myMapInfo = planeInfo.GetComponent<CreateMap>();
            m_enemy_i = myMapInfo.getEnemies();
            myGridSize = myMapInfo.getGridSize();
            myLocationOfFirstCube = myMapInfo.getFirstLocationOfCube();
            myMap = myMapInfo.GetMyMap();

            //Reduce player size if player size is bigger than grid size
            Vector3 player_size = this.transform.localScale;
            if (player_size[0] > myGridSize[0])
                player_size[0] = myGridSize[0] - myGridSize[0] / 10;
            if (player_size[2] > myGridSize[2])
                player_size[2] = myGridSize[2] - myGridSize[2] / 10;
            this.transform.localScale = player_size;

            this.transform.position = LocateFirstAvailableSpace(myMap, myLocationOfFirstCube, myGridSize) + new Vector3(0f, transform.position[1], 0f);
            //+new Vector3(this.transform.localScale[0] / 2, 0f, this.transform.localScale[2] / 2);

            flag_got_map_info = true;
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (!updated_env)
        {
            myMapInfo = FindObjectOfType<CreateMap>();
            myGridSize = myMapInfo.getGridSize();
            myLocationOfFirstCube = myMapInfo.getFirstLocationOfCube();
            myMap = myMakeCopyOf(myMapInfo.GetMyMap());
            int rand_col = UnityEngine.Random.Range((int)0, (int)2);
            this.transform.localScale = new Vector3(myGridSize[0]/2, this.transform.localScale[1], myGridSize[2]/2);
            transform.position = myFindFirstRandomPlace(myMap, myLocationOfFirstCube, myGridSize, rand_col) + new Vector3(0f, transform.position[1], 0f);
            setTargetPos(transform.position - new Vector3(0f, this.transform.position[1], 0f), false);
            updated_env = true;

        }

        if (EnemyType == myEnemyType.NotFollowingPlayer)
        {
            float threshold = Mathf.Abs(EnemySpeed);
            bool flag_find_new_target = false;
            if ((this.transform.position - new Vector3(0.0f, transform.position[1], 0.0f) - TragetPos).magnitude < threshold)
            {
                flag_find_new_target = true;
            }
            else if (myUpdatedPath != null)
            {
                if (myUpdatedPath.Count == 0)
                {
                    flag_find_new_target = true;
                }
            }
            if (flag_find_new_target)
            {
                int rand_pos = UnityEngine.Random.Range((int)0, (int)2);
                if (rand_pos == 0)
                    TragetPos = myFindRandomPlace(myMap, myLocationOfFirstCube, myGridSize, true) + new Vector3(0f, transform.position[1], 0f);
                else
                    TragetPos = myFindRandomPlace(myMap, myLocationOfFirstCube, myGridSize, false) + new Vector3(0f, transform.position[1], 0f);
                flag_update_path = true;
            }
        }

        if (flag_update_path)
        {
            if (EnemyType == myEnemyType.FollowingPlayer)
            {
            }
            else
            {
                setTargetPos(TragetPos, false);
            }
            Vector3 pos1 = mPosToMapIndex(transform.position, myLocationOfFirstCube, myGridSize);
            pos1[0] = Mathf.Round(pos1[0]);
            pos1[2] = Mathf.Round(pos1[2]);
            Vector3 pos2 = TragetPos;
            myUpdatedPath = mFindPath(pos1, pos2, myUpdatedPath);
            flag_update_path = false;
        }

        mMoveOnThePath(myUpdatedPath, myLocationOfFirstCube, myGridSize);
    }