public Vector2 getGermiExitPosition(DoorPlacement prevDoorPlacement) { DoorPlacement exitPos; switch (prevDoorPlacement) { case DoorPlacement.SCREEN_BOTTOM: exitPos = DoorPlacement.SCREEN_TOP; break; case DoorPlacement.SCREEN_LEFT: exitPos = DoorPlacement.SCREEN_RIGHT; break; case DoorPlacement.SCREEN_RIGHT: exitPos = DoorPlacement.SCREEN_LEFT; break; case DoorPlacement.SCREEN_TOP: exitPos = DoorPlacement.SCREEN_BOTTOM; break; default: throw new NotSupportedException("Unknown door placement: " + prevDoorPlacement); } Door exitDoorPlacement = getDoorInPlacement(exitPos); Vector2 exitPosition = exitDoorPlacement.getExitGermiPosition(); return(exitPosition); }
//------------------------------------------------------------------- // This checks if a door is needed in the room at a specific direction. // roomGen: the roomgenerator that the door is part of. // doorPlace: a doorPlace that gives us information about the door // index: the index of the room in the map // x: the x position of the door // y: the y position of the door //------------------------------------------------------------------- void Checkdoor(RoomGenerator roomGen, DoorPlacement doorPlace, int index, float x, float y) { if (!roomGen.CheckAvailability(doorPlace.m_dir)) { Drawdoor(roomGen, new Vector3(x, y, 1), doorPlace.m_quat, doorPlace.m_ori, index, doorPlace.m_offset); } }
public Door(GameplayScreen gameplayScreen, Vector2 pkaardiAsukoht, DoorPlacement placement, int row, int col) : base(gameplayScreen, pkaardiAsukoht, "uks1_avatud_2t", -1) { this.placement = placement; this.row = row; this.col = col; }
public Door getDoorInPlacement(DoorPlacement placement) { Door ret = doors[placement]; if (ret == null) { // Fail fast throw new NotSupportedException("Tile does not contain door on placement: " + placement); } return(ret); }
public Door getDoorOnPlacement(DoorPlacement placement) { return(doors[placement]); }
public void switchTile(int row, int col, DoorPlacement enterPlacement) { currentTile = tiles[row][col]; getCurrentTile().reset(); MainCharacter.Instance.setNewLocation(getCurrentTile().getGermiExitPosition(enterPlacement)); }
//------------------------------------------------------------------- // This instantiates the actual game objects into the game world //------------------------------------------------------------------- void DrawMap() { Vector3 rotationAxis = new Vector3(0, 0, 1); SortFinalRooms(); DoorPlacement up = new DoorPlacement(Direction.Up, Quaternion.identity, Door.Orientation.Horizontal, m_cols); DoorPlacement down = new DoorPlacement(Direction.Down, Quaternion.AngleAxis(180, rotationAxis), Door.Orientation.Horizontal, -m_cols); DoorPlacement left = new DoorPlacement(Direction.Left, Quaternion.AngleAxis(90, rotationAxis), Door.Orientation.Vertical, -1); DoorPlacement right = new DoorPlacement(Direction.Right, Quaternion.AngleAxis(270, rotationAxis), Door.Orientation.Vertical, 1); //------------------------------------------------------------------- // Generated List of room style that's going to be used //------------------------------------------------------------------- //Track the total count of room style int totalRoom = 1; //We start from 1 because we need to include the starting rooom int totalProbability = 0; //Set the room count to the minimum number for (int i = 0; i < m_generatedRooms.Length; ++i) { //Set the room count to minimum m_generatedRooms[i].m_count = m_generatedRooms[i].m_min; totalRoom += m_generatedRooms[i].m_count; //Count the total probability (For randomization) totalProbability += m_generatedRooms[i].m_probability; } //Add a random room style until it reaches the number we want while (totalRoom < m_roomGenMap.Count) { //Choose a random room int randomValue = Random.Range(0, totalProbability); int roomIndex = -1; while (randomValue >= 0) { ++roomIndex; randomValue -= m_generatedRooms[roomIndex].m_probability; } //If the room hasn't reached it's max limit if (m_generatedRooms[roomIndex].m_count < m_generatedRooms[roomIndex].m_max) { //Add it as a new room style ++m_generatedRooms[roomIndex].m_count; ++totalRoom; } } //Store list of room style into an array of index int[] roomIndexArray = new int[totalRoom]; int curIndex = 0; for (int i = 0; i < m_generatedRooms.Length; ++i) { for (int j = 0; j < m_generatedRooms[i].m_count; ++j) { roomIndexArray[curIndex] = i; ++curIndex; } } //Shuffle the array for (int i = roomIndexArray.Length - 1; i > 0; --i) { int swapIndex = Random.Range(0, i); //Swap int temp = roomIndexArray[swapIndex]; roomIndexArray[swapIndex] = roomIndexArray[i]; roomIndexArray[i] = temp; } curIndex = 0; foreach (KeyValuePair <int, RoomGenerator> kvp in m_roomGenMap) { //------------------------------------------------------------------- // Draw Rooms //------------------------------------------------------------------- Room room = m_startingRoom; // Set the final room if (kvp.Key == m_finalRooms[m_finalRooms.Count - 1]) { Debug.Assert(m_finalRoom != null, "Final room cannot be empty!"); room = m_finalRoom; } // If it is neither the starting room nor the final room, // use the room style from the shuffled array else if (kvp.Key != m_startIndex) { int roomIndex = roomIndexArray[curIndex]; room = m_generatedRooms[roomIndex].m_style; ++curIndex; } // The cell of the room int cellX = kvp.Key % m_cols; int cellY = kvp.Key / m_cols; // The dimensions of the room float floorWidth = room.GetComponent <SpriteRenderer>().bounds.size.x; float floorHeight = room.GetComponent <SpriteRenderer>().bounds.size.y; // The position of the room in world space float renderX = cellX * floorWidth; float renderY = cellY * floorHeight; // Create the room GameObject newRoom = Instantiate(room.gameObject, new Vector3(renderX, renderY, 1), Quaternion.identity); newRoom.SetActive(false); m_map.Add(kvp.Value.GetIndex(), newRoom); // Setup the starting room with the player and have camera focus on it if (kvp.Key == m_startIndex) { FindObjectOfType <CameraManager>().targetRoom = newRoom.GetComponent <SpriteRenderer>(); if (SceneManagerSingleton.instance.hasPlayer == false) { Debug.Log("Creating new player"); SceneManagerSingleton.instance.player = Instantiate(m_player, new Vector3(renderX, renderY, 1), Quaternion.identity); SceneManagerSingleton.instance.hasPlayer = true; } else { Debug.Log("Teleporting old player"); SceneManagerSingleton.instance.player.transform.position = new Vector3(renderX, renderY, 1); } } // find the room closest to the start for (int i = 0; i < m_finalRooms.Count - 1; ++i) { if (kvp.Key == m_finalRooms[i]) { GameObject keyInstance = Instantiate(m_key, new Vector3(renderX, renderY, 1), Quaternion.identity, newRoom.transform); keyInstance.GetComponent <Key>().SetType((Key.Type)i); } } } //------------------------------------------------------------------- // Draw Doors //------------------------------------------------------------------- foreach (KeyValuePair <int, RoomGenerator> kvp in m_roomGenMap) { // The cell of the room int cellX = kvp.Key % m_cols; int cellY = kvp.Key / m_cols; // The dimensions of the room //[TEDO]: //I temporarily use the room index 0 as reference. This is NOT the correct solution float floorWidth = m_generatedRooms[0].m_style.GetComponent <SpriteRenderer>().bounds.size.x; float floorHeight = m_generatedRooms[0].m_style.GetComponent <SpriteRenderer>().bounds.size.y; // The position of the room in world space float renderX = cellX * floorWidth; float renderY = cellY * floorHeight; DoorPlacement toPlace = null; DoorPlacement adjoiningDoor = null; float doorX = renderX; float doorY = renderY; float adjX = renderX; float adjY = renderY; if (kvp.Key == m_startIndex) { continue; } //Debug.Assert(kvp.Value.Parent != null && kvp.Value.ParDir == Direction.None); if (kvp.Value.ParDir == Direction.Up) { toPlace = up; adjoiningDoor = down; doorX = renderX; adjX = renderX; doorY = renderY + (floorHeight / 2); adjY = renderY + (floorHeight / 2); } else if (kvp.Value.ParDir == Direction.Down) { toPlace = down; adjoiningDoor = up; doorX = renderX; doorY = renderY - (floorHeight / 2); adjY = renderY - floorHeight / 2; } else if (kvp.Value.ParDir == Direction.Left) { toPlace = left; adjoiningDoor = right; doorX = renderX - (floorWidth / 2); adjX = renderX - floorWidth / 2; doorY = renderY; adjY = renderY; } else if (kvp.Value.ParDir == Direction.Right) { toPlace = right; adjoiningDoor = left; doorX = renderX + (floorWidth / 2); adjX = renderX + floorWidth / 2; doorY = renderY; adjY = renderY; } if (kvp.Key != m_startIndex) { Debug.Assert(toPlace != null); Drawdoor(kvp.Value, new Vector3(doorX, doorY, 1), toPlace.m_quat, toPlace.m_ori, kvp.Key, toPlace.m_offset); Drawdoor(kvp.Value.Parent, new Vector3(adjX, adjY, 1), adjoiningDoor.m_quat, adjoiningDoor.m_ori, kvp.Key + toPlace.m_offset, adjoiningDoor.m_offset); } } }