Exemplo n.º 1
0
        private void DrawBody(Graphic g)
        {
            var v = _body.LinearVelocity;
            var l = v.Length();
            Vector2 pos;
            if (l == 0)
            {
                pos = _body.Position;
            }
            else
            {
                var d = Interpolation.From(l, 0, 10, 0, .2f);
                v.Normalize();
                v *= d;
                pos = _body.Position + v;
            }

            g.DrawSolidCircle(pos, .2f, _actorColor);
            g.DrawCircleStrip(_body.Position, .5f, .1f, _actorColor);

            foreach (var poly in _staticBodiesContours)
            {
                g.DrawSolidPolygon(poly, _actorColor);
            }
        }
Exemplo n.º 2
0
Arquivo: Grid.cs Projeto: hgrandry/Mgx
        public override void Draw(Graphic g)
        {
            var screenArea = Render.Camera.ScreenArea;

            var xo = (screenArea.Left / _size).Floor() * _size;
            var yo = (screenArea.Top / _size).Floor() * _size;

            var xn = (int)Math.Floor(screenArea.Width / _size) + 1;
            var yn = (int)Math.Floor(screenArea.Height / _size) + 1;

            for (int i = 0; i <= xn; i++)
            {
                var x = xo + i * _size;
                if (x.IsBetween(screenArea.Left, screenArea.Right))
                {
                    g.DrawSegment(new Vector2(x, screenArea.Top), new Vector2(x, screenArea.Bottom), _color);
                }
            }

            for (int i = 0; i <= yn; i++)
            {
                var y = yo + i * _size;
                if (y.IsBetween(screenArea.Top, screenArea.Bottom))
                {
                    g.DrawSegment(new Vector2(screenArea.Left, y), new Vector2(screenArea.Right, y), _color);
                }
            }
        }
Exemplo n.º 3
0
        public override void Draw(Graphic g)
        {
            foreach (var info in _bodies.Where(info => info.Body.FixtureList != null))
            {
                info.Body.GetTransform(out _xf);

                foreach (var fixture in info.Body.FixtureList.Where(f => !f.IsSensor))
                {
                    DrawFixture(g, info.Body, fixture, info.Color);
                }
            }
        }
Exemplo n.º 4
0
Arquivo: Mask.cs Projeto: hgrandry/Mgx
        public void Draw(Graphic g)
        {
            //Draw.Device.Clear(ClearOptions.Target | ClearOptions.Stencil, Color.Transparent, 0, 0);
            /*
            // draw mask
            _spriteBatch.Begin(SpriteSortMode.Immediate, null, null, _maskStencilState, null, _alphaTestEffect);
            _spriteMask.Render(_spriteBatch);
            _spriteBatch.End();

            // draw mask target
            _spriteBatch.Begin(SpriteSortMode.Immediate, null, null, _targetStencilState, null, null);
            _spriteTarget.Render(_spriteBatch);
            _spriteBatch.End();*/
        }
Exemplo n.º 5
0
        private void DrawFixture(Graphic g, Body body, Fixture fixture, Color color)
        {
            switch (fixture.Shape.ShapeType)
            {
                case ShapeType.Circle:
                    {
                        var circle = (CircleShape)fixture.Shape;

                        Vector2 center = body.GetWorldPoint(circle.Position);
                        if (DrawSolidShape)
                        {
                            g.DrawSolidCircle(center, circle.Radius, color);
                        }
                        else
                        {
                            g.DrawCircle(center, circle.Radius, color);
                        }

                        break;
                    }

                case ShapeType.Polygon:
                    {
                        TempVertices.Clear();
                        var poly = fixture.Shape as PolygonShape;
                        int vertexCount = poly.Vertices.Count;

                        for (int i = 0; i < vertexCount; ++i)
                        {
                            var p = body.GetWorldPoint(poly.Vertices[i]);
                            TempVertices.Add(p);
                        }

                        if (DrawSolidShape)
                        {
                            g.DrawSolidPolygon(TempVertices.ToArray(), color);
                        }
                        else
                        {
                            g.DrawPolygon(TempVertices.ToArray(), color);
                        }

                        break;
                    }
            }
        }
Exemplo n.º 6
0
        private void Draw(Graphic g)
        {
            _mask.MaskTexture = _maskTexture;
            //_mask.MaskCoord = new Vector2(0, 0);

            // start a spritebatch for our effect
            _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
                null, null, null, _mask.Effect);

            _spriteBatch.Draw(_texture,
                new Vector2(0, 0),
                null,
                Color.White,
                0f,
                new Vector2(0, 0),
                1f,
                SpriteEffects.None,
                1f);

            _spriteBatch.End();
        }
Exemplo n.º 7
0
        public void Draw(Graphic g)
        {
            // This looks WAY more comlicated than it is, but it's pretty simple,
            // Draw the objects you wan to have occlude the rays in black and store them in an RT, this creates a mask.
            // Hand this RT onto the pp manager, it will render all the rays for you to a new RT
            // Re render the scene in color this time to another RT
            // Finaly do an additive blend with the godray RT and the scene you just rendered.
            // Give me a shout if you need any help implementing it :D

            // Draw the stuff that is infront of the rays source
            Render.Device.SetRenderTarget(scene);
            Render.Device.Clear(Color.White);

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
            for (int bg = 0; bg < bgCnt; bg++)
            {
                spriteBatch.Draw(Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]), new Rectangle((int)bgPos[bg].X, (int)bgPos[bg].Y, Render.Device.Viewport.Width, Render.Device.Viewport.Height), new Rectangle(0, 0, Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]).Width, Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]).Height), Color.Black);
                spriteBatch.Draw(Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]), new Rectangle((int)bgPos2[bg].X, (int)bgPos[bg].Y, Render.Device.Viewport.Width, Render.Device.Viewport.Height), new Rectangle(0, 0, Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]).Width, Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]).Height), Color.Black);
            }
            // Draw mouse icon mask.
            spriteBatch.Draw(Hgl.Game.Content.Load<Texture2D>("Textures/mousemask"), new Rectangle(Mouse.GetState().X - 64, Mouse.GetState().Y - 64, 128, 128), Color.Black);
            spriteBatch.End();

            //Mgx.Render.Device.SetRenderTarget(_renderer.Layer.RenderTarget);

            // Apply the post processing maanger (just the rays in this one)
            ppm.Draw(scene);

            // Now blend that source with the scene..
            Render.Device.SetRenderTarget(scene);
            // Draw the scene in color now
            Render.Device.Clear(Color.Black);
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);

            for (int bg = 0; bg < bgCnt; bg++)
            {
                spriteBatch.Draw(Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]), new Rectangle((int)bgPos[bg].X, (int)bgPos[bg].Y, Render.Device.Viewport.Width, Render.Device.Viewport.Height), new Rectangle(0, 0, Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]).Width, Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]).Height), Color.White);
                spriteBatch.Draw(Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]), new Rectangle((int)bgPos2[bg].X, (int)bgPos[bg].Y, Render.Device.Viewport.Width, Render.Device.Viewport.Height), new Rectangle(0, 0, Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]).Width, Hgl.Game.Content.Load<Texture2D>(backgroundAssets[bg]).Height), Color.White);
            }
            // Draw mouse icon.
            spriteBatch.Draw(Hgl.Game.Content.Load<Texture2D>("Textures/mousemask"), new Rectangle(Mouse.GetState().X - 64, Mouse.GetState().Y - 64, 128, 128), Color.White);
            spriteBatch.End();

            //Mgx.Render.Device.SetRenderTarget(_renderer.Layer.RenderTarget);

            Render.Device.Clear(Color.Black);

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
            spriteBatch.Draw(ppm.Scene, new Rectangle(0, 0, Render.Device.Viewport.Width, Render.Device.Viewport.Height), Color.White);
            spriteBatch.Draw(scene, new Rectangle(0, 0, Render.Device.Viewport.Width, Render.Device.Viewport.Height), Color.White);
            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
            spriteBatch.DrawString(ResourceContext.GetFont("Fonts/DebugFont"), "F1 - F4 change light source texture", new Vector2(8, ResourceContext.GetFont("Fonts/DebugFont").LineSpacing * 1), Color.Gold);
            spriteBatch.DrawString(ResourceContext.GetFont("Fonts/DebugFont"), string.Format("WASD move light source [{0}]", rays.lightSource), new Vector2(8, ResourceContext.GetFont("Fonts/DebugFont").LineSpacing * 2), Color.Gold);
            spriteBatch.DrawString(ResourceContext.GetFont("Fonts/DebugFont"), string.Format("Q/Z Exposure up/down [{0}]", rays.Exposure), new Vector2(8, ResourceContext.GetFont("Fonts/DebugFont").LineSpacing * 3), Color.Gold);
            spriteBatch.DrawString(ResourceContext.GetFont("Fonts/DebugFont"), string.Format("E/C Size up/down [{0}]", rays.LightSourceSize), new Vector2(8, ResourceContext.GetFont("Fonts/DebugFont").LineSpacing * 4), Color.Gold);
            spriteBatch.DrawString(ResourceContext.GetFont("Fonts/DebugFont"), string.Format("R/V Density up/down [{0}]", rays.Density), new Vector2(8, ResourceContext.GetFont("Fonts/DebugFont").LineSpacing * 5), Color.Gold);
            spriteBatch.DrawString(ResourceContext.GetFont("Fonts/DebugFont"), string.Format("T/B Decay up/down [{0}]", rays.Decay), new Vector2(8, ResourceContext.GetFont("Fonts/DebugFont").LineSpacing * 6), Color.Gold);
            spriteBatch.DrawString(ResourceContext.GetFont("Fonts/DebugFont"), string.Format("Y/N Weight up/down [{0}]", rays.Weight), new Vector2(8, ResourceContext.GetFont("Fonts/DebugFont").LineSpacing * 7), Color.Gold);
            spriteBatch.End();
        }
Exemplo n.º 8
0
 public override void Draw(Graphic g)
 {
     var p = UI.Mouse.ScreenPosition;
     Position = p + Offset;
     base.Draw(g);
 }
Exemplo n.º 9
0
 public virtual void Draw(Graphic g)
 {
     g.DrawLayer(this);
 }
Exemplo n.º 10
0
        private void Draw(Graphic g)
        {
            // draw cards
            for (int i = 0; i < GridSize; i++)
            {
                for (int j = 0; j < GridSize; j++)
                {
                    var cardValue = _cards[i][j];
                    if(cardValue == 0)
                        continue;

                    Color cardColor;
                    if(!CardColors.TryGetValue(cardValue, out cardColor))
                    {
                        cardColor = Color.White;
                    }

                    var cardPosition = new Vector2(i * CardWidth + (i + 1) * Spacing, j * CardHeight + (j + 1) * Spacing) + _offset[i][j];
                    g.DrawRectangle(GridOrigin + cardPosition, CardWidth, CardHeight, true, cardColor);

                    // draw digit
                    var cardRect = new Rect(GridOrigin.X + cardPosition.X, GridOrigin.Y + cardPosition.Y, CardWidth, CardHeight);
                    var digitColor = cardValue > 2 ? Color.Black : Color.White;
                    g.Write(cardValue.ToString(), _font, cardRect, HorizontalAlignment.Center, VerticalAlignment.Center, digitColor, 3);
                }
            }
        }
Exemplo n.º 11
0
 public override void Draw(Graphic g)
 {
     g.DrawRectangle((_c.Position + _c.Margin.TopLeft) * _c.Scale, _c.Size * _c.Scale, true, ForegroundColor);
     g.Write(_c.Name, _font, _c.Bounds, HorizontalAlignment.Center, VerticalAlignment.Center, Style.FontColor);
 }
Exemplo n.º 12
0
 public override void Draw(Graphic g)
 {
     g.Write(Fps.ToString(), _font, new Vector2(50, 50));
 }
Exemplo n.º 13
0
        private void Draw(Graphic g)
        {
            var v = VectorKit.AngleToVector(Body.Rotation);
            g.DrawSolidPolygon(ShapeFactory.Triangle(Body.Position - v * .5f, 2f, Body.Rotation + MathKit.Pi), Color.DarkRed);
            g.DrawSolidPolygon(ShapeFactory.Triangle(Body.Position + v * 1f, 1.5f, Body.Rotation), Color.DarkRed);
            g.FlushPrimitives();

            //            var color = _isActive ? Color.Orange : Color.White;
            var color = Color.Orange;
            g.DrawSolidPolygon(ShapeFactory.Triangle(Body.Position, 1, Body.Rotation + MathKit.Pi), color);
            g.DrawSolidPolygon(ShapeFactory.Triangle(Body.Position + v, 1, Body.Rotation), color);
        }
Exemplo n.º 14
0
 public override void Draw(Graphic g)
 {
     _skeletonRenderer.Begin();
     _skeletonRenderer.Draw(Skeleton);
     _skeletonRenderer.End();
 }
Exemplo n.º 15
0
 public abstract void Draw(Graphic g);
Exemplo n.º 16
0
 public override void Draw(Graphic g)
 {
     g.DrawTexture(_control.Texture, _control.Bounds.ToRectangle(), Color.White);
 }
Exemplo n.º 17
0
 public override void Draw(Graphic g)
 {
     base.Draw(g);
     g.DrawObject(_sprite);
 }
Exemplo n.º 18
0
 public void Init()
 {
     _rootLayer = new Layer();
     _graphic = new Graphic();
 }
Exemplo n.º 19
0
        private void DrawBg(Graphic g)
        {
            // draw screen bg
            g.DrawRectangle(Vector2.Zero, ScreenSize.X, ScreenSize.Y, true, Color.White);

            // draw grid bg
            g.DrawRectangle(GridOrigin, GridArea.X, GridArea.Y, true, Color.DarkGray);

            // draw card slot
            for (int i = 0; i < GridSize; i++)
            {
                for (int j = 0; j < GridSize; j++)
                {
                    Color cardColor = CardColors[0];
                    var cardPosition = new Vector2(i * CardWidth + (i + 1) * Spacing, j * CardHeight + (j + 1) * Spacing);
                    g.DrawRectangle(GridOrigin + cardPosition, CardWidth, CardHeight, true, cardColor);
                }
            }
        }