Ejemplo n.º 1
0
        public override void Load()
        {
            //Physics.SetMeter(10);
            //m_world.SetGravity(0, -100);
            //float scale = 1 / Physics.GetMeter();
            {
                float a        = 0.5f * scale;
                var   ground   = Physics.NewBody(m_world, 0, -a);
                int   N        = 200;
                int   M        = 10;
                var   position = new Vector2();
                for (int32 j = 0; j < M; ++j)
                {
                    position.X = -N * a;
                    for (int32 i = 0; i < N; ++i)
                    {
                        var shape = Physics.NewRectangleShape(position.X * scale, position.Y * scale, a * 2 * scale, a * 2 * scale, 0);
                        Physics.NewFixture(ground, shape, 0);
                        ++m_fixtureCount;
                        groundToDraw.Add(new KeyValuePair <Body, PolygonShape>(ground, shape));

                        position.X += 2.0f * a;
                    }
                    position.Y -= 2.0f * a;
                }
            }

            {
                float32 a     = 0.5f * scale;
                var     shape = Physics.NewRectangleShape(0, 0, a * 2 * scale, a * 2 * scale, 0);
                //var shape = Physics.NewRectangleShape(0, 0, a, a, 0);

                var x      = new Vector2(-7.0f, 0.75f) * scale;
                var y      = new Vector2();
                var deltaX = new Vector2(0.5625f, 1.25f) * scale;
                var deltaY = new Vector2(1.125f, 0.0f) * scale;

                for (int32 i = 0; i < e_count; ++i)
                {
                    y = x;

                    for (int32 j = i; j < e_count; ++j)
                    {
                        var body = Physics.NewBody(m_world, y.X * scale, y.Y * scale, BodyType.Dynamic);
                        Physics.NewFixture(body, shape, 5.0f * scale);


                        ++m_fixtureCount;
                        listToDraw.Add(new KeyValuePair <Body, PolygonShape>(body, shape));

                        y += deltaY;
                    }

                    x += deltaX;
                }
            }
            // end of Load


            foreach (var body in m_world.GetBodies())
            {
                foreach (var f in body.GetFixtureList())
                {
                    PolygonShape sp      = f.GetShape() as PolygonShape;
                    var          pp      = sp.GetPoints();
                    var          rawData = new Vertex[] {
                        new Vertex(pp[0].X, pp[0].Y),
                        new Vertex(pp[1].X, pp[1].Y),
                        new Vertex(pp[2].X, pp[2].Y),
                        new Vertex(pp[3].X, pp[3].Y),
                    };

                    var sinfo = Love.Misc.MeshUtils.StandardVertexDescribe;
                    var m     = Graphics.NewMesh(sinfo, sinfo.TransToByte(rawData), MeshDrawMode.Fan, SpriteBatchUsage.Dynamic);

                    //Console.WriteLine("------------------------");
                    //Console.WriteLine(Love.Misc.MeshUtils.GetVertexFromData(m.GetVertex(0)));
                    //Console.WriteLine(Love.Misc.MeshUtils.GetVertexFromData(m.GetVertex(1)));
                    //Console.WriteLine(Love.Misc.MeshUtils.GetVertexFromData(m.GetVertex(2)));
                    //Console.WriteLine(Love.Misc.MeshUtils.GetVertexFromData(m.GetVertex(3)));

                    meshToDraw.Add(new KeyValuePair <Body, Mesh>(body, m));
                }
            }
        }