private ERoomDirection FindDirection(IntVector2 gridPos, ERoomDirection previousDirection) { List <ERoomDirection> directions = new List <ERoomDirection>() { ERoomDirection.Left, ERoomDirection.Right, ERoomDirection.Top }; if (gridPos.x <= 0) { directions.Remove(ERoomDirection.Left); } if (gridPos.x >= LEVEL_SIZE.x - 1) { directions.Remove(ERoomDirection.Right); } if (gridPos.y >= LEVEL_SIZE.y - 1) { directions.Remove(ERoomDirection.Top); } directions.Remove(previousDirection == ERoomDirection.Left ? ERoomDirection.Right : previousDirection == ERoomDirection.Right ? ERoomDirection.Left : previousDirection); if (gridPos.y == 1 && previousDirection == ERoomDirection.Top) { directions.Add(previousDirection); } return(directions[UnityEngine.Random.Range(0, directions.Count)]); }
private void GeneratePath(IntVector2 refPos, ERoomType roomType, ERoomDirection fromDir) { Room newRoom = new Room() { ID = ID_ROOM_ITERATOR, type = roomType, gridPos = refPos, enDirection = fromDir }; _rooms[newRoom.gridPos.x, newRoom.gridPos.y] = newRoom; ERoomDirection nextDir = roomType == ERoomType.End ? ERoomDirection.Top : FindDirection(refPos, fromDir); refPos.x += nextDir == ERoomDirection.Left ? -1 : nextDir == ERoomDirection.Right ? 1 : 0; refPos.y += nextDir == ERoomDirection.Top ? 1 : 0; newRoom.exDirection = nextDir; roomsList.Add(newRoom); ID_ROOM_ITERATOR++; bool reachTop = roomsList.Find(r => r.gridPos.y == LEVEL_SIZE.y - 1) != null; if (roomType != ERoomType.End) { GeneratePath(refPos, RoomNumber >= 12 && reachTop ? ERoomType.End : ERoomType.Classic, nextDir); } }
public void Init(ERoomDirection iDirection) { _direction = iDirection == ERoomDirection.Right ? 1 : -1; _renderer = GetComponent <SpriteRenderer>(); _renderer.sortingOrder = 1000; _renderer.sprite = MainLoader <Sprite> .Instance.GetResource("test_player"); _init = true; }