コード例 #1
0
    public void createMonterInRoom()
    {
        for (int i = 0; i < rooms.Count; i++)
        {
            Room2D tmpRoom = rooms[i];
            if (i == 0) //生成小弟
            {
                firstPos = new Vector3Int(tmpRoom.pos.x, csPosY, tmpRoom.pos.y);
                //   addMonster(firstPos, false);
            }
            else    //生成怪物
            {
                Vector2 tmpVect2   = tmpRoom.getCenterPos();
                Vector3 tmpMonster = new Vector3(tmpVect2.x, csPosY, tmpVect2.y);
                addMonster(tmpMonster, true);
            }
        }

        int monsterNum = rooms.Count - 1;
        int tmp        = monsterNum / 2;

        if (tmp > 0)
        {
            monsterNum = monsterNum / 2;
        }

        int level = 0;

        stageMgr.stage().initStage(level, monsterNum, finishState);
    }
コード例 #2
0
    public void createPlance()
    {
        for (int i = 0; i < rooms.Count; i++)
        {
            //int i = 0;
            Room2D tmpRoom = rooms[i];
            tmpRoom.makeAllPlane();  //铺房间
            //if (i == 0)
            //{
            //    firstPos = new Vector3Int(tmpRoom.pos.x, csPosY, tmpRoom.pos.y);
            // break;
            //}
            //break;
#if !TESTPATH
            tmpRoom.makeAllWall();  //铺墙
#endif
        }
    }
コード例 #3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var o    = JObject.Load(reader);
            var room = new Room2D();

            room.Identifier           = o[nameof(room.Identifier)].Value <string>();
            room.IsTopExposed         = o[nameof(room.IsTopExposed)].Value <bool>();
            room.IsGroundContact      = o[nameof(room.IsGroundContact)].Value <bool>();
            room.FloorToCeilingHeight = o[nameof(room.FloorToCeilingHeight)].Value <double>();

            var constructionSetIdentifier = o[nameof(room.Properties.Energy.ConstructionSet)].Value <string>();

            room.Properties.Energy.ConstructionSet = new ConstructionSet(constructionSetIdentifier);

            var programTypeIdentifier = o[nameof(room.Properties.Energy.ProgramType)].Value <string>();

            room.Properties.Energy.ProgramType = new ProgramType(programTypeIdentifier);

            return(room);
        }
コード例 #4
0
 public void CreateNewGeneration()
 {
     if (!paused)
     {
         List <GameObject> matingPool = GetMatingPool();
         foreach (GameObject room in roomPopulation)
         {
             //room.SetActive(false);
             Destroy(room);
         }
         roomPopulation = new List <GameObject>();
         GenerateRooms();
         List <GameObject> childGeneration = Crossover(matingPool);
         for (int i = 0; i < roomPopulation.Count; i++)
         {
             Room2D child = childGeneration[i].GetComponent <Room2D>();
             Room2D room  = roomPopulation[i].GetComponent <Room2D>();
             for (int j = 0; j < furnPrefabs.Count; j++)
             {
                 room.spawnBox(furnPrefabs[j], child.Boxes[j].transform.localPosition, child.Boxes[j].transform.localRotation);
                 if (mutationRate > Random.Range(0, 1f))
                 {
                     room.mutate(j);
                     Debug.Log("mutated");
                 }
                 else if (mutationRate > Random.Range(0, 1f))
                 {
                     room.mutateRotation(j);
                     Debug.Log("mutated rotation");
                 }
             }
         }
         updateFitness();
         normalizeFitness();
     }
 }
コード例 #5
0
ファイル: Grid2D.cs プロジェクト: fuzhoustone/csd
    public Room2D getGridDataObj(Vector2Int pos)
    {
        Room2D res = dataObjLst[GetIndex(pos)];

        return(res);
    }
コード例 #6
0
ファイル: Grid2D.cs プロジェクト: fuzhoustone/csd
 public void setGridDataObj(Room2D obj, Vector2Int pos)
 {
     dataObjLst[GetIndex(pos)] = obj;
     this.setDataIsCreate(pos, true);
 }
コード例 #7
0
    void PlaceRooms()
    {
        for (int i = 0; i < roomCount; i++)
        {
            Vector2Int location = new Vector2Int(
                random.Next(0, size.x),
                random.Next(0, size.y)
                );

            Vector2Int roomSize = new Vector2Int(
                random.Next(roomMinSize.x, roomMaxSize.x + 1),
                random.Next(roomMinSize.y, roomMaxSize.y + 1)
                );

            bool       add        = true;
            GameObject newRoomObj = new GameObject();
            newRoomObj.transform.SetParent(mazeParent.transform);
            newRoomObj.name = "room" + location.x.ToString() + "_" + location.y.ToString() + "_" + location.y.ToString();

            Room2D newRoom = newRoomObj.AddComponent <Room2D>();
            newRoom.initData(location, roomSize, planePrefab, wallPrefab, roomPlaceMaterial, placeGrid, roomIndex, newRoomObj);
            //Room2D newRoom = new Room2D(location, roomSize);
            //Room2D buffer = new Room2D(location + new Vector2Int(-1, -1), roomSize + new Vector2Int(2, 2));

            RectInt buffer = new RectInt(location + new Vector2Int(-1, -1), roomSize + new Vector2Int(2, 2));

            foreach (var room in rooms)
            {
                if (Room2D.IntersectBuff(room.bounds, buffer))
                {
                    add = false;
                    break;
                }
            }

            if (newRoom.bounds.xMin < 0 || newRoom.bounds.xMax >= size.x ||
                newRoom.bounds.yMin < 0 || newRoom.bounds.yMax >= size.y)
            {
                add = false;
            }

            if (add)
            {
                rooms.Add(newRoom);
                //上方块图,可无视
                PlaceRoom(newRoom.bounds.position, newRoom.bounds.size);
                //add by csd
                roomIndex++;
                //end

                foreach (var pos in newRoom.bounds.allPositionsWithin)
                {
                    grid[pos] = CellType.Room;
                    //add by csd
                    grid.setGridDataObj(newRoom, pos);
                    //grid.setDataIsCreate(pos, true);
                    //add end
                }
            }
            else
            {
                GameObject.Destroy(newRoomObj);
            }
        }
    }
コード例 #8
0
    //判断两个相交的地块之间哪面墙要敲掉, 发现相交时返回true
    private bool judgePlaceDelWall(Vector2Int sourPos, Vector2Int destPos)
    {
        bool res      = false;
        bool sourNeed = false; //是否要敲墙
        bool destNeed = false; //是否要敲墙

        Vector3Int sourPosParent = Vector3Int.zero;
        Vector3Int destPosParent = Vector3Int.zero;

        if (isRoomOrHillWay(sourPos)) //判断是否为房间或过道
        {
            sourNeed = true;
        }

        if (isRoomOrHillWay(destPos)) //判断是否为房间或过道
        {
            destNeed = true;
        }

        if (sourNeed && destNeed)  //判断是否为同一个房间,只有房间和过道才加入, 楼梯的路径点未加入gird
        {
            Room2D sourRoom = grid.getGridDataObj(sourPos);
            Room2D destRoom = grid.getGridDataObj(destPos);

            if (sourRoom.pos == destRoom.pos)
            {
                //Debug.LogWarning("is same place");
                return(false);
            }
        }

        if (sourPos.x == destPos.x)
        {  //Z轴相交集, X相同的
           // if (sourPos.y == destPos.y) //Y轴相同
           // {

            //if (sourPos.z == destPos.z + 1) //sourPos在destPos的上面
            if (sourPos.y > destPos.y)
            {
                setHideWallByZ(sourPos, destPos, sourNeed, destNeed);
            }
            else     //if (sourPos.z + 1 == destPos.z)
            {
                setHideWallByZ(destPos, sourPos, destNeed, sourNeed);
            }
            //   }
        }
        else if (sourPos.y == destPos.y)
        { //X轴相交集, Z相同的
            if (sourPos.x > destPos.x)
            //if (sourPos.x == destPos.x + 1) //sourPos在destPos的右边
            {
                setHideWallByX(destPos, sourPos, destNeed, sourNeed);
            }
            else //if (sourPos.x + 1 == destPos.x)
            {
                setHideWallByX(sourPos, destPos, sourNeed, destNeed);
            }
        }
        return(res);
    }
コード例 #9
0
ファイル: Room2D.cs プロジェクト: fuzhoustone/csd
 public static bool Intersect(Room2D a, Room2D b)
 {
     return(!((a.bounds.position.x >= (b.bounds.position.x + b.bounds.size.x)) || ((a.bounds.position.x + a.bounds.size.x) <= b.bounds.position.x) ||
              (a.bounds.position.y >= (b.bounds.position.y + b.bounds.size.y)) || ((a.bounds.position.y + a.bounds.size.y) <= b.bounds.position.y)));
 }