Example #1
0
        /// <summary>
        /// Starts a new game.
        /// </summary>
        public void NewGame()
        {
            // :: Change the game state and make sure that no level
            // :: is loaded so that we have a black background.
            this.state = GameState.Intro;

            this.CurrentLevel.Unload();
            this.mainMenu.Hide();

            // :: Initialise a new player character.
            CharacterAttributes playerAttributes = new CharacterAttributes();
            playerAttributes.Health = 100;
            playerAttributes.Defence = 2;
            playerAttributes.Strength = 15;
            playerAttributes.Magic = 50;

            this.playerCharacter = new PlayerCharacter(playerAttributes);
            this.playerCharacter.Moves.Add(new MeleeAttack());

            // :: Temporarily change the dialogue event handlers so that
            // :: they don't change the game state to Exploring / Cutscene.
            DialogueEventDelegate introEndDelegate = null;

            introEndDelegate = new DialogueEventDelegate(delegate
            {
                this.DialogueManager.OnEnd -= introEndDelegate;
                this.DialogueManager.OnStart += this.dialogueStartDelegate;
                this.DialogueManager.OnEnd += this.dialogueEndDelegate;

                this.LoadLevel(@"Levels\PlayerHouse.xml", "Default", false);
                this.character.Enabled = false;

                FadeScreenEventDelegate fadeEndEvent = null;
                fadeEndEvent = new FadeScreenEventDelegate(delegate
                {
                    this.fadeScreen.Finished -= fadeEndEvent;
                    this.fadeScreen.Enabled = false;
                    this.fadeScreen.Visible = false;

                    this.character.Enabled = true;
                    this.state = GameState.Exploring;
                });

                this.fadeScreen.Finished += fadeEndEvent;
                this.fadeScreen.Visible = true;
                this.fadeScreen.Enabled = true;
                this.fadeScreen.FadeOut(1.0d);

                this.state = GameState.LevelTransition;
            });

            this.DialogueManager.OnStart -= this.dialogueStartDelegate;
            this.DialogueManager.OnEnd -= this.dialogueEndDelegate;
            this.DialogueManager.OnEnd += introEndDelegate;

            this.DialogueManager.PlayDialogue(@"FSEGame\Dialogues\Intro.xml");
        }
Example #2
0
        /// <summary>
        /// Loads the game state from the slot with the specified ID.
        /// </summary>
        /// <param name="slot">The ID of the save slot to load the game state from.</param>
        public void LoadGame(Byte slot)
        {
            String path = Path.Combine(
                this.savesFolder, String.Format("Slot{0}.sav", slot));

            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            using (BinaryReader br = new BinaryReader(fs))
            {
                Byte version = br.ReadByte();

                if (version != 0x01)
                    throw new Exception("!!! Invalid save file");

                String levelFilename = br.ReadString();

                this.CurrentLevel.Load(this.Content, levelFilename);

                this.character.CellPosition = new Vector2(
                    br.ReadSingle(), br.ReadSingle());
                this.character.Orientation = br.ReadSingle();

                // :: Load the player character's attributes.
                CharacterAttributes baseAttributes = new CharacterAttributes();
                CharacterAttributes currentAttributes = new CharacterAttributes();

                baseAttributes.LoadFromBinary(br);
                currentAttributes.LoadFromBinary(br);

                // :: Initialise the player character using the attributes obtained
                // :: previously.
                this.playerCharacter = new PlayerCharacter(baseAttributes);
                this.playerCharacter.CurrentAttributes = currentAttributes;

                // ::
                Int32 moveCount = br.ReadInt32();

                for (Int32 i = 0; i < moveCount; i++)
                {
                    this.playerCharacter.Moves.Add(
                        MoveHelper.CreateFromName(br.ReadString()));
                }

                // :: Load the persistent storage data. The persistent storage
                // :: contains quest status information, etc.
                this.PersistentStorage.Load(br);

                // :: Hide the menues and enable the character controller.
                this.mainMenu.Hide();
                this.loadScreen.Hide();

                this.state = GameState.Exploring;
                this.character.Enabled = true;
            }
        }