基本信息
源码名称:c#做的喷泉效果 示例源码
源码大小:0.08M
文件格式:.rar
开发语言:C#
更新时间:2018-01-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 5 元×
微信扫码支付:5 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
c#做的喷泉效果
using System.Drawing;
namespace Particles
{
/// <summary>
/// Summary description for Firework.
/// </summary>
public class PSExplosion : ParticlesSystem
{
private static readonly int DEFAULT_NUM_PARTICLES = 150;
// Random numbers generator
private Random m_rand = new Random();
/// <summary>
/// Default constructor
/// </summary>
public PSExplosion() : this(Vector.Zero, Color.Black)
{ }
/// <summary>
/// Constructor
/// </summary>
/// <param name="pos">Starting position of system</param>
public PSExplosion(Vector pos) : this(Vector.Zero, Color.Black)
{ }
/// <summary>
/// Constructor
/// </summary>
/// <param name="pos">Starting position of system</param>
/// <param name="col">Color of the particles in the system</param>
public PSExplosion(Vector pos, Color col)
{
// Set system's position at given position
m_Position = pos;
// Set system color to given color
m_Color = col;
// Create all the particles in the system
for (int i = 0; i < DEFAULT_NUM_PARTICLES; i )
{
// Create particle, and add it to the list of particles
m_Particles.Add(GenerateParticle());
}
}
/// <summary>
/// Update all the particles in the system
/// </summary>
/// <returns>False - if there are no more particles in system
/// True - otherwise</returns>
public override bool Update()
{
Particle part;
// Get number of particles in the system
int count = m_Particles.Count;
// For each particle
for (int i=0; i<count; i )
{
// Get particle from list
part = (Particle)m_Particles[i];
// Update particle and check age
part.Update();
if (part.Life > particleMaxLife)
{
// Remove old particles
m_Particles.RemoveAt(i);
// Update counter and index
i--;
count = m_Particles.Count;
}
}
// If there are no more particles in the system
if (m_Particles.Count <= 0)
return false;
return true;
}
/// <summary>
/// Generate a single particle in the system.
/// This function is used when particles are first created, and when they are regenerated
/// </summary>
/// <returns>New particle</returns>
protected override Particle GenerateParticle()
{
// Generate random direction & speed for new particle
float rndX = 2 * ((float)m_rand.NextDouble() - 0.5f);
float rndY = 2 * ((float)m_rand.NextDouble() - 0.5f);
float rndZ = 2 * ((float)m_rand.NextDouble() - 0.5f);
// Create new particle at system's starting position
Particle part = new Particle(m_Position,
// With generated direction and speed
new Vector(rndX, rndY, rndZ), m_Color,
// And a random starting life
m_rand.Next(50));
// Return newly created particle
return part;
}
}
}
c#做的喷泉效果
using System;
using System.Drawing;
namespace Particles
{
/// <summary>
/// Summary description for Firework.
/// </summary>
public class PSExplosion : ParticlesSystem
{
private static readonly int DEFAULT_NUM_PARTICLES = 150;
// Random numbers generator
private Random m_rand = new Random();
/// <summary>
/// Default constructor
/// </summary>
public PSExplosion() : this(Vector.Zero, Color.Black)
{ }
/// <summary>
/// Constructor
/// </summary>
/// <param name="pos">Starting position of system</param>
public PSExplosion(Vector pos) : this(Vector.Zero, Color.Black)
{ }
/// <summary>
/// Constructor
/// </summary>
/// <param name="pos">Starting position of system</param>
/// <param name="col">Color of the particles in the system</param>
public PSExplosion(Vector pos, Color col)
{
// Set system's position at given position
m_Position = pos;
// Set system color to given color
m_Color = col;
// Create all the particles in the system
for (int i = 0; i < DEFAULT_NUM_PARTICLES; i )
{
// Create particle, and add it to the list of particles
m_Particles.Add(GenerateParticle());
}
}
/// <summary>
/// Update all the particles in the system
/// </summary>
/// <returns>False - if there are no more particles in system
/// True - otherwise</returns>
public override bool Update()
{
Particle part;
// Get number of particles in the system
int count = m_Particles.Count;
// For each particle
for (int i=0; i<count; i )
{
// Get particle from list
part = (Particle)m_Particles[i];
// Update particle and check age
part.Update();
if (part.Life > particleMaxLife)
{
// Remove old particles
m_Particles.RemoveAt(i);
// Update counter and index
i--;
count = m_Particles.Count;
}
}
// If there are no more particles in the system
if (m_Particles.Count <= 0)
return false;
return true;
}
/// <summary>
/// Generate a single particle in the system.
/// This function is used when particles are first created, and when they are regenerated
/// </summary>
/// <returns>New particle</returns>
protected override Particle GenerateParticle()
{
// Generate random direction & speed for new particle
float rndX = 2 * ((float)m_rand.NextDouble() - 0.5f);
float rndY = 2 * ((float)m_rand.NextDouble() - 0.5f);
float rndZ = 2 * ((float)m_rand.NextDouble() - 0.5f);
// Create new particle at system's starting position
Particle part = new Particle(m_Position,
// With generated direction and speed
new Vector(rndX, rndY, rndZ), m_Color,
// And a random starting life
m_rand.Next(50));
// Return newly created particle
return part;
}
}
}