Пример #1
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
                                         Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection,
                                         Vector3 center, float radius, Quaternion rotation, Color color)
        {
            // Draw three orthogonal discs.
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Up, rotation)), radius, color, true);
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Forward, rotation)), radius, color, true);
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Left, rotation)), radius, color, true);

            // Draw disc aligned with camera. To do this, first calculate the largest visible cross section using
            // the technique described here: http://www.quantimegroup.com/solutions/pages/Article/Article.html

            // Solve for dy.
            Vector3 cameraToCenter   = center - cameraPosition;
            float   distanceToCenter = cameraToCenter.Length();
            float   radius2          = radius * radius;
            float   dy = radius2 / distanceToCenter;
            float   r  = MathUtility.Sqrt(radius2 - (dy * dy));

            Vector3 directionToCenter = Vector3.Normalize(cameraToCenter);
            Vector3 newCenter         = cameraPosition + directionToCenter * (distanceToCenter - dy);

            // Disc aligned with camera
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection,
                               newCenter, directionToCenter, r, Color.White, false);
        }
        public void Render()
        {
            Gl.glClearColor(1, 1, 1, 0);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

            _pathFinder.Polygons.ForEach(x => PolyDrawer.RenderPoly(x));



            if (_drawingPath)
            {
                PrimitiveDrawer.DrawFilledCircle(_pathStart, 15, new Color(0, 0, 0, 1));
            }


            GLUtil.SetColor(new Color(1, 0, 0, 1));
            Gl.glBegin(Gl.GL_LINE_STRIP);
            {
                foreach (Point p in _path)
                {
                    GLUtil.DrawPointVertex(p);
                }
            }
            Gl.glEnd();



            _renderer.DrawText(0, 0, "Path Drawing State", _font);
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            _renderer.Render();
            Gl.glDisable(Gl.GL_TEXTURE_2D);
        }
Пример #3
0
        public MainWindowViewModel()
        {
            LoadDuck    = new LoadCommand(this);
            PhysicsTest = new PhysicsTestCommand(this);

            MoveToCenterWorld  = new MoveToCenterWorldCommand(this);
            ShowAxis           = new ShowAxisCommand(this);
            ClearConsoleOutput = new ClearConsoleOutputCommand(this);

            primitiveDrawer = new PrimitiveDrawer();

            VisualTreeviewer = new VisualTreeviewerViewModel();
            SystemsView      = new SystemViewPresenter();
            ScriptsConsole   = new ScriptsConsoleVM(primitiveDrawer);

            items       = new ObservableCollection <LoadedItem>();
            Items       = CollectionViewSource.GetDefaultView(items);
            notificator = new EngineNotificator();

            notificator.Subscribe(new ViewportSubscriber(this));

            plugins       = new PluginImporter();
            ConsoleOutput = new ObservableCollection <string>();
            System.Diagnostics.Trace.Listeners.Add(new TraceOutputListener(ConsoleOutput, App.Current.Dispatcher));

            //new Debugger.Modules.Obj.ObjDetailsWindow().Show();
        }
        public void Render()
        {
            Gl.glClearColor(1, 1, 1, 0);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Point mousePosition = _input.Mouse.Position;

            PrimitiveDrawer.DrawCrosshair(mousePosition.X, mousePosition.Y);
            _pathData.NavMesh.Render();
            _nodeUI.ForEach(x => x.Render());

            if (_start != null)
            {
                PrimitiveDrawer.DrawSquare(_start.Position.X, _start.Position.Y, 20, new Color(0, 0, 0, 1));
            }

            if (_end != null)
            {
                PrimitiveDrawer.DrawSquare(_end.Position.X, _end.Position.Y, 20, new Color(0.1f, 0.1f, 0.1f, 1));
            }

            if (_astar.Path.Count != 0)
            {
                DrawPath(_astar.Path);
            }
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            _renderer.Render();
            Gl.glDisable(Gl.GL_TEXTURE_2D);
            _textBuffer.Clear();
        }
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice)
        {
            Rectangle numRect = this.ToRectangle();
            numRect.Width = numWidth;

            Rectangle rect = this.ToRectangle();
            this.width = (rect.Width = (int)fontHandler.GetVerdana().MeasureString(" " + this.text + " ").X + 3) + numWidth;
            rect.X += numWidth;

            if(this.text.Length > 0 || this.GetSelected())
            if (selected)
            {
                primitiveDrawer.DrawRoundedRectangle(graphicsDevice, rect, colorB);
            }
            else
            {
                primitiveDrawer.DrawRoundedRectangle(graphicsDevice, rect, colorA);
            }

            primitiveDrawer.DrawRoundedRectangle(graphicsDevice, numRect, new Color(0x3D, 0x70, 0xBC));

            Vector2 vector = this.GetVector();

            vector.X += 3;
            vector.Y += 3;

            spriteBatch.DrawString(fontHandler.GetVerdana(), " # ", vector + TetrisGameRunner.GetOffsetVector(), Color.White);

            vector.X += numWidth - 3;

            spriteBatch.DrawString(fontHandler.GetVerdana(), " " + this.text + " ", vector + TetrisGameRunner.GetOffsetVector(), Color.White);
            spriteBatch.End();
            spriteBatch.Begin();
        }
Пример #6
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
                                         Matrix cameraView, Matrix cameraProjection,
                                         BoundingFrustum frustum, Color color)
        {
            // The points returned correspond to the corners of the BoundingFrustum faces that are
            // perpendicular to the z-axis. The near face is the face with the larger z value, and
            // the far face is the face with the smaller z value. Points 0 to 3 correspond to the
            // near face in a clockwise order starting at its upper-left corner when looking toward
            // the origin from the positive z direction. Points 4 to 7 correspond to the far face
            // in a clockwise order starting at its upper-left corner when looking toward the
            // origin from the positive z direction.
            frustum.GetCorners(Corners);

            FrustumVertices[6].Position = Corners[0];
            FrustumVertices[7].Position = Corners[1];
            FrustumVertices[5].Position = Corners[2];
            FrustumVertices[4].Position = Corners[3];
            FrustumVertices[2].Position = Corners[4];
            FrustumVertices[3].Position = Corners[5];
            FrustumVertices[1].Position = Corners[6];
            FrustumVertices[0].Position = Corners[7];

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
                                 PrimitiveType.LineList, FrustumVertices, WireFrustumIndices, false);
        }
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice)
        {
            if(varLink != null)
            {
                Vector2 vec = this.GetVector();
                this.varLink.SetVector(ref vec);
                this.SetWidth(varLink.GetWidth());
                this.SetHeight(varLink.GetHeight());

                varLink.Draw(spriteBatch, primitiveDrawer, fontHandler, graphicsDevice);
            }
            else
            {
                primitiveDrawer.DrawRoundedRectangle(graphicsDevice, this, colorA);
                Vector2 ve = fontHandler.GetVerdana().MeasureString(this.typeOfVariable);

                this.width = (int)ve.X + 3;
                this.height = 30;

                Vector2 vec = this.GetVector();
                vec.Y += 3;
                vec.X += 3;

                spriteBatch.DrawString(fontHandler.GetVerdana(), this.typeOfVariable, vec + TetrisGameRunner.GetOffsetVector(), Color.White);
                spriteBatch.End();
                spriteBatch.Begin();
            }
        }
Пример #8
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection,
                                         Vector3 center, Vector3 size, Quaternion rotation, Color color)
        {
            var world = Matrix.CreateScale(size) * Matrix.CreateFromQuaternion(rotation) * Matrix.CreateTranslation(center);

            var vertices = new VertexPositionColor[WireframeLines.Length * 2];

            for (int i = 0; i < WireframeLines.Length; i++)
            {
                var     transformedLine = WireframeLine.Transform(WireframeLines[i], world);
                Vector3 cameraToLine    = Vector3.Normalize(((transformedLine.Point1 + transformedLine.Point2) / 2) - cameraPosition);

                Color lineColor = color;
                if (!IsCameraFacing(cameraToLine, transformedLine.FaceNormal1) && !IsCameraFacing(cameraToLine, transformedLine.FaceNormal2))
                {
                    lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25);
                }

                vertices[i * 2]       = new VertexPositionColor(transformedLine.Point1, lineColor);
                vertices[(i * 2) + 1] = new VertexPositionColor(transformedLine.Point2, lineColor);
            }

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                                 Color.White, null, PrimitiveType.LineList, vertices, false);
        }
Пример #9
0
        public void Draw(PrimitiveDrawer pd, GraphicsDevice graphics)
        {
            vector.X = x;
            vector.Y = y;

            pd.DrawFilledRectangle(graphics, this, Color.Red);
        }
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice)
        {
            String text = mode ? "True" : "False";
            Color color = !GetSelected() ? colorA : colorB;

            Rectangle numRect = this.ToRectangle();
            numRect.Width = boolWidth;

            Rectangle rect = this.ToRectangle();

            this.width = (rect.Width = (int)fontHandler.GetVerdana().MeasureString(" " + text + " ").X + 3) + boolWidth;

            rect.X += boolWidth;
            primitiveDrawer.DrawRoundedRectangle(graphicsDevice, rect, color);
            primitiveDrawer.DrawRoundedRectangle(graphicsDevice, numRect, new Color(0x3D, 0x70, 0xBC));
            Vector2 vector = this.GetVector();

            vector.X += 3;
            vector.Y += 3;

            spriteBatch.DrawString(fontHandler.GetVerdana(), " Bool ", vector + TetrisGameRunner.GetOffsetVector(), Color.White);

            vector.X += boolWidth - 3;

            spriteBatch.DrawString(fontHandler.GetVerdana(), " " + text + " ", vector + TetrisGameRunner.GetOffsetVector(), Color.White);
            spriteBatch.End();
            spriteBatch.Begin();
        }
Пример #11
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
			Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection,
			Vector3 center, float radius, Quaternion rotation, Color color)
        {
            // Draw three orthogonal discs.
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Up, rotation)), radius, color, true);
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Forward, rotation)), radius, color, true);
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Left, rotation)), radius, color, true);

            // Draw disc aligned with camera. To do this, first calculate the largest visible cross section using
             			// the technique described here: http://www.quantimegroup.com/solutions/pages/Article/Article.html

            // Solve for dy.
            Vector3 cameraToCenter = center - cameraPosition;
            float distanceToCenter = cameraToCenter.Length();
            float radius2 = radius * radius;
            float dy = radius2 / distanceToCenter;
            float r = MathUtility.Sqrt(radius2 - (dy * dy));

            Vector3 directionToCenter = Vector3.Normalize(cameraToCenter);
            Vector3 newCenter = cameraPosition + directionToCenter * (distanceToCenter - dy);

            // Disc aligned with camera
            Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection,
                newCenter, directionToCenter, r, Color.White, false);
        }
Пример #12
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
			Matrix cameraView, Matrix cameraProjection,
			BoundingFrustum frustum, Color color)
        {
            // The points returned correspond to the corners of the BoundingFrustum faces that are
            // perpendicular to the z-axis. The near face is the face with the larger z value, and
            // the far face is the face with the smaller z value. Points 0 to 3 correspond to the
            // near face in a clockwise order starting at its upper-left corner when looking toward
            // the origin from the positive z direction. Points 4 to 7 correspond to the far face
            // in a clockwise order starting at its upper-left corner when looking toward the
            // origin from the positive z direction.
            frustum.GetCorners(Corners);

            FrustumVertices[6].Position = Corners[0];
            FrustumVertices[7].Position = Corners[1];
            FrustumVertices[5].Position = Corners[2];
            FrustumVertices[4].Position = Corners[3];
            FrustumVertices[2].Position = Corners[4];
            FrustumVertices[3].Position = Corners[5];
            FrustumVertices[1].Position = Corners[6];
            FrustumVertices[0].Position = Corners[7];

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
                PrimitiveType.LineList, FrustumVertices, WireFrustumIndices, false);
        }
Пример #13
0
        private void Render(ConvexPolyForm poly)
        {
            if (poly == _selectedPoly)
            {
                GLUtil.SetColor(new Color(0, 0, 0, 1));
            }
            else
            {
                GLUtil.SetColor(new Color(0.1f, 0.1f, 0.1f, 0.5f));
            }
            PolyDrawer.RenderPoly(poly);

            RenderNormals(poly);
            RenderCentroid(poly);


            if (poly == _selectedPoly)
            {
                RenderNearestEdge(poly);
                RenderVerts(poly);
            }

            if (_editState == EditState.ConnectPressed)
            {
                GLUtil.SetColor(new Color(0, 0, 0, 1));
                PrimitiveDrawer.DrawLine2d(_connectStart, _input.Mouse.Position);
                RenderCrossedEdges();
            }
        }
Пример #14
0
        private void RenderConnections()
        {
            // Render the connections between the edges
            foreach (Connection connection in _connections)
            {
                Point firstStart = connection.StartPoly.Vertices[connection.StartEdgeIndex.Start];
                Point firstEnd   = connection.StartPoly.Vertices[connection.StartEdgeIndex.End];
                float length1    = EdgeIndex.Length(firstStart, firstEnd);

                Point secondStart = connection.EndPoly.Vertices[connection.EndEdgeIndex.Start];
                Point secondEnd   = connection.EndPoly.Vertices[connection.EndEdgeIndex.End];
                float length2     = EdgeIndex.Length(secondStart, secondEnd);

                if (length1 <= length2)
                {
                    Point point = LineSegment.GetMiddle(firstStart, firstEnd);
                    PrimitiveDrawer.DrawFilledCircle(point, 15, new Color(0, 0, 1, 1));
                }
                else
                {
                    Point point = LineSegment.GetMiddle(secondStart, secondEnd);
                    PrimitiveDrawer.DrawFilledCircle(point, 15, new Color(0, 0, 1, 1));
                }
            }
        }
Пример #15
0
        public void Draw(GraphicsDevice graphicsDevice, SpriteBatch batch, PrimitiveDrawer drawer, FontHandler font)
        {
            Vector2 headPlacement = testingRectangle.GetVector();
            headPlacement.Y -= 46;
            headPlacement.X += (testingRectangle.GetWidth() / 2);

            if(textBox.GetSelected())
            textBox.Draw(batch, drawer, font, graphicsDevice);

            drawer.DrawRoundedRectangle(graphicsDevice, testingRectangle.ScalePosition(-1,-1).ScaleSize(2,2), Color.Black);
            drawer.DrawRoundedRectangle(graphicsDevice, testingRectangle, color);

            drawer.DrawCircle(graphicsDevice, headPlacement, 50, Color.Black, sides);
            drawer.DrawCircle(graphicsDevice, headPlacement, 49, Color.Wheat, sides);

            Vector2 lower = testingRectangle.GetVector();
            lower.Y += 30;

            lower.X += testingRectangle.GetWidth();

            headPlacement.Y += -16;
            headPlacement.X += -28;

            // e     e\n , ____ ,
            string face = " l l\n";
            if (squareOrCircle) face = " n n\n";
            bool blinking = false;
            string face2 = " ____ ";
            if ((blink > 43 && blink < 56) )
            {
                face = "  _  _\n";
                blinking = true;
            }

            if(blink == 110)
            {
                blink = 0;
            }

            if(blink % 140 < 15 )
            {
                face2 = "  ____ ";
            }

            left.Draw(graphicsDevice, batch, drawer, font);
            right.Draw(graphicsDevice, batch, drawer, font);
            lleft.Draw(graphicsDevice, batch, drawer, font);
            lright.Draw(graphicsDevice, batch, drawer, font);
            Vector2 dis = new Vector2(TetrisGameRunner.GetOffsetX(), TetrisGameRunner.GetOffsetY());
            batch.DrawString(font.GetVerdana(), "Frame : " + ff + "     "+"S: Save Frame     C: Correct Frame        V: Correct Frame Dynamic\nH: Hide Dots", new Vector2(300, 0) + dis, Color.White);

            batch.DrawString(((!blinking) ? font.GetWingdings() : font.GetVerdana()), face, headPlacement + dis, Color.Black);

            batch.DrawString(font.GetVerdana(), "\n\n", testingRectangle.GetVector(), Color.Black, 0, dis + new Vector2(), .82f, SpriteEffects.None, 0);

            batch.DrawString(font.GetVerdana(), "\n"+face2, dis + headPlacement, Color.Black);
        }
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice)
        {
            SetWidth((int)fontHandler.GetVerdana().MeasureString(this.eventName).X + 8);
            Vector2 adjust = GetVector();
            adjust.X += 4;
            spriteBatch.DrawString(fontHandler.GetVerdana(), this.eventName, adjust + TetrisGameRunner.GetOffsetVector(), Color.White);

            primitiveDrawer.DrawRoundedRectangle(graphicsDevice, this, Color.Green);
            spriteBatch.End();
            spriteBatch.Begin();
        }
Пример #17
0
 public void MouseClick(MapEventInfo mei)
 {
     oldvalue = mei.getTile(mei.start.tx, mei.start.ty);
     newvalue = mei.tile;
     if (oldvalue != newvalue)
     {
         mei.opManager.beginGroup("Map: FloodFill");
         PrimitiveDrawer.FloodFill(mei.start.tx, mei.start.ty, new PrimitiveDrawer.CheckCallback(ccb), new PrimitiveDrawer.Callback(cb), mei);
         mei.opManager.endGroup();
     }
 }
Пример #18
0
        public void Draw(GraphicsDevice graphicsDevice, SpriteBatch batch, PrimitiveDrawer drawer, FontHandler font)
        {
            if(showMode && !neverEditAgain)
            {
                drawer.DrawRoundedRectangle(graphicsDevice, a.ScalePosition(start), Color.White);
                drawer.DrawRoundedRectangle(graphicsDevice, b.ScalePosition(start), Color.Red);
                drawer.DrawRoundedRectangle(graphicsDevice, c.ScalePosition(start), Color.Blue);
            }

            drawer.DrawCurve(graphicsDevice, start, a.ScalePosition(start).GetVector(), b.ScalePosition(start).GetVector(), c.ScalePosition(start).GetVector(), 1, 0, Color.Black);
        }
Пример #19
0
        public override void Draw(PrimitiveDrawer drawer, GraphicsDevice graphics, SpriteBatch batch, FontHandler font)
        {
            Vector2 headPlacement = GetVector();
            headPlacement.Y -= 46;
            headPlacement.X += (GetWidth() / 2);

            base.Draw(drawer, graphics, batch, font);

            drawer.DrawCircle(graphics, headPlacement, 50, Color.Black, 60);
            drawer.DrawCircle(graphics, headPlacement, 49, Color.Wheat, 60);

            Vector2 lower = GetVector();
            lower.Y += 30;

            lower.X += GetWidth();

            headPlacement.Y += -16;
            headPlacement.X += -28;

            // e     e\n , ____ ,
            string face = " l l\n";
            bool blinking = false;
            string face2 = " ____ ";
            if ((blink > 43 && blink < 56))
            {
                face = "  _  _\n";
                blinking = true;
            }

            if (blink == 110)
            {
                blink = 0;
            }

            if (blink % 140 < 15)
            {
                face2 = "  ____ ";
            }

            if (left != null)
            {
                left.Draw(graphics, batch, drawer, font);
                right.Draw(graphics, batch, drawer, font);
                leg_left.Draw(graphics, batch, drawer, font);
                leg_right.Draw(graphics, batch, drawer, font);
            }

            Vector2 dis = new Vector2(TetrisGameRunner.GetOffsetX(), TetrisGameRunner.GetOffsetY());

            batch.DrawString(((!blinking) ? font.GetWingdings() : font.GetVerdana()), face, headPlacement + dis, Color.Black);
            batch.DrawString(font.GetVerdana(), "\n\n", GetVector(), Color.Black, 0, dis + new Vector2(), .82f, SpriteEffects.None, 0);
            batch.DrawString(font.GetVerdana(), "\n" + face2, dis + headPlacement, Color.Black);
        }
Пример #20
0
        public static void Draw(
			PrimitiveDrawer primitiveDrawer, Matrix cameraView, Matrix cameraProjection,
			Vector3 start, Vector3 end, Color color)
        {
            var vertices = new[]
            {
                new VertexPositionColor(start, Color.White),
                new VertexPositionColor(end, Color.White)
            };
            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                color, null, PrimitiveType.LineList, vertices, false);
        }
Пример #21
0
        public void Render()
        {
            Gl.glClearColor(1, 1, 1, 0);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Point mousePosition = _input.Mouse.Position;

            PrimitiveDrawer.DrawCrosshair(mousePosition.X, mousePosition.Y);

            _pathData.NavMesh.Render();

            _plotter.Render();
        }
Пример #22
0
        public static void Draw(
            PrimitiveDrawer primitiveDrawer, Matrix cameraView, Matrix cameraProjection,
            Vector3 start, Vector3 end, Color color)
        {
            var vertices = new[]
            {
                new VertexPositionColor(start, Color.White),
                new VertexPositionColor(end, Color.White)
            };

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                                 color, null, PrimitiveType.LineList, vertices, false);
        }
Пример #23
0
        public static void DrawSolid(PrimitiveDrawer primitiveDrawer, Matrix cameraView, Matrix cameraProjection,
			Vector3[] corners, Color color)
        {
            if (corners == null || corners.Length != 4)
                throw new ArgumentException("corners");

            Vertices[0].Position = corners[0];
            Vertices[1].Position = corners[1];
            Vertices[2].Position = corners[2];
            Vertices[3].Position = corners[3];

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
                PrimitiveType.TriangleList, Vertices, SolidIndices, false);
        }
Пример #24
0
        private void RenderCrossedEdges()
        {
            foreach (var tuple in _connectIntersectedEdges)
            {
                ConvexPolyForm poly = tuple.Item1;
                EdgeIndex      edge = tuple.Item2;

                Point start = poly.Vertices[edge.Start];
                Point end   = poly.Vertices[edge.End];

                GLUtil.SetColor(new Color(0, 0, 1, 1));
                PrimitiveDrawer.DrawLine2d(start, end);
            }
        }
Пример #25
0
        public static void DrawWireframe(
            PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition,
            Matrix cameraView, Matrix cameraProjection,
            Vector3 center, Vector3 normal, float radius,
            Color color, bool fadeBackFace)
        {
            // Calculate basis vectors.
            Vector3 from = Vector3.Cross(normal, Vector3.Up);

            if (from.LengthSquared() < 0.0001f)
            {
                from = Vector3.Cross(normal, Vector3.Right);
            }
            from.Normalize();

            // We need two vertices per line, so we can allocate our vertices.
            const int numSegments = 64;
            const int numLines    = numSegments + 1;
            var       vertices    = new VertexPositionColor[numLines * 2];

            // Calculate initial orientation.
            Quaternion rotation = Quaternion.CreateFromAxisAngle(normal, MathHelper.TwoPi / (numSegments - 1));

            // Compute vertex positions.
            Vector3 edge = from * radius;

            for (int i = 0; i < numSegments; i++)
            {
                // Calculate line positions.
                Vector3 start = center + edge;
                edge = Vector3.Transform(edge, rotation);
                Vector3 end = center + edge;

                // Calculate line normal.
                Vector3 cameraToEdge = start - cameraPosition;
                var     lineColor    = color;
                if (fadeBackFace && Vector3.Dot(cameraToEdge, edge) > 0)
                {
                    lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25);
                }

                vertices[(i * 2) + 0] = new VertexPositionColor(start, lineColor);
                vertices[(i * 2) + 1] = new VertexPositionColor(end, lineColor);
            }

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                                 Color.White, null, PrimitiveType.LineList, vertices, false);
        }
Пример #26
0
        public static void DrawSolid(PrimitiveDrawer primitiveDrawer, Matrix cameraView, Matrix cameraProjection,
                                     Vector3[] corners, Color color)
        {
            if (corners == null || corners.Length != 4)
            {
                throw new ArgumentException("corners");
            }

            Vertices[0].Position = corners[0];
            Vertices[1].Position = corners[1];
            Vertices[2].Position = corners[2];
            Vertices[3].Position = corners[3];

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
                                 PrimitiveType.TriangleList, Vertices, SolidIndices, false);
        }
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice)
        {
            if (width == 0)
            {
                Vector2 measure = fontHandler.GetLucidaSansTypewriter().MeasureString(" New Class ");

                this.width = (int)measure.X;
                this.height = (int)measure.Y;
            }

                primitiveDrawer.DrawRoundedRectangle(graphicsDevice, this, Color.Orange);
                spriteBatch.DrawString(fontHandler.GetLucidaSansTypewriter(), " New Class ", TetrisGameRunner.GetOffsetVector() +this.GetVector(), Color.White);

            spriteBatch.End();
            spriteBatch.Begin();
        }
Пример #28
0
        public override void Draw(PrimitiveDrawer drawer, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphics, SpriteBatch batch, FontHandler font)
        {
            if(borderMode)
            {
                drawer.DrawCircle(graphics, GetVector(), GetWidth(), border);
                drawer.DrawCircle(graphics, GetVector(), GetWidth()-1, color);
            }
            else
            {
                drawer.DrawCircle(graphics, GetVector(), GetWidth(), color);
            }

            if(editing)
            {
                drawer.DrawFilledRectangle(graphics, point, Color.White);
            }
        }
Пример #29
0
        private void RenderVerts(ConvexPolyForm poly)
        {
            for (int i = 0; i < poly.Vertices.Count; i++)
            {
                Point p = poly.Vertices[i];
                PrimitiveDrawer.DrawCircle(new Circle(p.X, p.Y, 16), new Color(0, 0, 0, 1));

                if (i == _selectedVert && _editState == EditState.VertexPressed)
                {
                    PrimitiveDrawer.DrawFilledCircle(p, 15, new Color(0, 1, 1, 1));
                }
                else
                {
                    PrimitiveDrawer.DrawFilledCircle(p, 15, new Color(1, 1, 1, 1));
                }
            }
        }
Пример #30
0
        public void Draw(GraphicsDevice graphicsDevice, SpriteBatch batch, PrimitiveDrawer drawer, FontHandler font)
        {
            foreach (LevelObject o in objects)
            {
                if (o is LightLevelCircle) continue;
                o.Draw(drawer, graphicsDevice, batch, font);
            }


            drawer.DrawFilledRectangle(graphicsDevice, (Rectangle)(new GameRectangle(0, 0, 2000, 1000)), new Color(0, 0, 0, 220), false);


            foreach (LevelObject o in objects)
            {
                if (o is LightLevelCircle)
                    o.Draw(drawer, graphicsDevice, batch, font);
            }

        }
Пример #31
0
        public static void DrawWireframe(
			PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition,
			Matrix cameraView, Matrix cameraProjection,
			Vector3 center, Vector3 normal, float radius,
			Color color, bool fadeBackFace)
        {
            // Calculate basis vectors.
            Vector3 from = Vector3.Cross(normal, Vector3.Up);
            if (from.LengthSquared() < 0.0001f)
                from = Vector3.Cross(normal, Vector3.Right);
            from.Normalize();

            // We need two vertices per line, so we can allocate our vertices.
            const int numSegments = 64;
            const int numLines = numSegments + 1;
            var vertices = new VertexPositionColor[numLines * 2];

            // Calculate initial orientation.
            Quaternion rotation = Quaternion.CreateFromAxisAngle(normal, MathHelper.TwoPi / (numSegments - 1));

            // Compute vertex positions.
            Vector3 edge = from * radius;
            for (int i = 0; i < numSegments; i++)
            {
                // Calculate line positions.
                Vector3 start = center + edge;
                edge = Vector3.Transform(edge, rotation);
                Vector3 end = center + edge;

                // Calculate line normal.
                Vector3 cameraToEdge = start - cameraPosition;
                var lineColor = color;
                if (fadeBackFace && Vector3.Dot(cameraToEdge, edge) > 0)
                    lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25);

                vertices[(i * 2) + 0] = new VertexPositionColor(start, lineColor);
                vertices[(i * 2) + 1] = new VertexPositionColor(end, lineColor);
            }

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                Color.White, null, PrimitiveType.LineList, vertices, false);
        }
        public override void Draw(PrimitiveDrawer drawer, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphics, SpriteBatch batch, FontHandler font)
        {
            if(!normal)
             graphics.BlendState = TetrisGameRunner.LightState();
            for (int i = 0;i < 2;i++)
            {
                if(culled)
                drawer.DrawCulledCircle(graphics, GetVector(), GetWidth(), color, Color.Black, 60, new GameRectangle(320, 0, 1024 - 320, 768));
                else
                {
                    drawer.DrawCircle(graphics, GetVector(), GetWidth(), color, Color.Black, 60);

                }
            }
            graphics.BlendState = TetrisGameRunner.OriginalState();
            if (editing)
            {
                drawer.DrawFilledRectangle(graphics, point, Color.White);
            }
        }
Пример #33
0
        public override void Draw(SpriteBatch spriteBatch, PrimitiveDrawer pd, FontHandler fontHandler, GraphicsDevice graphicsDevice)
        {
            vector.X = x;
            vector.Y = y;

            if(true)
            {
                Vector2 measurement = fontHandler.GetSourceCodePro().MeasureString(" " + text + " ");
                width = (int)measurement.X;
                height = (int)measurement.Y;
            }

            if(selected)
                pd.DrawFilledRectangle(graphicsDevice, this, colorOne);
            else
                pd.DrawFilledRectangle(graphicsDevice, this, colorTwo);

            spriteBatch.DrawString(fontHandler.GetSourceCodePro(), " " + text + " ", vector + TetrisGameRunner.GetOffsetVector(), Color.White);
            spriteBatch.End();
            spriteBatch.Begin();
        }
Пример #34
0
        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection,
			Vector3 center, Vector3 size, Quaternion rotation, Color color)
        {
            var world = Matrix.CreateScale(size) * Matrix.CreateFromQuaternion(rotation) * Matrix.CreateTranslation(center);

            var vertices = new VertexPositionColor[WireframeLines.Length * 2];
            for (int i = 0; i < WireframeLines.Length; i++)
            {
                var transformedLine = WireframeLine.Transform(WireframeLines[i], world);
                Vector3 cameraToLine = Vector3.Normalize(((transformedLine.Point1 + transformedLine.Point2) / 2) - cameraPosition);

                Color lineColor = color;
                if (!IsCameraFacing(cameraToLine, transformedLine.FaceNormal1) && !IsCameraFacing(cameraToLine, transformedLine.FaceNormal2))
                    lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25);

                vertices[i * 2] = new VertexPositionColor(transformedLine.Point1, lineColor);
                vertices[(i * 2) + 1] = new VertexPositionColor(transformedLine.Point2, lineColor);
            }

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                Color.White, null, PrimitiveType.LineList, vertices, false);
        }
Пример #35
0
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice)
        {
            Vector2 vec = this.GetVector();

            holderA.SetVector(ref vec);
            vec.X += holderA.GetWidth() + 1;

            Rectangle rect = this.ToRectangle();
            rect.X = (int)vec.X;
            rect.Y = (int)vec.Y;
            rect.Width = 28;
            vec.X += 29;

            spriteBatch.DrawString(fontHandler.GetVerdana(), modes[mode], new Vector2(rect.X, rect.Y) + TetrisGameRunner.GetOffsetVector(), Color.White);

            holderB.SetVector(ref vec);

            this.width = holderA.GetWidth() + holderB.GetWidth() + 30;
            primitiveDrawer.DrawRoundedRectangle(graphicsDevice, rect, storedColor);
            holderA.Draw(spriteBatch, primitiveDrawer, fontHandler, graphicsDevice);

            holderB.Draw(spriteBatch, primitiveDrawer, fontHandler, graphicsDevice);
        }
Пример #36
0
        public override void Initialize()
        {
            base.Initialize();
            var arrowSprite = PrimitiveDrawer.CreateArrowSprite(this.EditorGame.GraphicsDevice, 64);

            this._xAxisArrowRenderer.Sprite     = arrowSprite;
            this._yAxisArrowRenderer.Sprite     = arrowSprite;
            this._xAxisArrowRenderer.OffsetType = OffsetType.Center;
            this._yAxisArrowRenderer.OffsetType = OffsetType.Center;
            this._xAxisArrowRenderer.AddChild(this._xAxisBody);
            this._yAxisArrowRenderer.AddChild(this._yAxisBody);
            this._xAxisArrowRenderer.Initialize(this.EditorGame.CurrentScene);
            this._yAxisArrowRenderer.Initialize(this.EditorGame.CurrentScene);

            var triangleSprite = PrimitiveDrawer.CreateRightTriangleSprite(this.EditorGame.GraphicsDevice, new Point(64));

            this._xAxisTriangleRenderer.Sprite     = triangleSprite;
            this._yAxisTriangleRenderer.Sprite     = triangleSprite;
            this._xAxisTriangleRenderer.OffsetType = OffsetType.Center;
            this._yAxisTriangleRenderer.OffsetType = OffsetType.Center;
            this._xAxisTriangleRenderer.AddChild(this._neutralAxisBody);
            this._xAxisTriangleRenderer.Initialize(this.EditorGame.CurrentScene);
            this._yAxisTriangleRenderer.Initialize(this.EditorGame.CurrentScene);
        }
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice)
        {
            Rectangle numRect = this.ToRectangle();
            numRect.Width = notWidth;
            this.width = notWidth + holder.GetWidth();

            primitiveDrawer.DrawRoundedRectangle(graphicsDevice, numRect, storedColor);

            Vector2 vector = this.GetVector();

            vector.X += 3;

            vector.Y += 3;

            spriteBatch.DrawString(fontHandler.GetVerdana(), modes[mode], vector + TetrisGameRunner.GetOffsetVector(), Color.White);

            vector.X += notWidth - 2;
            vector.Y -= 3;

            holder.SetVector(ref vector);
            holder.Draw(spriteBatch, primitiveDrawer, fontHandler, graphicsDevice);
            spriteBatch.End();
            spriteBatch.Begin();
        }
Пример #38
0
        protected override void LoadContent()
        {
            base.LoadContent();
            var scene = new Scene();

            var cameraScroller = new CameraScroller();

            scene.AddChild(cameraScroller);

            var camera = new Camera();

            cameraScroller.AddChild(camera);

            var movingDot = new MovingDot();

            camera.AddChild(movingDot);
            var spriteRenderer = new SpriteRenderer();

            spriteRenderer.Sprite     = new Sprite("WhiteSquare", this.Content, Point.Zero, new Point(32, 32));
            spriteRenderer.OffsetType = OffsetType.Center;
            movingDot.AddChild(spriteRenderer);

            var spriteAnimation = new SpriteAnimation();
            var step            = spriteAnimation.AddStep();

            step.Sprite = new Sprite("ColoredSquares", this.Content, Point.Zero, new Point(64, 64));
            step.Frames = 2;
            step        = spriteAnimation.AddStep();
            step.Sprite = new Sprite("ColoredSquares", this.Content, new Point(0, 64), new Point(64, 64));
            step.Frames = 2;
            step        = spriteAnimation.AddStep();
            step.Sprite = new Sprite("ColoredSquares", this.Content, new Point(64, 64), new Point(64, 64));
            step.Frames = 2;
            step        = spriteAnimation.AddStep();
            step.Sprite = new Sprite("ColoredSquares", this.Content, new Point(64, 0), new Point(64, 64));
            step.Frames = 2;

            var spriteAnimator = new SpriteAnimator(spriteAnimation)
            {
                FrameRate = 4
            };

            var spriteRenderer2 = spriteAnimator.AddChild <SpriteRenderer>();

            spriteRenderer2.DrawOrder  = -100;
            spriteRenderer2.OffsetType = OffsetType.Center;
            scene.AddChild(spriteAnimator);

            var spinner = new Spinner();

            spinner.LocalPosition -= new Vector2(2f, 0);
            scene.AddChild(spinner);
            var spriteRenderer3 = new SpriteRenderer();

            spinner.AddChild(spriteRenderer3);
            spriteRenderer3.DrawOrder  = -200;
            spriteRenderer3.Sprite     = new Sprite("WhiteSquare", this.Content, Point.Zero, new Point(32, 32));
            spriteRenderer3.OffsetType = OffsetType.Center;

            var middleSpinningDotBoundingArea = new BoundingAreaDrawer();

            spriteRenderer3.AddChild(middleSpinningDotBoundingArea);
            middleSpinningDotBoundingArea.Color         = Color.Red;
            middleSpinningDotBoundingArea.LineThickness = 3f;

            var spinner2 = new Spinner();

            spinner.AddChild(spinner2);
            spinner2.LocalPosition -= new Vector2(2f, 0f);
            var spriteRenderer4 = new SpriteRenderer();

            spinner2.AddChild(spriteRenderer4);
            spriteRenderer4.DrawOrder  = 100;
            spriteRenderer4.Sprite     = new Sprite("WhiteSquare", this.Content, Point.Zero, new Point(32, 32));
            spriteRenderer4.OffsetType = OffsetType.Center;
            var outwardSpinningDotBoundingArea = new BoundingAreaDrawer();

            spriteRenderer4.AddChild(outwardSpinningDotBoundingArea);
            outwardSpinningDotBoundingArea.Color         = Color.Red;
            outwardSpinningDotBoundingArea.LineThickness = 3f;

            var textRenderer = new TextRenderer();

            scene.AddChild(textRenderer);
            textRenderer.Text = "Hello, World";
            textRenderer.Font = new Font()
            {
                ContentPath = "Arial"
            };
            textRenderer.Color          = Color.Pink;
            textRenderer.LocalScale     = new Vector2(2f, 2f);
            textRenderer.LocalPosition -= new Vector2(5f, 5f);
            var textRendererBoundingArea = new BoundingAreaDrawer();

            textRendererBoundingArea.Color         = Color.Red;
            textRendererBoundingArea.LineThickness = 3f;
            textRenderer.AddChild(textRendererBoundingArea);

            scene.AddChild(new MouseClickDebugger());

            scene.SaveToFile(@"TestGame - CurrentLevel.json", new Serializer());
            this.CurrentScene = new Serializer().Deserialize <Scene>(@"TestGame - CurrentLevel.json");

            var arrowSprite1         = PrimitiveDrawer.CreateArrowSprite(this.GraphicsDevice, 32, Color.Goldenrod);
            var arrowSpriteRenderer1 = new SpriteRenderer();

            arrowSpriteRenderer1.Sprite         = arrowSprite1;
            arrowSpriteRenderer1.LocalPosition += new Vector2(2f, -2f);
            this.CurrentScene.AddChild(arrowSpriteRenderer1);

            var arrowSprite2         = PrimitiveDrawer.CreateArrowSprite(this.GraphicsDevice, 32);
            var arrowSpriteRenderer2 = new SpriteRenderer();

            arrowSpriteRenderer2.Color               = Color.LawnGreen;
            arrowSpriteRenderer2.Sprite              = arrowSprite2;
            arrowSpriteRenderer2.LocalPosition      += new Vector2(3f, -1f);
            arrowSpriteRenderer2.LocalScale          = new Vector2(0.75f, 2f);
            arrowSpriteRenderer2.LocalRotation.Angle = 1f;
            this.CurrentScene.AddChild(arrowSpriteRenderer2);

            var quadSprite1         = PrimitiveDrawer.CreateQuadSprite(this.GraphicsDevice, new Point(32, 32), Color.Magenta);
            var quadSpriteRenderer1 = new SpriteRenderer();

            quadSpriteRenderer1.Sprite         = quadSprite1;
            quadSpriteRenderer1.LocalPosition += new Vector2(3f, 2f);
            this.CurrentScene.AddChild(quadSpriteRenderer1);

            var quadSprite2         = PrimitiveDrawer.CreateQuadSprite(this.GraphicsDevice, new Point(32, 64));
            var quadSpriteRenderer2 = new SpriteRenderer();

            quadSpriteRenderer2.Color  = Color.Khaki;
            quadSpriteRenderer2.Sprite = quadSprite2;
            quadSpriteRenderer2.LocalRotation.Angle = 0.5f;
            quadSpriteRenderer2.LocalPosition      += new Vector2(3f, 1f);
            this.CurrentScene.AddChild(quadSpriteRenderer2);

            var rightTriangleSprite1         = PrimitiveDrawer.CreateRightTriangleSprite(this.GraphicsDevice, new Point(32, 32), Color.MediumVioletRed);
            var rightTriangleSpriteRenderer1 = new SpriteRenderer();

            rightTriangleSpriteRenderer1.Sprite        = rightTriangleSprite1;
            rightTriangleSpriteRenderer1.LocalPosition = new Vector2(-3f, 3f);
            this.CurrentScene.AddChild(rightTriangleSpriteRenderer1);
        }
Пример #39
0
 abstract public void Draw(PrimitiveDrawer drawer, GraphicsDevice graphics, SpriteBatch batch, FontHandler font);
 public abstract void Draw(SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, GraphicsDevice graphicsDevice);
 public void Draw(SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, GraphicsDevice graphicsDevice)
 {
     element.Draw(spriteBatch, primitiveDrawer, fontHandler, graphicsDevice);
 }
Пример #42
0
 public void Render()
 {
     _circle.Radius = _highlightTween.Value();
     PrimitiveDrawer.DrawDashedCircle(_circle, new Color(1, 0, 0, 1));
 }
 private void DrawModes(SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, GraphicsDevice graphics)
 {
     foreach (DragDropElement element in modes)
     {
         element.Draw(spriteBatch, primitiveDrawer, fontHandler, graphics);
     }
 }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if(primitiveDrawer == null)
            {
                primitiveDrawer = new PrimitiveDrawer(GraphicsDevice.Viewport.TitleSafeArea.Width, GraphicsDevice.Viewport.TitleSafeArea.Height);
                primitiveDrawer.Setup(GraphicsDevice, 0, 0);
                dragDropInterface = new DragDropInterface(VirtualWidth, VirtualHeight);

            }

            handler.Update();

            if(handler.CheckPressedKey(Keys.LeftShift) && handler.CheckPressedKey(Keys.Escape))
            {
                state = 0;
            }

            currentMouseX = handler.GetMouseX();
            currentMouseY = handler.GetMouseY();

            mainMenu.Update(handler);

            if(state == 2)
            {

                if (handler.CheckJustPressedKey(Keys.Escape))
                {
                    state = 7;
                }

                editor.Update(handler);
                if(editor.Finished())
                {
                    string fileName = editor.GetFileName();
                    string safeFileName = editor.GetSafeFileName();
                    dragDropInterface.SetFile(fileName, safeFileName);
                    state = 3;
                }
            }
            else
            if(state ==4)
            {
                cache.Update(handler);
                pieceMode.Update(handler);
                back.Update(handler);
                optionsMenu.Update(handler);
                if (handler.CheckMouseIn(back) && handler.CheckLeftMouseJustPressed())
                {
                    state = 0;
                }

                if (handler.CheckMouseIn(pieceMode) && handler.CheckLeftMouseJustPressed())
                {
                    pieceModeA = !pieceModeA;

                    pieceMode.SetText((pieceModeA) ? "Piece Mode B" : "Piece Mode A");
                    ClassicTetrisGame.SetPieceMode(pieceModeA);
                }
            }
            else
            if (state == 0)
            {
                classic.Update(handler);
                maker.Update(handler);
                story.Update(handler);

                anyLevel.Update(handler);
                options.Update(handler);
                exit.Update(handler);

                if (handler.CheckMouseIn(options) && handler.CheckLeftMouseJustPressed())
                {
                    state = 4;
                    //classicLink.CreateGame("TajLevel.taj");
                }

                if (handler.CheckMouseIn(story) && handler.CheckLeftMouseJustPressed())
                {
                    string[] levels = package.GetProtectedLevels();

                    this.levels = new MainMenuButton[levels.Length];

                    for (int i = 0;i < levels.Length; i++)
                    {
                        this.levels[i] = new MainMenuButton(levels[i]);
                        this.levels[i].ModifyY(51 * i);
                    }

                        state = 9;
                }

                if (handler.CheckMouseIn(anyLevel) && handler.CheckLeftMouseJustPressed())
                {
                    string[] levelsN = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/TajTetris/LevelPacks");

                    List<string> levels = new List<string>();
                    for (int i = 0;i < levelsN.Length; i++)
                    {
                        if(levelsN[i].EndsWith(".taj"))
                        levels.Add(levelsN[i]);
                    }

                    this.levels = new MainMenuButton[levels.Count];

                    for (int i = 0;i < levels.Count;i++)
                    {
                        this.levels[i] = new MainMenuButton(Path.GetFileNameWithoutExtension(levels[i]));
                        this.levels[i].ModifyY(51 * i);
                    }

                    state = 8;
                }

                if (handler.CheckMouseIn(classic) && handler.CheckLeftMouseJustPressed())
                {
                    classicLink.CreateGame("TajLevel.taj");
                    Logger.WriteLine("Started new Classic Game.");
                    state = 1;
                }

                if (handler.CheckMouseIn(maker) && handler.CheckLeftMouseJustPressed())
                {
                    state = 2;
                }

                if (handler.CheckMouseIn(exit) && handler.CheckLeftMouseJustPressed())
                {
                    this.Exit();
                }
            }
            else
            if(state == 1)
            {

                classicLink.Update(handler);

                if(handler.CheckJustPressedKey(Keys.Escape))
                {
                    state = 5;
                }
            }
            else
            if(state == 3)
            {
                dragDropInterface.Update(handler);
            }
            else
               //dragDropInterface.Update(handler);

            if (state == 5 || state == 12 || state == 13)
            {
                Save.Update(handler);
                Load.Update(handler);
                back.Update(handler);

                if (handler.CheckMouseIn(back) && handler.CheckLeftMouseJustPressed())
                {
                    state = 0;
                }

                if (state == 5)
                {
                    if (handler.CheckMouseIn(Save) && handler.CheckLeftMouseJustPressed())
                    {

                        state = 1;
                        classicLink.SetFullSave(true);

                        Logger.WriteLine("Saved Classic Game.");
                        SaveFileSystem.SaveObjectToFile(classicLink, "ClassicGame.tajSave");
                    }

                    if (handler.CheckMouseIn(Load) && handler.CheckLeftMouseJustPressed())
                    {
                        classicLink = SaveFileSystem.LoadObjectFromFile<TajLevelLinker>("ClassicGame.tajSave", new GameLoader());

                        Logger.WriteLine("Loaded Classic Game.");
                        state = 1;
                    }

                    if (handler.CheckJustPressedKey(Keys.Escape))
                    {
                        state = 1;
                    }

                }

                if (state == 12)
                {
                    if (handler.CheckMouseIn(Save) && handler.CheckLeftMouseJustPressed())
                    {

                        state = 11;
                        freePlayLink.SetFullSave(true);
                        Logger.WriteLine("Saved Free Play Game.");
                        SaveFileSystem.SaveObjectToFile(freePlayLink, "FreePlayGame.tajSave");
                    }

                    if (handler.CheckMouseIn(Load) && handler.CheckLeftMouseJustPressed())
                    {
                        freePlayLink = SaveFileSystem.LoadObjectFromFile<TajLevelLinker>("FreePlayGame.tajSave", new GameLoader());

                        Logger.WriteLine("Loaded Freeplay Game.");
                        state = 11;
                    }

                    if (handler.CheckJustPressedKey(Keys.Escape))
                    {
                        state = 11;
                    }

                }

                if (state == 13)
                {
                    if (handler.CheckMouseIn(Save) && handler.CheckLeftMouseJustPressed())
                    {

                        state = 10;
                        classicLink.SetFullSave(true);

                        Logger.WriteLine("Saved Story Game.");
                        SaveFileSystem.SaveObjectToFile(classicLink, "StoryGame.tajSave");
                    }

                    if (handler.CheckMouseIn(Load) && handler.CheckLeftMouseJustPressed())
                    {
                        classicLink = SaveFileSystem.LoadObjectFromFile<TajLevelLinker>("StoryGame.tajSave", new GameLoader());

                        Logger.WriteLine("Loaded Story Game.");
                        state = 10;
                    }

                    if (handler.CheckJustPressedKey(Keys.Escape))
                    {
                        state = 10;
                    }

                }
            }

            else if (state ==7)
            {
                back.Update(handler);
                if (handler.CheckJustPressedKey(Keys.Escape))
                {
                    state = 2;
                }
                if (handler.CheckMouseIn(back) && handler.CheckLeftMouseJustPressed())
                {
                    state = 0;
                }

            }
            else if (state == 8)
            {
                optionsMenu.Update(handler);

                if (handler.CheckJustPressedKey(Keys.Escape))
                {
                    state = 0;
                }

                foreach (MainMenuButton b in levels)
                {
                    b.Update(handler);
                    b.ModifyY((int)(handler.LeftMouseDraggedBy().Y / 40.0f));

                    if (handler.CheckMouseIn(b) && handler.CheckLeftMouseJustPressed())
                    {

                            freePlayLink = SaveFileSystem.LoadObjectFromFile<TajLevelLinker>("LevelPacks/" + b.GetText() + ".taj", new GameLoader());
                            state = 11;
                            break;
                    }
                }
            }
            else if (state == 9)
            {
                optionsMenu.Update(handler);

                if(handler.CheckJustPressedKey(Keys.Escape))
                {
                    state = 0;
                }

               foreach(MainMenuButton b in levels)
               {
                   b.Update(handler);
                   b.ModifyY((int)(handler.LeftMouseDraggedBy().Y / 40.0f));

                   if (handler.CheckMouseIn(b) && handler.CheckLeftMouseJustPressed())
                   {
                       if(b.GetText() != "Locked")
                       {
                           storyLink = SaveFileSystem.LoadObjectFromFile<TajLevelLinker>("LevelPacks/" + b.GetText() + ".taj", new GameLoader());
                           storyLink.SetLevelPack(package);
                           state = 10;
                           break;
                       }
                   }
               }

            } else if (state == 10)
            {
                if (handler.CheckJustPressedKey(Keys.Escape))
                {
                    state = 13;
                }
                storyLink.Update(handler);

            }
            else if (state == 11)
            {

                if (handler.CheckJustPressedKey(Keys.Escape))
                {
                    state = 12;
                }
                freePlayLink.Update(handler);
            }

            //lnk.Update(handler);
            //tGame.Update(handler);
            base.Update(gameTime);
        }
        private void DrawSuggestions(SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, GraphicsDevice graphics)
        {
            int helperY = 50;

            foreach (LooseDragDropLink element in suggestions)
            {
                element.SetY(helperY);
                element.SetX(20);
                element.Draw(spriteBatch, primitiveDrawer, fontHandler, graphics);

                helperY += 31;
            }
        }
 public void Draw(SpriteBatch batch, FontHandler handler, GraphicsDevice graphics, PrimitiveDrawer drawer)
 {
     drawer.DrawRoundedRectangle(graphics, this, col);
     batch.DrawString(handler.GetVerdana(), text, GetVector() + new Vector2(20, 10), Color.Black);
 }
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, PrimitiveDrawer primitiveDrawer, FontHandler fontHandler, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice)
        {
           
            if(selected)
            {
                primitiveDrawer.DrawRoundedRectangle(graphicsDevice, this, colorB);
            } else
            {
                primitiveDrawer.DrawRoundedRectangle(graphicsDevice, this, colorA);
            }
            Vector2 vector = this.GetVector() + new Vector2(TetrisGameRunner.GetOffsetX(), TetrisGameRunner.GetOffsetY());
            
            vector.X += 3;
            vector.Y += 3;

            spriteBatch.DrawString(fontHandler.GetVerdana(), formatText(fontHandler), vector, Color.White);
            spriteBatch.End();
            spriteBatch.Begin();
        }
Пример #48
0
 private void RenderCentroid(ConvexPolyForm poly)
 {
     PrimitiveDrawer.DrawFilledCircle(poly.GetCentroid(), 15, new Color(1, 1, 0, 1));
 }
        public void Draw(GraphicsDevice graphicsDevice, SpriteBatch batch, PrimitiveDrawer drawer, FontHandler font)
        {
            world.Draw(graphicsDevice, batch, drawer, font);

            game.Draw(graphicsDevice, drawer, batch, font);

            if(GameEnded)
            {

                if(GameLost)
                batch.DrawString(font.GetVerdana(), "You Lost!", new Vector2(320,0) + TetrisGameRunner.GetOffsetVector(), Color.White);
                else
                batch.DrawString(font.GetVerdana(), "You Win!", new Vector2(320, 0) + TetrisGameRunner.GetOffsetVector(), Color.White);
            }
               batch.DrawString(font.GetVerdana(), text, new Vector2(320, 0) + TetrisGameRunner.GetOffsetVector(), Color.White);
        }
Пример #50
0
 protected override void onTweak()
 {
     PrimitiveDrawer.DrawFilledRectangle(mei.start.tx, mei.start.ty, mei.current.tx, mei.current.ty, new PrimitiveDrawer.Callback(cbTweak), null);
 }