Example #1
0
        public void AddPhysicsBodies()
        {
            Shape groundShape = new Shape();
            groundShape.Begin(true);
            groundShape.Add(new Vector2(-15, 0));
            groundShape.Add(new Vector2(-15, 1));
            groundShape.Add(new Vector2(15, 1));
            groundShape.Add(new Vector2(15, 0));
            groundShape.End();

            ground = new SpringBody(groundShape, float.PositiveInfinity, 0, 0, 0, 0);
            ground.is_static = true;
            ground.position.Y = -1;
            physics.Add(ground);

            float scale = 0.5f;
            Shape boxShape = new Shape();
            boxShape.Begin(true);
            boxShape.Add(new Vector2(0, 0));
            boxShape.Add(new Vector2(0, scale * 0.5f));
            boxShape.Add(new Vector2(scale * 0.5f, scale * 0.5f));
            boxShape.Add(new Vector2(scale * 0.5f, 0));
            boxShape.End();

            for (int i = 0; i < 50; i++)
            {
                bubble = new PressureBody(boxShape, 1, 1, 1300, 20, 1000, 20);
                bubble.position.Y = i * scale * 0.5f;
                bubble.position.X = 0;
                physics.Add(bubble);
            }

            Shape circleShape = new Shape();
            circleShape.Begin(true);
            for (int i = 320; i >= 0; i -= 40)
            {
                circleShape.Add(new Vector2((float)Math.Cos(i / 180f * Math.PI) * 0.25f, (float)Math.Sin(i / 180f * Math.PI) * 0.25f));
            }
            circleShape.End();

            bubble = new PressureBody(circleShape, 1, 1, 130, 20, 130, 20);
            bubble.position.Y = 5;
            bubble.position.X = 5;
            physics.Add(bubble);
        }