Guest User

Untitled

a guest
Aug 2nd, 2012
46
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Everything displays correctly, but I am not able to update the particle values. Am I not passing in // the BlueParticleEmitter correctly?
  2.  
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8.  
  9. using Microsoft.Xna.Framework;
  10. using Microsoft.Xna.Framework.Graphics;
  11. using Microsoft.Xna.Framework.Content;
  12. using Microsoft.Xna.Framework.Input;
  13.  
  14.  
  15. namespace Pong
  16. {
  17.     class DebuggingTools
  18.     {
  19.  
  20.         GraphicsDevice graphicsDevice;
  21.         SpriteBatch spriteBatch;
  22.         ContentManager contentManager;
  23.         SpriteFont arial;
  24.         SpriteFont gameFont;
  25.         GameTime gameTime;
  26.  
  27.         GameplayScreen gameplayScreen; // to access gameplayScreen
  28.         BlueParticleEmitter blueParticleEmitter; // to access BlueParticleEmitter class
  29.         Game game; // pass it into BlueParticleEmitter constructor
  30.         KeyboardState current, previous; // Keyboard states to adjust values at runtime
  31.      
  32.  
  33.         /// <summary>
  34.         /// Constructor
  35.         /// </summary>
  36.         public DebuggingTools(GameplayScreen screen, BlueParticleEmitter BPE)
  37.         {
  38.             gameplayScreen = screen;
  39.             blueParticleEmitter = BPE;
  40.         }
  41.  
  42.         public void LoadContent(ContentManager contentManager)
  43.         {
  44.             arial = contentManager.Load<SpriteFont>(@"gfx/fonts/Arial");
  45.         }
  46.  
  47.         public void Draw(SpriteBatch spriteBatch)
  48.         {
  49.             //disableTurboCooldown
  50.             spriteBatch.DrawString(arial, string.Format("DTCooldown: {0}", gameplayScreen.disableTurboCooldown),
  51.             new Vector2(20, 100), Color.White);
  52.  
  53.             //twoSecondBurst
  54.             spriteBatch.DrawString(arial, string.Format("2SecBurst: {0}", gameplayScreen.twoSecondBurst),
  55.             new Vector2(20, 130), Color.White);
  56.  
  57.             //fiveSecondCoolDown
  58.             spriteBatch.DrawString(arial, string.Format("5SecCD: {0}", gameplayScreen.fiveSecondCoolDown),
  59.             new Vector2(20, 160), Color.White);
  60.  
  61.             //CoolDown
  62.             spriteBatch.DrawString(arial, string.Format("CoolDown: {0}", gameplayScreen.coolDown),
  63.             new Vector2(20, 190), Color.White);
  64.  
  65.             //ParicleRotation
  66.             spriteBatch.DrawString(arial, string.Format("ParticleRotation: {0}", blueParticleEmitter.ParticleRotation),
  67.             new Vector2(20, 220), Color.White);
  68.  
  69.             //ParticleGrowthRate
  70.             spriteBatch.DrawString(arial, string.Format("ParticleGrowthRate {0}", blueParticleEmitter.ParticleGrowthRate),
  71.             new Vector2(20, 250), Color.White);
  72.  
  73.             //ParticleScale
  74.             spriteBatch.DrawString(arial, string.Format("ParticleScale: {0}", blueParticleEmitter.ParticleScale),
  75.             new Vector2(20, 280), Color.White);
  76.  
  77.         }
  78.  
  79.         public void Update(GameTime gameTime)
  80.         {
  81.             // Adjusts values of particle variables at runtime
  82.             previous = current;
  83.             current = Keyboard.GetState();
  84.  
  85.             // Adjust particle rotation
  86.             if (current.IsKeyDown(Keys.A))
  87.             {
  88.                 blueParticleEmitter.ParticleRotation ++;  
  89.             }
  90.  
  91.             // Adjust particle growth rate
  92.             if (current.IsKeyDown(Keys.S))
  93.             {
  94.                 blueParticleEmitter.ParticleGrowthRate ++;
  95.             }
  96.  
  97.             // Adjust particle scale
  98.             if (current.IsKeyDown(Keys.D))
  99.             {
  100.                 blueParticleEmitter.ParticleScale ++;
  101.             }
  102.         }
  103.  
  104.     }
  105. }
  106.  
  107.  
  108.  
  109.  
  110. ////////////////////////////////////////////////
  111.  
  112.  
  113. using System;
  114. using System.Collections.Generic;
  115. using System.Linq;
  116. using System.Text;
  117.  
  118. using Microsoft.Xna.Framework;
  119. using Microsoft.Xna.Framework.Graphics;
  120.  
  121. namespace Pong
  122. {
  123.     public class BlueParticleEmitter : EmitterBase
  124.     {
  125.  
  126.         // Debug variables, accessible from the debug class
  127.         public int ParticleRotation = 1;
  128.         public float ParticleGrowthRate = 1f;
  129.         public float ParticleScale = .5f;
  130.  
  131.         public BlueParticleEmitter(Game game)
  132.             : base(game, @"gfx/Particles/blueParticle")
  133.         {
  134.             particleCount = 200;
  135.             Scale = .5f;
  136.         }
  137.  
  138.         public override void Initialize()
  139.         {
  140.             base.Initialize();
  141.             activeParticle[0] = true;
  142.         }
  143.  
  144.         public override void Update(GameTime gameTime)
  145.         {
  146.             // set particle positions.
  147.             for (int p = 0; p < ParticleCount; p++)
  148.             {
  149.                 if (activeParticle[p])
  150.                 {
  151.                     //rotationParticle[p] -= (p + 1) / ParticleCount; // rotation
  152.                     //particles[p].Y += 1f; // rate at which they grow
  153.                     //scaleParticle[p] += .15f; // Start small, grows big at tail
  154.                     //float dist = Vector2.Distance(Position, particles[p]);
  155.  
  156.                     rotationParticle[p] -= (p + ParticleRotation) / ParticleCount; // rotation
  157.                     particles[p].Y += ParticleGrowthRate; // rate at which they grow
  158.                     scaleParticle[p] += ParticleScale; // Start small, grows big at tail
  159.                     float dist = Vector2.Distance(Position, particles[p]);
  160.  
  161.                     if (dist > 125) // How far until it disappears
  162.                         activeParticle[p] = false;
  163.                 }
  164.                 else
  165.                 {
  166.                     particles[p] = Position;
  167.                     particles[p].X += MathHelper.Lerp(-5, 5, (float)rnd.NextDouble());
  168.  
  169.                     scaleParticle[p] = Scale;
  170.                     int nextP = p - 1;
  171.  
  172.                     if (p == 0)
  173.                     {
  174.                         nextP = ParticleCount - 1;
  175.                     }
  176.  
  177.                     float dist = Vector2.Distance(particles[nextP], particles[p]);
  178.                     if (dist > 25)
  179.                         activeParticle[p] = true;
  180.                 }
  181.             }
  182.             base.Update(gameTime);
  183.         }
  184.     }
  185. }
RAW Paste Data