Example #1
0
        /// <summary>
        /// Interacts with the given object and interaction type.
        /// </summary>
        /// <param name="otherObject">The object to interaction type.</param>
        /// <param name="interactionType">The type of interaction to take place.</param>
        public override InteractionActions InteractWith(GameObject otherObject, InteractionTypes interactionType)
        {
            if (otherObject.ItemType != ItemList.NullItem && interactionType == InteractionTypes.Collision)
            {
                PickUpItem(otherObject);
            }
            else
            {
                switch (otherObject.ObjectName)
                {
                    case "Door":
                        if (interactionType == InteractionTypes.PlayerAction)
                        {
                            Door door = (Door)otherObject;

                            if (!door.IsOpen)
                            {
                                if (!itemArray[(byte)door.LockType])
                                    hudCallback("This door is locked.", false, true);
                                else if (door.LinkedRoomName == "(unassigned)")
                                    hudCallback("This door appears to go nowhere.", false, true);
                                else
                                    door.Open();

                                return InteractionActions.None;
                            }
                        }
                        else if (!otherObject.IsSolid && interactionType == InteractionTypes.Collision)
                        {
                            Door door = (Door)otherObject;
                            if (door.IsRoomLoaded)
                                roomCallback(door.LinkedRoom);
                            else
                            {
                                loadingDoor = door;
                                GameManager.ToggleFreeze(true);
                                hudCallback("Loading room...", false, false);
                            }

                            if (door.Orientation == Door.DoorOrientations.FacingLeft)
                                ResetActionStates(XDirection.Right);
                            else
                                ResetActionStates(XDirection.Left);

                            return InteractionActions.None;
                        }
                        break;

                    case "SavePoint":
                        if (interactionType == InteractionTypes.PlayerAction)
                        {
                            currentHealth = maxHealth;
                            saveCallback();
                            return InteractionActions.None;
                        }
                        break;
                    case "Lever":
                        if (interactionType == InteractionTypes.PlayerAction)
                        {
                            otherObject.SwitchLever();
                            return InteractionActions.Lever;
                        }
                        break;
                    default:
                        return InteractionActions.None;
                }
            }
            return InteractionActions.None;
        }
Example #2
0
        /// <summary>
        ///  Loads the room into memory. 
        ///  If IsPersistant is set to true, loads up the previously saved State file
        /// </summary>
        /// <param name="doorIndex">Represents which door the player is entering from.
        /// If set to -1, player will enter at the default spawning location.</param>
        public void Load(string filePath, int doorIndex)
        {
            if (filePath != "" && filePath != null)
            {
                try
                {
                    int numberOfDoors;
                    int numberOfEnemies;
                    int numberOfEnvironmentObjects;

                    using (Stream stream = TitleContainer.OpenStream(filePath))
                    {
                        using (StreamReader sr = new StreamReader(stream))
                        {
                            longName = GameResources.getNextDataLine(sr, "#");
                            graphicsName = GameResources.getNextDataLine(sr, "#");

                            spawnLocation = new Vector2(Convert.ToInt16(GameResources.getNextDataLine(sr, "#")),
                                                        Convert.ToInt16(GameResources.getNextDataLine(sr, "#")));

                            isPersistant = bool.Parse(GameResources.getNextDataLine(sr, "#"));
                            hasLighting = bool.Parse(GameResources.getNextDataLine(sr, "#"));

                            musicName = GameResources.getNextDataLine(sr, "#");

                            numberOfDoors = Convert.ToInt16(GameResources.getNextDataLine(sr, "#"));
                            doorArray = new Door[numberOfDoors];
                            for (int i = 0; i < numberOfDoors; i++)
                            {
                                Door.DoorOrientations orientation = (Door.DoorOrientations)byte.Parse(GameResources.getNextDataLine(sr, "#"));
                                string roomName = GameResources.getNextDataLine(sr, "#");
                                int connectedDoorIndex = Convert.ToInt16(GameResources.getNextDataLine(sr, "#"));
                                Locks lockType = (Locks)byte.Parse(GameResources.getNextDataLine(sr, "#"));

                                doorArray[i] = new Door(Content, soundEngine, orientation, roomName, connectedDoorIndex, lockType);

                                doorArray[i].Spawn(new Vector2(float.Parse(GameResources.getNextDataLine(sr, "#")),
                                                               float.Parse(GameResources.getNextDataLine(sr, "#"))));
                            }

                            numberOfEnemies = Int16.Parse(GameResources.getNextDataLine(sr, "#"));
                            enemyArray = new Enemy[numberOfEnemies];

                            for (int i = 0; i < numberOfEnemies; i++)
                            {
                                String enemyName = GameResources.getNextDataLine(sr, "#");

                                enemyArray[i] = new Enemy(enemyName, Content);

                                enemyArray[i].Spawn(new Vector2(Int16.Parse(GameResources.getNextDataLine(sr, "#")),
                                    Int16.Parse(GameResources.getNextDataLine(sr, "#"))));
                            }

                            numberOfEnvironmentObjects = Int16.Parse(GameResources.getNextDataLine(sr, "#"));
                            environmentArray = new PhysicsObject[numberOfEnvironmentObjects];

                            for (int i = 0; i < numberOfEnvironmentObjects; i++)
                            {
                                String objectName = GameResources.getNextDataLine(sr, "#");

                                bool objHasGraphics = bool.Parse(GameResources.getNextDataLine(sr, "#"));

                                environmentArray[i] = new PhysicsObject(objectName, Content, new Vector2(0,0), objHasGraphics, soundEngine, false);

                                environmentArray[i].IsSolid = bool.Parse(GameResources.getNextDataLine(sr, "#"));

                                environmentArray[i].Spawn(new Vector2(Int16.Parse(GameResources.getNextDataLine(sr, "#")),
                                    Int16.Parse(GameResources.getNextDataLine(sr, "#"))));
                            }

                            objectArray = new GameObject[numberOfDoors + numberOfEnemies + numberOfEnvironmentObjects];
                            int arrayIndex = 0;

                            for (int i = 0; i < numberOfDoors; i++)
                            {
                                objectArray[i + arrayIndex] = doorArray[i + arrayIndex];
                            }
                            arrayIndex += numberOfDoors;

                            for (int i = 0; i < numberOfEnemies; i++)
                            {
                                objectArray[i + arrayIndex] = enemyArray[i];
                            }
                            arrayIndex += numberOfEnemies;

                            for (int i = 0; i < numberOfEnvironmentObjects; i++)
                            {
                                objectArray[i + arrayIndex] = environmentArray[i];
                            }

                            if (doorIndex != -1)
                            {
                                spawnLocation = doorArray[doorIndex].Position;
                                if (doorArray[doorIndex].Orientation == Door.DoorOrientations.FacingLeft)
                                    spawnLocation.X -= Player.PLAYER_WIDTH;
                                else
                                    spawnLocation.X += doorArray[doorIndex].HitBox.Width;
                            }

                            sr.Close();
                            isLoaded = true;
                        }
                    }

                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("An error occurred: " + e.Message);
                }
            }
        }
Example #3
0
 public bool CheckLoadedRoom()
 {
     if (loadingDoor != null && loadingDoor.IsRoomLoaded)
     {
         GameManager.ToggleFreeze(false);
         roomCallback(loadingDoor.LinkedRoom);
         loadingDoor = null;
         return true;
     }
     return false;
 }