Пример #1
0
        public Dialog(Game game, DialogData dialogData)
        {
            this.game       = game;
            this.dialogData = dialogData;
            this.color      = Color.White;
            this.running    = true;

            // Load font
            spriteFont20 = game.Content.Load <SpriteFont>("SpriteFont20");

            // Load backgroundTexture
            backgroundTexture = game.Content.Load <Texture2D>(dialogData.background);

            // Load and create the face animations
            for (int i = 0; i < dialogData.dialogs.Length; i++)
            {
                FaceData         faceData    = XMLHandler.LoadXML <FaceData>(dialogData.dialogs[i].faceAnimation);
                List <Texture2D> textureList = new List <Texture2D>();
                for (int j = 0; j < faceData.textures.Length; j++)
                {
                    textureList.Add(game.Content.Load <Texture2D>(faceData.textures[j]));
                }
                Animation anim = new Animation(textureList, faceData.frameChangeSpeed);
                faceAnimationsList.Add(anim);
            }

            // Number of dialogs
            this.dialogCount = dialogData.dialogs.Length;

            // Timer for changing the dialog
            timer = new Timer(dialogData.dialogs[0].textDisplayTime, true);


            MakeDialogTextFit();
        }
Пример #2
0
        /// <summary>
        /// Loads the next game stage
        /// </summary>
        /// <param name="next">True to load next stage, false to repeat the current.</param>
        private void LoadStage(bool next)
        {
            if (next)
            {
                this.currentStage++;
            }

            if (this.cutsceneVideoFile != null)
            {
                this.videoPlayer.Stop();
            }

            this.map = null;
            this.cutsceneVideoFile   = null;
            this.cutsceneSkipAttempt = false;

            // Run the garbage collectors to cleanup now.
            GC.Collect();
            GC.WaitForPendingFinalizers();

            if (this.currentStage >= this.mapperData.stages.Length)
            {
                Console.WriteLine("End of stages reached!");
                this.stagesCompleted = true;
                return;
            }

            // Load map if the currentStage is a map else load video file
            if (this.mapperData.stages[this.currentStage].isMap == true)
            {
                Console.WriteLine("Load map #{0}: " + this.mapperData.stages[this.currentStage].xmlDescriptor, this.currentStage);

                this.map = new Map(game, XMLHandler.LoadXML <MapData>(this.mapperData.stages[this.currentStage].xmlDescriptor));
                // Update map once with zero to have all animations set and ready.
                this.map.Update(new GameTime());
            }
            else
            {
                Console.WriteLine("Play video #{0}: " + this.mapperData.stages[this.currentStage].xmlDescriptor, this.currentStage);

                this.cutsceneVideoFile = this.game.Content.Load <Video>(this.mapperData.stages[this.currentStage].xmlDescriptor);
                this.videoPlayer.Play(this.cutsceneVideoFile);
            }

            // New stage, set totalGameTimeUpdated flag to not set
            this.totalGameTimeUpdated = false;

            this.game.ResetElapsedTime();

            // Set effect to Fade In
            Fader.GetInstance().Add(Fader.Fade.In, 1);
        }
Пример #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            this.mainMenu = new Menu(this, XMLHandler.LoadXML <MenuData>(@"Menus\Mainmenu"));

            this.gameIntro = new Intro(this, "punyware");

            this.spriteFont20 = Content.Load <SpriteFont>("SpriteFont20");
        }
Пример #4
0
        public Placeable(Game game, Vector2 position, Rectangle areaBorders, PlaceableData data, char symbol)
            : base(game, position)
        {
            this.Enabled = false;

            List <Texture2D> textureList = new List <Texture2D>();

            foreach (string texture in data.sprites)
            {
                textureList.Add(game.Content.Load <Texture2D>(texture));
            }

            this.animation = new Animation(textureList, data.animSpeed);

            this.animation.LayerDepth = data.layerDepth;

            this.symbol       = symbol;
            this.moveable     = data.moveable;
            this.gravity      = data.gravity;
            this.drillable    = data.drillable;
            this.incollidable = data.incollidable;
            this.areaBorders  = areaBorders;
            this.destroyable  = data.destroyable;
            this.endCondition = data.endCondition;
            this.damage       = data.damage;
            this.health       = data.health;
//            this.placeableData = data;

            this.velocity = Vector2.Zero;

            // data.dialog is a string so test against string "null" instead of null.
            if (data.dialog != "null")
            {
                this.dialog = new Dialog(game, XMLHandler.LoadXML <DialogData>(data.dialog));
            }

            // Load destroyed sound
            if (data.destroyedSound != "null")
            {
                this.soundEffectDestroyed = game.Content.Load <SoundEffect>(@data.destroyedSound);
            }
            else
            {
                this.soundEffectDestroyed = null;
            }

            game.Components.Add(this);
        }
Пример #5
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);
        }
Пример #6
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;
            }
        }