public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType) { var terrainObj = otherBox.AbsParent as TerrainObj; if (otherBox.AbsParent.Bounds.Top < TerrainBounds.Bottom - 20 && terrainObj != null && terrainObj.CollidesLeft && terrainObj.CollidesRight && terrainObj.CollidesBottom && collisionResponseType == 1 && otherBox.AbsRotation == 0f && m_collisionCheckTimer <= 0f && CollisionMath.CalculateMTD(thisBox.AbsRect, otherBox.AbsRect).X != 0f) { TurnHorse(); } base.CollisionResponse(thisBox, otherBox, collisionResponseType); }
public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType) { if (collisionResponseType == 1 && (otherBox.AbsParent is TerrainObj || otherBox.AbsParent is HazardObj) && !(otherBox.AbsParent is DoorObj)) { base.CollisionResponse(thisBox, otherBox, collisionResponseType); AccelerationX = 0f; Y = (int)Y; if (DropType == 10 && CurrentFrame == 1 && CollisionMath.CalculateMTD(thisBox.AbsRect, otherBox.AbsRect).Y < 0f) { PlayAnimation(2, TotalFrames); } } }
public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType) { IPhysicsObj absParent = otherBox.AbsParent as IPhysicsObj; if (collisionResponseType == Consts.COLLISIONRESPONSE_FIRSTBOXHIT) { if ((absParent.CollisionTypeTag == GameTypes.CollisionType_PLAYER || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL && IsWeighted) && (!(otherBox.AbsParent is RogueAPI.Projectiles.ProjectileObj) && m_invincibleCounter <= 0f || otherBox.AbsParent is RogueAPI.Projectiles.ProjectileObj && (m_invincibleCounterProjectile <= 0f || (otherBox.AbsParent as RogueAPI.Projectiles.ProjectileObj).IgnoreInvincibleCounter)) ) { //Show demented question mark and return if (IsDemented) { m_invincibleCounter = InvincibilityTime; m_invincibleCounterProjectile = InvincibilityTime; RogueAPI.Effects.QuestionMarkEffect.Display(this); //m_levelScreen.ImpactEffectPool.DisplayQuestionMark(new Vector2(X, Bounds.Top)); return; } int damage; if (absParent is RogueAPI.Projectiles.ProjectileObj) { damage = (absParent as RogueAPI.Projectiles.ProjectileObj).Damage; } else { damage = (absParent as IDealsDamageObj).Damage; } //Apply critical damage bool isPlayer = absParent == m_target; if (isPlayer) { if (CDGMath.RandomFloat(0f, 1f) <= m_target.TotalCritChance && !NonKillable) { RogueAPI.Effects.CriticalTextEffect.Display(this); //m_levelScreen.ImpactEffectPool.DisplayCriticalText(new Vector2(X, Bounds.Top)); damage = (int)(damage * m_target.TotalCriticalDamage); } m_invincibleCounter = InvincibilityTime; } //Destroy projectile var projectileObj = otherBox.AbsParent as RogueAPI.Projectiles.ProjectileObj; if (projectileObj != null) { m_invincibleCounterProjectile = InvincibilityTime; if (projectileObj.DestroysWithEnemy && !NonKillable) { projectileObj.RunDestroyAnimation(false); } } if (projectileObj != null || absParent.CollisionTypeTag != GameTypes.CollisionType_GLOBAL_DAMAGE_WALL || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL && IsWeighted) { var allow = true; if (projectileObj != null) { var kbAmount = CanBeKnockedBack && !IsPaused ? (KnockBack != Vector2.Zero ? KnockBack : m_target.EnemyKnockBack) : Vector2.Zero; allow = projectileObj != null?projectileObj.OnCollision(this, false, kbAmount) : true; } if (allow) { Point center = (thisBox.AbsRotation != 0f || otherBox.AbsRotation != 0f) ? Rectangle.Intersect(thisBox.AbsParent.Bounds, otherBox.AbsParent.Bounds).Center : Rectangle.Intersect(thisBox.AbsRect, otherBox.AbsRect).Center; HitEnemy(damage, new Vector2(center.X, center.Y), isPlayer); } } ////Apply shout knockback //if (projectileObj != null && projectileObj.Spell == SpellType.Shout) //{ // if (CanBeKnockedBack && !IsPaused) // { // float inertia = 3f; // var knockback = KnockBack != Vector2.Zero ? KnockBack : m_target.EnemyKnockBack; // CurrentSpeed = 0f; // AccelerationX = knockback.X * (X >= m_target.X ? inertia : -inertia); // AccelerationY = -knockback.Y * inertia; // } //} //else if (projectileObj != null || absParent.CollisionTypeTag != GameTypes.CollisionType_GLOBAL_DAMAGE_WALL || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL && IsWeighted) //{ // Point center = (thisBox.AbsRotation != 0f || otherBox.AbsRotation != 0f) // ? Rectangle.Intersect(thisBox.AbsParent.Bounds, otherBox.AbsParent.Bounds).Center // : Rectangle.Intersect(thisBox.AbsRect, otherBox.AbsRect).Center; // HitEnemy(damage, new Vector2(center.X, center.Y), isPlayer); //} } } else if (collisionResponseType == Consts.COLLISIONRESPONSE_TERRAIN) { if ((absParent.CollisionTypeTag == GameTypes.CollisionType_WALL || absParent.CollisionTypeTag == GameTypes.CollisionType_WALL_FOR_ENEMY || absParent.CollisionTypeTag == GameTypes.CollisionType_GLOBAL_DAMAGE_WALL) && CollisionTypeTag != GameTypes.CollisionType_ENEMYWALL) { Vector2 vector2 = CollisionMath.CalculateMTD(thisBox.AbsRect, otherBox.AbsRect); if (CurrentSpeed != 0f && vector2.X != 0f && Math.Abs(vector2.X) > 10f && (vector2.X > 0f && absParent.CollidesRight || vector2.X < 0f && absParent.CollidesLeft)) { CurrentSpeed = 0f; } if (m_numTouchingGrounds <= 1 && CurrentSpeed != 0f && vector2.Y < 0f && !CanFallOffLedges) { if (Bounds.Left < absParent.Bounds.Left && HeadingX < 0f) { X = absParent.Bounds.Left + (AbsX - Bounds.Left); CurrentSpeed = 0f; } else if (Bounds.Right > absParent.Bounds.Right && HeadingX > 0f) { X = absParent.Bounds.Right - (Bounds.Right - AbsX); CurrentSpeed = 0f; } m_isTouchingGround = true; } if (AccelerationX != 0f && m_isTouchingGround) { AccelerationX = 0f; } bool flag1 = false; if (Math.Abs(vector2.X) < 10f && vector2.X != 0f && Math.Abs(vector2.Y) < 10f && vector2.Y != 0f) { flag1 = true; } if (m_isTouchingGround && !absParent.CollidesBottom && absParent.CollidesTop && absParent.TerrainBounds.Top < TerrainBounds.Bottom - 30) { flag1 = true; } if (!absParent.CollidesRight && !absParent.CollidesLeft && absParent.CollidesTop && absParent.CollidesBottom) { flag1 = true; } Vector2 vector22 = CollisionMath.RotatedRectIntersectsMTD(thisBox.AbsRect, thisBox.AbsRotation, Vector2.Zero, otherBox.AbsRect, otherBox.AbsRotation, Vector2.Zero); if (!flag1) { base.CollisionResponse(thisBox, otherBox, collisionResponseType); } if (vector22.Y < 0f && otherBox.AbsRotation != 0f && IsWeighted) { X -= vector22.X; } } } }
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); }