Exemplo n.º 1
0
    ////////////////////////////////////////////////////////////////

    private void OnTriggerEnter(Collider other)
    {
        if (other.name == "Player" && activated != this)
        {
            ////////////////////////////////////////////////////////////////

            activated = this;
            if (gm is RoomGameManager)
            {
                RoomGameManager rGameManager = gm as RoomGameManager;
                rGameManager.ChangeRoom(transform.parent.Find("Door").gameObject);
            }

            ActivateEnemies();

            ////////////////////////////////////////////////////////////////

            if (enemyCount <= 0)
            {
                gm.Cleared();

                if (gm.GetComponent <RoomGameManager>())
                {
                    transform.parent.Find("Door").gameObject.SetActive(false);
                }
            }

            ////////////////////////////////////////////////////////////////
        }
    }
Exemplo n.º 2
0
        public RoomArea FindRoomArea(Vector3Int startPosition)
        {
            Queue <Vector3Int> tilesToCheck = new Queue <Vector3Int>();

            tilesToCheck.Enqueue(startPosition);

            RoomArea room = new RoomArea();

            while (tilesToCheck.Any())
            {
                var position = tilesToCheck.Dequeue();

                if (!searchedTiles.ContainsKey(position))
                {
                    searchedTiles.Add(position, position);

                    var tileType = TilemapHelper.GetTileTypeFromPosition(position, tilemap);

                    if (tileType == TileType.ROOM)
                    {
                        // Add current tile to room
                        room.tiles.Add(new TileObject(position, tileType));

                        tilesToCheck = AddNeighborsInQueue(tilesToCheck, position);
                    }
                }
            }

            return(room);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Parses raw data into C# object.
 /// </summary>
 /// <param name="headerOffset"></param>
 /// <param name="data"></param>
 public RoomHeader(uint headerOffset, byte[] data)
 {
     this.headerOffset = headerOffset;
     raw             = data;
     roomIndex       = data[0];
     roomArea        = (RoomArea)data[1];
     pos             = new Vector2(data[2], data[3]);
     size            = new Vector2(data[4], data[5]);
     upScroll        = data[6];
     downScroll      = data[7];
     gfxBitFlag      = data[8];
     ptrDoorOut      = Get2Byte(9, 10);
     roomstate       = Get2Byte(11, 12);
     ptrLevelData    = Get3Byte(13, 14, 15);
     tileset         = data[16];
     musicCollection = data[17];
     musicPlay       = data[18];
     ptrFX1          = Get2Byte(19, 20);
     ptrEnemyPop     = Get2Byte(21, 22);
     ptrEnemySet     = Get2Byte(23, 24);
     layer2Scrolling = Get2Byte(25, 26);
     scrollPointer   = Get2Byte(27, 28);
     unknown         = Get2Byte(29, 30);
     ptrFX2          = Get2Byte(31, 32);
     ptrPLM          = Get2Byte(33, 34);
     bgData          = Get2Byte(35, 36);
     later1_2        = Get2Byte(37, 38);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Set reference to instances. Assert valid value for NumberOfCubes.
 /// </summary>
 void Start()
 {
     room = GameObject.FindObjectOfType <RoomArea>();
     if (NumberOfCubes <= 0)
     {
         NumberOfCubes = 10;
     }
 }
Exemplo n.º 5
0
 // Start is called before the first frame update
 void Start()
 {
     dockPoints   = GetComponentsInChildren <DockPoint>();
     roomArea     = GetComponentInChildren <RoomArea>();
     meshRenderer = GetComponent <MeshRenderer>();
     meshCollider = GetComponent <MeshCollider>();
     //dockPoint.AlignDock();
 }
Exemplo n.º 6
0
    private void OnTriggerEnter(Collider other)
    {
        RoomArea otherArea = other.GetComponent <RoomArea>();

        if (otherArea == null)
        {
            return;
        }
        roomBlocked = true;
    }
Exemplo n.º 7
0
 public Room(Rect rect, RoomArea area)
 {
     RoomRect = rect;
     OverLapRooms = new List<Room>();
     Area = area;
     isMonsterHouse = false;
     isShop = false;
     EntranceDoorPositions = new Vector2[] { };
     ID = InstanceID++;
     ConnectingPathways = new Pathway[0];
 }
Exemplo n.º 8
0
        public List <Vector3Int> CalculatePathBetweenRooms(RoomArea roomA, RoomArea roomB)
        {
            // Find tiles with minimum distance between rooms
            TileObject tileA       = roomA.tiles[0];
            TileObject tileB       = roomB.tiles[0];
            int        minDistance = ManhatanDistance(tileA, tileB);
            int        distance;

            foreach (var tilea in roomA.tiles)
            {
                foreach (var tileb in roomB.tiles)
                {
                    distance = ManhatanDistance(tilea, tileb);
                    if (distance < minDistance)
                    {
                        tileA       = tilea;
                        tileB       = tileb;
                        minDistance = distance;
                    }
                }
            }

            TileObject startTile = tileA;
            TileObject endTile   = tileB;

            if (tileA.Position.x > tileB.Position.x)
            {
                startTile = tileB;
                endTile   = tileA;
            }

            List <Vector3Int> path = new List <Vector3Int>();

            while (startTile.Position.x != endTile.Position.x || startTile.Position.y != endTile.Position.y)
            {
                if (startTile.Position.x < endTile.Position.x)
                {
                    startTile.Position = new Vector3Int(startTile.Position.x + 1, startTile.Position.y, startTile.Position.z);
                }
                else if (startTile.Position.y < endTile.Position.y)
                {
                    startTile.Position = new Vector3Int(startTile.Position.x, startTile.Position.y + 1, startTile.Position.z);
                }
                else if (startTile.Position.y > endTile.Position.y)
                {
                    startTile.Position = new Vector3Int(startTile.Position.x, startTile.Position.y - 1, startTile.Position.z);
                }
                path.Add(startTile.Position);
            }

            return(path);
        }
Exemplo n.º 9
0
    public Vector2 getRoomAreaSideRandomPoint(RoomArea.Side side, RndGenerator rnd)
    {
        float x = 0, y = 0;
        switch (side)
        {
            case Side.TOP:
                y = RoomRect.yMax;
                x = rnd.Next((int)RoomRect.xMin,(int)RoomRect.xMax);
                break;
            case Side.BOTTOM:
                y = RoomRect.yMin;
                x = rnd.Next((int)RoomRect.xMin, (int)RoomRect.xMax);
                break;
            case Side.LEFT:
                x = RoomRect.xMin;
                y = rnd.Next((int)RoomRect.yMin, (int)RoomRect.yMax);
                break;
            case Side.RIGHT:
                x = RoomRect.xMax;
                y = rnd.Next((int)RoomRect.yMin, (int)RoomRect.yMax);
                break;
        }

        return new Vector2(x, y);
    }
Exemplo n.º 10
0
 void selectRoomAreas()
 {
     double mu = Mathf.Min(DgParam.AvrateRoomCount, RoomAreas.Count);
     double sigma = mu * Rnd.nextFloat(0.15f,0.45f);
     int count = (int)Rnd.nextGaussian(mu, sigma);
     count = Mathf.Clamp(count, DungeonParameter.RoomCountLowerLimit, DungeonParameter.RoomCountUpperLimit);
     //count = 3;
     int retry = 0;
     List<RoomArea> orglist = new List<RoomArea>(RoomAreas.ToArray());
     List<RoomArea> selectlist = new List<RoomArea>();
     if (DgParam.AllowedCreatingShopRoom) {
         var shops = orglist.FindAll( r => r.Size.x >= DungeonParameter.RequiredShopRoomSize.x && r.Size.y >= DungeonParameter.RequiredShopRoomSize.y );
         if (shops.Count != 0)
         {
             var shop = shops[Rnd.Next(shops.Count)];
             selectlist.Add(shop);
             orglist.Remove(shop);
         }
         else {
             Vector2 pos = new Vector2(Rnd.Next(10, (int)DgParam.MaxMapSize.x-10), Rnd.Next(10, (int)DgParam.MaxMapSize.y-10));
             var shop = new RoomArea(pos,DungeonParameter.RequiredShopRoomSize);
             selectlist.Add(shop);
         }
         count++;
     }
     while (selectlist.Count < count && retry < 100) {
         if (orglist.Count == 0) break;
         RoomArea select = orglist[Rnd.Next(orglist.Count)];
         if (selectlist.TrueForAll(a => !a.OutsideWall.Overlaps(select.RoomRect))){
             selectlist.Add(select);
             orglist.Remove(select);
         }
         else {
             retry++;
         }
     }
     RoomAreas = selectlist;
 }
Exemplo n.º 11
0
    List<Pathway> createPathWays(RoomArea start, RoomArea end, RoomArea.Side startside, RoomArea.Side endside, RndGenerator rnd)
    {
        List<Pathway> ret = new List<Pathway>();
        Vector2 sv = start.getRoomAreaSideRandomPoint(startside, rnd);
        Vector2 ev = end.getRoomAreaSideRandomPoint(endside, rnd);
        float sx = 0, sy = 0, ex = 0, ey = 0;
        float xmin = start.RoomRect.xMin, xmax = start.RoomRect.xMax, ymin = start.RoomRect.yMin, ymax = start.RoomRect.yMax;
        int max = 0, min = 0;
        xmin++; xmax--;
        ymin++; ymax--;
        int sideline = (int)start.getSideLine(startside);
        switch (startside)
        {
            case RoomArea.Side.TOP:
                sx = rnd.Next((int)xmin, (int)xmax);
                sy = sideline-1;
                ex = sx;
                max = (int)Mathf.Max(end.Center.y, end.RoomRect.yMax, sideline + 6);
                min = sideline + 1;
                if (min >= max) max += min - max;
                ey = rnd.Next(min, max);
                break;
            case RoomArea.Side.BOTTOM:
                sx = rnd.Next((int)xmin, (int)xmax);
                sy = sideline+1;
                ex = sx;
                min = (int)Mathf.Min(end.Center.y, end.RoomRect.yMin, sideline - 6);
                min = Mathf.Max(0, min);
                max = sideline - 1;
                if (min >= max) max += min - max;
                ey = rnd.Next(min, max);
                break;
            case RoomArea.Side.LEFT:
                sy = rnd.Next((int)ymin, (int)ymax);
                ey = sy;
                sx = sideline+1;
                min = (int)Mathf.Min(end.Center.x, end.RoomRect.xMin, sideline - 6);
                min = Mathf.Max(0, min);
                max = sideline - 1;
                if (min >= max) max += min - max;
                ex = rnd.Next(min, max);
                break;
            case RoomArea.Side.RIGHT:
                sy = rnd.Next((int)ymin, (int)ymax);
                ey = sy;
                sx = sideline-1;
                max = (int)Mathf.Max(end.Center.x, end.RoomRect.xMin, sideline - 6);
                min = sideline + 1;
                if (min >= max) max += min - max;
                ex = rnd.Next(min, max);
                break;
        }
        sx = Mathf.Clamp(sx, 0, Size.x);
        ex = Mathf.Clamp(ex, 0, Size.x);
        sy = Mathf.Clamp(sy, 0, Size.y);
        ey = Mathf.Clamp(ey, 0, Size.y);
        Pathway pw = new Pathway(new Vector2(sx, sy), new Vector2(ex, ey));
        ret.Add(pw);
        int retry = 0;
        while (!end.RoomRect.Contains(pw.EndPosition)) {
            Vector2 sp = pw.EndPosition;
            Vector2 ep = Vector2.zero;
            if (pw.CurrentAxis == Pathway.Axis.HORIZONTAL)
            {
                ep = new Vector2(sp.x, end.CenterToInt.y);
            }
            else
            {
                ep = new Vector2(end.CenterToInt.x, sp.y);
            }
            pw = new Pathway(sp, ep);
            if (pw.CurrentAxis == Pathway.Axis.UNKWON) {
                if (sp.x == end.CenterToInt.x)
                {
                    ep.y = end.CenterToInt.y;
                }
                else if(sp.y == end.CenterToInt.y){
                    ep.x = end.CenterToInt.x;
                }
                pw = new Pathway(sp, ep);
            }

            //Debug.LogFormat("{0} {1} {2}", pw.ToString(), end.RoomRect.ToString(), end.RoomRect.Contains(pw.EndPosition));
            retry++;
            if (retry > 100) {
                Debug.LogFormat("Break Loop: {0} {1}", pw.ToString(),end.CenterToInt);
                break;
            }
            ret.Add(pw);
        }
        return ret;
    }
Exemplo n.º 12
0
 public Room(Vector2 pos, Vector2 size, RoomArea area)
     : this(new Rect(pos, size),area)
 {
 }
Exemplo n.º 13
0
 public RoomAreaEntity createRoomAreaEntity(RoomArea area,GameObject parent)
 {
     GameObject obj = GameObject.Instantiate(roomarea);
     obj.transform.position = area.Position;
     obj.transform.localScale = area.Size+Vector2.one;
     obj.SetActive(false);
     RoomAreaEntity entity = obj.GetComponent<RoomAreaEntity>();
     entity.GetComponent<BoxCollider2D>().size = new Vector2(1.04f, 1.04f);
     if(parent!=null) entity.transform.SetParent(parent.transform);
     return entity;
 }
Exemplo n.º 14
0
    public void ReadRoomsData()
    {
        rooms.Clear();
        for (var id = 0; id < 100; id++)
        {
            string roomData = PlayerPrefs.GetString("room_" + id);

            if (roomData != "" && roomData != null)
            {
              //  print("room_" + id + "   ---->  " + roomData);
                Room room = new Room();

                string[] result = roomData.Split(":"[0]);
                room.url = result[0];
                room.id = id;

                string[] areas = result[1].Split("+"[0]);

                room.area = new List<RoomArea>();

                foreach (string area in areas)
                {
                    string[] res = area.Split("_"[0]);
                   // print("area: " + area);
                    if (res.Length > 1)
                    {
                        RoomArea roomArea = new RoomArea();
                        roomArea.width = float.Parse(res[0]);
                        roomArea.height = float.Parse(res[1]);
                        roomArea.position = new Vector3(GetFloat(res[2]), GetFloat(res[3]), 1);

                        roomArea.pointers = new Vector3[4];

                        roomArea.pointers[0] = new Vector3(GetFloat(res[4]), GetFloat(res[5]), 0);
                        roomArea.pointers[1] = new Vector3(GetFloat(res[6]), GetFloat(res[7]), 0);
                        roomArea.pointers[2] = new Vector3(GetFloat(res[8]), GetFloat(res[9]), 0);
                        roomArea.pointers[3] = new Vector3(GetFloat(res[10]), GetFloat(res[11]), 0);

                        string[] artworks = res[12].Split("*"[0]);

                        roomArea.artworks = new List<RoomAreaArtWork>();

                        foreach (string artwork in artworks){
                            string[] resu = artwork.Split("/"[0]);
                            // print("area: " + area);
                            if (resu.Length > 1){
                                RoomAreaArtWork roomArt = new RoomAreaArtWork();
                                roomArt.position = new Vector3(GetFloat(resu[0]),GetFloat(resu[1]),0);
                                roomArt.galleryID = int.Parse(resu[2]);
                                roomArt.galleryArtID = int.Parse(resu[3]);
                                roomArea.artworks.Add(roomArt);
                            }
                        }

                        room.area.Add(roomArea);
                    }
                }
                rooms.Add(room);
            }
        }
    }