public override void Update(GameTime gameTime) { base.Update(gameTime); BounceOnScreen(); if (Global.probability(0.15)) { Particle p = Global.currentGame.particlePool.getParticle(); if (p != null) { p.location.X = Global.randFloat(Global.windowWidth); p.location.Y = Global.randFloat(Global.windowHeight); p.velocity.X = Global.randFloat(-.2f, -.05f); p.velocity.Y = -.1f; p.scale = Global.randFloat(); Global.randomizeBrightColor(ref p.color); p.changeState(STATE_ACTIVE); } } }
public void MultiActivateExplosion(Vector2 loc, int howMany) { for (int i = 0; i < howMany; i++) { Particle p = getParticle(); if (p != null) { float r = Global.randFloat(0.05f, 12.0f); float theta = Global.randAngle(); p.location = loc; p.velocity.X = r * (float)Math.Cos(theta); p.velocity.Y = r * (float)Math.Sin(theta); p.changeState(Particle.STATE_ACTIVE); } else { break; } } }
public override void Setup() { state = STATE_FLYING; location.X = Global.randFloat() * Global.windowWidth; location.Y = Global.randFloat() * Global.windowHeight; velocity.X = Global.randFloat(-0.05f, 0.05f); velocity.Y = Global.randFloat(-0.05f, 0.05f); rotation = Global.randAngle(); angularVelocity = Global.randFloat(-0.0003f, 0.0003f); layer = .02f; scale = 2.5f; friction = 1.0f; image = Global.bluePlanetImage; base.Setup(); //color.A = 140; }
public override void Update(GameTime gameTime) { switch (state) { case STATE_INACTIVE: break; case STATE_ACTIVE: if (hit) { changeState(STATE_KILL); } base.Update(gameTime); break; case STATE_CHARGING: if (parent == null) { break; } base.Update(gameTime); collideType = COLLIDE_TYPE_NONE; rotation = Global.randFloat((float)MathHelper.PiOver4); if (charger < 0.05f) { charger *= 1.05f; } else if (charger < 0.1f) { charger += .01f; } else if (charger < 1.5f) { charger += .005f; } scale = (float)(30.75 / 137) * Global.currentGame.Table.scale; scale *= charger; sRadius = radius * charger; //play with these numbers to adjust striker massScale = scale * 3; mass = 2000 * (massScale); speedScale += .1f; bulletSpeed = speedScale; float d = 137 + parent.radius; location.X = (float)(d * Math.Cos(facingAngle)); location.Y = (float)(d * Math.Sin(facingAngle)); oldLocation = location; break; case STATE_FIRING: charger = 0.0001f; if (parent == null) { break; } collideType = COLLIDE_TYPE_BALL; int x = this.state; //debug base.Update(gameTime); rotation = 0; hit = false; hitWall = false; velocity.X = bulletSpeed * (float)Math.Cos(facingAngle); velocity.Y = bulletSpeed * (float)Math.Sin(facingAngle); oldVelocity = velocity; changeParent(parent.parent); changeState(STATE_FIRED); break; case STATE_FIRED: if (parent == null) { break; } base.Update(gameTime); BounceOnTableWalls(); BounceOnTableWallObjects(); DieInPockets(); if (hitWall) { hitSound.Play(); changeState(STATE_KILL); } else if (hit) { changeState(STATE_DEATH); } break; case STATE_DEATH: base.Update(gameTime); if (color.A < 10) { changeState(STATE_KILL); } else { color.A = (byte)(color.A - (byte)(Global.rand.Next(5, 10))); } break; case STATE_KILL: //return to pool parent = null; velocity = Vector2.Zero; location = Vector2.Zero; absoluteLocation = Vector2.Zero; acceleration = Vector2.Zero; scale = 0.005f; massScale = scale; speedScale = 2; hit = false; hitWall = false; color = Color.White; changeState(STATE_INACTIVE); break; } }