Example #1
0
        public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType)
        {
            var terrainObj = otherBox.Parent as TerrainObj;

            if (terrainObj != null && !(terrainObj is DoorObj) && terrainObj.CollidesBottom && terrainObj.CollidesLeft &&
                terrainObj.CollidesRight && terrainObj.CollidesTop)
            {
                var value = CollisionMath.RotatedRectIntersectsMTD(thisBox.AbsRect, (int)thisBox.AbsRotation,
                                                                   Vector2.Zero, otherBox.AbsRect, (int)otherBox.AbsRotation, Vector2.Zero);
                if (value != Vector2.Zero)
                {
                    var heading  = Heading;
                    var vector   = new Vector2(value.Y, value.X * -1f);
                    var heading2 = 2f * (CDGMath.DotProduct(heading, vector) / CDGMath.DotProduct(vector, vector)) *
                                   vector - heading;
                    X      += value.X;
                    Y      += value.Y;
                    Heading = heading2;
                    SoundManager.Play3DSound(this, Game.ScreenManager.Player, "GiantSpike_Bounce_01",
                                             "GiantSpike_Bounce_02", "GiantSpike_Bounce_03");
                    m_selfDestructCounter++;
                    m_selfDestructTimer = 1f;
                }
            }
        }
Example #2
0
        public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType)
        {
            if (Spell == 20)
            {
                var projectileObj = otherBox.AbsParent as ProjectileObj;
                if (projectileObj != null && projectileObj.CollisionTypeTag != 2 && projectileObj.CanBeFusRohDahed)
                {
                    projectileObj.RunDestroyAnimation(false);
                }
            }
            var terrainObj = otherBox.Parent as TerrainObj;

            if (CollidesWithTerrain && !(otherBox.Parent is DoorObj) && terrainObj != null &&
                ((terrainObj.CollidesTop && terrainObj.CollidesBottom && terrainObj.CollidesLeft &&
                  terrainObj.CollidesRight) || CollidesWith1Ways))
            {
                var spell = Spell;
                if (spell != 3)
                {
                    if (spell == 7)
                    {
                        base.CollisionResponse(thisBox, otherBox, collisionResponseType);
                        IsWeighted = false;
                        ActivateEffect();
                        return;
                    }
                    if (spell != 12)
                    {
                        if (DestroysWithTerrain)
                        {
                            RunDestroyAnimation(false);
                            return;
                        }
                        AccelerationY = 0f;
                        AccelerationX = 0f;
                        IsWeighted    = false;
                    }
                    else
                    {
                        var value = CollisionMath.RotatedRectIntersectsMTD(thisBox.AbsRect, thisBox.AbsRotation,
                                                                           Vector2.Zero, otherBox.AbsRect, otherBox.AbsRotation, Vector2.Zero);
                        if (value != Vector2.Zero)
                        {
                            SoundManager.Play3DSound(this, Game.ScreenManager.Player, "Spike_Bounce_01",
                                                     "Spike_Bounce_02", "Spike_Bounce_03");
                            var heading = Heading;
                            var vector  = new Vector2(value.Y, value.X * -1f);
                            var pt      = 2f * (CDGMath.DotProduct(heading, vector) / CDGMath.DotProduct(vector, vector)) *
                                          vector - heading;
                            X          += value.X;
                            Y          += value.Y;
                            Orientation = MathHelper.ToRadians(CDGMath.VectorToAngle(pt));
                        }
                    }
                }
                else if (terrainObj.CollidesBottom && terrainObj.CollidesTop && terrainObj.CollidesLeft &&
                         terrainObj.CollidesRight)
                {
                    var vector2 = CollisionMath.RotatedRectIntersectsMTD(thisBox.AbsRect, thisBox.AbsRotation,
                                                                         Vector2.Zero, otherBox.AbsRect, otherBox.AbsRotation, Vector2.Zero);
                    base.CollisionResponse(thisBox, otherBox, collisionResponseType);
                    if ((vector2.Y <= 0f && vector2.X == 0f) || otherBox.AbsRotation != 0f)
                    {
                        AccelerationY = 0f;
                        AccelerationX = 0f;
                        IsWeighted    = false;
                    }
                }
                else if (!terrainObj.CollidesBottom && terrainObj.CollidesTop && !terrainObj.CollidesLeft &&
                         !terrainObj.CollidesRight)
                {
                    var vector3 = CollisionMath.RotatedRectIntersectsMTD(thisBox.AbsRect,
                                                                         thisBox.AbsRotation, Vector2.Zero, otherBox.AbsRect, otherBox.AbsRotation, Vector2.Zero);
                    if (vector3.Y <= 0f && AccelerationY > 0f)
                    {
                        base.CollisionResponse(thisBox, otherBox, collisionResponseType);
                        if ((vector3.Y <= 0f && vector3.X == 0f) || otherBox.AbsRotation != 0f)
                        {
                            AccelerationY = 0f;
                            AccelerationX = 0f;
                            IsWeighted    = false;
                        }
                    }
                }
            }
            else if (otherBox.Type != 0)
            {
                var spell2 = Spell;
                if (spell2 == 5)
                {
                    if (otherBox.AbsParent == Target)
                    {
                        CollisionTypeTag = 2;
                    }
                }
                else
                {
                    base.CollisionResponse(thisBox, otherBox, collisionResponseType);
                }
            }
        }
Example #3
0
 public override void Update(GameTime gameTime)
 {
     if (!IsPaused)
     {
         var num    = (float)gameTime.ElapsedGameTime.TotalSeconds;
         var value  = Vector2.Zero;
         var bounds = m_levelScreen.CurrentRoom.Bounds;
         if (Y < bounds.Top + 10)
         {
             value = CollisionMath.CalculateMTD(Bounds, new Rectangle(bounds.Left, bounds.Top, bounds.Width, 10));
         }
         else if (Y > bounds.Bottom - 10)
         {
             value = CollisionMath.CalculateMTD(Bounds,
                                                new Rectangle(bounds.Left, bounds.Bottom - 10, bounds.Width, 10));
         }
         if (X > bounds.Right - 10)
         {
             value = CollisionMath.CalculateMTD(Bounds,
                                                new Rectangle(bounds.Right - 10, bounds.Top, 10, bounds.Height));
         }
         else if (X < bounds.Left + 10)
         {
             value = CollisionMath.CalculateMTD(Bounds, new Rectangle(bounds.Left, bounds.Top, 10, bounds.Height));
         }
         if (value != Vector2.Zero)
         {
             var heading  = Heading;
             var vector   = new Vector2(value.Y, value.X * -1f);
             var heading2 = 2f * (CDGMath.DotProduct(heading, vector) / CDGMath.DotProduct(vector, vector)) *
                            vector - heading;
             Heading = heading2;
             SoundManager.Play3DSound(this, Game.ScreenManager.Player, "GiantSpike_Bounce_01",
                                      "GiantSpike_Bounce_02", "GiantSpike_Bounce_03");
             m_selfDestructCounter++;
             m_selfDestructTimer = 1f;
         }
         if (m_selfDestructTimer > 0f)
         {
             m_selfDestructTimer -= num;
             if (m_selfDestructTimer <= 0f)
             {
                 m_selfDestructCounter = 0;
             }
         }
         if (m_selfDestructCounter >= m_selfDestructTotalBounces)
         {
             Kill(false);
         }
         if (CurrentSpeed == 0f)
         {
             CurrentSpeed = Speed;
         }
         if (HeadingX > 0f)
         {
             Rotation += RotationSpeed * num;
         }
         else
         {
             Rotation -= RotationSpeed * num;
         }
     }
     base.Update(gameTime);
 }