Exemple #1
0
        public void Render(IScreenBuffer screen, PlayerInfo player)
        {
            screen.Clear();

            var center       = screen.Dimensions.DivideBy(2).ToVector2();
            var shortestSide = center.SmallestSide();

            var radius = 0.9f * shortestSide;

            const int numSegments  = 5;
            var       radianOffset = MathHelper.TwoPi / numSegments / 2;

            // This fixes jittering
            var pixelOffset = new Vector2(0.5f, 0.5f);

            foreach (var segment in Enumerable.Range(0, numSegments))
            {
                var rotation  = Matrix.CreateRotationZ(segment * radianOffset + _angle);
                var direction = Vector2.Transform(Vector2.UnitX, rotation);

                var start = (center - direction * radius + pixelOffset).ToPoint();
                var end   = (center + direction * radius + pixelOffset).ToPoint();

                _drawLine(screen, start, end, Color.Red);
            }
        }
Exemple #2
0
        public void Render(IScreenBuffer screen, PlayerInfo player)
        {
            screen.Clear();

            // The screen has an origin in the top left.  Positive Y is DOWN
            // Maps have an origin in the bottom left.  Positive Y is UP

            var screenDimensionsV      = screen.Dimensions.ToVector2();
            var desiredMapScreenBounds = screenDimensionsV * DefaultMapToScreenRatio;

            var gameToScreenFactor = Math.Min(desiredMapScreenBounds.X / _map.Area.X, desiredMapScreenBounds.Y / _map.Area.Y);

            var screenAreaInMapCoords = screenDimensionsV / gameToScreenFactor;
            var mapCenteringOffset    = (screenAreaInMapCoords - _map.Area) / 2 - _map.BottomLeftCorner;

            // Transform all vertices
            for (int v = 0; v < _map.Vertices.Length; v++)
            {
                _verticesInScreenCoords[v] = ToScreenCoords(_map.Vertices[v]);
            }

            Point ToScreenCoords(Vector2 worldCoordinate)
            {
                var shiftedWorldCoordinate = worldCoordinate + mapCenteringOffset;

                // This fixes jittering
                var pixelOffset = new Vector2(0.5f, 0.5f);

                return(((shiftedWorldCoordinate * gameToScreenFactor) + pixelOffset).ToPoint().InvertY(screen.Height));
            }

            void DrawLineFromVertices(int v1, int v2, Color c) =>
            DrawLineFromScreenCoordinates(_verticesInScreenCoords[v1], _verticesInScreenCoords[v2], c);

            void DrawLineFromWorldCoordinates(Vector2 wc1, Vector2 wc2, Color c)
            {
                var sc1 = ToScreenCoords(wc1);
                var sc2 = ToScreenCoords(wc2);

                DrawLineFromScreenCoordinates(sc1, sc2, c);
            }

            void DrawLineFromScreenCoordinates(Point sc1, Point sc2, Color c)
            {
                var result = LineClipping.ClipToScreen(screen, sc1, sc2);

                if (result.shouldDraw)
                {
                    screen.PlotLineSmooth(result.p0, result.p1, c);
                }
            }

            foreach (var lineDef in _map.Map.LineDefs.Take((int)_linesToDraw))
            {
                ref Vector2 vertex1 = ref _map.Vertices[lineDef.V1];
                ref Vector2 vertex2 = ref _map.Vertices[lineDef.V2];
        public void Render(IScreenBuffer screen, PlayerInfo player)
        {
            screen.Clear();
            Interpreter.Settings = player.CameraSettings;

            void DrawLineFromScreenCoordinates(Point sc1, Point sc2, Color c)
            {
                var result = LineClipping.ClipToScreen(screen, sc1, sc2);

                if (result.shouldDraw)
                {
                    _drawLine(screen, result.p0, result.p1, c);
                }
            }

            foreach (SectorInfo sector in _map.Sectors)
            {
                foreach (Line line in sector.Lines)
                {
                    Vector3 cameraPosition = new Vector3(player.Position, player.VerticalPosition + player.ViewHeight);

                    _camera.Center            = cameraPosition;
                    _camera.RotationInRadians = player.Angle - MathHelper.PiOver2;

                    Vector3 topLeftConverted     = _camera.WorldToPerspective(new Vector3(line.Vertex1.X, line.Vertex1.Y, sector.Info.HeightCeiling));
                    Vector3 topRightConverted    = _camera.WorldToPerspective(new Vector3(line.Vertex2.X, line.Vertex2.Y, sector.Info.HeightCeiling));
                    Vector3 bottomLeftConverted  = _camera.WorldToPerspective(new Vector3(line.Vertex1.X, line.Vertex1.Y, sector.Info.HeightFloor));
                    Vector3 bottomRightConverted = _camera.WorldToPerspective(new Vector3(line.Vertex2.X, line.Vertex2.Y, sector.Info.HeightFloor));

                    var topLineResult = Interpreter.ConvertWorldLineToScreenPoints(screen, topLeftConverted, topRightConverted);
                    if (topLineResult.shouldDraw)
                    {
                        DrawLineFromScreenCoordinates(topLineResult.p1, topLineResult.p2, Color.Red);
                    }

                    var bottomLineResult = Interpreter.ConvertWorldLineToScreenPoints(screen, bottomLeftConverted, bottomRightConverted);
                    if (bottomLineResult.shouldDraw)
                    {
                        DrawLineFromScreenCoordinates(bottomLineResult.p1, bottomLineResult.p2, Color.Red);
                    }

                    var leftLineResult = Interpreter.ConvertWorldLineToScreenPoints(screen, topLeftConverted, bottomLeftConverted);
                    if (leftLineResult.shouldDraw)
                    {
                        DrawLineFromScreenCoordinates(leftLineResult.p1, leftLineResult.p2, Color.Red);
                    }

                    var rightLineResult = Interpreter.ConvertWorldLineToScreenPoints(screen, topRightConverted, bottomRightConverted);
                    if (rightLineResult.shouldDraw)
                    {
                        DrawLineFromScreenCoordinates(rightLineResult.p1, rightLineResult.p2, Color.Red);
                    }
                }
            }
        }
        public void Render(IScreenBuffer screen, PlayerInfo player)
        {
            screen.Clear();
            if (_lastScreenSize != screen.Dimensions)
            {
                _lastScreenSize = screen.Dimensions;
                _size           = new Point(screen.Dimensions.X, FireHeight);
                _fireBuffer     = new byte[_size.Area()];
                InitializeFire();
            }

            var yOffset = screen.Height - FireHeight;

            for (int y = 0; y < _size.Y; y++)
            {
                for (int x = 0; x < _size.X; x++)
                {
                    var colorIndex = _fireBuffer[y * _size.X + x];
                    var color      = _palette[colorIndex];
                    screen.DrawPixel(x, yOffset + y, color);
                }
            }
        }
Exemple #5
0
        public void Render(IScreenBuffer screen, PlayerInfo player)
        {
            screen.Clear();

            // The screen has an origin in the top left.  Positive Y is DOWN
            // Maps have an origin in the bottom left.  Positive Y is UP

            _camera.ScreenBounds      = screen.Dimensions;
            _camera.Center            = player.Position;
            _camera.RotationInRadians = _settings.RotateMode ? player.Angle - MathHelper.PiOver2 : 0;

            // Transform all vertices
            for (int v = 0; v < _map.Vertices.Length; v++)
            {
                _verticesInScreenCoords[v] = ToScreenCoords(_map.Vertices[v]);
            }


            Point ToScreenCoords(Vector2 worldCoordinate)
            {
                return(_camera.WorldToScreen(worldCoordinate).ToPoint());
            }

            void DrawLineFromVertices(int v1, int v2, Color c) =>
            DrawLineFromScreenCoordinates(_verticesInScreenCoords[v1], _verticesInScreenCoords[v2], c);

            void DrawLineFromWorldCoordinates(Vector2 wc1, Vector2 wc2, Color c)
            {
                var sc1 = ToScreenCoords(wc1);
                var sc2 = ToScreenCoords(wc2);

                DrawLineFromScreenCoordinates(sc1, sc2, c);
            }

            void DrawLineFromScreenCoordinates(Point sc1, Point sc2, Color c)
            {
                var result = LineClipping.ClipToScreen(screen, sc1, sc2);

                if (result.shouldDraw)
                {
                    _drawLine(screen, result.p0, result.p1, c);
                }
            }

            void DrawCircle(Vector2 center, float radiusInWorldCoordinates, Color c)
            {
                screen.PlotCircle(_camera.WorldToScreen(center).ToPoint(), (int)(radiusInWorldCoordinates * _camera.TotalZoom), c);
            }

            void DrawBox(Vector2 center, float halfWidth, Color c)
            {
                var topLeft     = center + new Vector2(-halfWidth, halfWidth);
                var topRight    = center + new Vector2(halfWidth, halfWidth);
                var bottomLeft  = center + new Vector2(-halfWidth, -halfWidth);
                var bottomRight = center + new Vector2(halfWidth, -halfWidth);

                DrawLineFromWorldCoordinates(topLeft, topRight, c);
                DrawLineFromWorldCoordinates(topRight, bottomRight, c);
                DrawLineFromWorldCoordinates(bottomRight, bottomLeft, c);
                DrawLineFromWorldCoordinates(bottomLeft, topLeft, c);
            }

            void DrawVertex(Vector2 wc, Color c) => DrawBox(wc, VertexHalfWidth, c);

            foreach (var lineDef in _map.Map.LineDefs)
            {
                ref Vector2 vertex1 = ref _map.Vertices[lineDef.V1];
                ref Vector2 vertex2 = ref _map.Vertices[lineDef.V2];