#region LICENSE
/*
* $RCSfile: ParticlesExample.cs,v $
* Copyright (C) 2005 Rob Loach (http://www.robloach.net)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#endregion LICENSE
using System;
using System.IO;
using System.Drawing;
using SdlDotNet.Particles;
using SdlDotNet.Particles.Emitters;
using SdlDotNet.Particles.Manipulators;
using SdlDotNet.Graphics.Sprites;
using SdlDotNet.Core;
using SdlDotNet.Input;
using SdlDotNet.Graphics;
namespace EjemploParticulas
{
public class Ejemplo3 : IDisposable
{
ParticleSystem particles = new ParticleSystem();
ParticleVortex vort = new ParticleVortex(1f, 200f);
public Ejemplo3()
{
Video.WindowIcon();
Video.WindowCaption = "SDL.NET - Particula Pixel y Particula Sprite";
Video.SetVideoMode(400, 300);
Events.KeyboardDown += new EventHandler(this.KeyboardDown);
Events.MouseMotion += new EventHandler(this.MouseMotion);
Events.Fps = 30;
Events.Tick += new EventHandler(this.Tick);
Events.Quit += new EventHandler(this.Quit);
}
public void Go()
{
//creamos una particula que es un pixel
ParticlePixel first = new ParticlePixel(Color.White, 100, 200, new Vector(0, 0, 0), -1);
particles.Add(first); // la agregamos al sistema
//hacemos otra particula que es sprite animado
AnimationCollection anim = new AnimationCollection();
SurfaceCollection surfaces = new SurfaceCollection();
surfaces.Add("BALL2.png", new Size(50, 50));
anim.Add(surfaces, 1);
AnimatedSprite marble = new AnimatedSprite(anim);
marble.Animate = true;
ParticleSprite second = new ParticleSprite(marble, 200, 200, new Vector(-7, -9, 0), 500);
second.Life = -1;
particles.Add(second); // la agregamos al sistema
// agregamos manipuladores
ParticleGravity grav = new ParticleGravity(0.5f);
particles.Manipulators.Add(grav); // Gravedad de 0.5f
particles.Manipulators.Add(new ParticleFriction(0.3f)); // Slow down particles
particles.Manipulators.Add(vort); // se agrega el efecto de vórtice si el mouse se acerca a la partícula
particles.Manipulators.Add(new ParticleBoundary(SdlDotNet.Graphics.Video.Screen.Size)); // fix particles on screen.
Events.Run();
}
[STAThread]
public static void Main()
{
Ejemplo3 particula = new Ejemplo3();
particula.Go();
}
private void Tick(object sender, TickEventArgs e)
{
particles.Update();
Video.Screen.Fill(Color.Black);
particles.Render(Video.Screen);
Video.Screen.Update();
}
private void KeyboardDown(object sender, KeyboardEventArgs e)
{
if (e.Key == Key.Escape)
{
Events.QuitApplication();
}
}
private void Quit(object sender, QuitEventArgs e)
{
Events.QuitApplication();
}
private void MouseMotion(object sender, MouseMotionEventArgs e)
{
vort.X = e.X;
vort.Y = e.Y;
}
#region IDisposable Members
private bool disposed;
///
/// Destroy object
///
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Destroy object
///
public void Close()
{
Dispose();
}
///
/// Destroy object
///
~Ejemplo3()
{
Dispose(false);
}
///
///
///
///
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
this.disposed = true;
}
}
#endregion
}
}
|