Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LittleFlyingCritterParticle.cs
Go to the documentation of this file.
1using System;
5
7
9{
10 private int _lifeTimeCounted;
11
12 private int _lifeTimeTotal;
13
15
17
19
20 private float _neverGoBelowThis;
21
22 public bool IsRestingInPool { get; private set; }
23
24 public bool ShouldBeRemovedFromRenderer { get; private set; }
25
26 public void Prepare(Vector2 position, int duration)
27 {
28 _spawnPosition = position;
29 _localPosition = position + Main.rand.NextVector2Circular(4f, 8f);
30 _neverGoBelowThis = position.Y + 8f;
33 _lifeTimeTotal = 300 + Main.rand.Next(6) * 60;
34 }
35
36 private void RandomizeVelocity()
37 {
38 _velocity = Main.rand.NextVector2Circular(1f, 1f);
39 }
40
41 public void RestInPool()
42 {
43 IsRestingInPool = true;
44 }
45
46 public virtual void FetchFromPool()
47 {
48 IsRestingInPool = false;
50 }
51
52 public void Update(ref ParticleRendererSettings settings)
53 {
55 {
57 }
58 _velocity += new Vector2((float)Math.Sign(_spawnPosition.X - _localPosition.X) * 0.02f, (float)Math.Sign(_spawnPosition.Y - _localPosition.Y) * 0.02f);
59 if (_lifeTimeCounted % 30 == 0 && Main.rand.Next(2) == 0)
60 {
62 if (Main.rand.Next(2) == 0)
63 {
64 _velocity /= 2f;
65 }
66 }
69 {
70 _localPosition.Y = _neverGoBelowThis;
71 if (_velocity.Y > 0f)
72 {
73 _velocity.Y *= -1f;
74 }
75 }
76 }
77
78 public void Draw(ref ParticleRendererSettings settings, SpriteBatch spritebatch)
79 {
80 Vector2 vector = settings.AnchorPosition + _localPosition;
81 if (vector.X < -10f || vector.X > (float)(Main.screenWidth + 10) || vector.Y < -10f || vector.Y > (float)(Main.screenHeight + 10))
82 {
84 return;
85 }
87 int frameY = _lifeTimeCounted % 6 / 3;
88 Rectangle value2 = value.Frame(1, 2, 0, frameY);
89 Vector2 origin = new Vector2((!(_velocity.X > 0f)) ? 1 : 3, 3f);
90 float num = Utils.Remap(_lifeTimeCounted, 0f, 90f, 0f, 1f) * Utils.Remap(_lifeTimeCounted, _lifeTimeTotal - 90, _lifeTimeTotal, 1f, 0f);
91 spritebatch.Draw(value, settings.AnchorPosition + _localPosition, value2, Lighting.GetColor(_localPosition.ToTileCoordinates()) * num, 0f, origin, 1f, (_velocity.X > 0f) ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0f);
92 }
93}
void Draw(Texture2D texture, Vector2 position, Color color)
static int Sign(decimal value)
Definition Math.cs:1202
static Asset< Texture2D >[] Extra
void Draw(ref ParticleRendererSettings settings, SpriteBatch spritebatch)
static Color GetColor(Point tileCoords)
Definition Lighting.cs:182
static int screenHeight
Definition Main.cs:1721
static UnifiedRandom rand
Definition Main.cs:1387
static int screenWidth
Definition Main.cs:1719
static float Remap(float fromValue, float fromMin, float fromMax, float toMin, float toMax, bool clamped=true)
Definition Utils.cs:233