Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- namespace Pong
- {
- public class EmitterBase : DrawableGameComponent, IParticleEmitter
- {
- public SpriteBatch SpriteBatch
- {
- get
- {
- return (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
- }
- }
- public ParticleEmitterService ParticleEmitter
- {
- get { return (ParticleEmitterService)Game.Services.GetService(typeof(ParticleEmitterService)); }
- }
- public BlendState ParticleBlendState { get; set; }
- public IGameEntity GameEntity { get; set; }
- public Vector2 EnityOffset { get; set; }
- protected Matrix transform { get; set; }
- public Vector2 Position { get; set; }
- public Vector2 Origin { get; set; }
- public float Scale { get; set; }
- public float Rotation { get; set; }
- public Texture2D texture { get; set; }
- public Vector2[] particles { get; set; }
- public float[] scaleParticle { get; set; }
- public float[] rotationParticle { get; set; }
- public bool[] activeParticle { get; set; }
- public Color Color { get; set; }
- public bool Alive { get; set; }
- protected int particleCount = 0;
- public int ParticleCount { get { return particleCount; } }
- protected Random rnd = new Random(DateTime.Now.Millisecond);
- protected string textureAsset;
- public Rectangle bounds { get { return new Rectangle(); } }
- public EmitterBase(Game game, string TextureAsset)
- : base(game)
- {
- textureAsset = TextureAsset;
- Position = Vector2.Zero;
- Origin = Vector2.Zero;
- Scale = 1f;
- Rotation = 0;
- ParticleBlendState = BlendState.Additive;
- Color = Color.White;
- }
- public override void Update(GameTime gameTime)
- {
- if (GameEntity != null)
- {
- Rotation = GameEntity.Rotation;
- Position = GameEntity.Position + EnityOffset;
- }
- }
- public override void Initialize()
- {
- particles = new Vector2[ParticleCount];
- scaleParticle = new float[ParticleCount];
- rotationParticle = new float[ParticleCount];
- activeParticle = new bool[ParticleCount];
- texture = Game.Content.Load<Texture2D>(textureAsset);
- Origin = new Vector2(texture.Width / 2, texture.Height / 2);
- for (int p = 0; p < ParticleCount; p++)
- {
- rotationParticle[p] = 0;
- particles[p] = Vector2.Zero;
- scaleParticle[p] = Scale;
- }
- }
- public override void Draw(GameTime gameTime)
- {
- SpriteBatch.Begin(SpriteSortMode.Deferred, ParticleBlendState);
- for (int p = 0; p < ParticleCount; p++)
- {
- if (activeParticle[p])
- SpriteBatch.Draw(texture, particles[p], null, Color, rotationParticle[p], Origin, scaleParticle[p], SpriteEffects.None, 0);
- }
- SpriteBatch.End();
- }
- public virtual bool DoCollision(IGameEntity entity)
- {
- return false;
- }
- public virtual void Die()
- {
- }
- }
- }
RAW Paste Data