/// <summary> /// Deals a certain amount of damage to the entity. /// </summary> /// <param name="damageDealer">Can be null.</param> /// <param name="damage"></param> public virtual void TakeDamage(Entity damageDealer, int damage) { if (TMBAW_Game.CurrentGameMode == GameMode.Play) { if (IsTakingDamage || IsPlayingDeathAnimation || !CanTakeDamage) { return; } if (this is Player) { Overlay.ColoredCorners.FlashColor(Color.Red); } // Main.TimeFreeze.AddFrozenTime(damage*3); IsTakingDamage = true; Health -= damage; ParticleSystem.Add("-" + damage, Center, new Vector2(TMBAW_Game.Random.Next(0, 2) * -2 + 1, -15), new Color(255, 108, 108)); _hitRecentlyTimer.ResetAndWaitFor(500); _hitRecentlyTimer.SetTimeReached += HitByPlayerTimer_SetTimeReached; //Creates damage particles. int particleCount = damage / 2; if (particleCount > 100) { particleCount = 100; } for (int i = 0; i < particleCount; i++) { ParticleSystem.Add(ParticleType.Round_Common, CalcHelper.GetRandXAndY(CollRectangle), null, Color.Red); } //if (damageDealer == null) // return; //Velocity.Y = -8f; //Velocity.X = (Weight / 2f); //if (!damageDealer.IsFacingRight) // Velocity.X *= -1; HasTakenDamage?.Invoke(); } }
/// <summary> /// Creates death particles and calls event to do other death related things. /// </summary> private void DeathAnimationEnded() { _deathAnimationTimer.SetTimeReached -= DeathAnimationEnded; IsDead = true; for (int i = 0; i < 20; i++) { ParticleSystem.Add(ParticleType.Smoke, CalcHelper.GetRandXAndY(CollRectangle), new Vector2(0, -TMBAW_Game.Random.Next(1, 5) / 10f), Color.White); } //Rectangle[] desinRectangles; //GetDisintegratedRectangles(out desinRectangles); //foreach (Rectangle rect in desinRectangles) //{ // EntityTextureParticle par = new EntityTextureParticle(CalcHelper.GetRandomX(CollRectangle), CalcHelper.GetRandomY(CollRectangle), rect, new Vector2(Main.Random.Next(-5, 5) / 10f, -Main.Random.Next(-5, 5) / 10f), this); // GameWorld.ParticleSystem.Add(par); //} HasFinishedDying?.Invoke(this); }