示例#1
0
        private BuoyancyTest()
        {
            World.Gravity = new Vector2(0, -9.82f);

            BodyFactory.CreateEdge(World, new Vector2(-40, 0), new Vector2(40, 0));

            float offset = 5;
            for (int i = 0; i < 3; i++)
            {
                Body rectangle = BodyFactory.CreateRectangle(World, 2, 2, 1, new Vector2(-30 + offset, 20));
                rectangle.Rotation = Rand.RandomFloat(0, 3.14f);
                rectangle.BodyType = BodyType.Dynamic;
                offset += 7;
            }

            for (int i = 0; i < 3; i++)
            {
                Body rectangle = BodyFactory.CreateCircle(World, 1, 1, new Vector2(-30 + offset, 20));
                rectangle.Rotation = Rand.RandomFloat(0, 3.14f);
                rectangle.BodyType = BodyType.Dynamic;
                offset += 7;
            }

            AABB container = new AABB(new Vector2(0, 10), 60, 10);
            BuoyancyController buoyancy = new BuoyancyController(container, 2, 2, 1, World.Gravity);
            World.AddController(buoyancy);
        }
示例#2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="game"></param>
 /// <param name="world"></param>
 /// <param name="position">The top left corner</param>
 /// <param name="width">The width of the container</param>
 /// <param name="height">The height of a container</param>
 public Water(Game game, SpriteBatch spriteBatch, World world, Vector2 position, float width, float height)
 {
     sprite = new LoopSpriteAnimator(game, spriteBatch, game.Content.Load<Texture2D>("Images/Sprites/gb"), 200, 6, 1, 6);
     position = new Vector2(position.X + width/2,position.Y + height/2);
     texture = new TexturedGameEntity(game, position,0,"Images/water",0.3f);
     var container = new AABB(ConvertUnits.ToSimUnits(position),ConvertUnits.ToSimUnits(width),ConvertUnits.ToSimUnits(height));
     var buoyancy = new BuoyancyController(container, 1.1f, 2, 1, world.Gravity);
     world.AddController(buoyancy);
 }
示例#3
0
 public Water(World w, int index, Vector2 pos, string width, string height)
     : base()
 {
     this.world = w;
     this.Index = index;
     this.width = float.Parse(width);
     this.height = float.Parse(height);
     this.Position = pos;
     this.Container = new AABB((pos - new Vector2(this.width / 2, this.height / 2)) * MainGame.PIXEL_TO_METER, (pos + new Vector2(this.width / 2, this.height / 2)) * MainGame.PIXEL_TO_METER);
     BuoyancyController buoyancy = new BuoyancyController(Container, 1.0f, 0.3f, 0.3f, w.Gravity);
     buoyancy.AddDisabledCategory(Category.Cat1);
     w.AddController(buoyancy);
     this.texture = MainGame.blank;
 }
示例#4
0
        public override void Start()
        {
            base.Start();

            AABB waterBounds = new AABB(new FVector2(0f, -360f / physScale), new FVector2(640f / physScale, -200f / physScale));
            controller = new BuoyancyController(waterBounds, 2.0f, 5f, 2f, FSWorldComponent.PhysicsWorld.Gravity);

            // add the controller
            FSWorldComponent.PhysicsWorld.AddController(controller);

            bodies = new List<FSBody>();
            FSBody tbody;
            // Spawn in a bunch of crap
            for(int i = 0; i < 5; i++)
            {
                tbody = BodyFactory.CreateRectangle(FSWorldComponent.PhysicsWorld, (Random.value * 5f + 10f) / physScale, (Random.value * 5f + 10f) / physScale, 1f, new FVector2((Random.value * 400f + 120f) / physScale, (Random.value * -150f - 50f) / physScale));
                tbody.Rotation = Random.value * Mathf.PI;
                tbody.BodyType = BodyType.Dynamic;
                bodies.Add(tbody);
            }
            for(int i = 0; i < 5; i++)
            {
                tbody = BodyFactory.CreateCircle(FSWorldComponent.PhysicsWorld, (Random.value * 5f + 10f) / physScale, 0.5f, new FVector2((Random.value * 400f + 120f) / physScale, (Random.value * -150f - 50f) / physScale));
                tbody.Rotation = Random.value * Mathf.PI;
                tbody.BodyType = BodyType.Dynamic;
                bodies.Add(tbody);
            }
            for(int i = 0; i < 15; i++)
            {
                Vertices vlist = new Vertices();
                if(Random.value > 0.66f)
                {
                    vlist.Add(new FVector2((10f + Random.value * 10f) / physScale, (-10f - Random.value * 10f) / physScale));
                    vlist.Add(new FVector2((5f + Random.value * 10f) / physScale, (10f + Random.value * 10f) / physScale));
                    vlist.Add(new FVector2((-5f - Random.value * 10f) / physScale, (10f + Random.value * 10f) / physScale));
                    vlist.Add(new FVector2((-10f - Random.value * 10f) / physScale, (-10f - Random.value * 10f) / physScale));
                }
                else if(Random.value > 0.5f)
                {
                    FVector2 v00 = new FVector2(0f, (-10f - Random.value * 10f) / physScale);
                    FVector2 v02 = new FVector2((-5f - Random.value * 10f) / physScale, (10f + Random.value * 10f) / physScale);
                    FVector2 v03 = new FVector2((5f + Random.value * 10f) / physScale, (10f + Random.value * 10f) / physScale);
                    FVector2 v01 = new FVector2(v00.X + v02.X, v00.Y + v02.Y);
                    v01 *= Random.value / 2f + 0.8f;
                    FVector2 v04 = new FVector2(v03.X + v00.X, v03.Y + v00.Y);
                    v04 *= Random.value / 2f + 0.8f;
                    vlist.Add(v04); vlist.Add(v03); vlist.Add(v02); vlist.Add(v01); vlist.Add(v00);
                }
                else
                {
                    vlist.Add(new FVector2((5f + Random.value * 10f) / physScale, (10f + Random.value * 10f) / physScale));
                    vlist.Add(new FVector2((-5f - Random.value * 10f) / physScale, (10f + Random.value * 10f) / physScale));
                    vlist.Add(new FVector2(0f, (-10f - Random.value * 10f) / physScale));
                }
                tbody = BodyFactory.CreateCompoundPolygon(FSWorldComponent.PhysicsWorld, new List<Vertices>{vlist}, 1f, new FVector2((Random.value * 400f + 120f) / physScale, (Random.value * -150f - 50f) / physScale));
                tbody.Rotation = Random.value * Mathf.PI;
                tbody.BodyType = BodyType.Dynamic;
                bodies.Add(tbody);
            }

            //Add some exciting bath toys
            tbody = new FSBody(FSWorldComponent.PhysicsWorld);
            tbody.Position = new FVector2(50f / physScale, -300f / physScale);
            tbody.BodyType = BodyType.Dynamic;
            FixtureFactory.AttachRectangle(80f / physScale, 20f / physScale, 3f, FVector2.Zero, tbody);
            bodies.Add(tbody);

            tbody = new FSBody(FSWorldComponent.PhysicsWorld);
            tbody.Position = new FVector2(300f / physScale, -300f / physScale);
            tbody.BodyType = BodyType.Dynamic;
            FixtureFactory.AttachSolidArc(2f, Mathf.PI * 2f, 8, 7f / physScale,
                new FVector2(30f / physScale, 0f), 0f, tbody);
            FixtureFactory.AttachSolidArc(2f, Mathf.PI * 2f, 8, 7f / physScale,
                new FVector2(-30f / physScale, 0f), 0f, tbody);
            FixtureFactory.AttachRectangle(60f / physScale, 4f / physScale, 2f, FVector2.Zero, tbody);
            FixtureFactory.AttachSolidArc(2f, Mathf.PI * 2f, 8, 7f / physScale,
                new FVector2(0f, 30f / physScale), 0f, tbody);
            FixtureFactory.AttachSolidArc(2f, Mathf.PI * 2f, 8, 7f / physScale,
                new FVector2(0f, -30f / physScale), 0f, tbody);
            FixtureFactory.AttachRectangle(4f / physScale, 60f / physScale, 2f, FVector2.Zero, tbody);
        }