示例#1
0
        /// <summary>
        /// Creates a new HUD object.
        /// </summary>
        /// <param name="content">The content manager to use for assets.</param>
        /// <param name="player">The player to attack this HUD to.</param>
        public HUD(ContentManager content, Player player)
        {
            Content = content;

            healthBar = new GameGraphic("HealthBar", Content);
            keyChain = new GameGraphic("KeyChain", Content);

            grayTexture = new Texture2D(GameResources.Device, 1, 1);
            grayTexture.SetData(new[] { Color.Gray });

            redTexture = new Texture2D(GameResources.Device, 1, 1);
            redTexture.SetData(new[] { Color.Red });

            darkGrayTexture = new Texture2D(GameResources.Device, 1, 1);
            darkGrayTexture.SetData(new[] { new Color(102, 102, 102) });

            healthBar.Coordinates = new Vector2(HP_BAR_X, HP_BAR_Y);
            keyChain.Coordinates = new Vector2(KEYCHAIN_X, KEYCHAIN_Y);

            roomFont = Content.Load<SpriteFont>("Fonts/Philo42");
            saveFont = Content.Load<SpriteFont>("Fonts/Philo18");
            infoFont = Content.Load<SpriteFont>("Fonts/Philo24");

            keyArray = new bool[1];
            for (int i = 0; i < keyArray.Length; i++)
                keyArray[i] = false;
        }
示例#2
0
        /// <summary>
        /// Update the state of the HUD based on the state of the player.
        /// </summary>
        /// <param name="time">The GameTime to use.</param>
        /// <param name="player">The player to reference.</param>
        public void Update(GameTime time, Player player)
        {
            currentHP = (float)player.CurrentHealth / (float)player.MaximumHealth;

            for (int i = 0; i < keyArray.Length; i++)
            {
                if (keyArray[i] == false && player.CurrentItems[i + 1] == true)
                    keyArray[i] = true;
            }
        }
        /// <summary>
        /// Loads the previously saved game
        /// </summary>
        private void LoadGame()
        {
            try
            {
                currentStorageDevice = GetStorageDevice();
                using (StorageContainer container = GetStorageContainer(currentStorageDevice))
                {
                    using (Stream stream = container.OpenFile("SaveGame.txt", FileMode.Open))
                    {
                        using (StreamReader sr = new StreamReader(stream))
                        {
                            string line = GameResources.getNextDataLine(sr, "#");
                            currentRoom = new Room(line, -1);
                            int playerHealth = int.Parse(GameResources.getNextDataLine(sr, "#"));
                            bool[] playerItems = new bool[int.Parse(GameResources.getNextDataLine(sr, "#"))];
                            for (int i = 0; i < playerItems.Length; i++)
                                playerItems[i] = bool.Parse(GameResources.getNextDataLine(sr, "#"));

                            RoomSaveData[] roomSaves = new RoomSaveData[int.Parse(GameResources.getNextDataLine(sr, "#"))];

                            for (int i = 0; i < roomSaves.Length; i ++)
                            {
                                roomSaves[i].roomName = GameResources.getNextDataLine(sr, "#");
                                bool[] objects = new bool[int.Parse(GameResources.getNextDataLine(sr, "#"))];
                                for (int j = 0; j < objects.Length; j++)
                                    objects[j] = bool.Parse(GameResources.getNextDataLine(sr, "#"));
                                roomSaves[i].objectsAreSpawned = objects;
                            }

                            GameResources.RoomSaves = new List<RoomSaveData>();
                            foreach (RoomSaveData save in roomSaves)
                                GameResources.RoomSaves.Add(save);

                            player = new Player(gameContent, SaveGame, SwitchRooms, DisplayInfoBox);
                            player.Spawn(currentRoom.SpawnLocation);
                            player.LoadSave(playerHealth, playerItems);
                            gameHUD = new HUD(gameContent, player);

                            isPaused = false;
                            inGame = true;

                            sr.Close();
                        }
                    }

                    StaticBGM.SwitchMusic(currentRoom.MusicName);

                }
            }
            catch (FileNotFoundException e)
            {
                System.Diagnostics.Debug.WriteLine("The save file could not be found: " + e.Message);
                StartNewGame();
            }
        }
        /// <summary>
        /// Starts a new game, getting rid of the menu, deleting old saves, and opening up the starting room.
        /// </summary>
        private void StartNewGame()
        {
            if (gameMenu != null)
            {
                gameMenu.Dispose();
                gameMenu = null;
            }

            DeleteSave();

            GameResources.RoomSaves = new List<RoomSaveData>();

            StaticBGM.SwitchMusic("Level");

            currentRoom = new Room("StartRoom", -1);
            player = new Player(gameContent, SaveGame, SwitchRooms, DisplayInfoBox);
            player.Spawn(currentRoom.SpawnLocation);
            gameHUD = new HUD(gameContent, player);
            gameHUD.DisplayRoomName(currentRoom.LongName);

            isPaused = false;
            inGame = true;
        }
示例#5
0
        /// <summary>
        /// Determines the velocities with which the Enemy will attempt to move, based on
        /// its current stimuli and (possibly) based on what the Player is currently doing.
        /// </summary>
        /// <param name="time">The time that's elapsed since the last frame.</param>
        /// <param name="player">The player object the Enemy is targetting.</param>
        public void Update(GameTime time, Player player)
        {
            switch (objectName)
            {
                case "FloorThing":
                    {
                        if (velocityX == 0)
                            velocityX = -movementSpeed;
                    }
                    break;
                case "WallThing":
                    {
                        if (velocityX == 0 & velocityY == 0)
                        {
                            if (isOnGround)
                                velocityX = movementSpeed;
                            else if (wallOnRight)
                                velocityY = -movementSpeed;
                            else if (ceilingAbove)
                                velocityX = -movementSpeed;
                            else //if (wallOnLeft)
                                velocityY = movementSpeed;
                        }

                        if (isOnGround)
                        {
                            if (wallOnRight)
                                velocityY = -movementSpeed;
                        }
                        else if (wallOnRight)
                        {
                            if (ceilingAbove)
                                velocityX = -movementSpeed;
                        }
                        else if (ceilingAbove)
                        {
                            if (wallOnLeft)
                                velocityY = movementSpeed;
                        }
                        else if (wallOnLeft)
                        {
                            if (isOnGround)
                                velocityX = movementSpeed;
                        }
                        else
                        {
                            if (velocityX > 0)
                            {
                                velocityX = 0;
                                velocityY = movementSpeed;
                            }
                            else if (velocityY > 0)
                            {
                                velocityX = -movementSpeed;
                                velocityY = 0;
                            }
                            else if (velocityX < 0)
                            {
                                velocityX = 0;
                                velocityY = -movementSpeed;
                            }
                            else //if (velocityY < 0)
                            {
                                velocityX = movementSpeed;
                                velocityY = 0;
                            }
                        }
                    }
                    break;
                case "Mummy":
                    {
                        if ((Math.Abs(player.Position.X + player.CollisionXs.First() - position.X + collisionXs.Last()) < 450) ||
                        ((Math.Abs(player.Position.X + player.CollisionXs.Last() - position.X + collisionXs.First()) < 450)))
                        {
                            movesOffEdges = true;
                            isChasingPlayer = true;
                        }
                        else if (isChasingPlayer)
                        {
                            isChasingPlayer = false;
                            movesOffEdges = false;
                            //velocityX /= 2;
                            velocityX = movementSpeed / 2;
                            accelerationX = 0;
                            velocityLimitX = 0;
                        }

                        if (isChasingPlayer)
                        {
                            if (isOnGround)
                            {
                                if (player.Position.X + player.CollisionXs.First() > position.X + collisionXs.Last())
                                {
                                    velocityLimitX = MUMMY_MAXSPEED;
                                    accelerationX = 2160;
                                }
                                else //if (player.Position.X + player.CollisionXs.Last() < position.X + collisionXs.First())
                                {
                                    velocityLimitX = -MUMMY_MAXSPEED;
                                    accelerationX = -2160;
                                }
                                if ((wallOnLeft && velocityX < 0) || (wallOnRight && velocityX > 0))
                                    velocityY = -900;
                            }
                        }
                        else if (velocityX == 0)
                        {
                            velocityX = -movementSpeed / 2;
                            velocityLimitX = 0;
                            accelerationX = 0;
                        }
                    }
                    break;
                default:
                    {
                        if (velocityX == 0)
                            velocityX = -movementSpeed;
                    }
                    break;
            }
            base.Update(time);
        }