/// <summary> /// Add a new particle to be managed by this instance of the class /// </summary> /// <param name="Image">Image to display for the particle.</param> /// <param name="Top">Top coordinate for the particle's initial position.</param> /// <param name="Left">Left coordinate of hte particle's initial position.</param> /// <param name="Height">Initial Height in pixes of the particle.</param> /// <param name="Width">Initial Width of the particle.</param> /// <param name="SpeedX">Speed of the particle along the X axis.</param> /// <param name="SpeedY">Speed of the particle along the Y axis.</param> /// <param name="Tint">Tint or color overlay for the particle.</param> public void AddParticle(Texture2D Image, float Top, float Left, int Height, int Width, float SpeedX, float SpeedY, Color Tint) { Particle2D NewBullet = new Particle2D(); NewBullet.TopLeft.X = (int)Left; NewBullet.TopLeft.Y = (int)Top; NewBullet.Width = Width; NewBullet.Height = Height; NewBullet.Image = Image; NewBullet.SpeedX = SpeedX; NewBullet.SpeedY = SpeedY; NewBullet.Tint = Tint; cParticleList.Add(NewBullet); }
/// <summary> /// Add a new particle to be managed by this instance of the class /// </summary> /// <param name="NewParticle">Particle object to be managed.</param> public void AddParticle(Particle2D NewParticle) { cParticleList.Add(NewParticle); }
private void CreateNewAsteroid(int Size, Vector2 Position) { Particle2D AstInfo; Vector2 AstSpeed; AstInfo = new Particle2D(); AstInfo.Width = Size; AstInfo.Height = Size; if ((Position.X == -1) && (Position.Y == -1)) { AstInfo.TopLeft.X = AstInfo.Width * -1; AstInfo.TopLeft.Y = AstInfo.Height * -1; } else { AstInfo.TopLeft.X = Position.X; AstInfo.TopLeft.Y = Position.Y; } AstInfo.Image = cTextureDict[Textures.Asteroid]; AstSpeed = MGMath.CalculateXYMagnitude((float)cRandom.NextDouble() * 6.28318531f, 2); AstInfo.SpeedX = AstSpeed.X; AstInfo.SpeedY = AstSpeed.Y; AstInfo.Tint = new Color(150 + cRandom.Next(0, 105), 150 + cRandom.Next(0, 105), 150 + cRandom.Next(0, 105), 255); AstInfo.SpeedRotate = ((float)cRandom.NextDouble() * 0.2f) - 0.1f; cAsteroids.AddParticle(AstInfo); }
private void CreateParticleBurst(Vector2 Position, int Count, int Size, Color Tint, Texture2D Image) { Particle2D NewSparkle; Vector2 Speed; for (int Ctr = 0; Ctr < Count; Ctr++) { NewSparkle = new Particle2D(); NewSparkle.AlphaFade = true; NewSparkle.TimeToLive = 100 + (cRandom.NextDouble() * 1000); NewSparkle.Height = Size; NewSparkle.Width = Size; NewSparkle.TopLeft = Position; NewSparkle.Image = Image; NewSparkle.Rotation = (float)(cRandom.NextDouble() * 6.2f); Speed = MGMath.CalculateXYMagnitude(NewSparkle.Rotation, (float)(cRandom.NextDouble() * (70 / Size))); NewSparkle.SpeedX = Speed.X; NewSparkle.SpeedY = Speed.Y; NewSparkle.SpeedRotate = (float)cRandom.NextDouble() * 0.25f; NewSparkle.Tint = Tint; cSparkles.AddParticle(NewSparkle); } }
private void CommandSentEventHandler(object Sender, string Command) { if (Tools.RegEx.QuickTest(Command, "^(quit|exit)$") == true) { Exit(); } else if (Tools.RegEx.QuickTest(Command, "^ship *stop$") == true) { cPlayerShip.cSpeedX = 0; cPlayerShip.cSpeedY = 0; cDevConsole.AddText("Ship speed set to 0"); } else if (Tools.RegEx.QuickTest(Command, "^ship *center$") == true) { cPlayerShip.Top = (cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Height) / 2 - (cPlayerShip.Height / 2); cPlayerShip.Left = (cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Width) / 2 - (cPlayerShip.Width / 2); cDevConsole.AddText("Ship position set to [X=" + cPlayerShip.Left + ", Y=" + cPlayerShip.Width + "]"); } else if (Tools.RegEx.QuickTest(Command, "^ship *state$") == true) { cDevConsole.AddText("Ship Position [X=" + cPlayerShip.Top + ", Y=" + cPlayerShip.Left + "]"); cDevConsole.AddText(" Speed X=" + cPlayerShip.cSpeedX + " Y=" + cPlayerShip.cSpeedY); cDevConsole.AddText(" Size Width=" + cPlayerShip.Width + " Height=" + cPlayerShip.Height); } else if (Tools.RegEx.QuickTest(Command, "^fire *spread$") == true) { cDevConsole.AddText("Firing Spread"); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation - 0.628f, 10, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation - 0.314f, 10, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation, 10, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation + 0.314f, 10, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation + 0.628f, 10, Color.White); } else if (Tools.RegEx.QuickTest(Command, "^fire *multi-?(ple|shot)$") == true) { cDevConsole.AddText("Firing Multi-Shot"); Vector2 BulletOrigin, BulletOffset; BulletOrigin = MGMath.CalculateXYMagnitude(-1 * cPlayerShip.cRotation, cPlayerShip.Width / 4); BulletOffset = MGMath.CalculateXYMagnitude(-1 * cPlayerShip.cRotation + 1.570796f, cPlayerShip.Width / 5); //Adjust it so that it's relative to the top left screen corner BulletOrigin.Y += cPlayerShip.Top + (cPlayerShip.Height / 2); BulletOrigin.X += cPlayerShip.Left + (cPlayerShip.Height / 2); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y + (BulletOffset.Y * 2) - 10, BulletOrigin.X + (BulletOffset.X * 2) - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y + BulletOffset.Y - 10, BulletOrigin.X + BulletOffset.X - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y - 10, BulletOrigin.X - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y - BulletOffset.Y - 10, BulletOrigin.X - BulletOffset.X - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y - (BulletOffset.Y * 2) - 10, BulletOrigin.X - (BulletOffset.X * 2) - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White); } else if (Tools.RegEx.QuickTest(Command, "^new *asteroid$") == true) { cDevConsole.AddText("Spawning Asteroid"); cAsteroids.AddParticle(cTextureDict[Textures.Asteroid], cPlayerShip.Top + (cPlayerShip.Height / 2) - 50, cPlayerShip.Left + (cPlayerShip.Height / 2) - 50, 100, 100, cPlayerShip.cRotation - 0.628f, 2, Color.White); } else if (Tools.RegEx.QuickTest(Command, @"^\s*ast(eroid)?\s*count\s*?$") == true) { cDevConsole.AddText("Current Asteroid Count: " + cAsteroids.ParticleList.Count); } else if (Tools.RegEx.QuickTest(Command, @"^\s*ast(eroid)?\s*clear$") == true) { cDevConsole.AddText("Destroying all asteroids"); cAsteroids.ParticleList.Clear(); } else if (Tools.RegEx.QuickTest(Command, @"^\s*mouse\s*turn\s*=\s*(on|true|enable|1)\s*$") == true) { cDevConsole.AddText("Using mouse position to rotate ship"); cPlayerShip.MouseRotate = true; } else if (Tools.RegEx.QuickTest(Command, @"^\s*mouse\s*turn\s*=\s*(off|false|disable|0)\s*$") == true) { cDevConsole.AddText("Using arrow keys to rotate ship"); cPlayerShip.MouseRotate = false; } else if (Tools.RegEx.QuickTest(Command, @"^\s*(spawn|new)\s*hunter\s*$") == true) { cDevConsole.AddText("Spawning new hunter UFO"); Vector2 StartPos = new Vector2(-50, -50); CreateNewHunter(100, StartPos); } else if (Tools.RegEx.QuickTest(Command, @"^\s*(sparkles|particles)\s*$") == true) { Particle2D NewSparkle; Vector2 Speed; cDevConsole.AddText("Particle burst on player ship"); for (int Ctr = 0; Ctr < 25; Ctr++) { NewSparkle = new Particle2D(); NewSparkle.AlphaFade = true; NewSparkle.TimeToLive = 100 + (cRandom.NextDouble() * 1000); NewSparkle.Height = 10; NewSparkle.Width = 10; NewSparkle.TopLeft.X = cPlayerShip.Left + (cPlayerShip.Width / 2); NewSparkle.TopLeft.Y = cPlayerShip.Top + (cPlayerShip.Height / 2); NewSparkle.Image = cTextureDict[Textures.Bullet]; NewSparkle.Rotation = (float)(cRandom.NextDouble() * 6.2f); Speed = MGMath.CalculateXYMagnitude(NewSparkle.Rotation, (float)(cRandom.NextDouble() * 5)); NewSparkle.SpeedX = Speed.X; NewSparkle.SpeedY = Speed.Y; NewSparkle.Tint = Color.White; cSparkles.AddParticle(NewSparkle); } } else if (Tools.RegEx.QuickTest(Command, @"^\s*(headlight|flashlight|dark)\s*=\s*(1|true|enable)\s*$") == true) { cDevConsole.AddText("Headlight mode enabled."); cHeadlightMode = true; } else if (Tools.RegEx.QuickTest(Command, @"^\s*(headlight|flashlight|dark)\s*=\s*(0|false|disable)\s*$") == true) { cDevConsole.AddText("Headlight mode disabled."); cHeadlightMode = false; } else if (Tools.RegEx.QuickTest(Command, @"^\s*stats\s*=\s*(1|true|enable|on)\s*$") == true) { cDevConsole.AddText("Stats enabled."); cShowStats = true; } else if (Tools.RegEx.QuickTest(Command, @"^\s*stats\s*=\s*(0|false|disable|off)\s*$") == true) { cDevConsole.AddText("Stats disabled."); cShowStats = false; } else { cDevConsole.AddText("Unrecognized command: " + Command); } }