private void MoveCamera(NamelessGame game, ConsoleCamera camera)
        {
            Position playerPosition = game.FollowedByCameraEntity
                                      .GetComponentOfType <Position>();

            Point p = camera.getPosition();

            p.X = (playerPosition.Point.X - game.GetSettings().GetWidthZoomed() / 2);
            p.Y = (playerPosition.Point.Y - game.GetSettings().GetHeightZoomed() / 2);
            camera.setPosition(p);
        }
        public override void Update(long gameTime, NamelessGame game)
        {
            this.gameTime = gameTime;

            game.GraphicsDevice.BlendState        = BlendState.AlphaBlend;
            game.GraphicsDevice.SamplerStates[0]  = sampler;
            game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            //todo move to constructor or some other place better suited for initialization
            if (tileAtlas == null)
            {
                InitializeTexture(game);
            }

            IEntity        worldEntity   = game.TimelineEntity;
            IWorldProvider worldProvider = null;

            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
            }

            var entity = game.CameraEntity;

            ConsoleCamera camera    = entity.GetComponentOfType <ConsoleCamera>();
            Screen        screen    = entity.GetComponentOfType <Screen>();
            Commander     commander = game.Commander;

            screen = UpdateZoom(game, commander, entity, screen, out bool zoomUpdate);

            if (foregroundModel == null || zoomUpdate)
            {
                foregroundModel = new TileModel(screen.Height, screen.Width);
            }

            if (backgroundModel == null || zoomUpdate)
            {
                backgroundModel = new TileModel(screen.Height, screen.Width);
            }


            if (camera != null && screen != null && worldProvider != null)
            {
                MoveCamera(game, camera);
                FillcharacterBufferVisibility(game, screen, camera, game.GetSettings(), worldProvider);
                FillcharacterBuffersWithWorld(screen, camera, game.GetSettings(), worldProvider);
                FillcharacterBuffersWithTileObjects(screen, camera, game.GetSettings(), game, worldProvider);
                FillcharacterBuffersWithWorldObjects(screen, camera, game.GetSettings(), game);
                RenderScreen(game, screen, game.GetSettings());
            }
        }
        void DrawTile(GraphicsDevice device, NamelessGame game, int screenPositionX, int screenPositionY, int positionX, int positionY,
                      AtlasTileData atlasTileData,
                      Color color, Color backGroundColor, TileModel foregroundModel, TileModel backgroundModel)
        {
            if (atlasTileData == null)
            {
                atlasTileData = new AtlasTileData(1, 1);
            }


            int tileHeight = game.GetSettings().GetFontSizeZoomed();
            int tileWidth  = game.GetSettings().GetFontSizeZoomed();


            float textureX = atlasTileData.X * (Constants.tileAtlasTileSize / (float)tileAtlas.Width);
            float textureY = atlasTileData.Y * (Constants.tileAtlasTileSize / (float)tileAtlas.Height);

            float textureXend = (atlasTileData.X + 1f) * (Constants.tileAtlasTileSize / (float)tileAtlas.Width);

            float textureYend = (atlasTileData.Y + 1f) * (Constants.tileAtlasTileSize / (float)tileAtlas.Height);

            var settings = game.GetSettings();

            var arrayPosition = (screenPositionX * 4) + (screenPositionY * settings.GetWidthZoomed() * 4);



            var foregroundvertices = foregroundModel.Vertices;

            foregroundvertices[arrayPosition] = new Vertex(new Vector3(positionX, positionY, 0), color.ToVector4(),
                                                           backGroundColor.ToVector4(), new Vector2(textureX, textureY));
            foregroundvertices[arrayPosition + 1] = new Vertex(new Vector3(positionX + tileWidth, positionY, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureY));
            foregroundvertices[arrayPosition + 2] = new Vertex(new Vector3(positionX, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureX, textureYend));
            foregroundvertices[arrayPosition + 3] = new Vertex(new Vector3(positionX + tileWidth, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureYend));

            var backgroundVertices = backgroundModel.Vertices;

            backgroundVertices[arrayPosition] = new Vertex(new Vector3(positionX, positionY, 0), color.ToVector4(),
                                                           backGroundColor.ToVector4(), new Vector2(textureX, textureY));
            backgroundVertices[arrayPosition + 1] = new Vertex(new Vector3(positionX + tileWidth, positionY, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureY));
            backgroundVertices[arrayPosition + 2] = new Vertex(new Vector3(positionX, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureX, textureYend));
            backgroundVertices[arrayPosition + 3] = new Vertex(new Vector3(positionX + tileWidth, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureYend));
        }
예제 #4
0
        public static GameContext GetWorldBoardContext(NamelessGame game)
        {
            if (WorldBoardContext != null)
            {
                return(WorldBoardContext);
            }
            else
            {
                var renderingSystem = new MapRenderingSystem(game.GetSettings(), game.WorldSettings);
                var systems         = new List <ISystem>();
                systems.Add(new InputSystem(new WorldMapKeyIntentTranslator(), game));
                systems.Add(new WorldBoardIntentSystem());
                systems.Add(new WorldBoardScreenSystem(renderingSystem));

                var uiSystem = new UIRenderSystem();

                // create and init the UI manager
                UiFactory.CreateWorldBoardScreen(game);
                WorldBoardContext = new GameContext(systems, new List <ISystem>()
                {
                    uiSystem, renderingSystem
                }, UiFactory.WorldBoardScreen);
                return(WorldBoardContext);
            }
        }
        public override void Update(long gameTime, NamelessGame game)
        {
            this.gameTime = gameTime;

            //todo move to constructor or some other place better suited for initialization
            if (tileAtlas == null)
            {
                InitializeTexture(game);
                _spriteBatch = new SpriteBatch(game.GraphicsDevice);
            }


            Commander commander = game.Commander;


            var           entity = game.CameraEntity;
            ConsoleCamera camera = entity.GetComponentOfType <ConsoleCamera>();
            Screen        screen = entity.GetComponentOfType <Screen>();

            screen = UpdateZoom(game, commander, entity, screen);

            _spriteBatch.Begin(SpriteSortMode.Deferred, null, null, DepthStencilState.None);


            IEntity        worldEntity   = game.TimelineEntity;
            IWorldProvider worldProvider = null;

            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
            }


            if (camera != null && screen != null && worldProvider != null)
            {
                MoveCamera(game, camera);
                FillcharacterBufferVisibility(game, screen, camera, game.GetSettings(), worldProvider);
                FillcharacterBuffersWithWorld(screen, camera, game.GetSettings(), worldProvider);
                FillcharacterBuffersWithTileObjects(screen, camera, game.GetSettings(), game, worldProvider);
                FillcharacterBuffersWithWorldObjects(screen, camera, game.GetSettings(), game);
                RenderScreen(game, screen, game.GetSettings());
            }
            _spriteBatch.End();
        }
        void DrawTile(GraphicsDevice device, NamelessGame game, int positionX, int positionY,
                      AtlasTileData atlasTileData,
                      Color color, Color backGroundColor)
        {
            if (atlasTileData == null)
            {
                atlasTileData = new AtlasTileData(1, 1);
            }
            var fontsize = game.GetSettings().GetFontSizeZoomed();
            var tilesize = tileAtlas.Width / 16;

            if (fontsize < 4)
            {
                _spriteBatch.Draw(whiteRectangle, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), null, color.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 0);
            }
            else
            {
                _spriteBatch.Draw(whiteRectangle, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), null, backGroundColor.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 0);
                _spriteBatch.Draw(tileAtlas, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), new Rectangle(atlasTileData.X * tilesize, atlasTileData.Y * tilesize, tilesize, tilesize), color.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 1);
            }
        }
        private static Screen UpdateZoom(NamelessGame game, Commander commander, IEntity entity, Screen screen, out bool zoomUpdate)
        {
            zoomUpdate = false;
            if (commander.DequeueCommand(out ZoomCommand zoom))
            {
                var settings = game.GetSettings();


                entity.RemoveComponent(screen);

                if (zoom.ZoomOut)
                {
                    if (settings.Zoom < 16)
                    {
                        settings.Zoom *= 2;
                    }
                    else
                    {
                        settings.Zoom = 1;
                    }
                }
                else
                {
                    if (settings.Zoom > 1)
                    {
                        settings.Zoom /= 2;
                    }
                    else
                    {
                        settings.Zoom = 16;
                    }
                }
                screen = new Screen(settings.GetWidthZoomed(), settings.GetHeightZoomed());
                entity.AddComponent(screen);
                zoomUpdate = true;
            }

            return(screen);
        }
예제 #8
0
        public static GameContext GetIngameContext(NamelessGame game)
        {
            if (IngameContext != null)
            {
                return(IngameContext);
            }
            else
            {
                var systems = new List <ISystem>();
                systems.Add(new InputSystem(new IngameKeyIntentTraslator(), game));
                systems.Add(new IngameIntentSystem());
                systems.Add(new AiSystem());
                systems.Add(new TurnManagementSystem());
                systems.Add(new CombatSystem());
                systems.Add(new InventorySystem());
                systems.Add(new SwitchSystem());
                systems.Add(new DamageHandlingSystem());
                systems.Add(new DeathSystem());
                systems.Add(new HudSystem());
                systems.Add(new ChunkManagementSystem());

                var renderingSystem = new RenderingSystem(game.GetSettings());
                var uiSystem        = new UIRenderSystem();

                // create and init the UI manager
                UiFactory.CreateHud(game);

                IngameContext = new GameContext(systems, new List <ISystem>()
                {
                    uiSystem, renderingSystem
                },
                                                UiFactory.HudInstance);

                return(IngameContext);
            }
        }
예제 #9
0
        public Hud(NamelessGame game)
        {
            Panel = new Panel()
            {
                Width = (int)game.GetSettings().HudWidth(), Height = game.GetActualCharacterHeight(), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top
            };

            var vPanel = new VerticalStackPanel();

            HealthBar                     = new HorizontalProgressBar();
            HealthBar.Width               = (int)game.GetSettings().HudWidth();
            HealthBar.Height              = 10;
            HealthBar.Maximum             = 100;
            HealthBar.Minimum             = 0;
            HealthBar.Value               = 0.5f;
            HealthBar.VerticalAlignment   = VerticalAlignment.Stretch;
            HealthBar.HorizontalAlignment = HorizontalAlignment.Left;
            HealthBar.SetColor(game.GraphicsDevice, Color.Red);

            StaminaBar                     = new HorizontalProgressBar();
            StaminaBar.Width               = (int)game.GetSettings().HudWidth();
            StaminaBar.Height              = 10;
            StaminaBar.Maximum             = 100;
            StaminaBar.Minimum             = 0;
            StaminaBar.VerticalAlignment   = VerticalAlignment.Stretch;
            StaminaBar.HorizontalAlignment = HorizontalAlignment.Left;
            StaminaBar.SetColor(game.GraphicsDevice, Color.Green);

            StrLabel = new Label()
            {
                Text = "Str"
            };
            PerLabel = new Label()
            {
                Text = "Per"
            };
            RefLabel = new Label()
            {
                Text = "Ref"
            };
            ImgLabel = new Label()
            {
                Text = "Img"
            };
            WillLabel = new Label()
            {
                Text = "Wil"
            };
            WitLabel = new Label()
            {
                Text = "Wit"
            };
            TurnLabel = new Label()
            {
                Text = "Turn"
            };

            var separator1         = new HorizontalSeparator();
            var separator2         = new HorizontalSeparator();
            ScrollableListBox list = new ScrollableListBox();

            list.Width  = (int)game.GetSettings().HudWidth();
            list.Height = 300;

            EventLog = list;

            WorldMapButton = new ImageTextButton()
            {
                GridColumn = 2,
                ContentHorizontalAlignment = HorizontalAlignment.Center,
                ContentVerticalAlignment   = VerticalAlignment.Center,
                Text = "Map",
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Right,
                Width  = 200,
                Height = 50
            };
            WorldMapButton.Click += OnClickWorldMap;

            InventoryButton = new ImageTextButton()
            {
                GridColumn = 0,
                Text       = "Inventory",
                ContentHorizontalAlignment = HorizontalAlignment.Center,
                ContentVerticalAlignment   = VerticalAlignment.Center,
                VerticalAlignment          = VerticalAlignment.Bottom,
                HorizontalAlignment        = HorizontalAlignment.Left,
                Width  = 200,
                Height = 50
            };
            InventoryButton.Click += (sender, args) => { ActionsThisTick.Add(HudAction.OpenInventory); };


            vPanel.Widgets.Add(TurnLabel);
            vPanel.Widgets.Add(HealthBar);
            vPanel.Widgets.Add(StaminaBar);
            vPanel.Widgets.Add(StrLabel);
            vPanel.Widgets.Add(PerLabel);
            vPanel.Widgets.Add(RefLabel);
            vPanel.Widgets.Add(ImgLabel);
            vPanel.Widgets.Add(WillLabel);
            vPanel.Widgets.Add(WitLabel);

            vPanel.Widgets.Add(separator1);
            vPanel.Widgets.Add(EventLog);
            vPanel.Widgets.Add(separator2);


            var grid = new Grid()
            {
                VerticalAlignment = VerticalAlignment.Bottom, ColumnSpacing = 3
            };



            grid.Widgets.Add(InventoryButton);
            grid.Widgets.Add(WorldMapButton);

            Panel.Widgets.Add(vPanel);
            Panel.Widgets.Add(grid);

            game.Desktop.Widgets.Add(Panel);
        }
예제 #10
0
        public WorldBoardScreen(NamelessGame game)
        {
            Panel = new Panel()
            {
                Width  = (int)game.GetSettings().HudWidth(),
                Height = game.GetActualCharacterHeight(),
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Top
            };


            var vPanel = new VerticalStackPanel();

            ReturnToGame        = CreateButton("Back", game.GetSettings().HudWidth() - 50);
            ReturnToGame.Click += ReturnToGameOnClick;
            ModeTerrain         = CreateButton("Terrain", game.GetSettings().HudWidth() - 50);
            ModeTerrain.Click  += OnClickModeTerrain;

            ModeRegions        = CreateButton("Regions", game.GetSettings().HudWidth() - 50);
            ModeRegions.Click += OnClickLandmasses;

            ModePolitical        = CreateButton("Political", game.GetSettings().HudWidth() - 50);
            ModePolitical.Click += OnClickPolitical;

            ModeArtifacts        = CreateButton("Artifacts", game.GetSettings().HudWidth() - 50);
            ModeArtifacts.Click += OnClickArtifacts;

            var grid = new Grid()
            {
                VerticalAlignment = VerticalAlignment.Top, ColumnSpacing = 3, Width = (int)game.GetSettings().HudWidth() - 50, HorizontalAlignment = HorizontalAlignment.Center
            };

            LocalMap                            = new ImageTextButton();
            LocalMap.Text                       = "Local";
            LocalMap.GridColumn                 = 0;
            LocalMap.Width                      = (int)game.GetSettings().HudWidth() / 2 - 50;
            LocalMap.Height                     = 50;
            LocalMap.Click                     += OnLocalMap;
            LocalMap.HorizontalAlignment        = HorizontalAlignment.Left;
            LocalMap.VerticalAlignment          = VerticalAlignment.Top;
            LocalMap.ContentHorizontalAlignment = HorizontalAlignment.Center;
            LocalMap.ContentVerticalAlignment   = VerticalAlignment.Center;


            WorldMap                            = new ImageTextButton();
            WorldMap.Text                       = "World";
            WorldMap.GridColumn                 = 2;
            WorldMap.Width                      = (int)game.GetSettings().HudWidth() / 2 - 50;
            WorldMap.Height                     = 50;
            WorldMap.Click                     += OnWorldMap;
            WorldMap.HorizontalAlignment        = HorizontalAlignment.Left;
            WorldMap.VerticalAlignment          = VerticalAlignment.Top;
            WorldMap.ContentHorizontalAlignment = HorizontalAlignment.Center;
            WorldMap.ContentVerticalAlignment   = VerticalAlignment.Center;


            grid.Widgets.Add(LocalMap);
            grid.Widgets.Add(WorldMap);

            TextBox list = new TextBox();

            list.Width     = (int)game.GetSettings().HudWidth() - 50;
            list.Height    = 100;
            list.Readonly  = true;
            DescriptionLog = list;

            vPanel.Widgets.Add(grid);
            vPanel.Widgets.Add(new HorizontalSeparator());
            vPanel.Widgets.Add(DescriptionLog);
            vPanel.Widgets.Add(new HorizontalSeparator());
            vPanel.Widgets.Add(ModeTerrain);
            vPanel.Widgets.Add(ModeRegions);
            vPanel.Widgets.Add(ModePolitical);
            vPanel.Widgets.Add(ModeArtifacts);
            vPanel.Widgets.Add(ReturnToGame);

            Panel.Widgets.Add(vPanel);

            game.Desktop.Widgets.Add(Panel);
        }