Beispiel #1
0
 /// <summary>
 /// Destroys the physics objects associated with an <see cref="Exit"/> object.
 /// </summary>
 /// <param name="physicsWorld">The physics world.</param>
 public void Dispose(ref World physicsWorld)
 {
     if (physicsWorld != null)
     {
         physicsWorld.RemoveBody(this.physicsBody);
     }
 }
Beispiel #2
0
        public void Dispose()
        {
            if (!IsDisposed)
            {
                //TODO: Revise
                // Forcing OnSeparation for contacts from the ContactList.
                //ContactEdge contactEdge = ContactList;
                //Contact contact;

                //while (contactEdge != null && (contact = contactEdge.Contact) != null)
                //{
                //    //Report the separation to both participants:
                //    if (contact.FixtureA != null && contact.FixtureA.OnSeparation != null)
                //        contact.FixtureA.OnSeparation(contact.FixtureA, contact.FixtureB);

                //    //Reverse the order of the reported fixtures. The first fixture is always the one that the
                //    //user subscribed to.
                //    if (contact.FixtureB != null && contact.FixtureB.OnSeparation != null)
                //        contact.FixtureB.OnSeparation(contact.FixtureB, contact.FixtureA);

                //    contactEdge = contactEdge.Next;
                //}

                _world.RemoveBody(this);
                IsDisposed = true;
                GC.SuppressFinalize(this);
            }
        }
Beispiel #3
0
        public override void RemoveBodies(World world)
        {
            foreach (var body in _bodies)
                world.RemoveBody(body);

            _bodies.Clear();
        }
        private void Decompose()
        {
            //Unsubsribe from the PostSolve delegate
            _world.ContactManager.PostSolve -= PostSolve;

            for (int i = 0; i < Parts.Count; i++)
            {
                Fixture oldFixture = Parts[i];

                Shape  shape    = oldFixture.Shape.Clone();
                object userData = oldFixture.UserData;

                MainBody.DestroyFixture(oldFixture);

                Body body = BodyFactory.CreateBody(_world);
                body.BodyType = BodyType.Dynamic;
                body.Position = MainBody.Position;
                body.Rotation = MainBody.Rotation;
                body.UserData = MainBody.UserData;

                Fixture newFixture = body.CreateFixture(shape);
                newFixture.UserData = userData;
                Parts[i]            = newFixture;

                body.AngularVelocity = _angularVelocitiesCache[i];
                body.LinearVelocity  = _velocitiesCache[i];
            }

            _world.RemoveBody(MainBody);
            _world.RemoveBreakableBody(this);
        }
Beispiel #5
0
        public void Dispose()
        {
            if (!IsDisposed)
            {
                ContactEdge contactEdge = ContactList;
                Contact     contact;
                while (contactEdge != null && (contact = contactEdge.Contact) != null)
                {
                    //Report the separation to both participants:
                    if (contact.FixtureA != null && contact.FixtureA.OnSeparation != null)
                    {
                        contact.FixtureA.OnSeparation(contact.FixtureA, contact.FixtureB);
                    }

                    //Reverse the order of the reported fixtures. The first fixture is always the one that the
                    //user subscribed to.
                    if (contact.FixtureB != null && contact.FixtureB.OnSeparation != null)
                    {
                        contact.FixtureB.OnSeparation(contact.FixtureB, contact.FixtureA);
                    }

                    contactEdge = contactEdge.Next;
                }

                World.RemoveBody(this);
                IsDisposed = true;
                GC.SuppressFinalize(this);
            }
        }
Beispiel #6
0
 public void Dispose()
 {
     if (!IsDisposed)
     {
         _world.RemoveBody(this);
         IsDisposed = true;
     }
 }
Beispiel #7
0
 public void Dispose()
 {
     if (!IsDisposed)
     {
         World.RemoveBody(this);
         IsDisposed = true;
         GC.SuppressFinalize(this);
     }
 }
Beispiel #8
0
        public void Dispose()
        {
            if (!IsDisposed)
            {
                World.RemoveBody(this);
                IsDisposed = true;
#if !Html5
                GC.SuppressFinalize(this);
#endif
            }
        }
Beispiel #9
0
        /// <summary>
        /// Clears all bullets from all kinds of lists and from the world
        /// </summary>
        /// <param name="world"></param>
        public void Clear(World world)
        {
            try
            {

                foreach (DrawableGameObject d in bullets)
                {
                    world.RemoveBody(d.body);
                }
                bullets.Clear();
                removeList.Clear();
            }
            catch (Exception ex)
            {
                logger.Fatal(ex.Message + "  " + ex.TargetSite + "  " + ex.StackTrace);
            }
        }
Beispiel #10
0
 public override void RemoveBodies(World world)
 {
     world.RemoveBody(_body);
 }
Beispiel #11
0
 public void RemoveFromWorld(Dyn.World world)
 {
     world.RemoveBody(PBody);
     PBody = PBody.Clone(world: DummyWorld);
 }
Beispiel #12
0
 public void DisposePhysics(World world)
 {
     world.RemoveBody(m_Body);
 }
        public void CreateFruitShot(Vector2 firingLocation, World physicsWorld)
        {
            appleCopterTimer = 0;
            isAppleCopter = false;
            shot.TextureID = 20;
            shot.TextureIndex = 0;
            shot.CurrentFrame = 0;
            shot.IsEffect = false;
            shot.SpriteType = Sprite.Type.FruitShot;
            if (selectedAmmo == 0) shot.TextureIndex = LevelDataManager.rand.Next(0, 3) * 7; //gets random color of apple (sets 0,7,14 texture index on fruit sheet) if its an apple
            if (selectedAmmo == 1) shot.TextureIndex = 21;
            if (selectedAmmo == 2) shot.TextureIndex = 28;
            if (selectedAmmo == 3) shot.TextureIndex = 35;
            if (selectedAmmo == 4) shot.TextureIndex = 42;
            if (selectedAmmo == 5) shot.TextureIndex = 49;
            if (selectedAmmo == 6) shot.TextureIndex = 56;

            shot.TotalRotation = 0;
            shot.SpriteRectangle = new Rectangle ((int)firingLocation.X - 32, (int)firingLocation.Y -32, 64, 64);
            shot.IsExpired = false;
            shot.IsCollidable = true;
            shot.IsAwake = true;
            shot.IsVisible = true;
            shot.IsHit = false;
            shot.TintColor = new Color(255f,255f,255f,255f);
            shot.Scale = 1.0f;
            shot.IsAnimated = false;
            shot.AnimationFPS = animationSpeed;
            shot.CurrentFrame = LevelDataManager.rand.Next(0, 3);
            shot.pathing = Sprite.Pathing.None;
            shot.InitPathingPoint();
            shot.pathingTravelled = 0f;

            //create new body
            physicsWorld.RemoveBody(shot.spriteBody);
            Vector2 position = ConvertUnits.ToSimUnits(shot.Location + shot.SpriteOrigin);
            int spriteRow = shot.TextureIndex / LevelDataManager.SpritesInRow(shot);
            switch (spriteRow)
            {
                case 0:
                case 1:
                case 2:
                    {
                        //apple
                        Vertices vertices = new Vertices(9);
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(14f, 29f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-12f, 29f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-24f, 16f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-30f, -4f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-30f, -8f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-18f, -18f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(18f, -18f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(26f, -10f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(26f, 12f)));
                        shot.spriteBody = BodyFactory.CreatePolygon(physicsWorld, vertices, 1.0f, position, shot);
                        break;
                    }
                case 3:
                    {
                        //orange
                        shot.spriteBody = BodyFactory.CreateEllipse(physicsWorld, ConvertUnits.ToSimUnits(30f), ConvertUnits.ToSimUnits(30f), 10, 1.0f, position, shot);
                        break;
                    }
                case 4:
                    {
                        //strawberry
                        Vertices vertices = new Vertices(8);
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(8f, 30f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-8f, 30f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-24f, 6f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-24f, -8f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-10f, -17f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(10f, -17f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(24f, -8f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(24f, 10f)));
                        shot.spriteBody = BodyFactory.CreatePolygon(physicsWorld, vertices, 1.0f, position, shot);
                        break;
                    }
                case 5:
                    {
                        //cherry
                        Vertices vertices = new Vertices(8);
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(26f, 20f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(2f, 29f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-11f, 29f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-30f, 7f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-30f, -2f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-21f, -11f)));
                        //vertices.Add(ConvertUnits.ToSimUnits(new Vector2(0f, 0f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(23f, -1f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(28f, 7f)));
                        shot.spriteBody = BodyFactory.CreatePolygon(physicsWorld, vertices, 1.0f, position, shot);
                        splitShot[0].IsExpired = false;
                        splitShot[1].IsExpired = false;
                        splitShot[2].IsExpired = false;
                        break;
                    }
                case 6:
                    {
                        //banana
                        Vertices vertices = new Vertices(9);
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(11f, 30f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-6f, 30f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-25f, 14f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-26f, -8f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-10f, -25f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(1f, -25f)));
                        //vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-2f, 10f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(25f, 11f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(28f, 17f)));
                        shot.spriteBody = BodyFactory.CreatePolygon(physicsWorld, vertices, 1.0f, position, shot);
                        break;
                    }
                case 7:
                    {
                        //lemon
                        Vertices vertices = new Vertices(8);
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(10f, 29f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-10f, 29f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-25f, 15f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-25f, -7f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-10f, -22f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(10f, -22f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(23f, -7f)));
                        vertices.Add(ConvertUnits.ToSimUnits(new Vector2(23f, 15f)));
                        shot.spriteBody = BodyFactory.CreatePolygon(physicsWorld, vertices, 1.0f, position, shot);
                        break;
                    }
                case 8:
                    {
                        //watermelon
                        shot.spriteBody = BodyFactory.CreateEllipse(physicsWorld, ConvertUnits.ToSimUnits(30f), ConvertUnits.ToSimUnits(30f), 10, 1.0f, position, shot);
                        break;
                    }
                default:
                    break;
            }
            shot.spriteBody.Position = position;
            shot.spriteBody.ResetDynamics();
            shot.spriteBody.Mass = GameSettings.FruitMass;
            shot.spriteBody.Rotation = shot.TotalRotation;
            shot.spriteBody.BodyType = BodyType.Dynamic;
            shot.spriteBody.IgnoreGravity = false;
            shot.spriteBody.IsBullet = true;
            shot.spriteBody.Restitution = GameSettings.FruitBouncy;
            shot.spriteBody.Friction = GameSettings.FruitFriction;
            shot.HitPoints = GameSettings.FruitHP;

            //watermelon adjustment
            if (spriteRow == 8) shot.spriteBody.Mass *= 3;
            if (spriteRow == 8) shot.HitPoints *= 3;

            //if the shot is not an apple, use the fruit up (if it was a star,relay,or grow barrel)
            if (selectedAmmo != 0)
            {
                if (ActivePowerUpBarrel.TextureIndex == 0 || ActivePowerUpBarrel.TextureIndex == 6 || ActivePowerUpBarrel.TextureIndex == 7)
                {
                    if (!GameSettings.CheatLegion) //except cheat
                    {
                        ammoUI[selectedAmmo].TintColor = Color.Gray;
                        ammoUI[selectedAmmo].Scale = 1f;
                        selectedAmmo = 0;
                    }
                }
            }
            return;
        }
Beispiel #14
0
 /// <summary>
 /// Disposes of the body associated with the platform.
 /// </summary>
 /// <param name="physicsWorld">The physics world containing the body.</param>
 public void Dispose(ref World physicsWorld)
 {
     physicsWorld.RemoveBody(this.body);
 }
        /// <summary>
        /// This is a high-level function to cuts fixtures inside the given world, using the start and end points.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="start">The startpoint.</param>
        /// <param name="end">The endpoint.</param>
        /// <param name="thickness">The thickness of the cut</param>
        public static void Cut(World world, Vector2 start, Vector2 end, float thickness)
        {
            List<Fixture> fixtures = new List<Fixture>();
            List<Vector2> entryPoints = new List<Vector2>();
            List<Vector2> exitPoints = new List<Vector2>();

            // Get the entry points
            world.RayCast((f, p, n, fr) =>
                              {
                                  fixtures.Add(f);
                                  entryPoints.Add(p);
                                  return 1;
                              }, start, end);

            // Reverse the ray to get the exitpoints
            world.RayCast((f, p, n, fr) =>
                              {
                                  exitPoints.Add(p);
                                  return 1;
                              }, end, start);

            // We only have a single point. We need at least 2
            if (entryPoints.Count + exitPoints.Count < 2)
                return;

            // There should be as many entry as exit points
            if (entryPoints.Count != exitPoints.Count)
            {
                if (entryPoints.Count > exitPoints.Count)
                {
                    entryPoints.RemoveAt(entryPoints.Count - 1);
                    fixtures.RemoveAt(fixtures.Count - 1);
                }

                if (exitPoints.Count > entryPoints.Count)
                {
                    exitPoints.RemoveAt(exitPoints.Count - 1);
                    fixtures.RemoveAt(fixtures.Count - 1);
                }
            }

            for (int i = 0; i < fixtures.Count; i++)
            {
                // can't cut circles yet !
                if (fixtures[i].Shape.ShapeType != ShapeType.Polygon)
                    continue;

                if (fixtures[i].Body.BodyType != BodyType.Static)
                {
                    // Split the shape up into two shapes
                    Vertices first;
                    Vertices second;
                    SplitShape(fixtures[i], entryPoints[i], exitPoints[i], thickness, out first, out second);

                    // Delete the original shape and create two new. Retain the properties of the body.
                    Fixture firstFixture = FixtureFactory.CreatePolygon(world, first, fixtures[i].Density,
                                                                        fixtures[i].Body.Position);
                    firstFixture.Body.BodyType = BodyType.Dynamic;

                    Fixture secondFixture = FixtureFactory.CreatePolygon(world, second, fixtures[i].Density,
                                                                         fixtures[i].Body.Position);
                    secondFixture.Body.BodyType = BodyType.Dynamic;

                    world.RemoveBody(fixtures[i].Body);
                }
            }
        }
 public void RemoveBody(World world)
 {
     world.RemoveBody(this.spriteBody);
     ActivatePhysics(world);
     return;
 }
Beispiel #17
0
 public void Dispose()
 {
     _farseerWorld.RemoveBody(this._body);
     this._body = null;
 }
Beispiel #18
0
 public void Remove(World world)
 {
     world.RemoveBody(phys_body);
 }
Beispiel #19
0
        public void Update(World world, GameTime gameTime)
        {
            if (shieldDuration <= 0 || shieldHP <= 0)
            {
                shieldActivate = false;
                world.RemoveBody(shieldGfx.body);
                removeShield = true;
            }

            if (shieldActivate)
            {

                shieldDuration -= gameTime.ElapsedGameTime.TotalSeconds;
            }
        }
 public void Remove(Coin coin, World world)
 {
     world.RemoveBody(coin.Body);
     _coins.Remove(coin);
 }
Beispiel #21
0
        public override void Initialize()
        {
            Settings.VelocityIterations = 2;
            Settings.PositionIterations = 4;

            GameInstance.ViewCenter = Vector2.Zero;

            _worldSize = 2 * GameInstance.ConvertScreenToWorld(GameInstance.Window.ClientBounds.Width, 0);

            //Create a World using QuadTree constructor
            World = new World(new Vector2(0.0f, -10.0f), new AABB(-_worldSize / 2, _worldSize / 2));

            //Create a World using DynamicTree constructor
            //World = new World(new Vector2(0.0f, -10.0f));

            //
            //set up border
            //

            float halfWidth = _worldSize.X / 2 - 2f;
            float halfHeight = _worldSize.Y / 2 - 2f;

            Vertices borders = new Vertices(4);
            borders.Add(new Vector2(-halfWidth, halfHeight));
            borders.Add(new Vector2(halfWidth, halfHeight));
            borders.Add(new Vector2(halfWidth, -halfHeight));
            borders.Add(new Vector2(-halfWidth, -halfHeight));

            Body anchor = BodyFactory.CreateLoopShape(World, borders);
            anchor.CollisionCategories = Category.All;
            anchor.CollidesWith = Category.All;

            //
            //box
            //

            Vertices bigbox = PolygonTools.CreateRectangle(3f, 3f);
            PolygonShape bigshape = new PolygonShape(bigbox, 5);

            Body bigbody = BodyFactory.CreateBody(World);
            bigbody.BodyType = BodyType.Dynamic;
            bigbody.Position = Vector2.UnitX * 25;
            bigbody.CreateFixture(bigshape);

            World.RemoveBody(bigbody);

            //
            //populate
            //
            //const int rad = 12;
            //const float a = 0.6f;
            //const float sep = 0.000f;

            //Vector2 cent = Vector2.Zero;

            //for (int y = -rad; y <= +rad; y++)
            //{
            //    int xrad = (int)Math.Round(Math.Sqrt(rad * rad - y * y));
            //    for (int x = -xrad; x <= +xrad; x++)
            //    {
            //        Vector2 pos = cent + new Vector2(x * (2 * a + sep), y * (2 * a + sep));
            //        Body cBody = BodyFactory.CreateCircle(World, a, 55, pos);
            //        cBody.BodyType = BodyType.Dynamic;
            //    }
            //}

            base.Initialize();
        }
Beispiel #22
0
 public void Dispose()
 {
     World.RemoveBody(this);
     GC.SuppressFinalize(this);
 }
Beispiel #23
0
        /// <summary>
        /// This is a high-level function to cuts fixtures inside the given world, using the start and end points.
        /// Note: We don't support cutting when the start or end is inside a shape.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="start">The startpoint.</param>
        /// <param name="end">The endpoint.</param>
        /// <returns>True if the cut was performed.</returns>
        public static bool Cut(World world, Vector2 start, Vector2 end)
        {
            List<Fixture> fixtures = new List<Fixture>();
            List<Vector2> entryPoints = new List<Vector2>();
            List<Vector2> exitPoints = new List<Vector2>();

            //We don't support cutting when the start or end is inside a shape.
            if (world.TestPoint(start) != null || world.TestPoint(end) != null)
                return false;

            //Get the entry points
            world.RayCast((f, p, n, fr) =>
                              {
                                  fixtures.Add(f);
                                  entryPoints.Add(p);
                                  return 1;
                              }, start, end);

            //Reverse the ray to get the exitpoints
            world.RayCast((f, p, n, fr) =>
                              {
                                  exitPoints.Add(p);
                                  return 1;
                              }, end, start);

            //We only have a single point. We need at least 2
            if (entryPoints.Count + exitPoints.Count < 2)
                return false;

            for (int i = 0; i < fixtures.Count; i++)
            {
                // can't cut circles or edges yet !
                if (fixtures[i].Shape.ShapeType != ShapeType.Polygon)
                    continue;

                if (fixtures[i].Body.BodyType != BodyType.Static)
                {
                    //Split the shape up into two shapes
                    Vertices first;
                    Vertices second;
                    SplitShape(fixtures[i], entryPoints[i], exitPoints[i], out first, out second);

                    //Delete the original shape and create two new. Retain the properties of the body.
                    if (first.CheckPolygon() == PolygonError.NoError)
                    {
                        Body firstFixture = BodyFactory.CreatePolygon(world, first, fixtures[i].Shape.Density, fixtures[i].Body.Position);
                        firstFixture.Rotation = fixtures[i].Body.Rotation;
                        firstFixture.LinearVelocity = fixtures[i].Body.LinearVelocity;
                        firstFixture.AngularVelocity = fixtures[i].Body.AngularVelocity;
                        firstFixture.BodyType = BodyType.Dynamic;
                    }

                    if (second.CheckPolygon() == PolygonError.NoError)
                    {
                        Body secondFixture = BodyFactory.CreatePolygon(world, second, fixtures[i].Shape.Density, fixtures[i].Body.Position);
                        secondFixture.Rotation = fixtures[i].Body.Rotation;
                        secondFixture.LinearVelocity = fixtures[i].Body.LinearVelocity;
                        secondFixture.AngularVelocity = fixtures[i].Body.AngularVelocity;
                        secondFixture.BodyType = BodyType.Dynamic;
                    }

                    world.RemoveBody(fixtures[i].Body);
                }
            }

            return true;
        }
Beispiel #24
0
 /// <summary>
 /// Destroys the physics objects associated with a <see cref="Switch"/> instance.
 /// </summary>
 /// <param name="physicsWorld">The physics world.</param>
 public void Dispose(ref World physicsWorld)
 {
     this.activated = false;
     if (physicsWorld != null)
     {
         physicsWorld.RemoveBody(this.physicsBody);
     }
 }
        /// <summary>
        /// Stops the ball and resets the Body's state.
        /// </summary>
        /// <param name="world">The World that the ball's Body is in.</param>
        public void Stop(World world)
        {
            if (_body == null) {
            throw new InvalidOperationException("Call InitBody() on the Ball object first.");
              }
              /* We need to make the ball's Body object a static one again, but we can't do that
               * directly because that causes assertions to fail. We also can't disable the body and
               * then re-enable it because if a Body is disabled during an OnCollision event,
               * the Body's Fixture becomes null, and that causes an exception in the physics engine's
               * code because it calls OnCollision for both Bodies. Thus, we need to resort to
               * this workaround. - Jorenz */

              // Store the current position of the body, as we'll need to restore that position
              // when we recreate the Body object.
              Vector2 currentPos = _body.Position;
              // RemoveBody() actually does not remove the body immediately, which allows any
              // OnCollision events involving the ball to finish safely. The Ball's body will be
              // removed during the next timestep.
              world.RemoveBody(_body);
              // Don't keep a reference to the old Body.
              _body = null;

              // Call InitBody() again to get a new Body that is set to be static.
              InitBody(world);
              // Set the Body's position to where the old one used to be. Normally, the launcher
              // moves the Body anyway after this step, but if the ball has hit a goal, we want
              // the ball to stay where it is.
              _body.Position = currentPos;
        }
Beispiel #26
0
 /// <summary>
 /// Remove from physical World
 /// </summary>
 /// <param name="PhysicalWorld"></param>
 public void RemovePhysics(World PhysicalWorld)
 {
     if (Fixture != null)
     {
         PhysicalWorld.RemoveBody(Fixture.Body);
         _Fixture = null;
     }
 }
Beispiel #27
0
        /// <summary>
        /// Removes the floor bodies from the world and clears the list.
        /// </summary>
        /// <param name="physicsWorld">The physics world containing the floor.</param>
        /// <param name="floorEdges">The list of floor edge bodies.</param>
        /// <param name="visualFloorEdges">The list of visual floor edges.</param>
        public static void DisposeOfFloor(ref World physicsWorld, ref List<Body> floorEdges, ref List<VisualEdge> visualFloorEdges)
        {
            visualFloorEdges.Clear();
            foreach (Body body in floorEdges)
            {
                physicsWorld.RemoveBody(body);
            }

            floorEdges.Clear();
        }
Beispiel #28
0
 /// <summary>
 /// Disposes of the entity's physics body.
 /// </summary>
 /// <param name="physicsWorld">The physics world.</param>
 public void Dispose(ref World physicsWorld)
 {
     if (this.physicsBody != null)
     {
         this.Active = false;
         physicsWorld.RemoveBody(this.physicsBody);
         this.physicsBody = null;
     }
 }
 protected override void OnRemoveFromGame(World world)
 {
     //TODO: probably not the best place to create the power up
     this.doodadFactory.CreateDoodad(new DoodadPlacement() { DoodadType = DoodadType.PowerUp, Position = this.Position });
     world.RemoveBody(this.sensor);
 }
        public void CreatePowerUpShot(Sprite _shot, Vector2 firingLocation, World physicsWorld, Vector2 linearVelocity)
        {
            appleCopterTimer = 0;
            isAppleCopter = false;
            _shot.spriteBody.IsSensor = false; //makes physical body live to damage leaving barrel

            switch (ActivePowerUpBarrel.TextureIndex)
            {
                //relay barrel
                case 0:
                    {
                        _shot.TotalRotation = ActivePowerUpBarrel.TotalRotation;
                        _shot.Location = new Vector2((int)firingLocation.X - _shot.SpriteRectWidth / 2, (int)firingLocation.Y - _shot.SpriteRectHeight / 2);
                        _shot.spriteBody.Position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.IgnoreGravity = false;
                        _shot.IsVisible = true;
                        break;
                    }
                //fire barrel
                case 1:
                    {
                        _shot.TextureID = 10;
                        _shot.TextureIndex = 0;
                        _shot.SpriteType = Sprite.Type.FireballShot;
                        _shot.SpriteRectangle = new Rectangle((int)firingLocation.X - 126, (int)firingLocation.Y - 126, 252, 252);
                        _shot.IsEffect = true;
                        _shot.TotalRotation = ActivePowerUpBarrel.TotalRotation + MathHelper.ToRadians(-90);
                        _shot.IsExpired = false;
                        _shot.IsCollidable = true;
                        _shot.HitPoints = 1;
                        _shot.IsAwake = true;
                        _shot.IsVisible = true;
                        _shot.IsHit = false;
                        _shot.TintColor = new Color(255f, 255f, 255f, 255f);
                        _shot.Scale = 1.0f;
                        _shot.IsAnimated = false;
                        _shot.AnimationFPS = fireicelitanimationspeed;
                        _shot.AnimationFramePrecise = 0.0f;
                        _shot.CurrentFrame = 0;
                        _shot.pathing = Sprite.Pathing.None;
                        _shot.InitPathingPoint();
                        _shot.pathingTravelled = 0.001f;

                        physicsWorld.RemoveBody(_shot.spriteBody);
                        Vector2 position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        _shot.spriteBody = BodyFactory.CreateEllipse(physicsWorld, ConvertUnits.ToSimUnits(32f), ConvertUnits.ToSimUnits(32f), 8, 1.0f, position, _shot);

                        _shot.spriteBody.ResetDynamics();
                        _shot.spriteBody.Mass = 0.15f;
                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.BodyType = BodyType.Dynamic;
                        _shot.spriteBody.IgnoreGravity = true;
                        _shot.spriteBody.IsBullet = true;
                        _shot.spriteBody.IsSensor = true;
                        _shot.spriteBody.Restitution = 0.5f;
                        _shot.spriteBody.Friction = 0.5f;

                        //poof barrel if its not the starting barrel
                        if (ActivePowerUpBarrel.HitPoints >= 0 && ActivePowerUpBarrel != ShotStartBarrel) ActivePowerUpBarrel.IsHit = true;

                        break;
                    }
                //ice barrel
                case 2:
                    {
                        _shot.TextureID = 5;
                        _shot.TextureIndex = 0;
                        _shot.SpriteType = Sprite.Type.IceShot;
                        _shot.SpriteRectangle = new Rectangle((int)firingLocation.X - 126, (int)firingLocation.Y - 126, 252, 252);
                        _shot.IsEffect = true;
                        _shot.TotalRotation = ActivePowerUpBarrel.TotalRotation + MathHelper.ToRadians(-90);
                        _shot.IsExpired = false;
                        _shot.IsCollidable = true;
                        _shot.HitPoints = 1;
                        _shot.IsAwake = true;
                        _shot.IsVisible = true;
                        _shot.IsHit = false;
                        _shot.TintColor = new Color(255f, 255f, 255f, 255f);
                        _shot.Scale = 1.0f;
                        _shot.IsAnimated = true;
                        _shot.IsAnimatedWhileStopped = true;
                        _shot.IsBounceAnimated = false;
                        _shot.IsAnimationDirectionForward = true;
                        _shot.AnimationFPS = fireicelitanimationspeed;
                        _shot.AnimationFramePrecise = 0.0f;
                        _shot.CurrentFrame = 0;
                        _shot.pathing = Sprite.Pathing.None;
                        _shot.InitPathingPoint();
                        _shot.pathingTravelled = 0.001f;

                        physicsWorld.RemoveBody(_shot.spriteBody);
                        Vector2 position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        _shot.spriteBody = BodyFactory.CreateEllipse(physicsWorld, ConvertUnits.ToSimUnits(32f), ConvertUnits.ToSimUnits(32f), 8, 1.0f, position, _shot);

                        _shot.spriteBody.ResetDynamics();
                        _shot.spriteBody.Mass = 0.15f;
                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.BodyType = BodyType.Dynamic;
                        _shot.spriteBody.IgnoreGravity = true;
                        _shot.spriteBody.IsBullet = true;
                        _shot.spriteBody.IsSensor = true;
                        _shot.spriteBody.Restitution = 0.5f;
                        _shot.spriteBody.Friction = 0.5f;

                        //poof barrel if its not the starting barrel
                        if (ActivePowerUpBarrel.HitPoints >= 0 && ActivePowerUpBarrel != ShotStartBarrel) ActivePowerUpBarrel.IsHit = true;
                        break;
                    }
                //lightning barrel
                case 3:
                    {
                        _shot.TextureID = 11; //lightning effect
                        _shot.TextureIndex = 0;
                        _shot.SpriteType = Sprite.Type.LightningShot;
                        _shot.SpriteRectangle = new Rectangle((int)firingLocation.X - 252, (int)firingLocation.Y - 252, 504, 504);
                        _shot.IsEffect = true;
                        _shot.TotalRotation = ActivePowerUpBarrel.TotalRotation + MathHelper.ToRadians(-90);
                        _shot.IsExpired = false;
                        _shot.IsCollidable = true;
                        _shot.HitPoints = 1;
                        _shot.IsAwake = true;
                        _shot.IsVisible = true;
                        _shot.IsHit = false;
                        _shot.TintColor = new Color(255f, 255f, 255f, 255f);
                        _shot.Scale = 1.0f;
                        _shot.IsAnimated = false;
                        _shot.AnimationFPS = fireicelitanimationspeed;
                        _shot.AnimationFramePrecise = 0.0f;
                        _shot.CurrentFrame = 0;
                        _shot.pathing = Sprite.Pathing.None;
                        _shot.InitPathingPoint();
                        _shot.pathingTravelled = 0.001f;

                        physicsWorld.RemoveBody(_shot.spriteBody);
                        Vector2 position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        _shot.spriteBody = BodyFactory.CreateEllipse(physicsWorld, ConvertUnits.ToSimUnits(32f), ConvertUnits.ToSimUnits(32f), 8, 1.0f, position, _shot);

                        _shot.spriteBody.ResetDynamics();
                        _shot.spriteBody.Mass = 0.15f;
                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.BodyType = BodyType.Dynamic;
                        _shot.spriteBody.IgnoreGravity = true;
                        _shot.spriteBody.IsBullet = true;
                        _shot.spriteBody.IsSensor = true;
                        _shot.spriteBody.Restitution = 0.5f;
                        _shot.spriteBody.Friction = 0.5f;

                        //poof barrel if its not the starting barrel
                        if (ActivePowerUpBarrel.HitPoints >= 0 && ActivePowerUpBarrel != ShotStartBarrel) ActivePowerUpBarrel.IsHit = true;
                        break;
                    }
                //tnt barrel
                case 4:
                    {
                        _shot.TextureID = 49; //tnt
                        _shot.TextureIndex = 0;
                        _shot.IsEffect = false;
                        _shot.HitPoints = 10;
                        _shot.IsAnimated = false;
                        _shot.AnimationFramePrecise = 0.0f;
                        _shot.CurrentFrame = 0;
                        _shot.IsCollidable = true;
                        _shot.IsAwake = true;
                        _shot.IsVisible = true;
                        _shot.SpriteType = Sprite.Type.ExplosiveShot;
                        _shot.TotalRotation = ActivePowerUpBarrel.TotalRotation;
                        _shot.SpriteRectangle = new Rectangle((int)firingLocation.X - 32, (int)firingLocation.Y - 32, 64, 64);
                        _shot.spriteBody.Position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        physicsWorld.RemoveBody(_shot.spriteBody);
                        Vector2 position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        _shot.spriteBody = BodyFactory.CreateRectangle(physicsWorld, ConvertUnits.ToSimUnits(64f), ConvertUnits.ToSimUnits(64f), GameSettings.WoodDensity, position, _shot);
                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.IgnoreGravity = false;
                        _shot.spriteBody.BodyType = BodyType.Dynamic;
                        _shot.spriteBody.IsBullet = true;
                        _shot.spriteBody.IsSensor = false;
                        _shot.spriteBody.Mass = _shot.spriteBody.Mass * GameSettings.WoodDensity;
                        _shot.spriteBody.Restitution = GameSettings.WoodRestitution;
                        _shot.spriteBody.Friction = GameSettings.WoodFriction;

                        //poof barrel if its not the starting barrel
                        if (ActivePowerUpBarrel.HitPoints >= 0 && ActivePowerUpBarrel != ShotStartBarrel) ActivePowerUpBarrel.IsHit = true;
                        break;
                    }
                //teleport barrel //NOt imlimented
                case 5:
                    {
                        ActivePowerUpBarrel.TotalRotation = _shot.TotalRotation;
                        _shot.Location = new Vector2((int)firingLocation.X - _shot.SpriteRectWidth / 2, (int)firingLocation.Y - _shot.SpriteRectHeight / 2);
                        _shot.spriteBody.Position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.IgnoreGravity = false;
                        _shot.IsVisible = true;
                        break;
                    }
                //star barrel
                case 6:
                    {
                        _shot.TotalRotation = ActivePowerUpBarrel.TotalRotation;
                        _shot.Location = new Vector2((int)firingLocation.X - _shot.SpriteRectWidth / 2, (int)firingLocation.Y - _shot.SpriteRectHeight / 2);
                        _shot.spriteBody.Position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.IgnoreGravity = false;
                        _shot.IsVisible = true;
                        break;
                    }
                //grow barrel
                case 7:
                    {
                        _shot.TotalRotation = ActivePowerUpBarrel.TotalRotation;
                        _shot.SpriteRectangle = new Rectangle((int)firingLocation.X - 32, (int)firingLocation.Y - 32, 64, 64);
                        _shot.spriteBody.IgnoreGravity = false;
                        _shot.IsVisible = true;
                        _shot.Scale = 1.5f;
                        _shot.HitPoints = GameSettings.FruitHP * 5;
                        _shot.spriteBody.Mass = _shot.spriteBody.Mass * 4f;
                        _shot.spriteBody.ResetDynamics();

                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.BodyType = BodyType.Dynamic;
                        _shot.spriteBody.IgnoreGravity = false;
                        _shot.spriteBody.IsBullet = true;
                        _shot.spriteBody.IsSensor = false;
                        _shot.spriteBody.Restitution = 0.5f;
                        _shot.spriteBody.Friction = 0.5f;

                        //poof barrel if its not the starting barrel
                        if (ActivePowerUpBarrel.HitPoints >= 0 && ActivePowerUpBarrel != ShotStartBarrel) ActivePowerUpBarrel.IsHit = true;
                        break;
                    }
                //cannonball barrel
                case 8:
                    {
                        _shot.TextureID = 30; //4x4 sphere
                        _shot.TextureIndex = 4;
                        _shot.IsEffect = false;
                        _shot.HitPoints = 10000;
                        _shot.IsAnimated = false;
                        _shot.AnimationFramePrecise = 0.0f;
                        _shot.CurrentFrame = 0;
                        _shot.IsCollidable = true;
                        _shot.IsAwake = true;
                        _shot.IsVisible = true;
                        _shot.SpriteType = Sprite.Type.CannonballShot;
                        _shot.TotalRotation = ActivePowerUpBarrel.TotalRotation;
                        _shot.SpriteRectangle = new Rectangle((int)firingLocation.X - 32, (int)firingLocation.Y - 32, 64, 64);
                        _shot.spriteBody.Position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        physicsWorld.RemoveBody(_shot.spriteBody);
                        Vector2 position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        _shot.spriteBody = BodyFactory.CreateEllipse(physicsWorld, ConvertUnits.ToSimUnits(32f), ConvertUnits.ToSimUnits(32f), 12, 1.0f, position, _shot);
                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.IgnoreGravity = false;
                        _shot.spriteBody.BodyType = BodyType.Dynamic;
                        _shot.spriteBody.IsBullet = true;
                        _shot.spriteBody.IsSensor = false;
                        _shot.spriteBody.Mass = _shot.spriteBody.Mass * GameSettings.MetalDensity;
                        _shot.spriteBody.Restitution = GameSettings.MetalRestitution;
                        _shot.spriteBody.Friction = GameSettings.MetalFriction;

                        //poof barrel if its not the starting barrel
                        if (ActivePowerUpBarrel.HitPoints >= 0 && ActivePowerUpBarrel != ShotStartBarrel) ActivePowerUpBarrel.IsHit = true;
                        break;
                    }
                //sawshot barrel
                case 9:
                    {
                        _shot.TextureID = 47; //64x64 saw
                        _shot.TextureIndex = 0;
                        _shot.IsEffect = false;
                        _shot.HitPoints = 10000;
                        _shot.IsAnimated = false;
                        _shot.AnimationFramePrecise = 0.0f;
                        _shot.CurrentFrame = 0;
                        _shot.IsCollidable = true;
                        _shot.IsAwake = true;
                        _shot.IsVisible = true;
                        _shot.SpriteType = Sprite.Type.SawShot;
                        _shot.TotalRotation = ActivePowerUpBarrel.TotalRotation;
                        _shot.SpriteRectangle = new Rectangle((int)firingLocation.X - 32, (int)firingLocation.Y - 32, 64, 64);
                        _shot.spriteBody.Position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        physicsWorld.RemoveBody(_shot.spriteBody);
                        Vector2 position = ConvertUnits.ToSimUnits(_shot.SpriteCenterInWorld);
                        _shot.spriteBody = BodyFactory.CreateEllipse(physicsWorld, ConvertUnits.ToSimUnits(32f), ConvertUnits.ToSimUnits(32f), 12, GameSettings.MetalDensity, position, _shot);
                        _shot.spriteBody.Rotation = _shot.TotalRotation;
                        _shot.spriteBody.IgnoreGravity = true;
                        _shot.spriteBody.BodyType = BodyType.Dynamic;
                        _shot.spriteBody.IsBullet = true;
                        _shot.spriteBody.IsSensor = true;
                        _shot.spriteBody.Restitution = GameSettings.MetalRestitution;
                        _shot.spriteBody.Friction = GameSettings.MetalFriction;

                        //poof barrel if its not the starting barrel
                        if (ActivePowerUpBarrel.HitPoints >= 0 && ActivePowerUpBarrel != ShotStartBarrel) ActivePowerUpBarrel.IsHit = true;
                        break;
                    }
                default:
                    break;
            }

            if (_shot.SpriteType == Sprite.Type.FireballShot || _shot.SpriteType == Sprite.Type.LightningShot || _shot.SpriteType == Sprite.Type.IceShot) fireicelitFixedVelocity = linearVelocity;

            return;
        }