Пример #1
0
        public void Update()
        {
            if (isHandled)
            {
                return;
            }

            currentMouse       = Mouse.GetState();
            mousePosition      = new Vector2(currentMouse.X, currentMouse.Y);
            mouseWorldPosition = viewportManager.GetWorldCoordinates(mousePosition);
            mouseWorldSpace    = world.WorldCoordsToCellPosition(mouseWorldPosition);
            selectedCell       = world.GetCellAt(mouseWorldPosition);

            justReleasedMouse = currentMouse.LeftButton == ButtonState.Released && previousMouse != null && previousMouse.LeftButton == ButtonState.Pressed;

            UpdateDraggingLMB();
            UpdateDraggingRMB();

            UpdateSelection();

            currentKeyboard = Keyboard.GetState();

            if (currentKeyboard.IsKeyDown(Keys.Escape) && !isDragging)
            {
                currentTask   = null;
                dragArea      = Rectangle.Empty;
                dragAreaCells = Rectangle.Empty;
            }

            if (previousKeyboard != null)
            {
                // on key release here
            }

            previousMouse    = currentMouse;
            previousKeyboard = currentKeyboard;
        }
Пример #2
0
        public void Draw()
        {
            // Get viewport space
            Vector2 originCoordinates = viewportManager.GetWorldCoordinates(new Vector2(0, 0));
            Vector2 boundsCoordinates = viewportManager.GetWorldCoordinates(new Vector2(viewportManager.Viewport.Width, viewportManager.Viewport.Height));

            Vector2 originWorldSpace = world.WorldCoordsToCellPosition(originCoordinates);
            Vector2 boundsWorldSpace = world.WorldCoordsToCellPosition(boundsCoordinates);


            // Draw lighting
            spriteBatch.GraphicsDevice.SetRenderTarget(lightsTarget);
            spriteBatch.GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, null, null, null, null, viewportManager.Camera.Transform);

            if (world.DayProgress < 0.3 || world.DayProgress > 0.8)
            {
                Vector2 mousePosition      = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                Vector2 mouseWorldPosition = viewportManager.GetWorldCoordinates(mousePosition);
                spriteBatch.Draw(lightTexture, new Rectangle((int)mouseWorldPosition.X - 256, (int)mouseWorldPosition.Y - 256, 512, 512), Color.White);
            }

            for (int x = (int)originWorldSpace.X; x <= (int)boundsWorldSpace.X; x++)
            {
                for (int y = (int)originWorldSpace.Y; y <= (int)boundsWorldSpace.Y; y++)
                {
                    Cell cell = world.GetCellAt(x, y);
                    if (cell != null && cell.Structure != null && cell.Structure is Light)
                    {
                        spriteBatch.Draw(lightTexture, new Rectangle(cell.X * World.BlockSize - 256, cell.Y * World.BlockSize - 256, 512, 512), Color.White);
                    }
                }
            }

            spriteBatch.End();

            // Draw world
            spriteBatch.GraphicsDevice.SetRenderTarget(mainTarget);
            spriteBatch.GraphicsDevice.Clear(Color.Gray);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, viewportManager.Camera.Transform);

            for (int x = (int)originWorldSpace.X; x <= (int)boundsWorldSpace.X; x++)
            {
                for (int y = (int)originWorldSpace.Y; y <= (int)boundsWorldSpace.Y; y++)
                {
                    Cell cell = world.GetCellAt(x, y);
                    if (cell != null)
                    {
                        if (cell.Floor != null)
                        {
                            cell.Floor.Draw(spriteBatch, x, y);
                        }
                        else
                        {
                            cell.Tile.Draw(spriteBatch, x, y);
                        }
                    }
                }
            }

            foreach (Zone zone in world.Zones)
            {
                zone.Draw(spriteBatch, currentView == ViewMode.Rooms ? 0.1f : 0.01f);
            }

            for (int x = (int)originWorldSpace.X; x <= (int)boundsWorldSpace.X; x++)
            {
                for (int y = (int)originWorldSpace.Y; y <= (int)boundsWorldSpace.Y; y++)
                {
                    Cell cell = world.GetCellAt(x, y);
                    if (cell != null)
                    {
                        if (cell.Structure != null)
                        {
                            cell.Structure.Draw(spriteBatch, x, y);
                        }

                        if (cell.FloorBlueprint != null)
                        {
                            cell.FloorBlueprint.Draw(spriteBatch, x, y);
                        }
                        if (cell.StructureBlueprint != null)
                        {
                            cell.StructureBlueprint.Draw(spriteBatch, x, y);
                        }

                        if (cell.SoftObject != null)
                        {
                            cell.SoftObject.Draw(spriteBatch, x * World.BlockSize, y * World.BlockSize);
                        }
                    }
                }
            }

            spriteBatch.End();


            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, viewportManager.Camera.Transform);

            foreach (Pawn pawn in world.Pawns)
            {
                pawn.Draw(spriteBatch, (int)(pawn.X * World.BlockSize), (int)(pawn.Y * World.BlockSize));
            }

            spriteBatch.End();

            // Combine with lighting
            lightEffect.Parameters["lightMask"].SetValue(lightsTarget);
            lightEffect.Parameters["lightIntensity"].SetValue(world.LightIntensity);

            spriteBatch.GraphicsDevice.SetRenderTarget(null);
            spriteBatch.GraphicsDevice.Clear(Color.Gray);

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, lightEffect);

            spriteBatch.Draw(mainTarget, new Vector2(0), Color.White);

            spriteBatch.End();
        }