Exemple #1
0
        protected override void Initialize()
        {
            Window.Title = String.Format("{0} v{1}", Project.title, Project.version);

            contentChest         = ContentChest.Instance;
            contentChest.content = Content;
            contentChest.LoadContent();

            graphics.PreferredBackBufferWidth  = Project.screenWidth;
            graphics.PreferredBackBufferHeight = Project.screenHeight;
            graphics.ApplyChanges();


            panes.Add("none", new Pane(Project.screenWidth, Project.screenHeight, 0, 0, Color.Black, "", null));
            panes.Add("inventory", new Pane(Project.inventoryWidth, Project.inventoryHeight, Project.statWidth, 0, Color.Black, "Inventory", new Inventory()));

            panes.Add("messages", new Pane(Project.messageWidth, Project.messageHeight, Project.statWidth, Project.inventoryHeight + Project.mapHeight, Color.Black, "Messages", new Messages(Project.statWidth, Project.inventoryHeight + Project.mapHeight, Project.messageHeight)));
            Map map = new Map(Project.statWidth, Project.inventoryHeight);

            panes.Add("stats", new Pane(Project.statWidth, Project.statHeight, 0, 0, Color.Black, "Stats", new Stats(0, 0, map.GetPlayer())));
            panes.Add("map", new Pane(Project.mapWidth, Project.mapHeight, Project.statWidth, Project.inventoryHeight, Color.Black, "Map", map));


            base.Initialize();
        }
Exemple #2
0
 public GameManager(ContentChest contentChest, World world)
 {
     ContentChest = contentChest;
     World        = world;
     FinaliseSetup();
     RecreateWorld();
 }
        private static IRenderer CreateRenderer(RendererData renderer, ContentChest contentChest)
        {
            if (renderer == null)
            {
                return(null);
            }

            switch (renderer.Name)
            {
            case "StaticRenderer":
                return(new StaticRenderer()
                {
                    ContentChest = contentChest
                });

            case "TransitionRenderer":
                return(new TransitionRenderer
                {
                    ContentChest = contentChest,
                    TransitionTextures = renderer.Textures,
                    MaxTransition = renderer.Textures.Length - 1,
                    TransitionTime = float.Parse(renderer.GetParameter("TransitionTime"))
                });

            default: return(null);
            }
        }
Exemple #4
0
        public GameManager(ContentChest contentChest)
        {
            ContentChest = contentChest;

            World = new World(MapWidth, MapHeight);
            FinaliseSetup();
        }
Exemple #5
0
 public void Render(SpriteBatch spriteBatch)
 {
     spriteBatch.Begin();
     spriteBatch.Draw(ContentChest.Get <Texture2D>("Images/splash"), new Rectangle(0, 0, 1280, 720),
                      Color.White);
     spriteBatch.End();
 }
Exemple #6
0
        public MainMenu(ContentChest contentChest)
        {
            _contentChest = contentChest;
            _inputManager = new InputManager();

            var buttonSettings = new ElementSettings
            {
                ImagePressed = contentChest.NewGameButtonPressed,
                ImageOff     = contentChest.NewGameButtonOff
            };
            var newGameButton = new Button(Screen.Width / 2 - buttonSettings.ImagePressed.Width / 2, Screen.Height / 2, buttonSettings);

            _inputManager.RegisterUIElement(NewGame, newGameButton);


            buttonSettings = new ElementSettings
            {
                ImagePressed = contentChest.LoadGameButtonPressed,
                ImageOff     = contentChest.LoadGameButtonOff
            };
            var loadGameButton = new Button(newGameButton.X, newGameButton.GetBounds().Y + newGameButton.GetBounds().Height + 10, buttonSettings);

            _inputManager.RegisterUIElement(LoadGame, loadGameButton);

            MenuButtons.Add(newGameButton);
            MenuButtons.Add(loadGameButton);

            _saves = GetSaves();
        }
Exemple #7
0
        public void Render(SpriteBatch spriteBatch)
        {
            // Background
            spriteBatch.Begin();
            spriteBatch.Draw(ContentChest.Get <Texture2D>("Images/pixel"), new Rectangle(0, 0, 1280, 720),
                             new Color(62, 59, 86));
            spriteBatch.End();

            // Content
            spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, _camera.GetMatrix());
            _mapRenderer.Render(spriteBatch, _mapEntityHistoryService.GetHistoricalEntities());
            spriteBatch.End();

            // UI
            spriteBatch.Begin();
            var titleFont = ContentChest.Get <SpriteFont>("Fonts/TitleFont");

            spriteBatch.DrawString(titleFont, _activeMap.Name,
                                   new Vector2(1, 0) * WindowSettings.Center + new Vector2(0, 70) - titleFont.MeasureString(_activeMap.Name) / 2.0f, Color.White);

            var font = ContentChest.Get <SpriteFont>("Fonts/MainFont");

            spriteBatch.DrawString(font, $"Redos: {_mapRefreshes}",
                                   new Vector2(40,
                                               WindowSettings.WindowHeight - font.MeasureString($"{_mapRefreshes}").Y - 40),
                                   Color.White);

            spriteBatch.DrawString(font, "W: Move Up",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("W: Move Up").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("W: Move Up").Y * 6 - 90),
                                   Color.White * _controlFadeIn);

            spriteBatch.DrawString(font, "D: Move Down",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("S: Move Down").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("S: Move Down").Y * 5 - 80),
                                   Color.White * _controlFadeIn);

            spriteBatch.DrawString(font, "A: Move Left",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("A: Move Left").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("A: Move Left").Y * 4 - 70),
                                   Color.White * _controlFadeIn);

            spriteBatch.DrawString(font, "D: Move Right",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("D: Move Right").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("D: Move Right").Y * 3 - 60),
                                   Color.White * _controlFadeIn);

            spriteBatch.DrawString(font, "X: Redo",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("X: Redo").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("X: Redo").Y * 2 - 50),
                                   Color.White * _controlFadeIn);

            spriteBatch.DrawString(font, "Z: Hard Restart",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("Z: Hard Restart").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("Z: Hard Restart").Y - 40),
                                   Color.White * _controlFadeIn);

            spriteBatch.End();
        }
 public void SetUp()
 {
     _contentManager = Substitute.For <IContentManager>();
     _contentChest   = new ContentChest
     {
         Content = _contentManager
     };
 }
Exemple #9
0
        public MainMenuScreen()
        {
            MediaPlayer.Play(ContentChest.Get <Song>("Music/menu"));
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Volume      = 0.2f;

            Game1.ActiveSong = "Music/menu";
        }
Exemple #10
0
        public override void Render(SpriteBatch spriteBatch)
        {
            var image = _onEntities.Count > 0
                ? ContentChest.Get <Texture2D>("Images/constant_pressure_switch2")
                : ContentChest.Get <Texture2D>("Images/constant_pressure_switch1");

            spriteBatch.Draw(image, new Vector2(Tile.RenderX, Tile.RenderY), Color.White);

            base.Render(spriteBatch);
        }
Exemple #11
0
        public override void Render(SpriteBatch spriteBatch)
        {
            var image = _steppedOn
                ? ContentChest.Get <Texture2D>("Images/pressure_switch2")
                : ContentChest.Get <Texture2D>("Images/pressure_switch1");

            spriteBatch.Draw(image, new Vector2(Tile.RenderX, Tile.RenderY), Color.White);

            base.Render(spriteBatch);
        }
Exemple #12
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _graphics.PreferredBackBufferWidth  = WindowSettings.WindowWidth;
            _graphics.PreferredBackBufferHeight = WindowSettings.WindowHeight;
            _graphics.ApplyChanges();

            ContentChest.SetContentManager(Content);
            ContentChest.Load();
        }
Exemple #13
0
        public void Open()
        {
            if (!_closed && !Closing)
            {
                return;
            }

            ContentChest.Get <SoundEffect>("Sounds/pressure_plate").Play();
            Opening = true;
            Closing = false;
            _closed = false;
        }
Exemple #14
0
        protected override void LoadContent()
        {
            ContentChest = new ContentChest(Content);
            ContentChest.Load();

            _mainMenu = new MainMenu(ContentChest);
            _mainMenu.OnNewGamePressed += NewGame;
            _mainMenu.OnLoadGame       += LoadGame;

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            WorldObjectChest.LoadPrototypes(ContentChest);
        }
Exemple #15
0
        public void Close()
        {
            _doorTimer = 0;

            if (!_open && !Opening)
            {
                return;
            }

            ContentChest.Get <SoundEffect>("Sounds/pressure_plate").Play();
            Closing  = true;
            Blocking = true;
            Opening  = false;
            _open    = false;
        }
        public static void LoadPrototypes(ContentChest contentChest)
        {
            var prototypeDirectory = "Content\\Prototypes";

            var prototypes = LoadFromFiles(prototypeDirectory);

            foreach (var prototype in prototypes)
            {
                var renderer  = CreateRenderer(prototype.Renderer, contentChest);
                var behaviour = CreateBehaviour(prototype.Behaviour, contentChest);
                CreatePrototype(
                    prototype,
                    behaviour,
                    renderer);
            }
        }
Exemple #17
0
        public override void Left(IEntity other)
        {
            var removed = _onEntities.Remove(other);

            if (_onEntities.Count > 0)
            {
                return;
            }

            if (!removed)
            {
                return;
            }

            var doors =
                CurrentMap?.Entities?.Where(x => x.GetType() == typeof(Door) && ((Door)x).DoorId == DoorId);

            if (doors == null)
            {
                return;
            }

            foreach (var entity in doors)
            {
                var door = (Door)entity;

                door.Requires++;

                if (door.Requires <= 0)
                {
                    continue;
                }

                if (door.ClosedAtStart)
                {
                    door.Close();
                }
                else
                {
                    door.Open();
                }
            }

            ContentChest.Get <SoundEffect>("Sounds/pressure_off").Play();
        }
Exemple #18
0
        public void Render(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();

            spriteBatch.DrawString(_titleFont, GameTitle,
                                   WindowSettings.Center - new Vector2(0, 1) * WindowSettings.Center / 2 - _gameTitleTextSize / 2,
                                   Color.White);

            _startGameText.Render(spriteBatch);


            var font = ContentChest.Get <SpriteFont>("Fonts/MainFont");

            spriteBatch.DrawString(font, "W: Move Up",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("W: Move Up").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("W: Move Up").Y * 6 - 90),
                                   Color.White);

            spriteBatch.DrawString(font, "D: Move Down",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("S: Move Down").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("S: Move Down").Y * 5 - 80),
                                   Color.White);

            spriteBatch.DrawString(font, "A: Move Left",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("A: Move Left").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("A: Move Left").Y * 4 - 70),
                                   Color.White);

            spriteBatch.DrawString(font, "D: Move Right",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("D: Move Right").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("D: Move Right").Y * 3 - 60),
                                   Color.White);

            spriteBatch.DrawString(font, "X: Redo",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("X: Redo").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("X: Redo").Y * 2 - 50),
                                   Color.White);

            spriteBatch.DrawString(font, "Z: Hard Restart",
                                   new Vector2(WindowSettings.WindowWidth - font.MeasureString("Z: Hard Restart").X - 40,
                                               WindowSettings.WindowHeight - font.MeasureString("Z: Hard Restart").Y - 40),
                                   Color.White);

            spriteBatch.End();
        }
Exemple #19
0
        public void Begin()
        {
            GameScreen.CurrentMap = 1;

            _titleFont         = ContentChest.Get <SpriteFont>("Fonts/TitleFont");
            _gameTitleTextSize = _titleFont.MeasureString(GameTitle);

            var mainFont = ContentChest.Get <SpriteFont>("Fonts/MainFont");

            Game1.Input.OnKeyPressed(Keys.X, () =>
            {
                Game1.Input.Reset();
                RequestScreenChange?.Invoke(new MapTransitionScreen());
                Ended = true;
            });

            _startGameText = new FadeyText(StartGameText, mainFont, WindowSettings.Center);
        }
        private static IBehaviour CreateBehaviour(BehaviourData behaviour, ContentChest contentChest)
        {
            if (behaviour == null)
            {
                return(null);
            }

            switch (behaviour.Name)
            {
            case "DoorBehaviour":
                return(new DoorBehaviour
                {
                    OpeningTime = float.Parse(behaviour.GetParameter("OpeningTime"))
                });

            default:
                return(null);
            }
        }
Exemple #21
0
        public override void Entered(IEntity other)
        {
            var added = _onEntities.Add(other);

            if (!added || _onEntities.Count != 1)
            {
                return;
            }

            var doors =
                CurrentMap?.Entities?.Where(x => x.GetType() == typeof(Door) && ((Door)x).DoorId == DoorId);

            if (doors == null)
            {
                return;
            }

            foreach (var entity in doors)
            {
                var door = (Door)entity;

                door.Requires--;

                if (door.Requires > 0)
                {
                    continue;
                }

                door.Requires = 0;

                if (door.ClosedAtStart)
                {
                    door.Open();
                }
                else
                {
                    door.Close();
                }
            }

            ContentChest.Get <SoundEffect>("Sounds/pressure_on").Play();
        }
Exemple #22
0
        public override void Render(SpriteBatch spriteBatch)
        {
            var orientationExtra = "";

            if (Side)
            {
                orientationExtra = "side";
            }

            if (Closing || Opening || !Blocking)
            {
                spriteBatch.Draw(ContentChest.Get <Texture2D>($"Images/closed_block_door{orientationExtra}{_currDoorImage}"),
                                 new Vector2(Tile.RenderX, Tile.RenderY), Color.White);
            }
            else if (Blocking)
            {
                spriteBatch.Draw(ContentChest.Get <Texture2D>($"Images/closed_block{orientationExtra}"), new Vector2(Tile.RenderX, Tile.RenderY), Color.White);
            }

            base.Render(spriteBatch);
        }
Exemple #23
0
        public GameScreen()
        {
            _mapLoader   = new MapLoader();
            _mapRenderer = new MapRenderer();

            if (CurrentMap > _currentMapHistoryState)
            {
                _currentMapHistoryState  = CurrentMap;
                _mapEntityHistoryService = new MapEntityHistoryService();
            }

            if (Game1.ActiveSong != "Music/background")
            {
                MediaPlayer.Play(ContentChest.Get <Song>("Music/background"));
                MediaPlayer.IsRepeating = true;
                Game1.ActiveSong        = "Music/background";
            }

            _activeMap = _mapLoader.LoadMap(CurrentMap);
            _mapRenderer.SetMap(_activeMap);

            _camera.Position = new Vector2(_activeMap.MapWidth * _activeMap.TileWidth / 2.0f, _activeMap.MapHeight * _activeMap.TileHeight / 2.0f);

            Game1.Input.OnKeyPressed(Keys.X, ResetMap);
            Game1.Input.OnKeyPressed(Keys.Z, HardRestart);

            TurnService.PlayersTurn = true;

            foreach (var entity in _mapEntityHistoryService.GetHistoricalEntities())
            {
                entity.CurrentMap = _activeMap;
                entity.Begin();
            }

            _activeMap.Begin();

            Ended = false;
        }
Exemple #24
0
        public void Toggle()
        {
            _doorTimer = 0;
            if (_open || Opening)
            {
                Closing  = true;
                Blocking = true;
                Opening  = false;
                _open    = false;
                ContentChest.Get <SoundEffect>("Sounds/pressure_plate").Play(0.5f, 0, 0);
                return;
            }

            if (!_closed && !Closing)
            {
                return;
            }

            Opening = true;
            Closing = false;
            _closed = false;
            ContentChest.Get <SoundEffect>("Sounds/pressure_plate").Play(0.5f, 0, 0);
        }
        public void Begin()
        {
            if (Ended)
            {
                return;
            }

            var activeLevel = GameScreen.CurrentMap;

            _mapNameFont = ContentChest.Get <SpriteFont>("Fonts/TitleFont");

            try
            {
                var activeMap = _mapLoader.LoadMap(activeLevel);
                _mapName     = activeMap.Name;
                _mapNameSize = _mapNameFont.MeasureString(_mapName);
            }
            catch (Exception)
            {
                _mapName     = "";
                _mapNameSize = Vector2.Zero;
            }

            var timer = new Timer
            {
                Interval = MillisecondsToShowFor
            };

            timer.Elapsed += (x, y) =>
            {
                timer.Stop();
                RequestScreenChange?.Invoke(new GameScreen());
                Ended = true;
            };

            timer.Start();
        }
Exemple #26
0
        public override void Entered(IEntity other)
        {
            if (_steppedOn)
            {
                return;
            }

            var doors =
                CurrentMap?.Entities?.Where(x => x.GetType() == typeof(Door) && ((Door)x).DoorId == _doorId);

            if (doors == null)
            {
                return;
            }

            foreach (var entity in doors)
            {
                var door = (Door)entity;
                door.Toggle();
            }

            ContentChest.Get <SoundEffect>("Sounds/pressure_on").Play();
            _steppedOn = true;
        }
Exemple #27
0
        private void EndLevel()
        {
            if (Ended)
            {
                return;
            }

            Ended = true;
            ContentChest.Get <SoundEffect>("Sounds/Clap").Play();
            _mapEntityHistoryService.Reset();
            Game1.Input.Reset();
            TurnService.PlayersTurn = true;
            CurrentMap++;
            _mapRefreshes = 0;

            if (_mapLoader.LoadMap(CurrentMap) == null)
            {
                RequestScreenChange?.Invoke(new MainMenuScreen());
            }
            else
            {
                RequestScreenChange?.Invoke(new MapTransitionScreen());
            }
        }
Exemple #28
0
 public void Do(IEntity entity)
 {
     entity.Move(_xChange, _yChange);
     ContentChest.Get <SoundEffect>("Sounds/Walk").Play();
 }
Exemple #29
0
 public void Update(float delta)
 {
     ContentChest.Load();
 }
Exemple #30
0
 public void Do(IEntity entity)
 {
     ContentChest.Get <SoundEffect>("Sounds/skip").Play();
     entity.Wait();
 }