Exemplo n.º 1
0
        // Update world physics
        public void Update(float dt)
        {
            // Update the position of each rigid body & texture
            foreach (PhysObject po in DynamicObjects)
            {
                po.RigidBody.Update(dt, this, po);
                po.TexturePos = new Vector2(po.RigidBody.Position.X - (po.RigidBody.Width / 2), po.RigidBody.Position.Y - (po.RigidBody.Height / 2));
                po.Position   = po.RigidBody.Position;

                if (po.IsTarget)
                {
                    if (Math.Abs(po.RigidBody.LinearVelocity.X) != _portalSpeed)
                    {
                        po.RigidBody.LinearVelocity = new Vector2(Math.Sign(po.RigidBody.LinearVelocity.X) * _portalSpeed, po.RigidBody.LinearVelocity.Y);
                    }
                }

                if (po is Projectile)
                {
                    if (Math.Abs(po.RigidBody.LinearVelocity.Length()) != _projectileSpeed)
                    {
                        po.RigidBody.LinearVelocity = Vector2.Normalize(po.RigidBody.LinearVelocity);
                        po.RigidBody.LinearVelocity = new Vector2(po.RigidBody.LinearVelocity.X * _projectileSpeed, po.RigidBody.LinearVelocity.Y * _projectileSpeed);
                    }
                }

                if (po.MarkedForDeletion)
                {
                    DeletionList.Add(po);
                }
            }

            foreach (PhysObject po in StaticObjects)
            {
                if (po is MovingPlatform || po is Pendulum)
                {
                    po.RigidBody.Update(dt, this, po);
                    po.TexturePos = new Vector2(po.RigidBody.Position.X - (po.RigidBody.Width / 2), po.RigidBody.Position.Y - (po.RigidBody.Height / 2));
                    po.Position   = po.RigidBody.Position;
                }
            }

            // Delete objects marked for deletion
            for (int i = 0; i < DeletionList.Count; i++)
            {
                DynamicObjects.Remove(DeletionList[i]);
                AllPhysObjects.Remove(DeletionList[i]);

                if (DeletionList[i] is Character)
                {
                    World.Enemies.Remove((Character)DeletionList[i]);
                }

                DeletionList[i] = null;
            }
            DeletionList.Clear();

            CollisionDetection();
        }