Ejemplo n.º 1
0
    override public void Execute()
    {
        // if I collided with someone, it means my other is someone
        // destroy my other
        HasCollided ch = this.gameObject.GetComponentInParent <HasCollided>();

        if (ch != null)
        {
            GameObject otherObj = ch.other;
            if (otherObj != null)
            {
                Destroy(otherObj);
            }
        }
    }
Ejemplo n.º 2
0
    public void OnCollisionEnter(Collision other)
    {
        Debug.Log("collided with " + other.gameObject.name);

        // both parties' other needs to be recorded
        HasCollided hc = this.gameObject.AddComponent <HasCollided> ();

        if (hc != null)
        {
            hc.other = other.gameObject;
        }

        HasCollided hcOther = other.gameObject.AddComponent <HasCollided> ();

        if (hcOther != null)
        {
            hcOther.other = this.gameObject;
        }
    }
    override public bool Evaluate()
    {
        bool rval = false;

        if (ch == null)
        {
            if (recipient != null)
            {
                ch = recipient.GetComponent <CollisionHelper> ();
            }
        }

        // check for presence of hasCollided flag
        if (ch != null)
        {
            HasCollided hc = recipient.GetComponent <HasCollided> ();
            if (hc != null)
            {
                rval = true;
            }
        }

        return(rval);
    }
Ejemplo n.º 4
0
        public virtual void CheckCollide(object sender, EventArgs e)
        {
            if (sender == this)
            {
                return;
            }

            //hack to prevent projectiles spinning around inside of mobs
            if ((this is Projectile && HasCollided.ContainsKey(sender.GetHashCode())) || (sender is Projectile && HasCollided.ContainsKey(GetHashCode())))
            {
                return;
            }

            Mob other = sender as Mob;

            if (IsCollidable && other != null && other.IsCollidable && !AlreadyCollided.Contains(other))
            {
                if (IsPhysicallyIntersecting(other))
                {
                    GhostPhysicalBody ghost      = PhysicalBody as GhostPhysicalBody;
                    GhostPhysicalBody otherGhost = other.PhysicalBody as GhostPhysicalBody;

                    if (ghost == null && otherGhost == null)
                    {
                        return; //two farseer bodies. Collision is handled elsewhere
                    }

                    thisCollidesWithOther = false;
                    otherCollidesWithThis = false;
                    VectorHelper.Zero(ref thisPositionOffset);
                    VectorHelper.Zero(ref otherPositionOffset);
                    VectorHelper.Zero(ref thisNewVelocity);
                    VectorHelper.Zero(ref otherNewVelocity);
                    VectorHelper.Zero(ref thisNewNetForces);
                    VectorHelper.Zero(ref otherNewNetForces);

                    //only apply collision forces if not a projectile or planet
                    thisApplyCollisionForces  = !(other is Projectile) && !PhysicalBody.IsStatic;
                    otherApplyCollisionForces = !(this is Projectile) && !other.PhysicalBody.IsStatic;

                    if (Collide(other) || (IsFixForBigColliding && other.IsFixForBigColliding && CollisionRectangle.Width > 100 && other.CollisionRectangle.Width > 100))
                    {
                        thisCollidesWithOther = true;
                        if (thisApplyCollisionForces)
                        {
                            CalculateCollisionForces(other, this, ghost, ref thisPositionOffset, ref thisNewVelocity, ref thisNewNetForces); //, true);
                        }

                        if (this is Projectile)
                        {
                            HasCollided.AddKeyIfMissing(other.GetHashCode());
                        }
                    }

                    if (other.Collide(this) || (IsFixForBigColliding && other.IsFixForBigColliding && CollisionRectangle.Width > 100 && other.CollisionRectangle.Width > 100))
                    {
                        otherCollidesWithThis = true;
                        if (otherApplyCollisionForces)
                        {
                            CalculateCollisionForces(this, other, otherGhost, ref otherPositionOffset, ref otherNewVelocity, ref otherNewNetForces); //, false);
                        }

                        if (other is Projectile)
                        {
                            HasCollided.AddKeyIfMissing(GetHashCode());
                        }
                    }

                    if (thisCollidesWithOther && thisApplyCollisionForces)
                    {
                        if (ghost != null) //This is null if the instance is a planet or the Gunman (the only Farseer bodies)
                        {
                            PhysicalBody.LinearVelocity = thisNewVelocity;
                            PhysicalBody.Position      += thisPositionOffset;
                            UpdateCollisionRectangle();

                            //normally, would do me.NetForces = newNetForces but need to hack so projectiles don't recollide with large bosses
                            if (!PhysicalBody.IsStatic && !other.PhysicalBody.IsStatic &&
                                (CollisionRectangle.Width >= 150 || other.CollisionRectangle.Width >= 150))
                            {
                                if (!ProjectileHasCollidedWithBoss)
                                {
                                    ghost.NetForces = thisNewNetForces;
                                }
                                //to prevent recollision, if colliding with 'boss' (i.e. large nonstatic mob), disable all further
                                //collisions WITH BOSSES ONLY (don't hack collision algorithm for cases involving small mobs)
                                ProjectileHasCollidedWithBoss = true;
                            }
                            else
                            {
                                ghost.NetForces = thisNewNetForces;
                            }
                        }
                    }

                    if (otherCollidesWithThis && otherApplyCollisionForces)
                    {
                        if (otherGhost != null) //This is null if the instance is a planet or the Gunman (the only Farseer bodies)
                        {
                            other.PhysicalBody.LinearVelocity = otherNewVelocity;
                            other.PhysicalBody.Position      += otherPositionOffset;
                            other.UpdateCollisionRectangle();

                            //normally, would do me.NetForces = newNetForces but need to hack so projectiles don't recollide with large bosses
                            if (!PhysicalBody.IsStatic && !other.PhysicalBody.IsStatic &&
                                (CollisionRectangle.Width >= 150 || other.CollisionRectangle.Width >= 150))
                            {
                                if (!other.ProjectileHasCollidedWithBoss)
                                {
                                    otherGhost.NetForces = otherNewNetForces;
                                }
                                //to prevent recollision, if colliding with 'boss' (i.e. large nonstatic mob), disable all further
                                //collisions WITH BOSSES ONLY (don't hack collision algorithm for cases involving small mobs)
                                other.ProjectileHasCollidedWithBoss = true;
                            }
                            else
                            {
                                otherGhost.NetForces = otherNewNetForces;
                            }
                        }
                    }

                    //Once the first mob handles the collision, we do not try again with the other mob
                    AlreadyCollided.Add(other);
                    //other.AlreadyCollided.Add(this); <- for whatever reason, this breaks collisions with ShardSkimmers. Handle with care
                }
            }
        }
Ejemplo n.º 5
0
 public void InvokeAction(ITakeDamage _currentView)
 {
     HasCollided?.Invoke(_currentView, currentBulletModel.GetPointDamage());
 }