Beispiel #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f;

            Input.GetInstance().Update();
            Fader.GetInstance().Update(elapsedTime);

            KeyboardState keyboardState   = Keyboard.GetState();
            GamePadState  gamePadOneState = GamePad.GetState(PlayerIndex.One);

            // Menu music playback handling:
            // Play music in mainmenu, credits and info
            // pause for start or gameplay
            switch (this.currentGameState)
            {
            case GameState.Mainmenu:
            case GameState.Info:
            case GameState.Credits:
                this.mainMenu.PlayMusic();
                break;

            case GameState.Start:
                this.mainMenu.PauseMusic();
                break;
            }

            // Allows the game to exit
            if (Input.GetInstance().IsPressed(Buttons.Back) ||
                (Input.GetInstance().IsPressed(Keys.Escape)))
            {
                //if (this.currentGameState != GameState.Start)
                {
                    // If not in the MainMenu go there else goto Quit.
                    if (this.currentGameState != GameState.Mainmenu && this.currentGameState != GameState.Quit)
                    {
                        this.currentGameState = GameState.Mainmenu;
                        if (this.mapper != null)
                        {
                            Fader.GetInstance().Add(Fader.Fade.In, 1.0f);
                            this.mapper.Reset();
                            this.mapper = null;
                        }
                    }
                    else
                    {
                        this.currentGameState = GameState.Quit;
                    }
                }
            }

            switch (this.currentGameState)
            {
            case GameState.Intro:
                this.gameIntro.Update(gameTime);
                if (this.gameIntro.Finished)
                {
                    Fader.GetInstance().Add(Fader.Fade.In, 1.0f);
                    this.gameIntro        = null;               // Shown it, not needed anymore
                    this.currentGameState = GameState.Mainmenu; // and goto main menu.
                }
                break;

            case GameState.Mainmenu:
                this.currentGameState = this.mainMenu.Update(gameTime, this.currentGameState);
                break;

            case GameState.Start:

                // Update StageChanger.
                if (this.mapper == null)
                {
                    this.mapper = new Mapper(this, XMLHandler.LoadXML <MapperData>(@"stages.xml"));
                }
                else
                {
                    this.mapper.Update(gameTime);


                    if (this.mapper.GameCompleted)
                    {       // All game stages completed. Game finished. Last videos and cutscenes played. Goto Credits.
                        this.mapper.Reset();
                        this.currentGameState = GameState.Credits;
                    }

                    if (this.mapper.Quitted)
                    {       // Quitted from the gameplay or Map. goto mainmenu.
                        this.mapper.Reset();
                        this.currentGameState = GameState.Mainmenu;
                    }
                }

                break;

            case GameState.Info:
                // Info or instructions goes here:
                if (this.info == null)
                {
                    this.info = new Credits(this, "info");
                }
                if (this.info.Update(gameTime))
                {
                    this.currentGameState = GameState.Mainmenu;
                    this.info             = null;
                }
                break;

            case GameState.Credits:
                // Credits goes here:
                if (credits == null)
                {
                    credits = new Credits(this, "credits");
                }
                if (this.credits.Update(gameTime))
                {
                    this.currentGameState = GameState.Mainmenu;
                    credits = null;
                }
                break;

            case GameState.Quit:
                // Exiting the game.
                if (!this.quitFadeOutSet)
                {
                    this.quitFadeOutSet = true;
                    Fader.GetInstance().Add(Fader.Fade.Out, 1.0f);
                }
                if (Fader.GetInstance().IsFadeFinished())
                {
                    this.Exit();
                }
                break;
            }

            base.Update(gameTime);
        }
Beispiel #2
0
        public Map(Game game, MapData mapData)
        {
            this.game                = game;
            this.completed           = false;
            this.isGamePaused        = false;
            this.endConditionReached = false;

            camera = new Camera(((PORAGame)game).Graphics);

            int offset = mapData.backgroundOffset;
            int width  = 0;
            int height = 0;

            this.completionTime = 0.0f;

            placeables = new List <Placeable>();

            background = game.Content.Load <Texture2D>(mapData.background);

            for (int y = mapData.Tiles.Length - 1; y >= 0; y--)
            {
                if (y + 1 > height)
                {
                    height = y + 1;
                }
                for (int x = 0; x < mapData.Tiles[y].Length; x++)
                {
                    if (x + 1 > width)
                    {
                        width = x + 1;
                    }
                    Vector2 position = new Vector2(x * 64 + 32, y * 64 + 32 + offset);

                    foreach (tileProperty item in mapData.tileInfo)
                    {
                        if (mapData.Tiles[y][x] == item.symbol)
                        {
                            PlaceableData placeableData = XMLHandler.LoadXML <PlaceableData>(item.name);
                            if (placeableData.player == true)
                            {
                                player = new Player(game, position, areaBorders, placeableData, item.symbol);
                            }
                            else
                            {
                                placeables.Add(
                                    new Placeable(
                                        game,
                                        position,
                                        areaBorders,
                                        placeableData,
                                        item.symbol
                                        )
                                    );
                            }
                        }
                    }
                }
            }


            // Apply area borders to all items and enable game components
            areaBorders = new Rectangle(0, 0, width * 64, height * 64 + offset);
            foreach (Placeable item in placeables)
            {
                item.SetBordersRectangle(areaBorders);
                item.Enabled = true;
            }
            player.SetBordersRectangle(areaBorders);
            player.Enabled = true;

            // Create the ending delay timer
            endingTimer = new Timer(mapData.endDelay, false);

            // Create timer for death's after effects
            deadTimer = new Timer(1.0f, false);

            // Create dialog and add it to the DialogEngine
            DialogEngine.GetInstance().AddDialog(new Dialog(game, XMLHandler.LoadXML <DialogData>(mapData.dialog)));

            // Load Game Over dialog
            textureGameOver = game.Content.Load <Texture2D>("gameover");

            //Load background music
            if (mapData.music != "null")
            {
                this.soundEffectMusic         = game.Content.Load <SoundEffect>(@mapData.music);
                this.soundEffectInstanceMusic = this.soundEffectMusic.CreateInstance();
            }
            else
            {
                this.soundEffectInstanceMusic = null;
                this.soundEffectMusic         = null;
            }
        }