コード例 #1
0
        public static void Test()
        {
            using (GameWindow gw = new GameWindow(800, 600, OpenTK.Graphics.GraphicsMode.Default, "Dank Game")) {
                Game.Rectangle r = new Game.Rectangle(new List <Vector2> {
                    new Vector2(0.0f, 0.0f),
                    new Vector2(0.0f, 1.0f),
                    new Vector2(0.9f, 0.9f),
                    new Vector2(1.0f, 0.0f),
                }, Color.Purple, true);

                gw.Load += (sender, e) => {
                    gw.VSync = VSyncMode.On;
                };

                gw.Resize += (sender, e) => {
                    GL.Viewport(0, 0, gw.Width, gw.Height);
                };

                gw.UpdateFrame += (sender, e) => {
                    r.Body.AddForce(new Vector2(0.01f, 0));
                    r.Body.Update(1f / 60f);
                };

                gw.RenderFrame += (sender, e) => {
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                    Matrix4 modelview = Matrix4.LookAt(Vector3.UnitZ, -1 * Vector3.UnitZ, Vector3.UnitY);
                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadMatrix(ref modelview);
                    GL.Ortho(-5, 5, -5, 5, -1, 1);

                    foreach (Shape s in Shape.AllShapes)
                    {
                        if (s.Visible)
                        {
                            s.Render();
                        }
                    }

                    gw.SwapBuffers();
                };

                gw.Run(60.0);
            }
        }
コード例 #2
0
        public static void Test()
        {
            using (GameWindow gw = new GameWindow(800, 600, OpenTK.Graphics.GraphicsMode.Default, "Dank Game")) {
                Circle.GlobalResolution = 12;

                Game.Circle c = new Circle(Color.Yellow, true, new List <Vector2> {
                    new Vector2(-5.0f, 0.0f)
                }, 8.0f);
                Game.Circle d = new Circle(Color.Yellow, true, new List <Vector2> {
                    new Vector2(5.0f, 0.0f)
                }, 2.0f);

                Game.Rectangle r = new Game.Rectangle(new List <Vector2> {
                    new Vector2(2.0f, -2.0f),
                    new Vector2(4.0f, -2.0f),
                    new Vector2(4.0f, 2.0f),
                    new Vector2(2.0f, 2.0f),
                }, Color.Purple, true);

                Game.Rectangle s = new Game.Rectangle(new List <Vector2> {
                    new Vector2(-4.0f, -2.0f),
                    new Vector2(-2.0f, -2.0f),
                    new Vector2(-2.0f, 2.0f),
                    new Vector2(-4.0f, 2.0f),
                }, Color.Purple, true);

                foreach (Collider i in c.Coll.TestCollision())
                {
                    if (i.Parent is Circle)
                    {
                        Console.WriteLine("Intersection of c and d!");
                    }
                }

                foreach (Collider i in r.Coll.TestCollision())
                {
                    if (i.Parent is Game.Rectangle)
                    {
                        Console.WriteLine("Intersection of r and s!");
                    }
                }
            }
        }