2 using FarseerPhysics.Dynamics;
3 using Microsoft.Xna.Framework;
4 using System.Collections.Generic;
46 get {
return Body.Position; }
51 get {
return ConvertUnits.ToDisplayUnits(
Body.Position); }
60 : base (vertices, color,
level, giftWrap)
62 MaxHealth = health ?? MathHelper.Clamp(
Body.Mass * 0.5f, 50.0f, 1000.0f);
63 Cells.ForEach(c => c.IsDestructible =
true);
66 public override void Update(
float deltaTime)
68 base.Update(deltaTime);
76 public void AddDamage(
float damage, Vector2 worldPosition)
78 AddDamageProjSpecific(damage, worldPosition);
91 partial
void AddDamageProjSpecific(
float damage, Vector2 worldPosition);
100 private void CreateFragments()
105 Vector2 center = Vector2.Zero;
107 List<List<Vector2>> triangles =
new List<List<Vector2>>();
108 foreach (var cell
in Cells)
112 List<Vector2> triangleVerts =
new List<Vector2>
114 edge.
Point1 + cell.Translation,
115 edge.Point2 + cell.Translation,
118 triangles.Add(triangleVerts);
120 center += cell.Center;
124 center /=
Cells.Count;
128 Pair<int, int> longestEdge =
new Pair<int, int>(-1, -1);
129 float longestEdgeLength = 0.0f;
132 longestEdge.First = -1;
133 longestEdge.Second = -1;
134 longestEdgeLength = 0.0f;
135 for (
int i = 0; i < triangles.Count; i++)
137 for (
int edge = 0; edge < 3; edge++)
139 float edgeLength = Vector2.Distance(triangles[i][edge], triangles[i][(edge + 1) % 3]);
140 if (edgeLength > longestEdgeLength)
142 longestEdge.First = i;
143 longestEdge.Second = edge;
144 longestEdgeLength = edgeLength;
148 if (longestEdgeLength < 1000.0f)
152 Vector2 p0 = triangles[longestEdge.First][longestEdge.Second];
153 Vector2 p1 = triangles[longestEdge.First][(longestEdge.Second + 1) % 3];
154 Vector2 p2 = triangles[longestEdge.First][(longestEdge.Second + 2) % 3];
155 triangles[longestEdge.First] =
new List<Vector2> { p0, (p0 + p1) / 2, p2 };
156 triangles.Add(
new List<Vector2> { (p0 + p1) / 2, p1, p2 });
159 }
while (triangles.Count < 32);
162 foreach (var triangle
in triangles)
164 Vector2 triangleCenter = (triangle[0] + triangle[1]+ triangle[2]) / 3;
165 triangle[0] -= triangleCenter;
166 triangle[1] -= triangleCenter;
167 triangle[2] -= triangleCenter;
168 Vector2 simTriangleCenter = ConvertUnits.ToSimUnits(triangleCenter);
171 fragment.Damage = fragment.MaxHealth;
172 fragment.Body.Position = simTriangleCenter;
173 fragment.Body.BodyType = BodyType.Dynamic;
174 fragment.Body.FixedRotation =
false;
175 fragment.Body.LinearDamping = Rand.Range(0.2f, 0.3f);
176 fragment.Body.AngularDamping = Rand.Range(0.1f, 0.2f);
177 fragment.Body.GravityScale = 0.1f;
178 fragment.Body.Mass *= 10.0f;
179 fragment.Body.CollisionCategories = Physics.CollisionNone;
180 fragment.Body.CollidesWith = Physics.CollisionWall;
181 fragment.FadeOutDuration = 20.0f;
183 Vector2 bodyDiff = simTriangleCenter -
Body.Position;
184 fragment.Body.LinearVelocity = (bodyDiff + Rand.Vector(0.5f)).ClampLength(15.0f);
185 fragment.Body.AngularVelocity = Rand.Range(-0.5f, 0.5f);
187 Level.Loaded.UnsyncedExtraWalls.Add(fragment);
190 for (
int i = 0; i < 5; i++)
192 int startEdgeIndex = Rand.Int(3);
193 Vector2 pos1 = triangle[startEdgeIndex];
194 Vector2 pos2 = triangle[(startEdgeIndex + 1) % 3];
196 var particle = GameMain.ParticleManager.CreateParticle(
"iceexplosion",
197 triangleCenter + Vector2.Lerp(pos1, pos2, Rand.Range(0.0f, 1.0f)),
198 velocity: (Rand.Vector(Rand.Range(50.0f, 1000.0f)) + fragment.Body.LinearVelocity * 100.0f));
199 if (particle !=
null)
201 particle.Size *= Rand.Range(1.0f, 5.0f);
202 particle.ColorMultiplier *= Rand.Range(0.7f, 1.0f);
214 foreach (var cell
in Cells)
217 cell.OnDestroyed?.Invoke();
218 cell.OnDestroyed =
null;
Attacks are used to deal damage to characters, structures and items. They can be defined in the weapo...
void AddDamage(float damage, Vector2 worldPosition)
override void Update(float deltaTime)
DestructibleLevelWall(List< Vector2 > vertices, Color color, Level level, float? health=null, bool giftWrap=false)
AttackResult AddDamage(Character attacker, Vector2 worldPosition, Attack attack, Vector2 impulseDirection, float deltaTime, bool playSound=true)
bool NetworkUpdatePending
static NetworkMember NetworkMember
List< LevelWall > UnsyncedExtraWalls
Purely decorative wall chunks whose positions don't need to be synced (e.g. the chunks created when a...
List< VoronoiCell > Cells