예제 #1
0
        public void DrawBlocker(int x1, int y1, int x2, int y2, MicroWorld.Graphics.Renderer renderer, float opacity, bool safe = false)
        {
            if (!safe)
            {
                if (x1 > x2)
                {
                    int t = x1;
                    x1 = x2;
                    x2 = t;
                }
                if (y1 > y2)
                {
                    int t = y1;
                    y1 = y2;
                    y2 = t;
                }
                if (x2 - x1 < 8 || y2 - y1 < 8)
                    return;
            }

            bool b = renderer.IsDrawing;
            if (b)
                renderer.End();

            renderer.Begin(SpriteSortMode.Immediate, null, SamplerState.PointWrap, null, null);
            Color c = Color.White * opacity;
            int sx = x2 - x1;
            int sy = y2 - y1;

            renderer.Draw(bg, new Rectangle(x1, y1, sx, sy), new Rectangle(0, 0, sx * 4, sy * 4), c * 0.6f);
            renderer.Draw(Shortcuts.pixel, new Vector2(x1, y1), null, c, 0, Vector2.Zero, new Vector2(0.25f, sy), SpriteEffects.None, 0);

            renderer.End();
            if (b)
                renderer.Begin();
        }
예제 #2
0
        public override void Draw(MicroWorld.Graphics.Renderer renderer)
        {
            if (texture0cw == null) return;
            if (!CanDraw()) return;
            Components.Logics.VoltageGraphLogics l = (Components.Logics.VoltageGraphLogics)parent.Logics;

            UpdateFBO();

            switch (parent.ComponentRotation)
            {
                case Component.Rotation.cw0:
                    renderer.Draw(texture0cw,
                        new Rectangle((int)Position.X, (int)Position.Y,
                            (int)GetSizeRotated(parent.ComponentRotation).X, (int)GetSizeRotated(parent.ComponentRotation).Y), null,
                            Color.White);
                    break;
                case Component.Rotation.cw90:
                    renderer.Draw(texture90cw,
                        new Rectangle((int)Position.X, (int)Position.Y,
                            (int)GetSizeRotated(parent.ComponentRotation).X, (int)GetSizeRotated(parent.ComponentRotation).Y), null,
                            Color.White);
                    break;
                case Component.Rotation.cw180:
                    renderer.Draw(texture180cw,
                        new Rectangle((int)Position.X, (int)Position.Y,
                            (int)GetSizeRotated(parent.ComponentRotation).X, (int)GetSizeRotated(parent.ComponentRotation).Y), null,
                            Color.White);
                    break;
                case Component.Rotation.cw270:
                    renderer.Draw(texture270cw,
                        new Rectangle((int)Position.X, (int)Position.Y,
                            (int)GetSizeRotated(parent.ComponentRotation).X, (int)GetSizeRotated(parent.ComponentRotation).Y), null,
                            Color.White);
                    break;
                default:
                    break;
            }

            if (parent.ComponentRotation == Component.Rotation.cw0 || parent.ComponentRotation == Component.Rotation.cw180)
                renderer.Draw(fbo, new Rectangle((int)Position.X + 15, (int)Position.Y + 11, 39, 23), null, Color.White);
            else
                renderer.Draw(fbo, new Rectangle((int)Position.X + 29, (int)Position.Y + 15, 39, 23), null, Color.White, (float)Math.PI / 2, Vector2.Zero);

            renderer.End();
            renderer.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.Default, RasterizerState.CullNone,
                null, Matrix.CreateScale(0.25f), true);
            if (parent.ComponentRotation == Component.Rotation.cw0 || parent.ComponentRotation == Component.Rotation.cw180)
            {
                renderer.DrawStringRight(font, l.max.ToString(), new Rectangle((int)Position.X * 4 + 42, (int)Position.Y * 4 + 47, 12, 8), Color.Gray);
                renderer.DrawStringRight(font, l.min.ToString(), new Rectangle((int)Position.X * 4 + 42, (int)Position.Y * 4 + 125, 12, 8), Color.Gray);
            }
            else
            {
                renderer.DrawStringLeft(font, l.min.ToString(), Position * 4 + new Vector2(26, 44), Color.Gray);
                renderer.DrawStringRight(font, l.max.ToString(), new Rectangle((int)Position.X * 4 + 102, (int)Position.Y * 4 + 44, 12, 8), Color.Gray);
            }
            renderer.End();
            renderer.Begin();
        }
예제 #3
0
        public void DrawFrame(int x1, int y1, int x2, int y2, MicroWorld.Graphics.Renderer renderer, float opacity, bool safe = false)
        {
            if (!safe)
            {
                if (x1 > x2)
                {
                    int t = x1;
                    x1 = x2;
                    x2 = t;
                }
                if (y1 > y2)
                {
                    int t = y1;
                    y1 = y2;
                    y2 = t;
                }
                if (x2 - x1 < 32 || y2 - y1 < 32)
                    return;
            }

            bool b = renderer.IsDrawing;
            if (!b)
                renderer.Begin(SpriteSortMode.Immediate, null, SamplerState.PointWrap, null, null);
            Color c = Color.White * opacity;
            int sx = x2 - x1;
            int sy = y2 - y1;

            renderer.Draw(bg, new Rectangle(x1 + 8, y1 + 8, sx - 16, sy - 16), new Rectangle(0, 0, sx * 4 - 64, sy * 4 - 64), c * 0.6f);

            renderer.Draw(top, new Rectangle(x1 + 8, y1, sx - 16, 8), new Rectangle(0, 0, sx * 4 - 64, 32), c);
            renderer.Draw(left, new Rectangle(x1, y1 + 8, 8, sy - 16), new Rectangle(0, 0, 32, sy * 4 - 64), c);
            renderer.Draw(bottom, new Rectangle(x1 + 8, y2 - 8, sx - 16, 8), new Rectangle(0, 0, sx * 4 - 64, 32), c);
            renderer.Draw(right, new Rectangle(x2 - 8, y1 + 8, 8, sy - 16), new Rectangle(0, 0, 32, sy * 4 - 64), c);

            if (!b)
                renderer.End();
        }
예제 #4
0
        public void DrawToFBO(MicroWorld.Graphics.Renderer renderer)
        {
            var p = parent as Frame;

            renderer.EnableFBO(p.fbo);
            renderer.GraphicsDevice.Clear(Color.Transparent);
            var s = Settings.GameScale;
            Settings.GameScale = MicroWorld.Graphics.Camera.ZOOM_MAX;
            var t = Shortcuts.camera.Center;
            var a = Shortcuts.camera.VisibleRectangle;
            Shortcuts.camera.Center = Position + new Vector2(a.Width / 2, a.Height / 2);

            renderer.Begin();

            DrawFrame((int)Position.X, (int)Position.Y, (int)(Position.X + Size.X), (int)(Position.Y + Size.Y), renderer, 1f, true);

            for (int i = 0; i < p.containsComponents.Length; i++)
            {
                if (!renderer.IsDrawing)
                    renderer.Begin();
                p.containsComponents[i].Graphics.IgnoreNextDraw = true;
                p.containsComponents[i].Graphics.Draw(renderer);
            }

            renderer.End();
            Shortcuts.camera.Center = t;
            Settings.GameScale = s;
            renderer.DisableFBO();
        }
예제 #5
0
        public void DrawTrajectory(MicroWorld.Graphics.Renderer renderer)
        {
            float rad = 100f;
            var p = parent as Motor;
            if (p.connector != null)
            {
                var a1 = p.connector.ConnectedComponent1.Graphics.Position + p.connector.ConnectedComponent1.Graphics.GetSize() / 2;
                var a2 = p.connector.ConnectedComponent2.Graphics.Position + p.connector.ConnectedComponent2.Graphics.GetSize() / 2;
                rad = Math.Abs((a2 - a1).Length());
            }
            else return;

            MicroWorld.Graphics.RenderHelper.DrawDottedCircle(rad, Position + GetSize() / 2, 60, (float)((Main.Ticks % 40) * Math.PI / 40f / 15f), renderer, Color.White);
            return;

            float opacity = 1f;
            VertexPositionColorTexture[] arr = new VertexPositionColorTexture[60];

            double d = (float)((Main.Ticks % 40)) * Math.PI / 40f / 15f;
            int c = 0;
            Vector2 off = Position + GetSize() / 2;
            for (double i = 0; i <= Math.PI * 2 - 0.001d; i += Math.PI / 30d)
            {
                arr[c] = new VertexPositionColorTexture(
                    new Vector3((float)Math.Cos(i + d) * rad + off.X, (float)Math.Sin(i + d) * rad + off.Y, 0),
                    Color.White * opacity, new Vector2());
                c++;
            }

            Main.renderer.Draw(MicroWorld.Graphics.GraphicsEngine.pixel, new Rectangle(0, 0, 0, 0), Color.White);
            bool a = renderer.IsDrawing;
            bool b = renderer.IsScaeld;
            if (renderer.IsDrawing) renderer.End();

            renderer.GraphicsDevice.DrawUserPrimitives<VertexPositionColorTexture>(PrimitiveType.LineList,
                arr, 0, arr.Length / 2);

            if (a) renderer.Begin(b);
        }
예제 #6
0
파일: Frame.cs 프로젝트: XZelnar/MicroWorld
        public void DrawGhost(MicroWorld.Graphics.Renderer renderer, int x1, int y1, int x2, int y2)
        {
            MicroWorld.Logics.GridHelper.GridCoords(ref x1, ref y1);
            MicroWorld.Logics.GridHelper.GridCoords(ref x2, ref y2);

            if (x1 > x2)
            {
                int t = x1;
                x1 = x2;
                x2 = t;
            }
            if (y1 > y2)
            {
                int t = y1;
                y1 = y2;
                y2 = t;
            }

            Graphics.Position = new Vector2(x1, y1);
            Graphics.Size = new Vector2(x2 - x1, y2 - y1);

            bool b = renderer.IsDrawing;
            if (b)
                renderer.End();
            renderer.Begin();
            if (CanEnd(x1, y1, x2, y2))
                renderer.Draw(MicroWorld.Graphics.GraphicsEngine.pixel, new Rectangle(x1, y1, x2 - x1, y2 - y1), Color.White * 0.3f);
            else
                renderer.Draw(MicroWorld.Graphics.GraphicsEngine.pixel, new Rectangle(x1, y1, x2 - x1, y2 - y1), Color.Red * 0.3f);
            renderer.End();

            (Graphics as Graphics.FrameGraphics).DrawFrame(x1, y1, x2, y2, renderer, 0.5f, false);

            if (b)
                renderer.Begin();
        }
        public override void Draw(MicroWorld.Graphics.Renderer renderer)
        {
            if (!CanDraw())
                return;
            MovementDetectorLaser p = parent as MovementDetectorLaser;
            if (p.Length == 0)
                return;

            renderer.End();
            Matrix projection = Matrix.CreateOrthographicOffCenter(0,
                Main.WindowWidth, Main.WindowHeight, 0, 0, 1);
            Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
            MicroWorld.Graphics.Effects.Effects.laser.Parameters["MatrixTransform"].SetValue(renderer.GetTransformMatrix() * halfPixelOffset * projection);
            float pw = 1f / Main.WindowWidth;
            MicroWorld.Graphics.Effects.Effects.laser.Parameters["halfpixel"].SetValue(new float[] { pw / 2f, 0.5f / Main.WindowHeight });
            MicroWorld.Graphics.Effects.Effects.laser.Parameters["horizontal"].SetValue(p.type == MovementDetectorLaser.Direction.Left || p.type == MovementDetectorLaser.Direction.Right);
            Random r = new Random();
            if (tb == 4)
            {
                tb = 0;
                for (int i = 0; i < rand.Length; i++)
                    rand[i] = r.Next(256);
            }
            tb++;
            MicroWorld.Graphics.Effects.Effects.laser.Parameters["random"].SetValue(rand);
            renderer.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone,
                MicroWorld.Graphics.Effects.Effects.laser);

            int dis = 1;
            switch (p.type)
            {
                case MovementDetectorLaser.Direction.Up:
                    renderer.Draw(Shortcuts.pixel, new Rectangle((int)Position.X - dis, (int)Position.Y - p.Length, dis * 2, p.Length), Color.White);
                    for (int i = 0; i < 2; i++)
                    {
                        MicroWorld.Graphics.ParticleManager.Add(
                            new MicroWorld.Graphics.Particles.Spark(
                                Position + new Vector2(r.Next(5) - 2, -r.Next(p.Length)),
                                new Vector2(1, 1),
                                new Vector2(((float)r.NextDouble() - 0.5f) / 4, ((float)r.NextDouble() - 0.5f) / 4),
                                (float)(r.NextDouble() + 0.1f) / 10,
                                Color.Red));
                    }
                    break;
                case MovementDetectorLaser.Direction.Left:
                    renderer.Draw(Shortcuts.pixel, new Rectangle((int)Position.X - p.Length, (int)Position.Y - dis, p.Length, dis * 2), Color.White);
                    for (int i = 0; i < 2; i++)
                    {
                        MicroWorld.Graphics.ParticleManager.Add(
                            new MicroWorld.Graphics.Particles.Spark(
                                Position + new Vector2(-r.Next(p.Length), r.Next(5) - 2),
                                new Vector2(1, 1),
                                new Vector2(((float)r.NextDouble() - 0.5f) / 4, ((float)r.NextDouble() - 0.5f) / 4),
                                (float)(r.NextDouble() + 0.1f) / 10,
                                Color.Red));
                    }
                    break;
                case MovementDetectorLaser.Direction.Down:
                    renderer.Draw(Shortcuts.pixel, new Rectangle((int)Position.X - dis, (int)Position.Y, dis * 2, p.Length), Color.White);
                    for (int i = 0; i < 2; i++)
                    {
                        MicroWorld.Graphics.ParticleManager.Add(
                            new MicroWorld.Graphics.Particles.Spark(
                                Position + new Vector2(r.Next(5) - 2, r.Next(p.Length)),
                                new Vector2(1, 1),
                                new Vector2(((float)r.NextDouble() - 0.5f) / 4, ((float)r.NextDouble() - 0.5f) / 4),
                                (float)(r.NextDouble() + 0.1f) / 10,
                                Color.Red));
                    }
                    break;
                case MovementDetectorLaser.Direction.Right:
                    renderer.Draw(Shortcuts.pixel, new Rectangle((int)Position.X, (int)Position.Y - dis, p.Length, dis * 2), Color.White);
                    for (int i = 0; i < 2; i++)
                    {
                        MicroWorld.Graphics.ParticleManager.Add(
                            new MicroWorld.Graphics.Particles.Spark(
                                Position + new Vector2(r.Next(p.Length), r.Next(5) - 2),
                                new Vector2(1, 1),
                                new Vector2(((float)r.NextDouble() - 0.5f) / 4, ((float)r.NextDouble() - 0.5f) / 4),
                                (float)(r.NextDouble() + 0.1f) / 10,
                                Color.Red));
                    }
                    break;
                default:
                    break;
            }
            renderer.End();
            renderer.Begin();
        }
        public void DrawConnector(int x1, int y1, int x2, int y2, MicroWorld.Graphics.Renderer renderer, float opacity)
        {
            Color c = new Color(1f, 1f, 1f) * opacity;

            renderer.Draw(MicroWorld.Graphics.GraphicsEngine.circle,
                new Rectangle(x1 - CONNECTION_CIRCLE_SIZE, y1 - CONNECTION_CIRCLE_SIZE,
                    CONNECTION_CIRCLE_SIZE * 2, CONNECTION_CIRCLE_SIZE * 2), c);
            renderer.Draw(MicroWorld.Graphics.GraphicsEngine.circle,
                new Rectangle(x2 - CONNECTION_CIRCLE_SIZE, y2 - CONNECTION_CIRCLE_SIZE,
                    CONNECTION_CIRCLE_SIZE * 2, CONNECTION_CIRCLE_SIZE * 2), c);

            VertexPositionColorTexture[] arr = new VertexPositionColorTexture[12];

            arr[0] = new VertexPositionColorTexture(new Vector3(x1 - 2, y1 - 2, 0), c, new Vector2());
            arr[1] = new VertexPositionColorTexture(new Vector3(x2 - 2, y2 - 2, 0), c, new Vector2());
            arr[2] = new VertexPositionColorTexture(new Vector3(x1 + 2, y1 + 2, 0), c, new Vector2());

            arr[3] = new VertexPositionColorTexture(new Vector3(x1 + 2, y1 + 2, 0), c, new Vector2());
            arr[4] = new VertexPositionColorTexture(new Vector3(x2 - 2, y2 - 2, 0), c, new Vector2());
            arr[5] = new VertexPositionColorTexture(new Vector3(x2 + 2, y2 + 2, 0), c, new Vector2());

            arr[6] = new VertexPositionColorTexture(new Vector3(x1 + 2, y1 - 2, 0), c, new Vector2());
            arr[7] = new VertexPositionColorTexture(new Vector3(x2 + 2, y2 - 2, 0), c, new Vector2());
            arr[8] = new VertexPositionColorTexture(new Vector3(x1 - 2, y1 + 2, 0), c, new Vector2());

            arr[9] = new VertexPositionColorTexture(new Vector3(x1 - 2, y1 + 2, 0), c, new Vector2());
            arr[10] = new VertexPositionColorTexture(new Vector3(x2 + 2, y2 - 2, 0), c, new Vector2());
            arr[11] = new VertexPositionColorTexture(new Vector3(x2 - 2, y2 + 2, 0), c, new Vector2());

            Main.renderer.Draw(MicroWorld.Graphics.GraphicsEngine.pixel, new Rectangle(0, 0, 0, 0), Color.White);
            bool a = renderer.IsDrawing;
            bool b = renderer.IsScaeld;
            if (renderer.IsDrawing) renderer.End();

            renderer.GraphicsDevice.PresentationParameters.MultiSampleCount = 4;
            renderer.GraphicsDevice.DrawUserPrimitives<VertexPositionColorTexture>(PrimitiveType.TriangleList,
                arr, 0, 4);

            if (a) renderer.Begin(b);
        }