public override void Draw(Renderer renderer) { base.Draw(renderer); if (Health.IsAlive) { int currentHP = Health.CurrentHealth; int cols = Math.Min(currentHP, NumIconsPerRow); Vector2 healthIconDim = Conversion.ToMeters(HealthIcon.ScaledDim); Vector2 spacing = healthIconDim + IconPadding; SpatialData anchor = this.GetWorldSpatialData(); anchor.Position.X -= 0.5f * (cols * spacing.X); float left = anchor.Position.X; int hpIndex = 0; while (true) { for (int x = 0; x < cols; x++) { if (hpIndex++ >= currentHP) { goto DONE; } HealthIcon.Draw(renderer, anchor); anchor.Position.X += spacing.X; } anchor.Position.X = left; anchor.Position.Y += spacing.Y; } DONE :; } }
public void Draw(Renderer renderer, float deltaSeconds) { CrossAnimation.Update(deltaSeconds); foreach (SpriteAnimationInstance anim in DigitAnimations) { anim.Update(deltaSeconds); } foreach (SpriteAnimationInstance anim in KeyAnimations) { anim.Update(deltaSeconds); } if (HealthIconAnimation != null) { HealthIconAnimation.Update(deltaSeconds); int hp = Owliver.Health.MaxHealth; SpatialData spatial = HealthIconAnchor.GetWorldSpatialData(); const float spacing = 3; for (int healthIndex = 0; healthIndex < hp; healthIndex++) { Color tint = healthIndex < Owliver.Health.CurrentHealth ? FullHealthTint : NoHealthTint; HealthIconAnimation.Draw(renderer, spatial.GetWorldSpatialData(), tint: tint); spatial.Position.X += HealthIconAnimation.ScaledDim.X + spacing; } } if (Owliver.MoneyBag != null) { MoneyBagIconAnimation.Update(deltaSeconds); SpatialData spatial = MoneyBagIconAnchor.GetWorldSpatialData(); MoneyBagIconAnimation.Draw(renderer, MoneyBagIconAnchor); const float spacing = 3; float previousAnimWidth = MoneyBagIconAnimation.ScaledDim.X; spatial.Position.X -= 0.5f * CrossAnimation.ScaledDim.X + 0.5f * previousAnimWidth + spacing; CrossAnimation.Draw(renderer, spatial); previousAnimWidth = CrossAnimation.ScaledDim.X; int value = Owliver.MoneyBag.CurrentAmount; while (true) { int digit = value % 10; SpriteAnimationInstance digitAnim = DigitAnimations[digit]; spatial.Position.X -= 0.5f * previousAnimWidth + 0.5f * digitAnim.ScaledDim.X + spacing; digitAnim.Draw(renderer, spatial); value /= 10; if (value == 0) { break; } previousAnimWidth = digitAnim.ScaledDim.X; } } if (Owliver.KeyRing != null) { SpatialData anchor = KeyRingAnchor.GetWorldSpatialData(); for (int keyTypeIndex = 0; keyTypeIndex < (int)KeyType.COUNT; keyTypeIndex++) { KeyType keyType = (KeyType)keyTypeIndex; int keyAmount = Owliver.KeyRing[keyType]; SpriteAnimationInstance keyAnim = KeyAnimations[keyTypeIndex]; SpatialData spatial = anchor.GetWorldSpatialData(); for (int keyIndex = 0; keyIndex < keyAmount; keyIndex++) { keyAnim.Draw(renderer, spatial); spatial.Position.X += 0.6f * keyAnim.ScaledDim.X; } anchor.Position.Y += 0.8f * keyAnim.ScaledDim.Y; } } }