Example #1
0
        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);
        }
Example #2
0
        /**
         * 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);
                         */
                    }
                }
            }
        }
Example #3
0
        /// <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);
        }
Example #4
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);
        }
Example #5
0
 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);
 }
Example #6
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;
 }
Example #7
0
 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;
 }
Example #8
0
        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;
        }
Example #9
0
        /// <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;
        }