-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added smoke particle generator. Moved Explode particles to Engine. Ad…
…ded Game Over and New Game. Towers get hit.
- Loading branch information
Showing
16 changed files
with
409 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using Microsoft.Xna.Framework.Input; | ||
using Microsoft.Xna.Framework.Audio; | ||
using XnaModel = Microsoft.Xna.Framework.Graphics.Model; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System; | ||
using Engine; | ||
|
||
namespace Engine | ||
{ | ||
public class Smoke : GameComponent, IBeginable, IUpdateableComponent, ILoadContent | ||
{ | ||
List<SmokeParticle> Particles; | ||
XnaModel Cube; | ||
Vector3 Position; | ||
float Radius; | ||
|
||
public bool Active { get => Enabled; } | ||
|
||
public Smoke(Game game) : base(game) | ||
{ | ||
Particles = new List<SmokeParticle>(); | ||
|
||
game.Components.Add(this); | ||
} | ||
|
||
public override void Initialize() | ||
{ | ||
|
||
base.Initialize(); | ||
LoadContent(); | ||
BeginRun(); | ||
} | ||
|
||
public void LoadContent() | ||
{ | ||
Cube = Services.LoadModel("Core/Cube"); | ||
} | ||
|
||
public void BeginRun() | ||
{ | ||
Enabled = false; | ||
} | ||
|
||
public override void Update(GameTime gameTime) | ||
{ | ||
foreach (SmokeParticle particle in Particles) | ||
{ | ||
if (!particle.Active) | ||
{ | ||
SpawnParticle(particle); | ||
} | ||
} | ||
|
||
base.Update(gameTime); | ||
} | ||
|
||
public void Spawn(Vector3 position, float radius, int minCount) | ||
{ | ||
Enabled = true; | ||
Position = position; | ||
Radius = radius; | ||
int count = Services.RandomMinMax(minCount, (int)(minCount + radius * 10)); | ||
|
||
if (count > Particles.Count) | ||
{ | ||
int more = count - Particles.Count; | ||
|
||
for (int i = 0; i < more; i++) | ||
{ | ||
Particles.Add(new SmokeParticle(Game)); | ||
Particles.Last().SetModel(Cube); | ||
Particles.Last().DefuseColor = new Vector3(0.415f, 0.435f, 0.627f); | ||
} | ||
} | ||
|
||
foreach (SmokeParticle particle in Particles) | ||
{ | ||
SpawnParticle(particle); | ||
} | ||
} | ||
|
||
public void Kill() | ||
{ | ||
foreach (SmokeParticle particle in Particles) | ||
{ | ||
particle.Active = false; | ||
Enabled = false; | ||
} | ||
} | ||
|
||
void SpawnParticle(SmokeParticle particle) | ||
{ | ||
Vector3 position = Position; | ||
position += new Vector3(Services.RandomMinMax(-Radius, Radius), | ||
Services.RandomMinMax(-Radius, Radius), 0); | ||
particle.Spawn(position); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using Microsoft.Xna.Framework.Input; | ||
using Microsoft.Xna.Framework.Audio; | ||
using XnaModel = Microsoft.Xna.Framework.Graphics.Model; | ||
using System.Collections.Generic; | ||
using System; | ||
using Engine; | ||
|
||
namespace Engine | ||
{ | ||
public class SmokeParticle : AModel | ||
{ | ||
Timer LifeTimer; | ||
|
||
public SmokeParticle(Game game) : base(game) | ||
{ | ||
LifeTimer = new Timer(game); | ||
} | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
|
||
} | ||
|
||
public override void LoadContent() | ||
{ | ||
|
||
} | ||
|
||
public override void BeginRun() | ||
{ | ||
base.BeginRun(); | ||
|
||
|
||
} | ||
|
||
public override void Update(GameTime gameTime) | ||
{ | ||
if (LifeTimer.Elapsed) | ||
Active = false; | ||
|
||
base.Update(gameTime); | ||
} | ||
|
||
public override void Spawn(Vector3 position) | ||
{ | ||
base.Spawn(position); | ||
|
||
Scale = Services.RandomMinMax(1, 2); | ||
LifeTimer.Reset(Services.RandomMinMax(3.1f, 15.5f)); | ||
Velocity.Y = Services.RandomMinMax(1.1f, 4.5f); | ||
float drift = 1.5f; | ||
Velocity.X = Services.RandomMinMax(-drift, drift); | ||
Velocity.Z = Services.RandomMinMax(-drift, drift); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.