public override bool getPowerup(BCBlockGameState gstate,Paddle onPaddle, GamePowerUp gpower) { if(onPaddle==null) return false; //don't accept it. //reject it with great prejudice. //move the location temporarily. PointF oldposition = gpower.Location; SizeF oldsize = gpower.Size; gpower.Location = PointF.Empty; //draw to a temporary bitmap. Bitmap drawtothis = new Bitmap(16, 16); Graphics useg = Graphics.FromImage(drawtothis); useg.Clear(Color.Transparent); gpower.Draw(useg); //reset position. gpower.Location = oldposition; gpower.Size = oldsize; //get average. var averagedpixel = Color.FromArgb((int)((from p in drawtothis.getPixels() select p.ToArgb()).Average())); ExplosionEffect ee = new ExplosionEffect(gpower.Location, 72); ee.ExplosionColor = averagedpixel; ee.DamageBlocks = false; ee.DamagePaddle = false; gstate.Defer(() => gstate.GameObjects.AddLast(ee)); //move gpower to above the paddle, and invert the Y speed. gpower.Location = new PointF(gpower.Location.X, onPaddle.BlockRectangle.Top - gpower.getRectangle().Height - 1); gpower.Velocity = new PointF(gpower.Velocity.X, -Math.Abs(gpower.Velocity.Y)*1.1f); return true; }
public virtual bool getPowerup(BCBlockGameState gstate,Paddle onPaddle, GamePowerUp gpower) { return false; // default to doing nothing. }