Example #1
0
 public doorinfo getDoorInfo(int doorId)
 {
     //foreach (doorinfo doorInfo in mDoorInfos) {
     for (int i = 0; i < mDoorInfos.Count; ++i)
     {
         doorinfo doorInfo = mDoorInfos[i];
         if (doorInfo.mId == doorId)
         {
             return(doorInfo);
         }
     }
     return(null);
 }
Example #2
0
    public roominfo getNextRoom(doorinfo doorInfo)
    {
        foreach (roominfo roomInfo in mRoomInfos)
        {
            if (roomInfo.mId == doorInfo.mNextRoomId)
            {
                roomInfo.mEnterDoorId = doorInfo.mNextDoorId;

                mCurRoomId = roomInfo.mId;
                return(roomInfo);
            }
        }
        return(null);
    }
Example #3
0
    public void initCharPos()
    {
        roominfo roomInfo = mMapInfo.getCurRoom();

        float x = 0;
        float y = 0;

        doorinfo doorInfo = roomInfo.getDoorInfo(roomInfo.mEnterDoorId);

        if (doorInfo != null)
        {
            //Debug.Log ("roomInfoEnterDoorId: " + roomInfo.mEnterDoorId + ",doorInfo:" + doorInfo.mId);
            //Debug.Log ("doorInfo.mDir:" + doorInfo.mDir);

            switch (doorInfo.mDir)
            {
            case constant.Direction.east:
                x = 4;
                break;

            case constant.Direction.west:
                x = -4;
                break;

            case constant.Direction.south:
                y = -4;
                break;

            case constant.Direction.north:
                y = 4;
                break;
            }

            GameObject door = getDoorTouchObj(doorInfo.mId);



            if (door != null)
            {
                GameObject role = GameObject.FindGameObjectWithTag(constant.TAG_PLAYER);
                role.gameObject.transform.position = new Vector3(door.transform.position.x + x, door.transform.position.y + y, -1);
            }
        }
        else
        {
            //Debug.Log("error roomInfo.mEnterDoorId:" + roomInfo.mEnterDoorId );
        }
    }
Example #4
0
    public roominfo()
    {
        mDoorInfos = new List <doorinfo> ();

        doorinfo doorInfo = new doorinfo();

        doorInfo.mId         = 1;
        doorInfo.mNextRoomId = 1;
        mDoorInfos.Add(doorInfo);

        mSceneIndex = 0;
        mFAcc       = 60.0f;

        mItemPrefabs    = new List <KeyValuePair <itemtemplate, Vector3> > ();
        mMonsterPrefabs = new List <KeyValuePair <monstertemplate, Vector3> > ();
    }
Example #5
0
    public mapinfo getFirstMap()
    {
        mapinfo mapInfo = new mapinfo();

        mapInfo.mRoomInfos = new List <roominfo> ();

        roominfo roomInfo = new roominfo();

        roomInfo.roomH = 1;
        roomInfo.roomW = 1;
        roomInfo.roomX = 4;
        roomInfo.roomY = 3;

        roomInfo.mSceneIndex = 0;
        roomInfo.mId         = 1;

        roomInfo.mDoorInfos = new List <doorinfo>();
        {
            doorinfo doorInfo = new doorinfo();
            doorInfo.mId         = 1;
            doorInfo.mDir        = constant.Direction.south;
            doorInfo.mNextDoorId = 2;
            doorInfo.mNextRoomId = 1;
            doorInfo.mX          = 0.5f;
            doorInfo.mY          = 1;
            roomInfo.mDoorInfos.Add(doorInfo);
        }
        {
            doorinfo doorInfo = new doorinfo();
            doorInfo.mId         = 2;
            doorInfo.mDir        = constant.Direction.north;
            doorInfo.mNextDoorId = 1;
            doorInfo.mNextRoomId = 1;
            doorInfo.mX          = 0.5f;
            doorInfo.mY          = 0;
            roomInfo.mDoorInfos.Add(doorInfo);
        }

        mapInfo.mRoomInfos.Add(roomInfo);

        mapInfo.mCurRoomId = 1;

        return(mapInfo);
    }
Example #6
0
    public void enterRoom(GameObject door, GameObject role)
    {
        doorinfo doorInfo = door.GetComponent <room_property>().mDoorInfo;

        //Debug.Log ("enterRoom doorInfo:" + doorInfo.mX + ","
        //           + doorInfo.mY + ","
        //           + doorInfo.mDir + ","
        //           + doorInfo.mNextRoomId + ","
        //           + doorInfo.mNextDoorId );

        role.gameObject.rigidbody.velocity = new Vector3(0, 0, 0);
        //role.gameObject.transform.position = new Vector3 (-6, 0, -1);

        //char_enter_script enter = door.GetComponent<char_enter_script> ();
        //Debug.Log ("enterRoom dir:" + enter.mDir);

        //GameObject.DontDestroyOnLoad (this.gameObject);
        GameObject.DontDestroyOnLoad(role);
        roominfo roomInfo = constant.getMapFactory().getNextRoom(mMapInfo, doorInfo);

        loadRoom(roomInfo);
    }
Example #7
0
    public mapinfo getRandomMap(maplogic logic)
    {
        mapinfo mapInfo = new mapinfo();

        mapInfo.mRoomInfos = new List <roominfo> ();

        int roomNum     = logic.getFloorTotalRoomNum();
        int itemRoomNum = roomNum / 4 + (Random.Range(-1, 1));

        if (itemRoomNum <= 0)
        {
            itemRoomNum = 1;
        }
        int roomId = 1;
        int doorId = 1;

        for (int i = 0; i < roomNum; ++i)
        {
            roominfo roomInfo = new roominfo();
            roomInfo.roomH = 1;
            roomInfo.roomW = 1;

            roomInfo.mRoomType = constant.RoomType.Monster;
            if (i == 0)
            {
                roomInfo.mRoomType = constant.RoomType.Start;
            }
            if (i == roomNum - 1)
            {
                roomInfo.mIsBossRoom = true;
            }

            roomInfo.mSceneIndex = 2;
            roomInfo.mId         = roomId;
            ++roomId;
            roomInfo.mDoorInfos = new List <doorinfo>();

            //左边门
            if (i > 0)
            {
                doorinfo doorInfo = new doorinfo();
                doorInfo.mId = doorId;
                ++doorId;

                doorInfo.mDir        = constant.Direction.east;
                doorInfo.mNextDoorId = doorId - 2;
                doorInfo.mNextRoomId = roomId - 2;
                doorInfo.mX          = 0f;
                doorInfo.mY          = 0.5f;
                roomInfo.mDoorInfos.Add(doorInfo);
            }

            //右边门
            if (i != roomNum - 1)
            {
                doorinfo doorInfo = new doorinfo();
                doorInfo.mId = doorId;
                ++doorId;

                doorInfo.mDir        = constant.Direction.west;
                doorInfo.mNextDoorId = doorId;
                doorInfo.mNextRoomId = roomId;
                doorInfo.mX          = 1f;
                doorInfo.mY          = 0.5f;
                doorInfo.mMain       = true;
                roomInfo.mDoorInfos.Add(doorInfo);
            }

            mapInfo.mRoomInfos.Add(roomInfo);
        }

        List <int> mMonsterRoomIds = new List <int>();

        for (int i = 1; i < roomId - 1; ++i)
        {
            mMonsterRoomIds.Add(i);
        }

        //创建几个到道具房间
        for (int i = 0; i < itemRoomNum; ++i)
        {
            //随机选择一个房间
            int nextRoomIndex = Random.Range(0, mMonsterRoomIds.Count - 1);
            int nextRoomId    = mMonsterRoomIds[nextRoomIndex];
            mMonsterRoomIds.RemoveAt(nextRoomIndex);
            roominfo nextRoomInfo = null;
            for (int j = 0; j < mapInfo.mRoomInfos.Count; ++j)
            {
                roominfo childInfo = mapInfo.mRoomInfos[j];
                if (childInfo.mId == nextRoomId)
                {
                    nextRoomInfo = childInfo;
                    break;
                }
            }

            if (nextRoomInfo != null)
            {
                roominfo roomInfo = new roominfo();
                roomInfo.roomH       = 1;
                roomInfo.roomW       = 1;
                roomInfo.mSceneIndex = 2;
                roomInfo.mRoomType   = constant.RoomType.Item;
                roomInfo.mId         = roomId;
                ++roomId;
                roomInfo.mDoorInfos = new List <doorinfo>();

                {
                    //随机选择一个门
                    List <constant.Direction> dirs     = nextRoomInfo.getRemainDirs();
                    constant.Direction        enterDir = dirs[Random.Range(0, dirs.Count - 1)];
                    Debug.Log("随机选择一个门:" + enterDir);
                    //加一个门给monster房间
                    {
                        doorinfo doorInfo = new doorinfo();
                        doorInfo.mId = doorId;
                        ++doorId;
                        doorInfo.mDir        = enterDir;
                        doorInfo.mNextDoorId = doorId;
                        doorInfo.mNextRoomId = roomInfo.mId;
                        //doorInfo.mX = 1f;
                        //doorInfo.mY = 0.5f;
                        doorInfo.mX = getDoorX(nextRoomInfo, doorInfo.mDir);
                        doorInfo.mY = getDoorY(nextRoomInfo, doorInfo.mDir);
                        nextRoomInfo.mDoorInfos.Add(doorInfo);
                    }

                    //加一个门给item房间指向上一个monster房间
                    {
                        doorinfo doorInfo = new doorinfo();
                        doorInfo.mId = doorId;
                        ++doorId;
                        doorInfo.mDir        = constant.getOppsiteDir(enterDir);                  //constant.Direction.west;
                        doorInfo.mNextDoorId = doorId - 2;
                        doorInfo.mNextRoomId = nextRoomInfo.mId;
                        doorInfo.mX          = getDoorX(roomInfo, doorInfo.mDir);
                        doorInfo.mY          = getDoorY(roomInfo, doorInfo.mDir);
                        roomInfo.mDoorInfos.Add(doorInfo);
                    }
                }

                {
                    roominfo nextNextRoomInfo = mapInfo.getNextMainRoomInfo(nextRoomInfo);
                    //随机选择一个门
                    List <constant.Direction> dirs     = roomInfo.getCanUseDirs(nextNextRoomInfo);
                    constant.Direction        enterDir = dirs[Random.Range(0, dirs.Count - 1)];
                    //加一个门给item房间指向下一个monster房间
                    {
                        doorinfo doorInfo = new doorinfo();
                        doorInfo.mId = doorId;
                        ++doorId;
                        doorInfo.mDir        = enterDir;
                        doorInfo.mNextDoorId = doorId;
                        doorInfo.mNextRoomId = nextNextRoomInfo.mId;
                        doorInfo.mX          = getDoorX(roomInfo, doorInfo.mDir);
                        doorInfo.mY          = getDoorY(roomInfo, doorInfo.mDir);
                        roomInfo.mDoorInfos.Add(doorInfo);
                    }

                    //加一个门给下一个monster房间
                    {
                        doorinfo doorInfo = new doorinfo();
                        doorInfo.mId = doorId;
                        ++doorId;
                        doorInfo.mDir        = constant.getOppsiteDir(enterDir);                  //constant.Direction.west;
                        doorInfo.mNextDoorId = doorId - 2;
                        doorInfo.mNextRoomId = roomInfo.mId;
                        doorInfo.mX          = getDoorX(nextNextRoomInfo, doorInfo.mDir);
                        doorInfo.mY          = getDoorY(nextNextRoomInfo, doorInfo.mDir);
                        nextNextRoomInfo.mDoorInfos.Add(doorInfo);
                    }
                }

                mapInfo.mRoomInfos.Add(roomInfo);
            }
        }

        mapInfo.mCurRoomId = 1;
        initMapScenes(mapInfo);

        return(mapInfo);
    }
Example #8
0
 public roominfo getNextRoom(mapinfo mapInfo, doorinfo doorInfo)
 {
     return(mapInfo.getNextRoom(doorInfo));
 }
 public room_property()
 {
     mDoorInfo = new doorinfo();
 }