/// <summary> /// Given the current room, this function checks if current room has the door /// opened at the direction chosen. /// </summary> /// <param name="current"></param> /// <param name="dir"></param> /// <returns></returns> private Boolean isDoorEnabled(Room current, int dir) { // No door required, no problem if (dir == NO_DOOR_REQUIRED) return true; // Intersections has all rooms open, no problem if (current.getRoomType() == Room.INTERSECTION) return true; // Only the previous rotation was open. if (current.getRoomType() == Room.DEAD_END) { return dir == current.getRotation(); } // Given the rotation of the room, only the opposite is not(!) allowed. if (current.getRoomType() == Room.TRIAD) { int rotation = current.getRotation() + 2; // get the opposite direction return !(rotation == (dir + 2) % 4); } if (current.getRoomType() == Room.CORRIDOR) { int rotation = current.getRotation(); return rotation == dir || rotation == ((dir + 2) % 4); // can open the direction of the room, or the opposite. } if (current.getRoomType() == Room.CORNER) { int rotation = current.getRotation(); return rotation == dir || rotation == ((dir + 1) % 4); // can open the direction of the room, or the next direction. } return false; }
public void teleport(Room roomGet) { Boolean loopCut = true; Vector2 positionGet = position; while (loopCut) { loopCut = false; Vector2 random = new Vector2(rand.Next(0, 600), rand.Next(0, 480)); Rectangle checkWall = new Rectangle((int)random.X, (int)random.Y, 2, 2); foreach (Rectangle wall in roomGet.getWalls()) { if (wall.Intersects(checkWall)) { loopCut = true; } } positionGet = random; } position = positionGet; }
//*/ #endif /// <summary> /// This method is read as "To the DIR of SOURCE is DESTINATION". /// </summary> /// <param name="dir"></param> /// <param name="source"></param> /// <param name="destination"></param> /// <returns></returns> private Boolean areRoomsConnected(int dir, Room source, Room destination) { // First Room is always conected if (source == null) return true; return isDoorEnabled(source, dir) && isDoorEnabled(destination, (dir + 2) % 4); }
private float getDebugRotation(Room r) { if (r.getRotation() == 1) return MathHelper.ToRadians(90); if (r.getRotation() == 2) return MathHelper.ToRadians(180); if (r.getRotation() == 3) return MathHelper.ToRadians(270); return MathHelper.ToRadians(0); }
public Color getColor(Room r) { switch (r.getRoomType()) { case Room.CORRIDOR: return Color.Yellow; case Room.DEAD_END: return Color.Red; case Room.INTERSECTION: return Color.Blue; case Room.TRIAD: return Color.Green; } return Color.White; }
public Room getRoomAt(Room r, int dir) { if (r == null) return null; Vector2 v = getPointAt(r, dir); return getRoom((int)v.X, (int)v.Y); }
/** * Debug purposes */ public void Draw(SpriteBatch spriteBatch, Room currentRoom) { if (DEBUG) { int offset = 150; int cellDistance = 32; for (int y = 0; y < mapDefinition.Height; y++) { for (int x = 0; x < mapDefinition.Width; x++) { Rectangle destination = new Rectangle(offset + x * cellDistance, offset + y * cellDistance, 32, 32); Room current = getRoom(x, y); if (current.getRoomType() == 0) continue; //Vector2 position = new Vector2(offset + x * cellDistance, offset + y * cellDistance); Texture2D selectedTexture = getDebugTexture(current, debugTextures); float rotation = getDebugRotation(current); Color color = getCurrentRoomColor(x, y, currentRoom); spriteBatch.Draw(selectedTexture, destination, null, color, rotation, new Vector2(1.5f, 1.5f), SpriteEffects.None, 0); /* spriteBatch.DrawString(spriteFont, getRoom(x,y).getRotation().ToString(), position, Color.Black); spriteBatch.DrawString(spriteFont, "Start- " + endLocation.X + ":" + endLocation.Y, new Vector2(10, 10), Color.Black); */ } } } }
private void transferSadakoToCurrentRoom() { if (entryPoint != null) { sadako.position = entryPoint; currentRoom.sadakoPositionInRoom = sadako.position; sadakoRoom = currentRoom; sadako.disable = false; songs.songGirl.Play(); } }
public void Initialize(Player playerGet, Sadako sadakoGet, Map mapGet, SongHandler songsGet, EventHandler eventsGet) { songs = songsGet; events = eventsGet; player = playerGet; sadako = sadakoGet; map = mapGet; currentLocation = new Vector2(0, 0); currentRoom = map.getRoom(currentLocation); sadakoRoom = currentRoom; sadako.disable = true; entryPoint = player.position; }
private void roomChaseHandler(GameTime gameTime) { if (chaseStart) { chaseCounter += gameTime.ElapsedGameTime.Milliseconds; if (chaseDelay * 300 < chaseCounter) { chaseStart = false; chaseCounter = 0; sadako.disable = false; if (sadakoRoom != roomTransition) { sadako.position = startLocationViaChase; sadakoRoom = roomTransition; } } } }
private void transferRoomViaChase(Vector2 start, int delay, Room currentRoom) { startLocationViaChase = start; chaseDelay = delay; chaseStart = true; roomTransition = currentRoom; }
private void moveTo(int dir) { Room checkRoom = map.getRoomAt(currentRoom, dir); if (checkRoom != null) { Vector2 start = checkRoom.getLocationStartFrom(dir); if (!start.Equals(Vector2.Zero)) { player.position = start; player.currentPosition = start; entryPoint = start; Room tempRoom = currentRoom; currentRoom.sadakoPositionInRoom = sadako.position; currentRoom = checkRoom; lurkDelay = 0; if (sadako.disturbed) { transferRoomViaChase(start, sadako.wayPoints.Count, currentRoom); } else { float difference = player.maxPresence - tempRoom.roomPresence; int threshold = (int)(difference / 1000); int chance = rand.Next(0, threshold); if (chance == 0 && sadakoRoom != currentRoom) { transferSadakoRandomly(currentRoom); } if (chance == 1 && sadakoRoom != tempRoom) { transferSadakoRandomly(tempRoom); } } sadako.wayPoints = new List<Vector2>(); sadako.wayPoints.Add(player.position); } if (currentRoom == sadakoRoom) { sadako.disable = false; sadako.position = currentRoom.sadakoPositionInRoom; } else sadako.disable = true; } }
private void moveSadakoTo(int dir) { Room checkRoom = map.getRoomAt(currentRoom, dir); if (checkRoom != null) { Vector2 start = checkRoom.getLocationStartFrom(dir); if (!start.Equals(Vector2.Zero)) { sadako.teleport(checkRoom); checkRoom.sadakoPositionInRoom = sadako.position; sadakoRoom = checkRoom; sadako.disable = true; } } }
public RoomConnection(Room a, Room b) { this.a = a; this.b = b; }
/// <summary> /// This method returns the direction that you need to open /// for the new room depending on the previous room. /// </summary> /// <param name="now">The current room</param> /// <param name="prev">The previous room</param> /// <returns>the direction of the door required to be open from the new room</returns> private int isToTheDirectionOf(Room now, Room prev) { if (prev == null) return NO_DOOR_REQUIRED; if (now.location.X > prev.location.X) return Room.LEFT; else if (now.location.X < prev.location.X) return Room.RIGHT; if (now.location.Y > prev.location.Y) return Room.UP; else if (now.location.Y < prev.location.Y) return Room.DOWN; return NO_DOOR_REQUIRED; }
public void transferSadakoRandomly(Room roomTransfer) { sadako.teleport(roomTransfer); sadakoRoom = roomTransfer; sadakoRoom.sadakoPositionInRoom = sadako.position; if (currentRoom == sadakoRoom) { sadako.disable = false; sadako.position = currentRoom.sadakoPositionInRoom; } else sadako.disable = true; }
public List<Room> getAccessibleRooms(Room current) { List<Room> listOfAccessibleRooms = new List<Room>(); Vector2 location = current.location; int rotation = current.getRotation(); // Intersection if (current.getRoomType() == Room.INTERSECTION) { for (int dir = Room.LEFT; dir <= Room.DOWN; dir++) { Room r = getRoomAt(current, dir); if (r != null) listOfAccessibleRooms.Add(r); } } // Triad else if (current.getRoomType() == Room.TRIAD) { for (int offset = -1; offset <= 1; offset++) { int dirToBeChecked = (rotation + offset) % 4; Room r = getRoomAt(current, dirToBeChecked); if (r != null) listOfAccessibleRooms.Add(r); } } // Corridor else if (current.getRoomType() == Room.CORRIDOR) { for (int offset = 0; offset <= 2; offset += 2) { int dirTobeChecked = (rotation + offset) % 4; Room r = getRoomAt(current, dirTobeChecked); if (r != null) listOfAccessibleRooms.Add(r); } } // Deadend else if (current.getRoomType() == Room.DEAD_END) { listOfAccessibleRooms.Add(getRoomAt(current, rotation)); } return listOfAccessibleRooms; }
public Edge(Room left, Room right) { this.left = left; this.right = right; }
public Vector2 getPointAt(Room r, int dir) { Vector2 v = r.location; switch (dir) { case Room.LEFT: return new Vector2(v.X - 1, v.Y); case Room.UP: return new Vector2(v.X, v.Y - 1); case Room.RIGHT: return new Vector2(v.X + 1, v.Y); case Room.DOWN: return new Vector2(v.X, v.Y + 1); } return v; }
/// <summary> /// Read as, connecting room 'destination' is at the 'dir' of 'source' /// </summary> /// <param name="destination"></param> /// <param name="dir"></param> /// <param name="source"></param> private void setRoomRelation(Room destination, int dir, Room source) { switch (dir) { case Room.UP: source.up = true; destination.down = true; break; case Room.DOWN: source.down = true; destination.up = true; break; case Room.LEFT: source.left = true; destination.right = true; break; case Room.RIGHT: source.right = true; destination.left = true; break; } }
private Color getCurrentRoomColor(int x, int y, Room currentRoom) { if (currentRoom.getLocation().X == x && currentRoom.getLocation().Y == y) return Color.Yellow; return Color.Brown; }
private List<Room> getListThatContains(List<List<Room>> bigList, Room r) { foreach (List<Room> currentList in bigList) { if (currentList.Contains(r)) return currentList; } return null; }
private Texture2D getDebugTexture(Room r, List<Texture2D> textures) { if (r.getRoomType() == Room.DEAD_END) return textures.ElementAt(0); if (r.getRoomType() == Room.CORRIDOR) return textures.ElementAt(1); if (r.getRoomType() == Room.TRIAD) return textures.ElementAt(2); if (r.getRoomType() == Room.INTERSECTION) return textures.ElementAt(3); if (r.getRoomType() == Room.CORNER) return textures.ElementAt(4); return null; }
// DFS Maze creation, fixed. // TODONT: Add corners for map generation. // Deprecated /** * 22, 22, 22, 22, 12% (deadend) chance. */ private void generateMaze(int x, int y, Room prev) { int roomType, roomRotation; Room current = getRoom(x, y); /** * BASE CASE END OF RECURSIVE ALGORITHM * * This checks if the room has already been * explored or if the room is out of bounds * from the map. */ if (exploredRooms.Contains(current)) return; if (current == null) return; /** * ROOM TYPE, ROTATION, DESIGN * * This handles the room generation with * regards to room type, rotation, and design */ do { if (prev == null) roomRotation = random.Next(4); else roomRotation = (prev.getRotation() + 2) % 4; current.setRotation(roomRotation); roomType = random.Next(4) + 2; current.setRoomType(roomType); } while (!areRoomsConnected(isToTheDirectionOf(current, prev), prev, current) || getAccessibleRooms(current).Count <= 0); int[,] roomDesign = roomDatabaseReference.getRoomDesign(roomType, roomRotation); if (roomDesign != null) { current.setRoomDesign(roomDesign); current.Initialize(); } else { // TODONT: Must use room designer java application to create corners. // Deprecated. Corner rooms are done already. throw new Exception("Undefined Room Design Exception!"); } /** * MAZE CREATION * * Start the DFS creation of the maze */ // Add the current room to list of explored rooms exploredRooms.Add(current); List<Room> roomsAvailable = getAccessibleRooms(current); do { // Get a random room from the list and remove it from the list int index = random.Next(roomsAvailable.Count); Room roomToVenture = roomsAvailable.ElementAt(index); roomsAvailable.RemoveAt(index); // The room is already explored, don't go set it anymore if (exploredRooms.Contains(roomToVenture)) continue; // There is no room to venture to, don't go there if (roomToVenture == null) continue; // Determine the direction to take and the coordinate of the target room int directionToTake = isToTheDirectionOf(current, roomToVenture); Vector2 destinationCoordinate = getPointAt(current, directionToTake); // Recurse -- DEPRECATED generateMaze((int)destinationCoordinate.X, (int)destinationCoordinate.Y, current); } while (roomsAvailable.Count > 0); }
/// <summary> /// This initializes a new map given a rectangle which has /// the starting X and Y locations of the player and the /// width and size of the map (not the room). /// </summary> /// <param name="init"></param> public void Initialize(Game game, Player playerReference, ContentManager Content, Rectangle init, Texture2D tileTexture, List<Texture2D> mapDebuggingTextures, RoomDatabase roomDatabaseReference, TileDatabase tileDatabaseReference) { gameReference = game; this.shadowTexture = Content.Load<Texture2D>("shadow"); this.playerReference = playerReference; mapDefinition = init; debugTextures = mapDebuggingTextures; this.roomDatabaseReference = roomDatabaseReference; // Generate rooms int width = init.Width; int height = init.Height; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Room r = new Room(gameReference, x, y, shadowTexture, tileDatabaseReference, playerReference, tileTexture); listOfRooms.Add(r); #if !KRUSKAL r.Initialize(); #else kruskalRooms.Add(r); // In Kruskal's, each room has a set of their own. List<Room> list = new List<Room>(); list.Add(r); sets.Add(list); #endif } } // Generate maze int destination_x = random.Next(width); int destination_y = random.Next(height); endLocation.X = destination_x; endLocation.Y = destination_y; #if KRUSKAL generateMaze(); #else generateMaze(destination_x, destination_y, null); #endif }
public void update(GameTime gameTime, Room currentRoom, TouchCollection locations) { presenceHandler(); heartBeatHandler(gameTime); if (locations.Count == 0) { viewDragged = false; isDragging = false; isPressing = false; viewDragStart = false; player.isMoving = false; player.inventory.itemGetCheck = false; if (isFlashlightTouched) { isFlashlightTouched = false; if (flashLightPosition.X > 685) { flashLightPosition.X = 720; flashLightArea.X = 720; player.isFlashLightOn = false; } else { flashLightPosition.X = 650; flashLightArea.X = 650; player.isFlashLightOn = true; } } } foreach (TouchLocation location in locations) { Rectangle touch = new Rectangle((int)location.Position.X,(int)location.Position.Y,buttonSize,buttonSize); if (flashLightArea.Intersects(touch)) { if (!isPressing && !isDragging && !viewDragged || isFlashlightTouched) { isFlashlightTouched = true; if (location.State == TouchLocationState.Pressed || location.State == TouchLocationState.Moved) { flashLightPosition.X = touch.X - 33; flashLightArea.X = touch.X - 33; if (flashLightPosition.X < 650) { flashLightPosition.X = 650; flashLightArea.X = 650; } if (flashLightPosition.X > 720) { flashLightPosition.X = 720; flashLightArea.X = 720; } } } } if (buttonarea.Intersects(touch)) { if (!isPressing && !isDragging && !viewDragged && !isFlashlightTouched) { isPressing = true; if (player._speed > 0.1F) { player._speed = 0.1F; } else player._speed = 0.18F; } } #if true foreach (Entity currentEntities in currentRoom.getEntities()) { if (!(currentEntities is HidingSpot)) continue; Rectangle currentLocation = new Rectangle((int)currentEntities.getPosition().X, (int)currentEntities.getPosition().Y, 64, 64); /* * currentEntity * at the currentLocation * using the currentTouch */ if (currentLocation.Intersects(touch)) { player.currentHidingSpot = (HidingSpot)currentEntities; if (currentEntities is HidingSpot) ((HidingSpot)currentEntities).Interact(player); break; } } #endif if (controllerarea.Intersects(touch)) { isDragging = true; } else { viewDragged = true; } if (viewDragged && !viewDragStart && !player.inventory.isOpen && !isPressing && !isFlashlightTouched && !player.inventory.itemGetCheck) { viewDragCurrent = new Vector2(location.Position.X, location.Position.Y); viewDragStart = true; } if (viewDragStart) { viewDragCurrent = location.Position; getViewDegree(); } if (isDragging) { if (!_viewDragged) TryDrag(location); if (_touchid != location.Id || !_viewDragged) continue; TryMove(location, gameTime); } } if(initialPosition!=currentPosition)getDegree(); }