Particles using display coordinates, particle growtime, character death&stun animations

This commit is contained in:
Regalis
2015-09-05 12:13:44 +03:00
parent 0cbcdd0b03
commit 04d55891f0
22 changed files with 346 additions and 206 deletions
+44 -54
View File
@@ -24,25 +24,22 @@ namespace Subsurface.Particles
private Color color;
private float alpha;
private float totalLifeTime;
private float lifeTime;
private Vector2 velocityChange;
private Vector2 drawPosition;
private float checkCollisionTimer;
//private float checkCollisionTimer;
private Hull currentHull;
public ParticlePrefab.DrawTargetType DrawTarget
{
get { return prefab.DrawTarget; }
}
public Vector2 yLimits
{
get;
set;
}
public Vector2 Size
{
get { return size; }
@@ -62,29 +59,33 @@ namespace Subsurface.Particles
this.position = position;
prevPosition = position;
drawPosition = ConvertUnits.ToDisplayUnits(position);
drawPosition = position;
velocity = speed;
this.rotation = rotation + Rand.Range(prefab.startRotationMin, prefab.startRotationMax);
this.rotation = rotation + Rand.Range(prefab.StartRotationMin, prefab.StartRotationMax);
prevRotation = rotation;
angularVelocity = prefab.angularVelocityMin + (prefab.angularVelocityMax - prefab.angularVelocityMin) * Rand.Range(0.0f, 1.0f);
angularVelocity = prefab.AngularVelocityMin + (prefab.AngularVelocityMax - prefab.AngularVelocityMin) * Rand.Range(0.0f, 1.0f);
lifeTime = prefab.lifeTime;
size = prefab.startSizeMin + (prefab.startSizeMax - prefab.startSizeMin) * Rand.Range(0.0f, 1.0f);
sizeChange = prefab.sizeChangeMin + (prefab.sizeChangeMax - prefab.sizeChangeMin) * Rand.Range(0.0f, 1.0f);
yLimits = Vector2.Zero;
color = prefab.startColor;
alpha = prefab.startAlpha;
totalLifeTime = prefab.LifeTime;
lifeTime = prefab.LifeTime;
velocityChange = prefab.velocityChange;
size = prefab.StartSizeMin + (prefab.StartSizeMax - prefab.StartSizeMin) * Rand.Range(0.0f, 1.0f);
if (prefab.rotateToDirection)
sizeChange = prefab.SizeChangeMin + (prefab.SizeChangeMax - prefab.SizeChangeMin) * Rand.Range(0.0f, 1.0f);
color = prefab.StartColor;
alpha = prefab.StartAlpha;
velocityChange = prefab.VelocityChange;
if (prefab.DeleteOnCollision)
{
currentHull = Hull.FindHull(position);
}
if (prefab.RotateToDirection)
{
this.rotation = MathUtils.VectorToAngle(new Vector2(velocity.X, -velocity.Y));
@@ -98,7 +99,7 @@ namespace Subsurface.Particles
position.X += velocity.X * deltaTime;
position.Y += velocity.Y * deltaTime;
if (prefab.rotateToDirection)
if (prefab.RotateToDirection)
{
if (velocityChange != Vector2.Zero || angularVelocity != 0.0f)
{
@@ -114,37 +115,18 @@ namespace Subsurface.Particles
velocity.Y += velocityChange.Y * deltaTime;
size.X += sizeChange.X * deltaTime;
size.Y += sizeChange.Y * deltaTime;
size.Y += sizeChange.Y * deltaTime;
alpha += prefab.colorChange.W * deltaTime;
alpha += prefab.ColorChange.W * deltaTime;
color = new Color(
color.R / 255.0f + prefab.colorChange.X * deltaTime,
color.G / 255.0f + prefab.colorChange.Y * deltaTime,
color.B / 255.0f + prefab.colorChange.Z * deltaTime);
if (yLimits!=Vector2.Zero)
color.R / 255.0f + prefab.ColorChange.X * deltaTime,
color.G / 255.0f + prefab.ColorChange.Y * deltaTime,
color.B / 255.0f + prefab.ColorChange.Z * deltaTime);
if (prefab.DeleteOnCollision && currentHull!=null)
{
if (position.Y>yLimits.X || position.Y<yLimits.Y)
{
return false;
}
}
if (prefab.deleteOnHit)
{
if (checkCollisionTimer > 0.0f)
{
checkCollisionTimer -= deltaTime;
}
else
{
if (Submarine.InsideWall(new Vector2(drawPosition.X, -drawPosition.Y)))
{
return false;
}
checkCollisionTimer = 0.05f;
}
if (!Submarine.RectContains(currentHull.Rect, position)) return false;
}
lifeTime -= deltaTime;
@@ -160,9 +142,17 @@ namespace Subsurface.Particles
drawPosition.Y = -drawPosition.Y;
float drawRotation = Physics.Interpolate(prevRotation, rotation);
drawPosition = ConvertUnits.ToDisplayUnits(drawPosition);
prefab.sprite.Draw(spriteBatch, drawPosition, color*alpha, prefab.sprite.origin, drawRotation, size, SpriteEffects.None, prefab.sprite.Depth);
//drawPosition = ConvertUnits.ToDisplayUnits(drawPosition);
Vector2 drawSize = size;
if (prefab.GrowTime>0.0f && totalLifeTime-lifeTime < prefab.GrowTime)
{
drawSize *= ((totalLifeTime - lifeTime) / prefab.GrowTime);
}
prefab.Sprite.Draw(spriteBatch, drawPosition, color*alpha, prefab.Sprite.origin, drawRotation, drawSize, SpriteEffects.None, prefab.Sprite.Depth);
//spriteBatch.Draw(
// prefab.sprite.Texture,
@@ -61,7 +61,7 @@ namespace Subsurface.Particles
public Particle CreateParticle(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation=0.0f)
{
if (!Submarine.RectContains(cam.WorldView, ConvertUnits.ToDisplayUnits(position))) return null;
if (!Submarine.RectContains(cam.WorldView, position)) return null;
if (particleCount >= MaxParticles) return null;
if (particles[particleCount] == null) particles[particleCount] = new Particle();
+68 -30
View File
@@ -1,5 +1,6 @@
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using FarseerPhysics;
namespace Subsurface.Particles
{
@@ -7,67 +8,104 @@ namespace Subsurface.Particles
{
public enum DrawTargetType { Air = 1, Water = 2, Both = 3 }
public readonly string name;
public readonly string Name;
public readonly Sprite sprite;
public readonly Sprite Sprite;
public readonly float angularVelocityMin, angularVelocityMax;
public readonly float AngularVelocityMin, AngularVelocityMax;
public readonly float startRotationMin, startRotationMax;
public readonly float StartRotationMin, StartRotationMax;
public readonly Vector2 startSizeMin, startSizeMax;
public readonly Vector2 sizeChangeMin, sizeChangeMax;
public readonly Vector2 StartSizeMin, StartSizeMax;
public readonly Vector2 SizeChangeMin, SizeChangeMax;
public readonly Color startColor;
public readonly float startAlpha;
public readonly Color StartColor;
public readonly float StartAlpha;
public readonly Vector4 colorChange;
public readonly Vector4 ColorChange;
public readonly float lifeTime;
public readonly float LifeTime;
public readonly bool deleteOnHit;
public readonly float GrowTime;
public readonly Vector2 velocityChange;
public readonly bool DeleteOnCollision;
public readonly Vector2 VelocityChange;
public readonly DrawTargetType DrawTarget;
public readonly bool rotateToDirection;
public readonly bool RotateToDirection;
public ParticlePrefab(XElement element)
{
name = element.Name.ToString();
Name = element.Name.ToString();
foreach (XElement subElement in element.Elements())
{
if (subElement.Name.ToString().ToLower() != "sprite") continue;
sprite = new Sprite(subElement);
Sprite = new Sprite(subElement);
}
angularVelocityMin = ToolBox.GetAttributeFloat(element, "angularvelocitymin", 0.0f);
angularVelocityMax = ToolBox.GetAttributeFloat(element, "angularvelocitymax", 0.0f);
if (element.Attribute("angularvelocity") == null)
{
AngularVelocityMin = ToolBox.GetAttributeFloat(element, "angularvelocitymin", 0.0f);
AngularVelocityMax = ToolBox.GetAttributeFloat(element, "angularvelocitymax", 0.0f);
}
else
{
AngularVelocityMin = ToolBox.GetAttributeFloat(element, "angularvelocity", 0.0f);
AngularVelocityMax = AngularVelocityMin;
}
startSizeMin = ToolBox.GetAttributeVector2(element, "startsizemin", Vector2.One);
startSizeMax = ToolBox.GetAttributeVector2(element, "startsizemax", Vector2.One);
if (element.Attribute("startsize") == null)
{
StartSizeMin = ToolBox.GetAttributeVector2(element, "startsizemin", Vector2.One);
StartSizeMax = ToolBox.GetAttributeVector2(element, "startsizemax", Vector2.One);
}
else
{
StartSizeMin = ToolBox.GetAttributeVector2(element, "startsize", Vector2.One);
StartSizeMax = StartSizeMin;
}
sizeChangeMin = ToolBox.GetAttributeVector2(element, "sizechangemin", Vector2.Zero);
sizeChangeMax = ToolBox.GetAttributeVector2(element, "sizechangemax", Vector2.Zero);
if (element.Attribute("sizechange") == null)
{
SizeChangeMin = ToolBox.GetAttributeVector2(element, "sizechangemin", Vector2.Zero);
SizeChangeMax = ToolBox.GetAttributeVector2(element, "sizechangemax", Vector2.Zero);
}
else
{
SizeChangeMin = ToolBox.GetAttributeVector2(element, "sizechange", Vector2.Zero);
SizeChangeMax = SizeChangeMin;
}
startRotationMin = ToolBox.GetAttributeFloat(element, "startrotationmin", 0.0f);
startRotationMax = ToolBox.GetAttributeFloat(element, "startrotationmax", 0.0f);
GrowTime = ToolBox.GetAttributeFloat(element, "growtime", 0.0f);
startColor = new Color(ToolBox.GetAttributeVector4(element, "startcolor", Vector4.One));
startAlpha = ToolBox.GetAttributeFloat(element, "startalpha", 1.0f);
if (element.Attribute("startrotation") == null)
{
StartRotationMin = ToolBox.GetAttributeFloat(element, "startrotationmin", 0.0f);
StartRotationMax = ToolBox.GetAttributeFloat(element, "startrotationmax", 0.0f);
}
else
{
StartRotationMin = ToolBox.GetAttributeFloat(element, "startrotatio", 0.0f);
StartRotationMax = StartRotationMin;
}
deleteOnHit = ToolBox.GetAttributeBool(element, "deleteonhit", false);
StartColor = new Color(ToolBox.GetAttributeVector4(element, "startcolor", Vector4.One));
StartAlpha = ToolBox.GetAttributeFloat(element, "startalpha", 1.0f);
colorChange = ToolBox.GetAttributeVector4(element, "colorchange", Vector4.Zero);
DeleteOnCollision = ToolBox.GetAttributeBool(element, "deleteoncollision", false);
lifeTime = ToolBox.GetAttributeFloat(element, "lifetime", 5.0f);
ColorChange = ToolBox.GetAttributeVector4(element, "colorchange", Vector4.Zero);
velocityChange = ToolBox.GetAttributeVector2(element, "velocitychange", Vector2.Zero);
LifeTime = ToolBox.GetAttributeFloat(element, "lifetime", 5.0f);
rotateToDirection = ToolBox.GetAttributeBool(element, "rotatetodirection", false);
VelocityChange = ToolBox.GetAttributeVector2(element, "velocitychange", Vector2.Zero);
VelocityChange = ConvertUnits.ToDisplayUnits(VelocityChange);
RotateToDirection = ToolBox.GetAttributeBool(element, "rotatetodirection", false);
switch (ToolBox.GetAttributeString(element, "drawtarget", "air").ToLower())
{