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

basic particle effects ( position is skewed, and will add boolean flags once position works. ) #97

Merged
merged 3 commits into from
Apr 17, 2024
Merged
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
84 changes: 65 additions & 19 deletions src/Client/GameModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Shared.Messages;
using Shared.Systems;
using Microsoft.Xna.Framework.Audio;
using CS5410;

namespace Client;

Expand All @@ -41,8 +42,17 @@ public class GameModel
private SoundEffect m_eatSpiceSound;
private SoundEffectInstance m_deathSoundInstance;
private SoundEffectInstance m_eatSpiceSoundInstance;

private ParticleSystem deathParticleSystem;
private ParticleSystem eatParticleSystem;
private ParticleSystemRenderer deathRenderer;
private ParticleSystemRenderer eatRenderer;
private bool collisionIsOn;
private bool spiceEaten;

private int clientId;


public GameModel(StringBuilder playerName)
{
m_playerName = playerName.ToString();
Expand All @@ -59,6 +69,22 @@ public void update(TimeSpan elapsedTime)
m_systemWormMovement.update(elapsedTime);
m_systemInterpolation.update(elapsedTime);
m_systemCamera.update(elapsedTime);



GameTime gameTime = new GameTime(totalGameTime: TimeSpan.Zero, elapsedGameTime: elapsedTime);


if (eatParticleSystem != null)
{
eatParticleSystem.update(gameTime);
}

if (deathParticleSystem != null)
{
deathParticleSystem.update(gameTime);
}

}

/// <summary>
Expand All @@ -67,7 +93,17 @@ public void update(TimeSpan elapsedTime)

public void render(TimeSpan elapsedTime, SpriteBatch spriteBatch)
{

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);

eatRenderer.draw(spriteBatch, eatParticleSystem);
deathRenderer.draw(spriteBatch, deathParticleSystem);


spriteBatch.End();

m_renderer.render(elapsedTime, spriteBatch, m_playerData);

}

/// <summary>
Expand All @@ -87,6 +123,15 @@ public bool initialize(ContentManager contentManager, Controls controls, Graphic
m_deathSoundInstance = m_deathSound.CreateInstance();
m_eatSpiceSoundInstance = m_eatSpiceSound.CreateInstance();

eatRenderer = new ParticleSystemRenderer("Textures/particle");
deathRenderer = new ParticleSystemRenderer("Textures/particle");

eatParticleSystem = new ParticleSystem(new Vector2(0, 0), 2, 1, 0.2f, 0.1f, 300, 150);
deathParticleSystem = new ParticleSystem(new Vector2(0, 0), 4, 2, 0.5f, 0.25f, 1000, 500);

eatRenderer.LoadContent(contentManager);
deathRenderer.LoadContent(contentManager);

m_contentManager = contentManager;
m_systemScore = new ScoreSystem();
m_playerData = new PlayerData(0, m_playerName);
Expand Down Expand Up @@ -160,7 +205,7 @@ private Entity createEntity(Shared.Messages.NewEntity message)
{
entity.add(new Collidable());
}

if (message.hasWall)
{
entity.add(new Shared.Components.Wall());
Expand Down Expand Up @@ -193,12 +238,12 @@ private Entity createEntity(Shared.Messages.NewEntity message)
{
entity.add(new ChildId(message.childId));
}

if (message.hasInvincible)
{
entity.add(new Invincible(message.invincibleDuration));
}

if (message.hasSpicePower)
{
entity.add(new SpicePower(message.spicePower));
Expand Down Expand Up @@ -274,8 +319,8 @@ private void handleRemoveEntity(Shared.Messages.RemoveEntity message)
{
removeEntity(message.id);
}


private void handleNewAnchorPoint(Shared.Messages.NewAnchorPoint message)
{
if (m_entities.ContainsKey(message.wormHeadId) && !m_entities.Values.ToArray()[0].id.Equals(message.wormHeadId))
Expand All @@ -284,10 +329,11 @@ private void handleNewAnchorPoint(Shared.Messages.NewAnchorPoint message)
var worm = WormMovement.getWormFromHead(wormHead, m_entities);
foreach (var segment in worm.Skip(1))
{
segment.get<AnchorQueue>().m_anchorPositions.Enqueue( new Position(message.position, message.orientation));
segment.get<AnchorQueue>().m_anchorPositions.Enqueue(new Position(message.position, message.orientation));
}
}
}


private Entity getPlayer()
{
Expand All @@ -300,7 +346,7 @@ private Entity getPlayer()
}
return null;
}

private void handleCollision(Shared.Messages.Collision message)
{
// Check where our current client is and see if the collision is relevant
Expand All @@ -309,6 +355,7 @@ private void handleCollision(Shared.Messages.Collision message)
{
return;
}

// We need to know if the collision occurred on the screen of the client
if (m_entities.ContainsKey(message.senderId) && m_entities.ContainsKey(message.receiverId))
{
Expand All @@ -317,37 +364,36 @@ private void handleCollision(Shared.Messages.Collision message)
var entity2 = m_entities[message.receiverId];
// Check the position
var position = message.position;

// Check for sound on the player
if (message.collisionType == Collision.CollisionType.ReceiverDies && player == entity1 || message.collisionType == Collision.CollisionType.SenderDies && player == entity2)
if (message.collisionType == Collision.CollisionType.ReceiverDies && player == entity1 ||
message.collisionType == Collision.CollisionType.SenderDies && player == entity2)
{
m_deathSoundInstance.Play();
}

if (message.collisionType == Collision.CollisionType.HeadToSpice && player == entity1)
{
m_eatSpiceSoundInstance.Play();
}


if (message.collisionType == Collision.CollisionType.HeadToSpice)
{
Vector2 foodPosition = new Vector2(message.position.X, message.position.Y);
eatParticleSystem.FoodEaten(foodPosition);

// TODO: Spice particle effect collision flag
}

else if (message.collisionType == Collision.CollisionType.HeadToWall)
{

// TODO: Wall particle effect collision flag
}


// We hit another worm
Vector2 deathPosition = new Vector2(message.position.X, message.position.Y);

deathParticleSystem.SnakeDeath(deathPosition);

// If it is relevant, we either send a boolean flag to the particle system and collision handling or we call those here.

// TODO: Implement this

// TODO: Wall particle effect collision flag
}
}
}
}
Expand Down
Loading