Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GravityObject"/> class.
        /// </summary>
        /// <param name="world">The World object.</param>
        /// <param name="debugViewXNA">The DebugViewXNA object.</param>
        /// <param name="content">The ContentManager object.</param>
        /// <param name="graphics">The GraphicsDeviceManager object.</param>
        /// <param name="position">The initial position of the sensor.</param>
        /// <param name="radius">The radius of the sensor's shape.</param>
        /// <param name="density">The density of the sensor.</param>
        /// <param name="strength">The gravity strength of the sensor.</param>
        /// <param name="minRadius">The minimum radius the gravity can affect.</param>
        /// <param name="maxRadius">The maximum radius the gravity can affect.</param>
        public GravityObject(World world,
            DebugViewXNA debugViewXNA,
            ContentManager content,
            GraphicsDeviceManager graphics,
            Vector2 position,
            float radius,
            float density,
            float strength,
            float minRadius,
            float maxRadius)
        {
            this.IsAlive = true;

            this.mWorld = world;
            this.mDebugViewXNA = debugViewXNA;
            this.mContent = content;
            this.mGraphics = graphics;
            //this.mPosition = ConvertUnits.ToSimUnits(position);
            this.mPosition = position;

            this.mRadius = ConvertUnits.ToSimUnits(radius);
            this.mDensity = density;
            this.mStrength = strength;
            this.mMinRadius = minRadius;
            this.mMaxRadius = maxRadius;

            this.mGravity = new GravityController(this.mStrength);
            this.mGravity.MinRadius = this.mMinRadius;
            this.mGravity.MaxRadius = this.mMaxRadius;
            this.mGravity.EnabledOnCategories = this.mEnabledOn;
            this.mGravity.GravityType = this.mGravityType;
            this.mGravity.Enabled = this.IsEnabled;

            this.mWorld.AddController(this.mGravity);

            this.mBody = BodyFactory.CreateBody(this.mWorld);
            this.mBody.Position = this.mPosition;
            this.mBody.IsSensor = true;

            this.mShape = new CircleShape(this.mRadius, this.mDensity);
            this.mBody.CreateFixture(this.mShape);
            this.mBody.CollidesWith = this.mCollidesWith;

            this.mBody.OnCollision += this.OnCollision;
            this.mBody.OnSeparation += this.OnSeparation;

            this.mGravity.AddBody(this.mBody);
        }