Skip to content

Commit

Permalink
Added smoke particle generator. Moved Explode particles to Engine. Ad…
Browse files Browse the repository at this point in the history
…ded Game Over and New Game. Towers get hit.
  • Loading branch information
LanceJZ committed Jan 13, 2018
1 parent 596f6fb commit 2677ac7
Show file tree
Hide file tree
Showing 16 changed files with 409 additions and 88 deletions.
8 changes: 5 additions & 3 deletions CFNGamejam2/CFNGamejam2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<AssemblyFileVersionSettings>MMddStamp.DayOfYearStamp.MonthStamp.TimeStamp</AssemblyFileVersionSettings>
<AssemblyInfoVersionSettings>YearStamp.DateStamp.DeltaDayStamp.Increment</AssemblyInfoVersionSettings>
<PrimaryVersionType>AssemblyVersionAttribute</PrimaryVersionType>
<AssemblyVersion>1.616.12.0101</AssemblyVersion>
<AssemblyVersion>1.662.13.0101</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -71,6 +71,8 @@
<Compile Include="Engine\PositionedObject.cs" />
<Compile Include="Engine\Services.cs" />
<Compile Include="Engine\SModel.cs" />
<Compile Include="Engine\Smoke.cs" />
<Compile Include="Engine\SmokeParticle.cs" />
<Compile Include="Engine\Sprite.cs" />
<Compile Include="Engine\SpriteFontDisplay.cs" />
<Compile Include="Engine\SpritePositionedObject.cs" />
Expand All @@ -79,8 +81,8 @@
<Compile Include="Entities\Bomb.cs" />
<Compile Include="Entities\Duck.cs" />
<Compile Include="Entities\EnemyControl.cs" />
<Compile Include="Entities\Explode.cs" />
<Compile Include="Entities\ExplodeParticle.cs" />
<Compile Include="Engine\Explode.cs" />
<Compile Include="Engine\ExplodeParticle.cs" />
<Compile Include="Entities\Gateway.cs" />
<Compile Include="Entities\Ground.cs" />
<Compile Include="Entities\Missile.cs" />
Expand Down
12 changes: 6 additions & 6 deletions CFNGamejam2/Engine/AModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AModel : PositionedObject, IDrawComponent, ILoadContent
{
public Vector3 DefuseColor = new Vector3(1,1,1);
Texture2D XNATexture;
Matrix[] ModelTransforms;
//Matrix[] ModelTransforms;
Matrix BaseWorld;
public Vector3 ModelScale = new Vector3(1);
public Vector3 ModelScaleVelocity = Vector3.Zero;
Expand Down Expand Up @@ -106,9 +106,9 @@ this point to position it in orbit.
}
}

public void Draw()
public virtual void Draw()
{
if (Visable & Active)
if (Visable)
{
if (XNAModel == null)
return;
Expand All @@ -129,7 +129,7 @@ public void Draw()
effect.World = BaseWorld;

//if (XNATexture != null)
//effect.Texture = XNATexture;// ?? effect.Texture; //Replace texture if XNATexture is not null.
//effect.Texture = XNATexture;// ?? effect.Texture; //Replace texture if XNATexture is not null.

Services.Camera.Draw(effect);
}
Expand Down Expand Up @@ -275,8 +275,8 @@ public virtual void LoadContent()

public void Destroy()
{
if (ModelTransforms != null)
ModelTransforms.Initialize();
//if (ModelTransforms != null)
// ModelTransforms.Initialize();

BaseWorld = Matrix.Identity;
XNAModel = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
using System.Collections.Generic;
using System.Linq;
using System;
using Engine;

namespace CFNGamejam2.Entities
namespace Engine
{
public class Explode : GameComponent, IBeginable, IUpdateableComponent, ILoadContent
{
Expand All @@ -22,14 +21,14 @@ public Explode(Game game) : base(game)
Particles = new List<ExplodeParticle>();

game.Components.Add(this);
LoadContent();
BeginRun();
}

public override void Initialize()
{

base.Initialize();
LoadContent();
BeginRun();
}

public void LoadContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
using XnaModel = Microsoft.Xna.Framework.Graphics.Model;
using System.Collections.Generic;
using System;
using Engine;

namespace CFNGamejam2.Entities
namespace Engine
{
public class ExplodeParticle : AModel
{
Expand Down Expand Up @@ -44,9 +43,10 @@ public override void Update(GameTime gameTime)

public override void Spawn(Vector3 position)
{
Velocity = RandomVelocity(100);
base.Spawn(position);
Scale = Services.RandomMinMax(1, 2);

Velocity = RandomVelocity(100);
ModelScale = new Vector3(Services.RandomMinMax(0.5f, 1.5f));
LifeTimer.Reset(Services.RandomMinMax(0.1f, 1));
}
}
Expand Down
27 changes: 22 additions & 5 deletions CFNGamejam2/Engine/PositionedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class PositionedObject : GameComponent, IBeginable
// Doing these as fields is almost twice as fast as if they were properties.
// Also, sense XYZ are fields they do not get data binned as a property.
public PositionedObject ParentPO;
public List<PositionedObject> ChildrenPOs;
public Vector3 Position = Vector3.Zero;
public Vector3 Acceleration = Vector3.Zero;
public Vector3 Velocity = Vector3.Zero;
Expand Down Expand Up @@ -78,7 +79,24 @@ public class PositionedObject : GameComponent, IBeginable
/// <summary>
/// Enabled causes the class to update. If base of Sprite, enables sprite to be drawn.
/// </summary>
public bool Active { get => Enabled; set => Enabled = value; }
public bool Active
{
get => Enabled;

set
{
Enabled = value;

if (m_Parent)
{
foreach (PositionedObject child in ChildrenPOs)
{
if (child.ActiveDependent)
child.Active = value;
}
}
}
}
/// <summary>
/// Enabled the active bool will mirror that of the parent.
/// </summary>
Expand Down Expand Up @@ -108,6 +126,7 @@ public Rectangle BoundingBox
/// <param name="game">The game class</param>
public PositionedObject(Game game) : base(game)
{
ChildrenPOs = new List<PositionedObject>();
game.Components.Add(this);
}
#endregion
Expand Down Expand Up @@ -154,9 +173,6 @@ public override void Update(GameTime gameTime)
WorldRotation = Rotation + ParentPO.WorldRotation;
}

if (ActiveDependent)
Active = ParentPO.Active;

base.Update(gameTime);
}
else
Expand All @@ -178,7 +194,8 @@ public virtual void AddAsChildOf(PositionedObject Parent, bool activeDependent,
Child = true;
ParentPO = Parent;
ParentPO.Parent = true;
}
ParentPO.ChildrenPOs.Add(this);
}

public void Remove()
{
Expand Down
102 changes: 102 additions & 0 deletions CFNGamejam2/Engine/Smoke.cs
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);
}
}
}
60 changes: 60 additions & 0 deletions CFNGamejam2/Engine/SmokeParticle.cs
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);
}
}
}
16 changes: 14 additions & 2 deletions CFNGamejam2/Entities/Bomb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ namespace CFNGamejam2.Entities
{
public class Bomb : AModel
{
GameLogic RefGameLogic;
Explode Explosion;
Timer LifeTimer;


public Bomb(Game game) : base(game)
public Bomb(Game game, GameLogic gameLogic) : base(game)
{
RefGameLogic = gameLogic;
Explosion = new Explode(game);
LifeTimer = new Timer(game, 5);

Expand Down Expand Up @@ -57,6 +58,8 @@ public override void Update(GameTime gameTime)
RotationVelocity.Z = 0;
}

CheckCollusion();

base.Update(gameTime);
}

Expand All @@ -76,5 +79,14 @@ public void HitTarget()
Acceleration.Y = 0;
Explosion.Spawn(Position, Radius * 0.5f, 100);
}

void CheckCollusion()
{
if (SphereIntersect(RefGameLogic.RefPlayer))
{
HitTarget();
RefGameLogic.RefPlayer.HitDamage(1);
}
}
}
}
Loading

0 comments on commit 2677ac7

Please sign in to comment.