private ControllerTest() { //Ground BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f)); //Create the gravity controller GravityController gravity = new GravityController(20); gravity.DisabledOnGroup = 3; gravity.EnabledOnGroup = 2; gravity.DisabledOnCategories = Category.Cat2; gravity.EnabledOnCategories = Category.Cat3; World.AddController(gravity); Vector2 startPosition = new Vector2(-10, 2); Vector2 offset = new Vector2(2); //Create the planet Body planet = BodyFactory.CreateBody(World); planet.Position = new Vector2(0, 20); CircleShape planetShape = new CircleShape(2, 1); planet.CreateFixture(planetShape); //Add the planet as the one that has gravity gravity.AddBody(planet); //Create 10 smaller circles for (int i = 0; i < 10; i++) { Body circle = BodyFactory.CreateBody(World); circle.BodyType = BodyType.Dynamic; circle.Position = startPosition + offset * i; circle.SleepingAllowed = false; CircleShape circleShape = new CircleShape(1, 0.1f); Fixture fix = circle.CreateFixture(circleShape); fix.CollisionCategories = Category.Cat3; fix.CollisionGroup = 2; if (i == 4) { circle.ControllerFilter.IgnoreController(ControllerType.GravityController); } if (i == 5) { fix.CollisionCategories = Category.Cat2; } if (i == 6) { fix.CollisionGroup = 3; } } }
public Blackhole(World world) : base(world) { gravityController = new GravityController(150.0f, 60f, 0f); gravityController.World = world; gravityController.AddDisabledCategory(Category.Cat1); gravityController.AddDisabledCategory(Category.Cat3); gravityController.AddDisabledCategory(Category.Cat2); gravityController.AddDisabledCategory(Category.Cat4); gravityController.AddBody(Body); Body.CollidesWith = Category.Cat5; Body.IgnoreGravity = true; Body.BodyType = BodyType.Static; HP = 99999999; }
public void performGravitySphere() { if (!performingGravitySphere && energy > 10) { performingGravitySphere = true; energy -= 10; //create sphere first gravity = new GravityController(5f, 10f, 2f); //gravity.DisabledOnGroup = 3; //gravity.EnabledOnGroup = 2; gravity.DisabledOnCategories = Category.Cat4; gravity.EnabledOnCategories = Category.Cat3; GameplayScreen._world.AddController(gravity); // fixture for planet (the one that has gravity) planet = BodyFactory.CreateBody(GameplayScreen._world); planet.Position = GameplayScreen.clickedPosition; CircleShape planetShape = new CircleShape(2, 1); planet.CreateFixture(planetShape); planet.CollidesWith = Category.None; planet.IgnoreCCD = false; gravity.AddBody(planet); listOfCurrentPlanets.Add(planet); for (int i = 0; i < GameplayScreen._world.BodyList.Count; i++) { Body p = GameplayScreen._world.BodyList[i]; GameplayScreen._world.BodyList[i] = p; } Timer newTimer = new Timer(new undoGravitySphereDelegate(this.undoGravitySphere), GameplayScreen.getInstance().getCurrentGameTime(), 2500); GameplayScreen.getInstance().gameTimers.addTimer(newTimer); } }