Пример #1
0
        bool _body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            Player player = fixtureB.UserData as Player;

            if (player == null)
            {
                return(true);
            }
            _hurtSound.Play(1f, 0f, 0);
            _body.LinearVelocity = new Vector2(0, -5);
            _body.IgnoreGravity  = true;
            _body.CollidesWith   = Category.None;
            Wait.Until(
                time =>
            {
                _sprite.Body.Rotation = 2 * time.Alive * MathHelper.TwoPi;
                _sprite.Body.Scale    = new Vector2(1 - 2 * time.Alive);
                return(time.Alive >= .5f);
            },
                () =>
            {
                _hitSound.Play();
                _play.Entities.Slimes.SlimeList.Remove(this);
                _play.World.RemoveBody(_body);
            });
            _play.LowerFactor();
            return(false);
        }
Пример #2
0
        public override bool OnCollision(Fixture f1, Fixture f2, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            CollidingSprite other = SyncedGameCollection.GetCollisionComponent(f2);

            if (other != null)
            {
                if (other.Tag == TagCategories.CRYSTAL)
                {
                    Grabbable g_other = (Grabbable)other;
                    if (g_other.HasOwner)
                    {
                        if (g_other.Owner.ID == _start.ID || g_other.Owner.ID == _end.ID)
                        {
                            return(false);
                        }
                        else
                        {
                            g_other.ForcedRelease();
                            return(true);
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(true);
        }
Пример #3
0
        bool RigidBody_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            HealthBar.RemoveHealth();


            return(true);
        }
Пример #4
0
        bool shot_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (fixtureB.Body.UserData != null)
            {
                // if EnemyTower gets hit by player shot
                if (fixtureB.Body.UserData.ToString() == "enemyTower" &&
                    fixtureA.Body.UserData.ToString() == "s")
                {
                    //FadeUp.AddTextMessage("-" + GameSettings.PlayerDamage, FadeUp.TextTypes.Damage, fixtureB.Body.Position);
                    fixtureA.Body.UserData = "disable";     // Disable user Shot!
                    fixtureB.Body.UserData = "damage";      // but save the damage the tower will receive
                }

                // if flying enemy gets hit by player shot
                if (fixtureB.Body.UserData.ToString() == "enemy" &&
                    fixtureA.Body.UserData.ToString() == "s")
                {
                    //FadeUp.AddTextMessage("-" + GameSettings.PlayerDamage, FadeUp.TextTypes.Damage, fixtureB.Body.Position);
                    fixtureA.Body.UserData = "disable";     // Disable user Shot!
                    fixtureB.Body.UserData = "damage";
                }

                // Disable Player Shots if they collide with the levelparts
                if (fixtureB.Body.UserData.ToString() == "physictexture" &&
                    fixtureA.Body.UserData.ToString() == "s")
                {
                    fixtureA.Body.UserData = "disable";     // disable damage for this shot
                }

                // if the player gets shot by EnemyTowers
                if (fixtureB.Body.UserData.ToString() == "player" &&
                    fixtureA.Body.UserData.ToString() == "enemyShot")
                {
                    FadeUp.AddTextMessage("-" + GameSettings.TowerDamage, FadeUp.TextTypes.Damage, fixtureB.Body.Position);
                    fixtureB.Body.UserData = "getroffen";   // Enable damage
                    fixtureA.Body.UserData = "disable";     // disable damage for this shot
                }

                // Disable enemy Shots if they collide with the levelparts
                if (fixtureB.Body.UserData.ToString() == "physictexture" &&
                    fixtureA.Body.UserData.ToString() == "enemyShot")
                {
                    fixtureA.Body.UserData = "disable";     // disable damage for this shot
                }

                // Disable player Shots if they collide with the Triggers
                else if (fixtureB.Body.UserData.ToString() == "trigger" &&
                         fixtureA.Body.UserData.ToString() == "s")
                {
                    return(false);
                }

                else if (fixtureB.Body.UserData.ToString() == "trigger" &&
                         fixtureA.Body.UserData.ToString() == "disable")
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #5
0
        bool RigidBodyCmp_OnCollision(FarseerPhysics.Dynamics.Contacts.Contact contact, RigidBodyComponent self, RigidBodyComponent other)
        {
            Player player = other.Owner.FindComponent <Player>();

            if (contact.FixtureA == m_laserFixture && player != null && m_state == LaserState.On)
            {
                bool playerHasBall = player.Ball != null;

                float side = Math.Sign(player.Position.X - m_laserPosition.X);

                Vector2 bashDirection = -player.MoveDirection;

                if (playerHasBall)
                {
                    player.DettachBall(-bashDirection * m_laserParameters.Content.BallBashImpulse);
                }

                if (player.Properties.Bashed.Value == false)
                {
                    PlayerBashEffect bashEffect = new PlayerBashEffect();
                    bashEffect.SetDuration(80);
                    bashEffect.Direction = bashDirection;
                    bashEffect.Strength  = m_laserParameters.Content.PlayerBashImpulse;
                    player.AddEffect(bashEffect);
                }
            }

            return(true);
        }
Пример #6
0
 private bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     Console.WriteLine("Bullet Collected");
     WasColected = true;
     this.body.Dispose();
     return(false);
 }
Пример #7
0
        private bool body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            Player player = fixtureB.Body.UserData as Player;

            if (player != null)
            {
                if (timerWrapper["player"] > 500)
                {
                    //Console.WriteLine("Collisionista damaa...");
                    HealthComponent healthComponent = player.Components
                                                      .FirstOrDefault(c => c is HealthComponent)
                                                      as HealthComponent;

                    healthComponent.TakeDamage(random.Next(5, 15));

                    timerWrapper.ResetTimer("player");

                    if (brain.CurrentState == Charge)
                    {
                        brain.PopState();

                        brain.PushState(GoBack);
                        brain.PushState(GetTarget);
                    }
                }
            }

            return(true);
        }
Пример #8
0
        /// <summary>
        /// Handles collisions.
        /// </summary>
        /// <param name="fixtureA"></param>
        /// <param name="fixtureB"></param>
        /// <param name="contact"></param>
        /// <returns></returns>
        private bool PhysicsBody_OnCollision(FarseerPhysics.Dynamics.Fixture fixtureA,
                                             FarseerPhysics.Dynamics.Fixture fixtureB,
                                             FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (Health > 0)
            {
                Health--;
            }
            if (Health > 0)
            {
                _BlockHitSound.Play();
            }
            else
            {
                _BlockDestroySound.Play();
                var state = Playground.State as Gamestates.BreakoutState;
                state.Score++;

                // Random chance of spawning a ball
                if (BreakoutPartyGame.Random.NextDouble() > 0.9)
                {
                    state.SpawnBall();
                }

                PhysicsBody.CollisionCategories = CollisionGroups.None;
                PhysicsBody.IgnoreGravity       = false;
            }

            return(true);
        }
Пример #9
0
        protected override bool CollideInternal(GameObject other, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (other.GetType().IsSubclassOf(typeof(Projectiles.Projectile)) && other.Alive)
            {
                var o = (Projectiles.Projectile)other;

                if (!IsDamageAllowed(o.Owner) || !o.CanDamage(this, Game.FriendlyFireEnabled))
                {
                    return(true);
                }

                //In case of friendly firing the spawning tank
                //because it spawned too close, ignore the collision to give it a chance.
                if (o.Owner == this && o.TimeAlive < TimeSpan.FromMilliseconds(500))
                {
                    return(false);
                }

                Health -= o.DamageAmount;

                o.CollidedWithTank(this);

                if (Health <= 0 && !_killed)
                {
                    if (Authoritative)
                    {
                        Game.RemoveGameObject(this, o);
                    }
                    _killed = true;
                }
                return(true);
            }

            return(base.CollideInternal(other, contact));
        }
Пример #10
0
        public bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            SceneItem dataA = ((SceneItem)fixtureA.Body.UserData);
            SceneItem dataB = ((SceneItem)fixtureB.Body.UserData);

            if (HaveTheseCollided(dataA, dataB))
            {
                return(false);
            }

            CollisionComponent collisionComponentA = dataA.GetComponent <CollisionComponent>();
            CollisionComponent collisionComponentB = dataB.GetComponent <CollisionComponent>();

            if (collisionComponentA != null)
            {
                CollisionEventArgs eventArgs = new CollisionEventArgs();
                eventArgs.CollidedSceneItemA = dataB;
                eventArgs.CollidedSceneItemB = dataA;
                collisionComponentA.OnCollision(eventArgs);
            }
            if (collisionComponentB != null)
            {
                CollisionEventArgs eventArgs = new CollisionEventArgs();
                eventArgs.CollidedSceneItemA = dataA;
                eventArgs.CollidedSceneItemB = dataB;
                collisionComponentB.OnCollision(eventArgs);
            }

            OnScreenStats.AddStat(string.Format("BODY! {0} {1}", dataA.Name, dataB.Name));
            return(false);
        }
Пример #11
0
        bool RigidBody_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            var collider = (GameModel)fixtureB.Body.UserData;

            if (collider != null)
            {
                if (collider.Name == "Ground")
                {
                    PickUpFromGround = true;
                    PullDirection    = 1.0f;
                    TakeHealth();
                    return(true);
                }
                else if (collider.Name == "Top")
                {
                    PickUpFromGround = false;
                    PullDirection    = -1.0f;
                    TakeHealth();
                    return(true);
                }
                else if (collider.Name == "Smash")
                {
                    TakeHealth();
                    return(true);
                }
            }

            return(true);
        }
Пример #12
0
        bool OnCollision(FarseerPhysics.Dynamics.Contacts.Contact contact, RigidBodyComponent self, RigidBodyComponent other)
        {
            object otherTag = "";

            other.UserData.TryGetValue("Tag", out otherTag);
            if ((string)otherTag == "Player")
            {
                //Projectile projectile = (Projectile)self.Owner.FindComponent<Projectile>();
                Player player = (Player)other.Owner.FindComponent <Player>();
                if (this.Player.Owner == player.Owner)
                {
                    return(true);
                }
                else
                {
                    Owner.Kill();
                    return(false);
                }
            }
            else
            {
                Owner.Kill();
            }
            return(false);

            ;
        }
Пример #13
0
        private bool Player_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if ((string)fixtureB.Body.UserData == "goal")
            {
                nextLevel();
            }

            else if ((string)fixtureB.Body.UserData == "enemy")
            {
                if (fixtureB.Body.Position.Y > fixtureA.Body.Position.Y + 0.2)
                {
                    explosion.Activate(fixtureB.Body);

                    enemyDie.Play();

                    fixtureA.Body.ApplyLinearImpulse(new Vector2(0, -3));
                    foreach (Component component in LevelReader.Levels.Components)
                    {
                        if (fixtureB.Body.BodyId == component.Body.BodyId)
                        {
                            ((Enemy)component).Die();
                        }
                    }
                    fixtureB.Body.Dispose();
                }
                else
                {
                    explosion.Activate(fixtureA.Body);
                    playerDie.Play();
                    if (playerLives > 0)
                    {
                        playerLives--;
                        resetLevel();
                    }
                    else
                    {
                        resetGame();
                    }
                }
            }

            //only one jump
            if (fixtureB.Body.Position.Y > fixtureA.Body.Position.Y + 0.2)
            {
                foreach (Component component in LevelReader.Levels.Components)
                {
                    if (fixtureA.Body.BodyId == component.Body.BodyId)
                    {
                        if (((Player)component).Airborne == true)
                        {
                            playerJump.Play();
                            ((Player)component).Airborne = false;
                        }
                    }
                }
            }

            return(true);
        }
Пример #14
0
        /// <summary>
        /// Fires on collision (narrowphase)
        /// </summary>
        /// <param name="fixtureA"></param>
        /// <param name="fixtureB"></param>
        /// <param name="contact"></param>
        /// <returns></returns>
        private Boolean _fxPea_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            var pea   = (fixtureA.UserData as DataPea) ?? (fixtureB.UserData as DataPea);
            var block = (fixtureB.UserData as DataBlock) ?? (fixtureA.UserData as DataBlock);

            // Falling on top face
            if (block == null || (block.IsPlaced && (block.Position.X < pea.Position.X && block.Position.X + 70 > pea.Position.X))) // &&
            //block.Position.Y  pea.Position.Y))
            {
                #if VERBOSE
                Debug.WriteLine("Fall: " + _fallHeight.ToString());
                #endif

                // If high fallen
                if ((block == null && _fallHeight >= MaxFallHeightGround) ||
                    ((block != null && (block.IsRampLeft || block.IsRampRight)) && _fallHeight >= MaxFallHeightRamp) ||
                    (block != null && !block.IsSpring && !block.IsGel) && _fallHeight >= MaxFallHeight)
                {
                    // TODO: option for kill on collision with pea
                    if (block == null || (fixtureB.UserData is DataPea) == false)
                    {
                        // Kills the pea
                        Die();

                        return(false);
                    }
                }

                // Register hurt
                if (_fallHeight >= HurtHeight)
                {
                    ChangeMood(Mood.Hurt);
                }

                _fallHeight = 0;
            }

            // If there is a block, didn't collide with ground
            if (block != null)
            {
                if (block.IsPlaced)
                {
                    _fxPea.Restitution = block.PeaRestitution;
                    _fxPea.Friction    = block.PeaFriction;
                }
                _collisions.Add(fixtureB);
                 #if VERBOSE
                Debug.WriteLine("Collision with fixture " + fixtureB.FixtureId);
                #endif
            }
            else
            {
                // Collision with ground
                _fxPea.Restitution = 0.7f;
                _fxPea.Friction    = 0.5f;
            }

            return(true);
        }
Пример #15
0
 private bool _body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (_collisionStart.IsOver && fixtureB.CollisionCategories == Category.Unit)
     {
         Dispose();
     }
     return(true);
 }
Пример #16
0
 bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (fixtureB.Body.Mass == 80.5051956f)
     {
         score++;
     }
     return(true);
 }
Пример #17
0
 /// <summary>
 /// Body_OnCollision re-enables jumping capability if on an object
 /// </summary>
 /// <param name="fixtureA">fixture passed in from Body A</param>
 /// <param name="fixtureB">fixture passed in from Body B</param>
 /// <param name="contact">Checking contact between fixtures</param>
 private bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if ((string)fixtureB.Body.UserData == "platform")
     {
         return(m_canJump = true);
     }
     return(false);
 }
Пример #18
0
        /// <summary>
        /// Farseer Physics callback.  Called when a contact is destroyed.
        /// </summary>
        /// <param name="contact">Contact point.</param>
        private void EndContact(Physics.Dynamics.Contacts.Contact contact)
        {
            // Get Entities from both shapes.
            Entity entA = (Entity)contact.FixtureA.Body.UserData;
            Entity entB = (Entity)contact.FixtureB.Body.UserData;

            entA.OnSeparate(entB, contact);
            entB.OnSeparate(entA, contact);
        }
Пример #19
0
        private bool OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (Math.Abs(_body.LinearVelocity.X) > 10f || Math.Abs(_body.LinearVelocity.Y) > 5f)
            {
                _boss.Game.Camera.Shake(0.2f, 10f);
            }

            return(true);
        }
Пример #20
0
 bool _body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (fixtureB.CollisionCategories == Category.Cat4 || fixtureB.CollisionCategories == Category.Cat5)
     {
         this._body.IgnoreCollisionWith(fixtureB.Body);
     }
     return(true);
     //throw new NotImplementedException();
 }
Пример #21
0
 private bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB,
                               FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (OnCollisionEvent != null)
     {
         OnCollisionEvent(this,
                          new OnCollisionEventArgs((GameObject)fixtureA.Body.UserData, (GameObject)fixtureB.Body.UserData));
     }
     return(true);
 }
Пример #22
0
        /// <summary>
        /// Farseer Physics callback.  Called when a contact point is created.
        /// </summary>
        /// <param name="contact">Contact point.</param>
        public void BeginContact(Physics.Dynamics.Contacts.Contact contact)
        {
            // PreSolve performs the same function as this, only continue if one is a sensor.
            if (!contact.FixtureA.IsSensor && !contact.FixtureB.IsSensor)
            {
                return;
            }

            HandleContact(contact);
        }
Пример #23
0
        bool body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (fixtureB.CollisionCategories == Category.Cat3)
            {
                this._blockFallingDelay.Enabled = true;
                //fixtureA.IgnoreCollisionWith(fixtureB);
            }

            return(true);
        }
Пример #24
0
        private bool OnCollision(Fixture me, Fixture collidedWith, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (collidedWith.Body.UserData is Wall && Body.LinearVelocity.Y < 0)
            {
                var wall = (Wall)collidedWith.Body.UserData;
                return(wall.SolidWall);
            }

            return(true);
        }
Пример #25
0
        bool body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (fixtureB.Body.Position.Y < fixtureA.Body.Position.Y)
            {
                _animationStart = true;
                fixtureB.Body.ApplyLinearImpulse(new Vector2(0f, ConvertUnits.ToDisplayUnits(-0.18f)));
            }

            return(true);
        }
Пример #26
0
        public override void OnCollide(Entity entB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            if (!passed)
            {
                passed = true;
                OnTrigger((Balloon)entB);
            }

            base.OnCollide(entB, contact);
        }
Пример #27
0
 /// <summary>
 /// Body_OnCollision re-enables jumping capability if on an object
 /// </summary>
 /// <param name="a_fixtureA">fixture passed in from Body A</param>
 /// <param name="a_fixtureB">fixture passed in from Body B</param>
 /// <param name="a_contact">Checking contact between fixtures</param>
 private bool Body_OnCollision(Fixture a_fixtureA, Fixture a_fixtureB, FarseerPhysics.Dynamics.Contacts.Contact a_contact)
 {
     if ((string)a_fixtureB.Body.UserData == "platform")
     {
         m_body.CollisionCategories = Category.None;
         m_body.OnCollision        -= Body_OnCollision;
         return(true);
     }
     return(false);
 }
Пример #28
0
 /// <summary>
 /// This function is called when the player is killed
 /// due to being shot by a bullet.
 /// This bool checks the collision of the player
 /// with the bullet via the bullet's UserData and
 /// by doing so resets the players position,
 /// resets gravity and adds 1 to the death counter
 ///
 /// essentially if the player is colliding with the
 /// bullet, reset player's pos, gravity's dir' and
 /// add 1 to deaths, but if the player isn't colliding
 /// with the bullet then the resultant is false.
 /// </summary>
 /// <param name="fixtureA">The testing body fixture (in this case it's player)</param>
 /// <param name="fixtureB">Conducted fixture (in this case it's a bullet)</param>
 /// <param name="contact">Required by delegate</param>
 /// <returns></returns>
 private bool KillPlayer(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if ((string)fixtureB.Body.UserData == "bullet")
     {
         m_player.m_body.Position = m_playerSpawnLocation;
         m_gravity.direction      = new Vector2(0, 1);
         m_score.m_deaths        += 1;
     }
     return(true);
 }
Пример #29
0
 bool body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (fixtureB.CollisionCategories == Category.Cat3)
     {
         this.body.IgnoreCollisionWith(fixtureB.Body);
         //fixtureB.IgnoreCollisionWith(fixtureA.Body);
         this._isAvailable = false;
     }
     return(true);
     //throw new System.NotImplementedException();
 }
 public override bool OnCollisionEnter(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
 {
     if (!this.triggered && !this.consumed)
     {
         if (fixtureB.Body.parent != null && fixtureB.Body.parent.identity.Equals(this.triggerer))
         {
             this.triggered = true;
         }
     }
     return(false);
 }