コード例 #1
0
        protected override void LoadContent()
        {
            Fonts.LoadFonts(Content, "Fonts.xml");
            Sounds.LoadSounds(Content, "Sounds.xml");

            // Load Game Content
            startingSpriteBatch = new SpriteBatch(this.graphics.GraphicsDevice);

            // Get Screen Size
            int screenWidth  = this.Window.ClientBounds.Width;
            int screenHeight = this.Window.ClientBounds.Height;

            // Load Control Content
            TextPickerControl.LoadContent(Content);

            // Load Screen Content
            SplashScreen.LoadContent(Content);
            SetupScreen.LoadContent(Content);
            InstructionsScreen.LoadContent(Content);
            GameOverScreen.LoadContent(Content);
            LoadScreens();

            // Load Subsystem Contents
            SurvivorSubsystem.LoadContent(Content);
            ZombiesSubsystem.LoadContent(Content);
            CollectablesSubsystem.LoadContent(Content);
            AchievmentsSubsystem.LoadContent(Content);

            // Load Entity Contents
            HUD.LoadContent(Content, screenWidth, screenHeight);

            String saveFilePath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "save.sav");

            if (File.Exists(saveFilePath))
            {
                FileStream     fileStream     = File.OpenRead(saveFilePath);
                XmlSerializer  fileSerializer = new XmlSerializer(typeof(GameSaveStruct));
                GameSaveStruct gameSaveStruct = (GameSaveStruct)fileSerializer.Deserialize(fileStream);
                fileStream.Close();
                File.Delete(saveFilePath);
                GameState = GameState.Playing;
                this.StartPlayingSavedGame(gameSaveStruct);
            }
            else
            {
                ResetToStarting(true);
            }

            base.LoadContent();
        }
コード例 #2
0
        private void UpdatePlaying(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || oldKeyboardState.IsKeyDown(Keys.Escape))
            {
                this.SaveGame();
                this.gameWillQuit = true;
            }

            if ((GamePad.GetState(PlayerIndex.One).Buttons.Start != oldGamePadState.Buttons.Start && GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed) || (Keyboard.GetState().IsKeyDown(Keys.Delete) && oldKeyboardState.IsKeyUp(Keys.Delete)))
            {
                SurvivorSubsystem.PlayerOneSurvivorSprite.GameOver();
                this.ResetToGameOver(Results, Options);
            }

            if (!GamePaused)
            {
                if ((GamePad.GetState(PlayerIndex.One).Buttons.Y != oldGamePadState.Buttons.Y && GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed) || (Keyboard.GetState().IsKeyDown(Keys.P) && oldKeyboardState.IsKeyUp(Keys.P)))
                {
                    this.GamePaused = true;
                }

                Results.SurvivalTime += gameTime.ElapsedGameTime.TotalSeconds;

                SurvivorSubsystem.Update(gameTime);
                ZombiesSubsystem.Update(gameTime);
                CollectablesSubsystem.Update(gameTime);
                AchievmentsSubsystem.Update(gameTime);

                // Check for Game Over
                if (SurvivorSubsystem.PlayerOneSurvivorSprite.CurrentHealth <= 0.0f)
                {
                    SurvivorSubsystem.PlayerOneSurvivorSprite.GameOver();
                    this.ResetToGameOver(Results, Options);
                }
            }
            else if (GamePaused)
            {
                if ((GamePad.GetState(PlayerIndex.One).Buttons.Y != oldGamePadState.Buttons.Y && GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed) || (Keyboard.GetState().IsKeyDown(Keys.P) && oldKeyboardState.IsKeyUp(Keys.P)))
                {
                    this.GamePaused = false;
                }
            }

            // Update HUD
            HUD.Update(gameTime, Results);
        }
コード例 #3
0
        private void StartPlayingSavedGame(GameSaveStruct saveStruct)
        {
            this.Options = new GameOptions(saveStruct.Options);
            this.StartPlayingGame();

            SurvivorSubsystem.AddPlayerOneSurvivorSprite(new SurvivorSprite(this, saveStruct.PlayerOneSurvivorSprite));
            foreach (ZombieSpriteSaveStruct zombieSpriteSaveStruct in saveStruct.ZombieSprites)
            {
                ZombieSprite zombieSprite = new ZombieSprite(this, zombieSpriteSaveStruct);
                ZombiesSubsystem.AddZombieSprite(zombieSprite);
            }

            foreach (CollectableSaveStruct collectableSaveStruct in saveStruct.Collectables)
            {
                CollectablesSubsystem.AddCollectable(new Collectable(this, collectableSaveStruct));
                switch (collectableSaveStruct.CollectableEntityType)
                {
                case CollectableEntityType.Health: CollectablesSubsystem.HealthCollectablesSpawned++; break;

                case CollectableEntityType.Gasoline: CollectablesSubsystem.GasolineCollectablesSpawned++; break;

                case CollectableEntityType.PistolAmmo: CollectablesSubsystem.PistolAmmoCollectablesSpawned++; break;

                case CollectableEntityType.ShotgunAmmo: CollectablesSubsystem.ShotgunAmmoCollectablesSpawned++; break;

                case CollectableEntityType.Energy: CollectablesSubsystem.EnergyCollectablesSpawned++; break;

                default: break;
                }
            }

            // Reset Zombie Subsystem
            ZombiesSubsystem.WaveTimer = saveStruct.WaveTimer;

            AchievmentsSubsystem.Initialize(saveStruct.Achievments);

            this.Results = new GameResults(saveStruct.Stats);

            this.GamePaused = true;
        }