Permalink
Browse files

Added a helper that generates a white noise static like entity.

  • Loading branch information...
Thraka committed Apr 20, 2016
1 parent e6869b1 commit 066e68bc4ce8ae8f1a3e525e347f89e0e9f14f66
Showing with 58 additions and 0 deletions.
  1. +57 −0 SadConsole.GameHelpers/Entities.cs
  2. +1 −0 SadConsole.GameHelpers/SadConsole.GameHelpers.projitems
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SadConsole.GameHelpers
{
/// <summary>
/// Helpers regarding <see cref="SadConsole.Entities.Entity"/> types and animations.
/// </summary>
public static class Entities
{
/// <summary>
///
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="frames"></param>
/// <param name="blankChance"></param>
/// <returns></returns>
public static SadConsole.Entities.Entity CreateStaticEntity(int width, int height, int frames, double blankChance)
{
SadConsole.Entities.Entity entity = new SadConsole.Entities.Entity();
SadConsole.Entities.Animation animation = new SadConsole.Entities.Animation("default", width, height);
for (int f = 0; f < frames; f++)
{
var frame = animation.CreateFrame();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
int character = Engine.Random.Next(48, 168);
if (Engine.Random.NextDouble() <= blankChance)
character = 32;
frame.SetCharacter(x, y, character);
frame.SetForeground(x, y, Microsoft.Xna.Framework.Color.White * (float)(Engine.Random.NextDouble() * (1.0d - 0.5d) + 0.5d));
}
}
}
animation.AnimationDuration = 1;
animation.Repeat = true;
entity.AddAnimation(animation);
entity.SetActiveAnimation(animation);
entity.Start();
return entity;
}
}
}
@@ -53,6 +53,7 @@
<Compile Include="$(MSBuildThisFileDirectory)AccidentalNoise\NoiseLookupTable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AccidentalNoise\Utilities.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Action.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GameConsole.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GameObject.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GameObjectCollection.cs" />

0 comments on commit 066e68b

Please sign in to comment.