Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle port sf #80

Merged
merged 6 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/Client/Content/Audio/death.wav
Binary file not shown.
Binary file added src/Client/Content/Audio/eatSpice.wav
Binary file not shown.
40 changes: 28 additions & 12 deletions src/Client/Content/Content.mgcb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
/processorParam:Quality=Best
/build:Audio/backgroundMusic.mp3

#begin Audio/death.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:Audio/death.wav

#begin Audio/menu.mp3
/importer:Mp3Importer
/processor:SoundEffectProcessor
Expand Down Expand Up @@ -123,6 +129,18 @@
/processorParam:TextureFormat=Color
/build:Textures/circleTail.png

#begin Textures/deadWormSpice.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/deadWormSpice.png

#begin Textures/head.png
/importer:TextureImporter
/processor:TextureProcessor
Expand All @@ -135,7 +153,7 @@
/processorParam:TextureFormat=Color
/build:Textures/head.png

#begin Textures/SandTile.png
#begin Textures/particle.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -145,9 +163,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/SandTile.png
/build:Textures/particle.png

#begin Textures/spice.webp
#begin Textures/SandTile.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -157,9 +175,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/spice.webp
/build:Textures/SandTile.png

#begin Textures/tail.png
#begin Textures/spice.webp
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -169,9 +187,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/tail.png
/build:Textures/spice.webp

#begin Textures/wall.png
#begin Textures/tail.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -181,9 +199,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/wall.png
/build:Textures/tail.png

#begin Textures/deadWormSpice.png
#begin Textures/wall.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
Expand All @@ -193,7 +211,5 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/deadWormSpice.png


/build:Textures/wall.png

Binary file added src/Client/Content/Textures/particle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 20 additions & 57 deletions src/Client/Systems/ParticleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,81 +29,44 @@ public ParticleSystem(Vector2 center, int sizeMean, int sizeStdDev, float speedM
m_lifetimeStdDev = lifetimeStdDev;
}

public void ShipThrust(Vector2 landerCenter, Vector2 direction, float landerRotation, float landerSize)
public void FoodEaten(Vector2 foodPosition)
{
Vector2 thrustOffset = new Vector2(0, landerSize / 2);

Matrix rotationMatrix = Matrix.CreateRotationZ(landerRotation);
thrustOffset = Vector2.Transform(thrustOffset, rotationMatrix);

Vector2 thrustStartPosition = landerCenter + thrustOffset;

Color[] particleColors = new Color[] { Color.Red, Color.Orange, Color.Yellow };

Vector2[] trianglePoints = new Vector2[]
Color[] particleColors = { Color.Green, Color.Yellow, Color.White };
for (int i = 0; i < 30; i++) // Smaller number of particles for food eaten
{
new Vector2(-0.5f, 1),
new Vector2(0.5f, 1),
new Vector2(0, 0)
};

float triangleScale = 5.0f;

// Scale the triangle points
for (int i = 0; i < trianglePoints.Length; i++)
{
trianglePoints[i] *= triangleScale;
}


for (int i = 0; i < 20; i++)
{
float size = (float)m_random.nextGaussian(m_sizeMean, m_sizeStdDev);
size *= 4;

float size = (float)m_random.nextGaussian(m_sizeMean / 2, m_sizeStdDev / 2); // Smaller particles
Color initialColor = particleColors[m_random.Next(particleColors.Length)];

Vector2 randomPoint = thrustStartPosition + trianglePoints[m_random.Next(trianglePoints.Length)];
Vector2 targetDirection = randomPoint - thrustStartPosition;


float angleVariation = MathHelper.ToRadians(10);
float randomAngle = (float)(m_random.NextDouble() * angleVariation - angleVariation / 2);
targetDirection = Vector2.Transform(targetDirection, Matrix.CreateRotationZ(randomAngle));

targetDirection.Y *= 1;
Vector2 direction = m_random.nextCircleVector();

var particle = new Particle(
thrustStartPosition,
direction + targetDirection * 0.2f,
(float)m_random.nextGaussian(m_speedMean, m_speedStDev) * 0.5f,
new Vector2(size, size),
TimeSpan.FromMilliseconds(m_random.nextGaussian(m_lifetimeMean / 2, m_lifetimeStdDev / 2)),
foodPosition,
direction * 0.3f, // Less forceful ejection
(float)m_random.nextGaussian(m_speedMean / 2, m_speedStDev / 2), // Slower speed
new Vector2(size, size),
TimeSpan.FromMilliseconds(m_random.nextGaussian(m_lifetimeMean / 3, m_lifetimeStdDev / 3)), // Shorter lifetime

initialColor
);
m_particles.Add(particle.name, particle);
}
}





public void ShipCrash(Vector2 position)
public void SnakeDeath(Vector2 snakePosition)
{
Color[] particleColors = { Color.Red, Color.Orange, Color.Yellow };
for (int i = 0; i < 500; i++)
Color[] particleColors = { Color.Red, Color.DarkRed, Color.Maroon };
for (int i = 0; i < 200; i++) // More particles for death to emphasize the event
{
float size = (float)m_random.nextGaussian(m_sizeMean, m_sizeStdDev);
Color initialColor = particleColors[m_random.Next(particleColors.Length)];
Vector2 direction = m_random.nextCircleVector() * 0.5f;
Vector2 direction = m_random.nextCircleVector() * 2; // More spread

var particle = new Particle(
position,
direction, // Less spread out direction
(float)m_random.nextGaussian(m_speedMean, m_speedStDev) * 0.3f, // Slower speed for a more condensed effect
snakePosition,
direction, // Greater spread
(float)m_random.nextGaussian(m_speedMean, m_speedStDev), // Normal speed
new Vector2(size, size),
TimeSpan.FromMilliseconds(m_random.nextGaussian(m_lifetimeMean, m_lifetimeStdDev)),
TimeSpan.FromMilliseconds(m_random.nextGaussian(m_lifetimeMean, m_lifetimeStdDev)), // Normal lifetime

initialColor
);
m_particles.Add(particle.name, particle);
Expand Down
Loading