Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Everything displays correctly, but I am not able to update the particle values. Am I not passing in // the BlueParticleEmitter correctly?
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Input;
- namespace Pong
- {
- class DebuggingTools
- {
- GraphicsDevice graphicsDevice;
- SpriteBatch spriteBatch;
- ContentManager contentManager;
- SpriteFont arial;
- SpriteFont gameFont;
- GameTime gameTime;
- GameplayScreen gameplayScreen; // to access gameplayScreen
- BlueParticleEmitter blueParticleEmitter; // to access BlueParticleEmitter class
- Game game; // pass it into BlueParticleEmitter constructor
- KeyboardState current, previous; // Keyboard states to adjust values at runtime
- /// <summary>
- /// Constructor
- /// </summary>
- public DebuggingTools(GameplayScreen screen, BlueParticleEmitter BPE)
- {
- gameplayScreen = screen;
- blueParticleEmitter = BPE;
- }
- public void LoadContent(ContentManager contentManager)
- {
- arial = contentManager.Load<SpriteFont>(@"gfx/fonts/Arial");
- }
- public void Draw(SpriteBatch spriteBatch)
- {
- //disableTurboCooldown
- spriteBatch.DrawString(arial, string.Format("DTCooldown: {0}", gameplayScreen.disableTurboCooldown),
- new Vector2(20, 100), Color.White);
- //twoSecondBurst
- spriteBatch.DrawString(arial, string.Format("2SecBurst: {0}", gameplayScreen.twoSecondBurst),
- new Vector2(20, 130), Color.White);
- //fiveSecondCoolDown
- spriteBatch.DrawString(arial, string.Format("5SecCD: {0}", gameplayScreen.fiveSecondCoolDown),
- new Vector2(20, 160), Color.White);
- //CoolDown
- spriteBatch.DrawString(arial, string.Format("CoolDown: {0}", gameplayScreen.coolDown),
- new Vector2(20, 190), Color.White);
- //ParicleRotation
- spriteBatch.DrawString(arial, string.Format("ParticleRotation: {0}", blueParticleEmitter.ParticleRotation),
- new Vector2(20, 220), Color.White);
- //ParticleGrowthRate
- spriteBatch.DrawString(arial, string.Format("ParticleGrowthRate {0}", blueParticleEmitter.ParticleGrowthRate),
- new Vector2(20, 250), Color.White);
- //ParticleScale
- spriteBatch.DrawString(arial, string.Format("ParticleScale: {0}", blueParticleEmitter.ParticleScale),
- new Vector2(20, 280), Color.White);
- }
- public void Update(GameTime gameTime)
- {
- // Adjusts values of particle variables at runtime
- previous = current;
- current = Keyboard.GetState();
- // Adjust particle rotation
- if (current.IsKeyDown(Keys.A))
- {
- blueParticleEmitter.ParticleRotation ++;
- }
- // Adjust particle growth rate
- if (current.IsKeyDown(Keys.S))
- {
- blueParticleEmitter.ParticleGrowthRate ++;
- }
- // Adjust particle scale
- if (current.IsKeyDown(Keys.D))
- {
- blueParticleEmitter.ParticleScale ++;
- }
- }
- }
- }
- ////////////////////////////////////////////////
- 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 BlueParticleEmitter : EmitterBase
- {
- // Debug variables, accessible from the debug class
- public int ParticleRotation = 1;
- public float ParticleGrowthRate = 1f;
- public float ParticleScale = .5f;
- public BlueParticleEmitter(Game game)
- : base(game, @"gfx/Particles/blueParticle")
- {
- particleCount = 200;
- Scale = .5f;
- }
- public override void Initialize()
- {
- base.Initialize();
- activeParticle[0] = true;
- }
- public override void Update(GameTime gameTime)
- {
- // set particle positions.
- for (int p = 0; p < ParticleCount; p++)
- {
- if (activeParticle[p])
- {
- //rotationParticle[p] -= (p + 1) / ParticleCount; // rotation
- //particles[p].Y += 1f; // rate at which they grow
- //scaleParticle[p] += .15f; // Start small, grows big at tail
- //float dist = Vector2.Distance(Position, particles[p]);
- rotationParticle[p] -= (p + ParticleRotation) / ParticleCount; // rotation
- particles[p].Y += ParticleGrowthRate; // rate at which they grow
- scaleParticle[p] += ParticleScale; // Start small, grows big at tail
- float dist = Vector2.Distance(Position, particles[p]);
- if (dist > 125) // How far until it disappears
- activeParticle[p] = false;
- }
- else
- {
- particles[p] = Position;
- particles[p].X += MathHelper.Lerp(-5, 5, (float)rnd.NextDouble());
- scaleParticle[p] = Scale;
- int nextP = p - 1;
- if (p == 0)
- {
- nextP = ParticleCount - 1;
- }
- float dist = Vector2.Distance(particles[nextP], particles[p]);
- if (dist > 25)
- activeParticle[p] = true;
- }
- }
- base.Update(gameTime);
- }
- }
- }
RAW Paste Data