1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
10 private Vector2 position;
12 private float fadeTimer;
18 get {
return fadeTimer; }
19 set { fadeTimer = MathHelper.Clamp(value, 0.0f,
LifeTime); }
24 get {
return Prefab.FadeInTime; }
29 get {
return Prefab.FadeOutTime; }
34 get {
return Prefab.LifeTime; }
53 Vector2 worldPos = position
54 + clippedSourceRect.Size.ToVector2() / 2 *
Scale
55 + hull.
Rect.Location.ToVector2();
79 private readonly HashSet<BackgroundSection> affectedSections;
81 private readonly
Hull hull;
85 private Rectangle clippedSourceRect;
87 private bool cleaned =
false;
98 Vector2 drawPos = position + hull.
Rect.Location.ToVector2();
100 SpriteIndex = spriteIndex ?? Rand.Range(0, prefab.
Sprites.Count, Rand.RandSync.Unsynced);
104 Rectangle drawRect =
new Rectangle(
110 Rectangle overFlowAmount =
new Rectangle(
111 (
int)Math.Max(hull.
Rect.X - drawRect.X, 0.0f),
112 (
int)Math.Max(drawRect.Y - hull.
Rect.Y, 0.0f),
113 (
int)Math.Max(drawRect.Right - hull.
Rect.Right, 0.0f),
114 (
int)Math.Max((hull.
Rect.Y - hull.
Rect.Height) - (drawRect.Y - drawRect.Height), 0.0f));
116 clippedSourceRect =
new Rectangle(
119 Sprite.
SourceRect.Width - (
int)((overFlowAmount.X + overFlowAmount.Width) / scale),
120 Sprite.
SourceRect.Height - (
int)((overFlowAmount.Y + overFlowAmount.Height) / scale));
124 position -=
new Vector2(
Sprite.
size.X / 2 * scale - overFlowAmount.X, -
Sprite.
size.Y / 2 * scale + overFlowAmount.Y);
128 foreach (
BackgroundSection section
in hull.GetBackgroundSectionsViaContaining(
new Rectangle((
int)position.X, (
int)position.Y - drawRect.Height, drawRect.Width, drawRect.Height)))
130 affectedSections ??=
new HashSet<BackgroundSection>();
131 affectedSections.Add(section);
137 fadeTimer += deltaTime;
149 fadeTimer =
Prefab.FadeInTime;
154 return affectedSections !=
null && affectedSections.Contains(section);
164 private float GetAlpha()
166 if (fadeTimer <
Prefab.FadeInTime && !cleaned)
readonly DecalPrefab Prefab
void ForceRefreshFadeTimer(float val)
void Update(float deltaTime)
bool AffectsSection(BackgroundSection section)
Vector2 NonClampedPosition
Decal(DecalPrefab prefab, float scale, Vector2 worldPosition, Hull hull, int? spriteIndex=null)
readonly float FadeOutTime
readonly List< Sprite > Sprites