示例#1
0
    void changeDir()
    {
        //防止再次碰撞
        deleteDistance();

        constant.Direction dir = getNextDir();
        if (dir == mDir)
        {
            mDir    = getRandomDir();
            mHasDes = false;
        }
        else
        {
            mDir    = dir;
            mHasDes = true;
            GameObject obj = constant.getPlayer();
            mEndX = obj.transform.position.x;
            mEndY = obj.transform.position.y;
        }

        move_script moveScript = this.gameObject.GetComponent <move_script> ();

        moveScript.stopMove();

        Debug.Log("chagneDir:" + mDir);
        playDirAni();
        setDirAcc();
    }
示例#2
0
    public float getDoorY(roominfo info, constant.Direction dir)
    {
        switch (dir)
        {
        case constant.Direction.east:
            return(0.5f);

            break;

        case constant.Direction.north:
            return(0);

            break;

        case constant.Direction.south:
            return(1);

            break;

        case constant.Direction.west:
            return(0.5f);

            break;
        }
        return(0);
    }
示例#3
0
 public doorinfo()
 {
     mDir        = constant.Direction.east;
     mId         = 0;
     mNextRoomId = 0;
     mMain       = false;
 }
示例#4
0
    void Start()
    {
        mDir = constant.Direction.east;

        mDics = new Dictionary <constant.Direction, string> ();
        mDics.Add(constant.Direction.east, "enemy1_right");
        mDics.Add(constant.Direction.west, "enemy1_right");
        mDics.Add(constant.Direction.north, "enemy1_up");
        mDics.Add(constant.Direction.south, "enemy1_down");

        changeDir();
    }
示例#5
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);
    }