Esempio n. 1
0
        private void Body_OnCollision(Fixture fixtureA, Fixture fixtureB, VelcroPhysics.Collision.ContactSystem.Contact contact)
        {
            WorldComponent ground = (fixtureB.Body.UserData as WorldComponent);

            if (ground != null)
            {
                RectangleFloat bounds     = ground.Bounds;
                RectangleFloat heroBounds = Platman.Bounds;

                var bottom = Math.Abs(heroBounds.Bottom - bounds.Top);
                var top    = Math.Abs(heroBounds.Top - bounds.Bottom);
                var left   = Math.Abs(heroBounds.Left - bounds.Right);
                var right  = Math.Abs(heroBounds.Right - bounds.Left);

                float[] values = new float[] { bottom, top, left, right };

                Array.Sort(values);

                float edge = values[0];

                bool b = false;

                if (World.Gravity == VelocityValues.Instance.GravityDown)
                {
                    if (heroBounds.Bottom <= bounds.Top && bottom == edge)
                    {
                        b = true;
                    }
                }
                else if (World.Gravity == VelocityValues.Instance.GravityUp)
                {
                    if (heroBounds.Top > bounds.Bottom && top == edge)
                    {
                        b = true;
                    }
                }
                else if (World.Gravity == VelocityValues.Instance.GravityRight)
                {
                    if (heroBounds.Right <= bounds.Left && right == edge)
                    {
                        b = true;
                    }
                }
                else if (World.Gravity == VelocityValues.Instance.GravityLeft)
                {
                    if (heroBounds.Left > bounds.Right && left == edge)
                    {
                        b = true;
                    }
                }

                if (b)
                {
                    isOverGround = true;
                    overGround   = ground;
                    ApplyFallColisionImpulse();
                }
            }
        }
Esempio n. 2
0
        private void Body_OnSeparation(Fixture fixtureA, Fixture fixtureB, VelcroPhysics.Collision.ContactSystem.Contact contact)
        {
            WorldComponent ground = (fixtureB.Body.UserData as WorldComponent);

            if (overGround == ground)
            {
                isOverGround = false;
            }
        }
Esempio n. 3
0
        private void Body_OnCollision(Fixture fixtureA, Fixture fixtureB, VelcroPhysics.Collision.ContactSystem.Contact contact)
        {
            if ((string)fixtureB.Body.UserData == (string)"Zombie" && cooldown > 20)
            {
                cooldown = 0;
                Vector2 mousePosition = ConvertUnits.ToDisplayUnits(fixtureB.Body.Position);

                Vector2 direction = mousePosition - ConvertUnits.ToDisplayUnits(fixtureA.Body.Position);
                direction.Normalize();
                float rotation = fixtureB.Body.Rotation;
                // движение к персонажу

                changedColor = Color.Red;
                fixtureB.Body.ApplyLinearImpulse(-(new Vector2((float)Math.Sin(rotation) * 10f, (float)Math.Cos(rotation) * 10f)));
                fixtureA.Body.ApplyLinearImpulse(new Vector2((float)Math.Sin(rotation) * 30f, (float)Math.Cos(rotation) * 30f));
                // fixtureA.Body.ApplyLinearImpulse(fixtureB.Body.Rotation)
            }
        }
Esempio n. 4
0
        private void OnCollision(Fixture ourFixture, Fixture theirFixture, VelcroPhysics.Collision.ContactSystem.Contact contact)
        {
            Body ourBody   = ourFixture.Body;
            Body theirBody = theirFixture.Body;

            Debug.Assert(ourBody == BodyComponent.Body);

            //Global.HandleDefaultHit(theirBody, ourBody.Position, Damage, ForceOnImpact);
            Global.HandleDefaultHit(theirBody, ourBody.Position, Damage, 0);

            DeathConfetti confetti = new DeathConfetti();

            confetti.Spatial.CopyFrom(this.Spatial);
            confetti.AutoDestruct.DestructionDelay           = TimeSpan.FromSeconds(ConfettiTimeToLive);
            confetti.ParticleEmitter.Emitter.MaxNumParticles = 16;
            Vector2 g = -2.5f * BodyComponent.Body.LinearVelocity;

            confetti.ParticleEmitter.Emitter.Gravity = g;
            Global.Game.AddGameObject(confetti);

            Global.Game.RemoveGameObject(this);
        }
Esempio n. 5
0
        private void MovingBody_OnCollision(Fixture ourFixture, Fixture theirFixture, VelcroPhysics.Collision.ContactSystem.Contact contact)
        {
            if (CurrentHitCooldown == TimeSpan.Zero)
            {
                Global.HandleDefaultHit(theirFixture.Body, ourFixture.Body.Position, Damage, ForceOnImpact);
                CurrentHitCooldown = HitCooldown;
            }

            switch (TrapState)
            {
            case SpikeTrapState.Attacking:
            case SpikeTrapState.Returning:
            {
                EnterState(SpikeTrapState.WaitingAfterAttacking);
            }
            break;
            }
        }
Esempio n. 6
0
 private void Body_OnCollision(VelcroPhysics.Dynamics.Fixture fixtureA, VelcroPhysics.Dynamics.Fixture fixtureB, VelcroPhysics.Collision.ContactSystem.Contact contact)
 {
     if ((string)fixtureB.Body.UserData == (string)"Bullet_1")
     {
         fixtureA.Body.ApplyLinearImpulse(0.0025f * fixtureB.Body.GetLinearVelocityFromLocalPoint(fixtureA.Body.Position + ConvertUnits.ToSimUnits(new Vector2(256, 256))));
         fixtureB.Body.Position = new Vector2(1000f, 1000f);
     }
 }