Ejemplo n.º 1
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();
 }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        public MainMenuScreen()
        {
            MediaPlayer.Play(ContentChest.Get <Song>("Music/menu"));
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Volume      = 0.2f;

            Game1.ActiveSong = "Music/menu";
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public void Open()
        {
            if (!_closed && !Closing)
            {
                return;
            }

            ContentChest.Get <SoundEffect>("Sounds/pressure_plate").Play();
            Opening = true;
            Closing = false;
            _closed = false;
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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();
        }
Ejemplo n.º 16
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());
            }
        }
Ejemplo n.º 17
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;
        }
Ejemplo n.º 18
0
 public void Do(IEntity entity)
 {
     ContentChest.Get <SoundEffect>("Sounds/skip").Play();
     entity.Wait();
 }
Ejemplo n.º 19
0
 public override void Render(SpriteBatch spriteBatch)
 {
     spriteBatch.Draw(ContentChest.Get <Texture2D>("Images/player"),
                      new Vector2(Tile.RenderX, Tile.RenderY), new Color(182, 158, 121));
 }
Ejemplo n.º 20
0
 public void Do(IEntity entity)
 {
     entity.Move(_xChange, _yChange);
     ContentChest.Get <SoundEffect>("Sounds/Walk").Play();
 }
Ejemplo n.º 21
0
        public void Render(SpriteBatch spriteBatch, IEnumerable <IEntity> historical)
        {
            if (_map == null)
            {
                return;
            }

            var tileSet = ContentChest.Get <Texture2D>("Images/tiles_1");

            foreach (var tile in _map.Tiles)
            {
                var rectX = tile.Id % (tileSet.Width / 16);
                var rectY = tile.Id / (tileSet.Height / 16);

                var tileSourceRectangle = new Rectangle(rectX * ActualTileSize, rectY * ActualTileSize, ActualTileSize,
                                                        ActualTileSize);
                var tileDestinationRectangle = new Rectangle(tile.X * TileRenderSize,
                                                             tile.Y * TileRenderSize, TileRenderSize, TileRenderSize);

                spriteBatch.Draw(tileSet, tileDestinationRectangle, tileSourceRectangle, Color.White);
            }

            foreach (var entity in _map.Entities)
            {
                entity.Render(spriteBatch);
            }

            _map.Player.Render(spriteBatch);

            var entitiesOnPlayer = 0;

            foreach (var entity in historical)
            {
                if (entity.X == _map.Player.X && entity.Y == _map.Player.Y)
                {
                    entitiesOnPlayer++;

                    spriteBatch.Draw(ContentChest.Get <Texture2D>("Images/player"),
                                     new Vector2(
                                         entity.X * TileRenderSize,
                                         entity.Y * TileRenderSize - 3 * entitiesOnPlayer),
                                     new Color(176, 182, 121) * (1.0f / entitiesOnPlayer));
                }
                else
                {
                    var entityTile   = _map.Tiles[entity.X, entity.Y];
                    var entitiesHere = entityTile.ThisFrameHistoryCount;

                    spriteBatch.Draw(ContentChest.Get <Texture2D>("Images/player"),
                                     new Vector2(
                                         entity.X * TileRenderSize,
                                         entity.Y * TileRenderSize - 3 * entitiesHere),
                                     new Color(176, 182, 121) * (1.0f / (entitiesHere + 1)));

                    entityTile.ThisFrameHistoryCount++;

                    _historyTiles.Add(entityTile);
                }
            }

            foreach (var tile in _historyTiles)
            {
                tile.ThisFrameHistoryCount = 0;
            }

            _historyTiles.Clear();
        }