Exemplo n.º 1
0
        protected override void LoadContent()
        {
            base.LoadContent();

            var Content = gameRef.Content;

            IOManager.Init();

            blackOverlay = new DrawableRectangle(GraphicsDevice,
                new Vector2(MainGame.GAME_WIDTH, MainGame.GAME_HEIGHT), Color.White, true).Texture;

            blurOverlay = new GaussianBlur(gameRef);
            blurOverlay.ComputeKernel(7, 2.0f);

            titleImage = Content.Load<Texture2D>("Images\\title");

            title = new Label();
            title.SpriteFont = Content.Load<SpriteFont>("Fonts\\title");
            title.Text = "";
            title.Color = Color.White;
            title.Position = new Vector2(MainGame.GAME_WIDTH / 2 - title.Width / 2, 90);
            controls.Add(title);

            Texture2D[] images = new Texture2D[8];
            for (int i = 0; i < images.Length; i++)
            {
                images[i] = Content.Load<Texture2D>("Images\\waterfall\\water" + i.ToString());
            }

            anim = new Animation(images);

            #region Menu State
            menuControls = new ControlManager(gameRef, Content.Load<SpriteFont>("Fonts\\default"));

            var start = new LinkLabel(0) { Name = "lnklblStart", Text = "New Game" };
            var load = new LinkLabel(1) { Name = "lnklblLoad", Text = "Load Game" };
            var options = new LinkLabel(2) { Name = "lnklblOptions", Text = "Options" };
            var quit = new LinkLabel(3) { Name = "lnklblQuit", Text = "Quit Game" };

            menuControls.Add(start);
            menuControls.Add(load);
            menuControls.Add(options);
            menuControls.Add(quit);

            Vector2 startPos = new Vector2(MainGame.GAME_WIDTH / 2, MainGame.GAME_HEIGHT / 1.8f);
            foreach (Control c in menuControls)
            {
                if (c is LinkLabel)
                {
                    var l = (LinkLabel)c;
                    var offset = new Vector2(c.Width / 2, 0);
                    c.Position = startPos - offset;
                    c.Selected += new EventHandler(LinkLabel_Selected);
                    c.Effect = ControlEffect.PULSE;
                    c.Color = Color.Black;
                    ((LinkLabel)c).SelectedColor = Color.DarkBlue;

                    l.OnMouseIn += LinkLabel_OnMouseIn;

                    startPos.Y += c.Height + 10f;
                }
            }

            menuControls.SelectControl(0);
            #endregion

            #region New Game State
            newGameControls = new ControlManager(gameRef, Content.Load<SpriteFont>("Fonts\\default"));

            Label prompt = new Label();
            prompt.Text = "Enter your name";
            prompt.Name = "lblNamePrompt";
            prompt.Position = new Vector2(MainGame.GAME_WIDTH / 2 -
                prompt.SpriteFont.MeasureString(prompt.Text).X / 2, 200);
            newGameControls.Add(prompt);

            TextBox name = new TextBox(GraphicsDevice);
            name.Name = "txtName";
            name.Position = new Vector2(prompt.Position.X + 40, prompt.Position.Y + prompt.Height + 10);
            name.BackColor = Color.Transparent;
            name.ForeColor = Color.White;
            newGameControls.Add(name);

            LinkLabel startGame = new LinkLabel(2) { Name = "lnklblNewGame", Text = "Start" };
            startGame.Position = new Vector2(prompt.Position.X, name.Position.Y + 44);
            startGame.OnMouseIn += LinkLabel_OnMouseIn;
            startGame.Selected += (o, e) =>
            {
                Config.currentlyPlaying = newGameControls[1].Text;
                SwitchStateWithFade(new LoadingState(gameRef, StateManager, new GameplayState(gameRef, StateManager)));
            };
            startGame.Effect = ControlEffect.PULSE;

            LinkLabel cancel = new LinkLabel(3) { Name = "lnklblCancel", Text = "Cancel" };
            cancel.Position = new Vector2(prompt.Position.X + prompt.Width - cancel.Width, startGame.Position.Y);
            cancel.OnMouseIn += LinkLabel_OnMouseIn;
            cancel.Selected += (o, e) => { currentState = State.Menu; };
            cancel.Effect = ControlEffect.PULSE;

            newGameControls.Add(startGame);
            newGameControls.Add(cancel);
            #endregion

            #region Load Game State
            loadGameControls = new ControlManager(gameRef, Content.Load<SpriteFont>("Fonts\\default"));

            List<EntityProperties> saves = new List<EntityProperties>();
            saves = IOManager.GetAllPlayerDatas();

            startPos = new Vector2(MainGame.GAME_WIDTH / 2, 0);
            int counter = 0;
            foreach (EntityProperties ep in saves)
            {
                var lnklblLoadSave = new LinkLabel(counter++);
                lnklblLoadSave.AutoSize = true;
                lnklblLoadSave.Name = "lnklblLoadSave";
                lnklblLoadSave.Text = ep.Name + " | " + ep.TimeOfSave;
                lnklblLoadSave.OnMouseIn += LinkLabel_OnMouseIn;
                lnklblLoadSave.Selected += (o, e) => { SwitchStateWithFade(new LoadingState(gameRef, StateManager, new GameplayState(gameRef, StateManager, ep))); };
                lnklblLoadSave.Effect = ControlEffect.PULSE;

                var offset = new Vector2(lnklblLoadSave.Width / 2, 0);
                lnklblLoadSave.Position = startPos - offset;
                startPos.Y += lnklblLoadSave.Height + 10;
                loadGameControls.Add(lnklblLoadSave);
            }

            var goBack_Load = new LinkLabel(loadGameControls.Count);
            goBack_Load.Name = "lnklblGoBackLoad";
            goBack_Load.Text = "Go Back";
            goBack_Load.Effect = ControlEffect.PULSE;
            goBack_Load.Position = new Vector2(MainGame.GAME_WIDTH / 2 - goBack_Load.Width / 2, MainGame.GAME_HEIGHT - goBack_Load.Height - 100);
            goBack_Load.OnMouseIn += LinkLabel_OnMouseIn;
            goBack_Load.Selected += (o, e) => { currentState = State.Menu; };
            loadGameControls.Add(goBack_Load);

            #endregion

            #region Options Game State

            #endregion

            #region Quit State
            quitControls = new ControlManager(gameRef, Content.Load<SpriteFont>("Fonts\\default"));

            Label areYouSure1 = new Label();
            areYouSure1.Name = "lblAreYouSure?";
            areYouSure1.Text = "Are you sure you want to quit?";
            areYouSure1.Position = new Vector2(MainGame.GAME_WIDTH / 2 - areYouSure1.SpriteFont.MeasureString(
                areYouSure1.Text).X / 2, 140);
            quitControls.Add(areYouSure1);

            LinkLabel yes = new LinkLabel(1) { Name = "lnklblYes", Text = "Yes" };
            yes.Position = new Vector2(areYouSure1.Position.X + 40, areYouSure1.Position.Y + areYouSure1.Height + 50);
            yes.OnMouseIn += LinkLabel_OnMouseIn;
            yes.Selected += (o, e) => { gameRef.Exit(); };
            yes.Effect = ControlEffect.PULSE;

            LinkLabel no = new LinkLabel(2) { Name = "lnklblNo", Text = "No" };
            no.Position = new Vector2(areYouSure1.Position.X + areYouSure1.Width - no.Width - 40, yes.Position.Y);
            no.OnMouseIn += LinkLabel_OnMouseIn;
            no.Selected += (o, e) => { currentState = State.Menu; };
            no.Effect = ControlEffect.PULSE;

            quitControls.Add(yes);
            quitControls.Add(no);
            #endregion

            debugFont = Content.Load<SpriteFont>("Fonts\\version");
        }
Exemplo n.º 2
0
        public override void LargeLoadContent(object sender)
        {
            var Content = gameRef.Content;

            background = new DrawableRectangle(gameRef.GraphicsDevice, new Vector2(10, 10), Color.Black, true).Texture;

            levelManager = new LevelManager(gameRef);
            Camera.Initialize(Vector2.Zero, new Rectangle(0, 0, MainGame.GAME_WIDTH, MainGame.GAME_HEIGHT),
                new Vector2(LevelManager.CurrentLevel.WidthInPixels, LevelManager.CurrentLevel.HeightInPixels));
            Camera.MaxClamp -= new Vector2(Camera.View.Width / 2, Camera.View.Height / 2);

            entityManager = new EntityManager(gameRef);

            if (!loadedGame)
            {
                EntityManager.Player.Name = Config.currentlyPlaying;

                if (LevelManager.CurrentLevel.PlayerSpawnPoint.X > -1 &&
                    LevelManager.CurrentLevel.PlayerSpawnPoint.Y > -1)
                    EntityManager.Player.Position = new Vector2(LevelManager.CurrentLevel.PlayerSpawnPoint.X, LevelManager.CurrentLevel.PlayerSpawnPoint.Y) * Engine.TileWidth ;
            }
            else
            {
                Config.SetLastLogin(loadedProps.Name);
                Config.currentlyPlaying = loadedProps.Name;
                EntityManager.Player.LoadFromData(loadedProps);
            }

            new Pathfinder(LevelManager.CurrentLevel);

            #region Pause_Normal
            pauseControls_Normal = new ControlManager(gameRef, gameRef.Content.Load<SpriteFont>("Fonts\\default"));
            {
                Label lblPauseDisplay = new Label()
                {
                    Name = "lblPauseDisplay",
                    Text = "P A U S E D",
                    Color = Color.White
                };
                lblPauseDisplay.Position = new Vector2(MainGame.GAME_WIDTH / 2 - lblPauseDisplay.Width / 2,
                    MainGame.GAME_HEIGHT / 1.8f - lblPauseDisplay.Height - 10);

                var back = new LinkLabel(1) { Name = "lnklblBack", Text = "Resume" };
                var save = new LinkLabel(2) { Name = "lnklblSave", Text = "Save Game" };
                var quit = new LinkLabel(3) { Name = "lnklblQuit", Text = "Quit to Menu" };

                pauseControls_Normal.Add(lblPauseDisplay);
                pauseControls_Normal.Add(back);
                pauseControls_Normal.Add(save);
                pauseControls_Normal.Add(quit);

                Vector2 startPos = new Vector2(MainGame.GAME_WIDTH / 2, MainGame.GAME_HEIGHT / 1.8f);
                foreach (Control c in pauseControls_Normal)
                {
                    if (c is LinkLabel)
                    {
                        var l = (LinkLabel)c;
                        var offset = new Vector2(c.Width / 2, 0);
                        c.Position = startPos - offset;
                        c.Selected += new EventHandler(LinkLabel_Selected);
                        c.Effect = ControlEffect.PULSE;
                        c.Color = Color.Black;
                        l.OnMouseIn += LinkLabel_OnMouseIn;

                        startPos.Y += c.Height + 10f;
                    }
                }
            }
            #endregion

            #region Pause_Save
            pauseControls_Save = new ControlManager(gameRef, gameRef.Content.Load<SpriteFont>("Fonts\\default"));

            Label status = new Label();
            status.AutoSize = true;
            status.Text = "Save game success!";
            status.Position = new Vector2(MainGame.GAME_WIDTH / 2 - status.Width / 2, MainGame.GAME_HEIGHT / 2 - status.Height);
            pauseControls_Save.Add(status);

            LinkLabel goBack_Save = new LinkLabel(0);
            goBack_Save.AutoSize = true;
            goBack_Save.Text = "Go Back";
            goBack_Save.Position = new Vector2(MainGame.GAME_WIDTH / 2 - goBack_Save.Width / 2, status.Position.Y + status.Height + 10);
            goBack_Save.Selected += (o, e) => { pauseState = State_Paused.Normal; };
            goBack_Save.OnMouseIn += LinkLabel_OnMouseIn;
            pauseControls_Save.Add(goBack_Save);
            #endregion

            #region Pause_Quit
            pauseControls_Quit = new ControlManager(gameRef, gameRef.Content.Load<SpriteFont>("Fonts\\default"));

            Label areYouSure1 = new Label();
            areYouSure1.Name = "lblAreYouSure?";
            areYouSure1.Text = "Are you sure you want to quit?";
            areYouSure1.Position = new Vector2(MainGame.GAME_WIDTH / 2 - areYouSure1.SpriteFont.MeasureString(
                areYouSure1.Text).X / 2, 140);
            pauseControls_Quit.Add(areYouSure1);

            LinkLabel yes = new LinkLabel(1) { Name = "lnklblYes", Text = "Yes" };
            yes.Position = new Vector2(areYouSure1.Position.X + 40, areYouSure1.Position.Y + areYouSure1.Height + 50);
            yes.OnMouseIn += LinkLabel_OnMouseIn;
            yes.Selected += (o, e) => { SwitchStateWithFade(new MainMenuState(gameRef, StateManager)); };
            yes.Effect = ControlEffect.PULSE;

            LinkLabel no = new LinkLabel(2) { Name = "lnklblNo", Text = "No" };
            no.Position = new Vector2(areYouSure1.Position.X + areYouSure1.Width - no.Width - 40, yes.Position.Y);
            no.OnMouseIn += LinkLabel_OnMouseIn;
            no.Selected += (o, e) => { pauseState = State_Paused.Normal; };
            no.Effect = ControlEffect.PULSE;

            pauseControls_Quit.Add(yes);
            pauseControls_Quit.Add(no);
            #endregion

            blurOverlay = new GaussianBlur(gameRef);
            renderTargetWidth = MainGame.GAME_WIDTH;
            renderTargetHeight = MainGame.GAME_HEIGHT;
            blurOverlay.ComputeKernel(7, 2.0f);

            mainTarget = new RenderTarget2D(gameRef.GraphicsDevice, MainGame.GAME_WIDTH, MainGame.GAME_HEIGHT);
            target1 = new RenderTarget2D(gameRef.GraphicsDevice, renderTargetWidth, renderTargetHeight, false,
                gameRef.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None);
            target2 = new RenderTarget2D(gameRef.GraphicsDevice, renderTargetWidth, renderTargetHeight, false,
                gameRef.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None);

            blurOverlay.ComputeOffsets(renderTargetWidth, renderTargetHeight);

            quests = new QuestManager();

            Quest q = new Quest(0, (QuestGiver)EntityManager.Npcs[0], EntityManager.Player);
            q.CheckSuccess += (delegate()
            {
                return EntityManager.Player.NoClip == true;
            });
            quests.AddQuest(q);

            ((QuestGiver)EntityManager.Npcs[0]).Quest = q;
            ((QuestGiver)EntityManager.Npcs[0]).OnQuestCompleted += (delegate(object sender2, EventArgs args)
            {
                var questGiverSender = (QuestGiver)sender2;
                questGiverSender.Dialogues[0] = "Good job!";
            });

            base.LargeLoadContent(sender);
        }