public ParticleForce(ParticleGenerator inOwner) { owner = inOwner; position = inOwner.position; velocity = new Vector2((inOwner.myGame.randomizer.Next(0, 50)) * ((inOwner.myGame.randomizer.Next(2) < 1) ? -1 : 1), (inOwner.myGame.randomizer.Next(0, 50)) * ((inOwner.myGame.randomizer.Next(2) < 1) ? -1 : 1)); maxVelocity = new Vector2(300, 300); gravAcceleration = new Vector2(0, 250); maxAcceleration = new Vector2(300, 300); // use the owner to load our sprite mySprite = owner.myGame.Content.Load<Texture2D>(mySpritePath); myRectangle = new Rectangle((int)position.X, (int)position.Y, 24, 24); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here if (Mouse.GetState().LeftButton == ButtonState.Pressed) { bLeftButtonPressed = true; } if( Mouse.GetState().LeftButton == ButtonState.Released && bLeftButtonPressed ) { bLeftButtonPressed = false; ParticleGenerator partGen = new ParticleGenerator( this, new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); partGen.SpawnParticles(20); Components.Add(partGen); partGenList.Add(partGen); } if (Mouse.GetState().RightButton == ButtonState.Pressed) { bRightButtonPressed = true; timeHeldKey += (float)gameTime.ElapsedGameTime.TotalSeconds; if (pendingMod == null) { if (bAddingRepulsor) { pendingMod = new ParticleRepulsor(this, new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); } else { pendingMod = new ParticleAttractor(this, new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); } Components.Add(pendingMod); partModList.Add(pendingMod); } if (pendingMod != null) { pendingMod.drawScale += (float)gameTime.ElapsedGameTime.TotalSeconds * 0.6f; } } if (Mouse.GetState().RightButton == ButtonState.Released && bRightButtonPressed) { bRightButtonPressed = false; if (pendingMod != null) { pendingMod.force = 50 + timeHeldKey * 300.0f; pendingMod = null; } timeHeldKey = 0.0f; } if (Keyboard.GetState().IsKeyDown(Keys.Space)) { bSpacebarPressed = true; } if (!Keyboard.GetState().IsKeyDown(Keys.Space)&& bSpacebarPressed) { bSpacebarPressed = false; bAddingRepulsor = !bAddingRepulsor; } base.Update(gameTime); }