Exemple #1
0
        private void chooseimage()
        {
            //April 6th, birthday of windows 3.1

            if (DateTime.Now.Month == 4 && DateTime.Now.Day == 6)
            {
                useBackground = panWin31.BackgroundImage;
            }
            else
            {
                //select a random start image from the available start images.
                Image[] selectfrom = new Image[] { panStandard.BackgroundImage, panStandard2.BackgroundImage, panStandard3.BackgroundImage };

                Image useimage = selectfrom[rgen.Next(selectfrom.Length)];



                useBackground = useimage;
            }


            //new as of July 14th 2011: colourize to a random hue 50% of the time.
            if (rgen.NextDouble() > 0.5d)
            {
                //choose a random colour...
                Color           colourizeto     = new HSLColor(rgen.NextDouble() * 240, 240, 120);
                ImageAttributes attribcolourize = new ImageAttributes();
                attribcolourize.SetColorMatrix(ColorMatrices.GetColourizer((float)(colourizeto.R) / 255, (float)(colourizeto.G) / 255,
                                                                           (float)(colourizeto.B) / 255));
                useBackground = BCBlockGameState.AppyImageAttributes(useBackground, attribcolourize);
            }
        }
Exemple #2
0
        private void threadinitroutine()
        {
            System.Windows.Forms.Cursor.Current = Cursors.AppStarting;
            DateTime InitTime = DateTime.Now;

            BCBlockGameState.Initgamestate(this);
            //start playing the intro music

            String[] introkeys = BCBlockGameState.Soundman.getMultiSounds("INTRO");

            BCBlockGameState.Soundman.PlayMusic(introkeys, cNewSoundManager.MultiMusicPlayMode.MultiMusic_Order);
            Cursor.Current = Cursors.Default;
            mProceed       = true;
            TimeSpan totalinittime = (DateTime.Now - InitTime);

            ShowMessage("Initialization completed in " + totalinittime);
            ShowMessage("Click Image above to continue...");

            //store that total init time in the initialization time log.
            TimeInitLog(totalinittime);


            //cmdCopy.Visible=true;
            cmdCopy.Invoke((MethodInvoker)(() => cmdCopy.Visible = true));
        }
 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;
 }
        /// <summary>
        /// sealed override, responsible for most of the bulk of the work of the TimedBehaviour.
        /// </summary>
        /// <param name="toPaddle"></param>
        /// <param name="gamestate"></param>
        public override sealed void BehaviourAdded(Paddle toPaddle, BCBlockGameState gamestate)
        {
            //call base implementation
            base.BehaviourAdded(toPaddle, gamestate);
            //check if we are SingleInstance. If so, that means that there can only be one instance at a time, which may not be surprising given the name.
            if (SingleInstance())
            {
                //check for existing instances of our class. If found, add our delay time to them.
                foreach (var iterate in (from p in toPaddle.Behaviours where p != this select p))
                {
                    if (iterate.GetType() == GetType())
                    {
                        //if same type, change delay, and break from routine.
                        (iterate as TimedPaddleBehaviour).ChangeDelayTime(gamestate, _BehaviourTime, true);
                        //make sure this instance get's removed, too! we are redundant now.
                        gamestate.NextFrameCalls.Enqueue
                            (new BCBlockGameState.NextFrameStartup(() => toPaddle.Behaviours.Remove(this)));

                        return;
                    }
                }
            }

            //if we are either not singleinstance or we are single instance but there are no existing  behaviours of our type attached,
            //do the stuff to add us.
            DelayIdentifier = gamestate.DelayInvoke(_BehaviourTime, TimeDelayRoutine, new object[] {gamestate});
            //if we have ability music, we play it now. Use the SoundManager's capacity to handle temporary music, which works rather well.
            if (_AbilityMusic != "") BCBlockGameState.Soundman.PlayTemporaryMusic(_AbilityMusic, 1.0f, true);
            //hook Death function. If the paddle dies, obviously the time delay will break out early, so we will need to stop the temporary music ourself.
            toPaddle.OnDeath += new Func<Paddle, bool>(toPaddle_OnDeath);
            //call abstract method for initialization.
            TimedBehaviourInitialize(toPaddle, gamestate);
        }
        public bool Callback(BCBlockGameState gamestate)
        {
            //iterate through all balls...
            BCBlockGameState.Soundman.PlaySound("RANDOMY");

            foreach (cBall iterateball in gamestate.Balls)
            {
                var gotspeed = iterateball.getMagnitude();
                //set a new velocity with that speed.
                iterateball.Velocity = BCBlockGameState.GetRandomVelocity(gotspeed);
                //add some randomly coloured lightorbs...
                foreach (Color addcolor in chosencolors)
                {
                    LightOrb lo = new LightOrb(iterateball.Location, addcolor, 17);
                    PointF usevelocity = BCBlockGameState.GetRandomVelocity(2, 5, BCBlockGameState.GetAngle(new PointF(0, 0), iterateball.Velocity));
                    BCBlockGameState.VaryVelocity(usevelocity, Math.PI / 4);
                    lo.Velocity = usevelocity;
                    gamestate.Particles.Add(lo);

                }

            }

            return true;
        }
        /// <summary>
        /// routine finds all the blocks that can be candidates for respawning.
        /// </summary>
        /// <returns></returns>
        public static List<Block> getRespawnCandidates(BCBlockGameState stateobj)
        {
            //first, we copy the Blocks from the state. This is to prevent a race condition. Note that
            //since it is a shallow clone, it shouldn't have a huge impact on memory usage.
            if (stateobj.PlayingLevel == null) return new List<Block>();
            List<Block> clonedlist;
            try
            {
                clonedlist = stateobj.Blocks.ShallowClone().ToList();

            }
            catch
            {
                return new List<Block>();
            }

            //the primary "issue" here is that we cloned them to make them disparate entities, so we can't just do a direct comparison.
            //truly, the best we can do is compare BlockRectangles. This has something of a weird effect in that Blocks that move can and may very well be
            //"respawned" by virtue of them no longer being in their original positions. It sounds like it could be an interestiong quirk and there isn't
            //a whole lot I can do to prevent it without keeping track of a lot of crap, so I'll see how that goes.

            //get all blocks in stateobj.PlayingLevel.levelblocks for which there is no block in clonedlist with the same BlockRectangle...

            var queried = from bb in stateobj.PlayingLevel.levelblocks
                          where (bb.GetType() != typeof(FrustratorBlock) &&
                                 !(clonedlist.Any((wep) => wep.BlockRectangle == bb.BlockRectangle)))
                          select bb;

            //convert to list, and return.
            return queried.ToList();
        }
 public StickyBehaviour(BCBlockGameState stateobject)
 {
     //add a hook to the stateobject's targetarea...
     //((PictureBox) stateobject.TargetObject).MouseClick += new MouseEventHandler(StickyBehaviour_MouseClick);
     //((PictureBox)stateobject.TargetObject).MouseClick += new MouseEventHandler(StickyBehaviour_MouseClick);
     stateobject.ClientObject.ButtonDown += ClientObject_ButtonDown;
     stateobject.ClientObject.ButtonUp += ClientObject_ButtonUp;
 }
        public BuilderShotBehaviour(BCBlockGameState stateobject)
        {
            gstate = stateobject;
            //stateobject.ClientObject.ButtonDown += new Func<ButtonConstants, bool>(ClientObject_ButtonDown);
            //stateobject.ClientObject.ButtonUp += new Func<ButtonConstants, bool>(ClientObject_ButtonUp);

            gstate.ClientObject.ButtonDown += ClientObject_ButtonDown;
        }
 public static IEnumerable<Block> getAboveBlocks(BCBlockGameState gstate, RectangleF testrect)
 {
     var aboveblocks = from b in gstate.Blocks where b.BlockRectangle.IntersectsWith(testrect) select b;
     return from bb in aboveblocks
            where Math.Abs(bb.CenterPoint().Y - testrect.CenterPoint().Y) >
                Math.Abs(bb.CenterPoint().X - testrect.CenterPoint().Y)
            select bb;
 }
        public override bool PerformFrame(BCBlockGameState gamestate)
        {
            if (removeobject is BasePaddleBehaviour)
                ((BasePaddleBehaviour) removeobject).BehaviourRemoved(RemoveFrompaddle, gamestate);

            RemoveFrompaddle.Behaviours.Remove(removeobject);
            Debug.Print("removed...");

            return true;
        }
        public override bool GivePowerTo(BCBlockGameState gamestate, GameCharacter gamechar)
        {
            BCBlockGameState.Soundman.PlaySound("1up");
            BasicFadingText bft = new BasicFadingText("1-Up", Location, new PointF(0, -2), new Font(BCBlockGameState.GetMonospaceFont(), 14), new Pen(Color.Black,2), new SolidBrush(Color.Green), 500);

            gamestate.playerLives++;
            gamestate.Forcerefresh = true;
            gamestate.Defer(() => gamestate.GameObjects.AddLast(bft));

            return true;
        }
        private bool BallSplit(BCBlockGameState gs)
        {
            List<cBall> removethese = new List<cBall>();
            List<cBall> addballs = new List<cBall>();
            if (gs.PlayerPaddle != null)
            {
                //check for Sticky...
                if (gs.PlayerPaddle.Behaviours.Any((w) => w is StickyBehaviour))
                {
                    foreach (var unstick in gs.PlayerPaddle.Behaviours.Where((w) => w is StickyBehaviour))
                        ((StickyBehaviour)unstick).ReleaseAllBalls();

                }

            }
            //            foreach(var splitball in (from m in gs.Balls where !m.hasBehaviour(typeof(TempBallBehaviour)) select m))
            foreach (var splitball in gs.Balls)
            {
                //split splitball into SplitCount new balls.
                //first, take note of the absolute speed of the ball.
                double magnitude = splitball.TotalSpeed;
                //how big will the angle be between them?
                double anglediff = (Math.PI * 2) / SplitCount;
                double startangle = BCBlockGameState.rgen.NextDouble() * Math.PI * 2;

                for (int i = 0; i < SplitCount; i++)
                {
                    double fireangle = startangle + (anglediff * i);

                    PointF usevelocity = new PointF((float)(Math.Cos(fireangle) * magnitude), (float)(Math.Sin(fireangle) * magnitude));

                    //clone the ball...
                    //use the proper type of the object, it could be a subclass!
                    cBall ballcreate = (cBall)Activator.CreateInstance(splitball.GetType(), splitball);

                    //set the velocity of the clone to the calculated value.

                    ballcreate.Velocity = usevelocity;
                    addballs.Add(ballcreate);

                }

                removethese.Add(splitball);
            }
            foreach (var addit in addballs) gs.Balls.AddLast(addit);

            foreach (cBall removeit in removethese)
            {
                gs.Balls.Remove(removeit);

            }
            BCBlockGameState.Soundman.PlaySound("ELECTRICLASER", false);
            return true;
        }
Exemple #13
0
        private void panImage_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImageUnscaled(BackgroundBitmap, 0, 0);

            lock (DrawParticles)
            {
                foreach (Particle drawpart in DrawParticles)
                {
                    drawpart.Draw(e.Graphics);
                }
            }
            lock (imagesdraw)
            {
                foreach (drawimagedata loopdata in imagesdraw)
                {
                    // e.Graphics.DrawImage(loopdata.DrawImage, loopdata.Location);
                    loopdata.Draw(e.Graphics);
                }
            }

            e.Graphics.DrawImageUnscaled(ImageBackBufferbitmap, 0, 0);


            if (CurrentProgress < 1.0f && !ShownAsAbout)
            {
                //get the appropriate dimensions...
                float      widthprogress = ImageBackBufferbitmap.Width * CurrentProgress;
                RectangleF drawprect     = new RectangleF((float)widthprogress, 0,
                                                          ImageBackBufferbitmap.Width - widthprogress,
                                                          ImageBackBufferbitmap.Height);

                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(128, Color.Red)), drawprect);

                SizeF  measuresize;
                String loadingtext = "Loading" + dupe('.', DateTime.Now.Millisecond / 100 % 5);
                System.Drawing.Font loadingtextfont = new Font("Arabia", 48);
                measuresize = e.Graphics.MeasureString(loadingtext, loadingtextfont);

                RectangleF largerect = new RectangleF((float)panImage.ClientRectangle.Left,
                                                      (float)panImage.ClientRectangle.Top,
                                                      (float)panImage.ClientRectangle.Width,
                                                      (float)panImage.ClientRectangle.Height);
                RectangleF   userect  = BCBlockGameState.CenterRect(largerect, measuresize);
                GraphicsPath pusepath = new GraphicsPath();

                pusepath.AddString(loadingtext, loadingtextfont.FontFamily, (int)loadingtextfont.Style,
                                   loadingtextfont.Size, new PointF(48, 48), StringFormat.GenericDefault);

                e.Graphics.FillPath(new SolidBrush(Color.Yellow), pusepath);
                e.Graphics.DrawPath(new Pen(Color.Black, 2), pusepath);
            }
        }
        public override void BehaviourAdded(Paddle toPaddle, BCBlockGameState gamestate)
        {
            ownerpaddle = toPaddle;

            //remove any existing terminator behaviour.
            foreach (var loopbeh in toPaddle.Behaviours)
            {
                if (loopbeh is TerminatorBehaviour)
                    gstate.GameObjects.AddLast(new BehaviourRemoverProxy(toPaddle, loopbeh));
            }

            base.BehaviourAdded(toPaddle, gamestate);
        }
        public override void BehaviourAdded(Paddle toPaddle, BCBlockGameState gamestate)
        {
            base.BehaviourAdded(toPaddle, gamestate);
            gamestate.Defer(()=>{
                                    addedobject = new ProxyObject((po, gs) =>
                                                                      {

                                                                          PerformFrame(toPaddle, gamestate);
                                                                          return false;

                                                                      }, null);
                                    gamestate.GameObjects.AddLast(addedobject);
            });
        }
        public override void PerformFrame(BCBlockGameState gamestate, Paddle pPaddle)
        {
            var rg = BCBlockGameState.rgen;
            base.PerformFrame(gamestate, pPaddle);
            useoverlaybrush = new SolidBrush(new HSLColor(rg.NextDouble()*240, 240f, 120f));
            //spawn a sparkle.
            var paddlerect = pPaddle.Getrect();
            PointF randompoint = new PointF(paddlerect.Left + (float) (paddlerect.Width*rg.NextDouble()),
                                            paddlerect.Top + (float) (paddlerect.Height*rg.NextDouble()));

            Sparkle s = new Sparkle(randompoint, BCBlockGameState.GetRandomVelocity(0, 2),
                                    new HSLColor(rg.NextDouble()*240, 240, 120));
            gamestate.NextFrameCalls.Enqueue(new BCBlockGameState.NextFrameStartup(() => gamestate.Particles.Add(s)));
        }
        public bool PowerupCallback(BCBlockGameState gamestate)
        {
            //PaddleMinusPowerup makes the paddle smaller...
            if ((gamestate.PlayerPaddle.PaddleSize.Width) > paddlesizechangeamount + 10)
            {

                SizeF changedsize = new SizeF(gamestate.PlayerPaddle.PaddleSize.Width - paddlesizechangeamount, gamestate.PlayerPaddle.PaddleSize.Height);
                //gamestate.PlayerPaddle.PaddleSize =
                //give it a size object that will change it's size...
                gamestate.PlayerPaddle.Behaviours.Add(new PaddleBehaviours.SizeChangeBehaviour(changedsize, new TimeSpan(0, 0, 0, 1)));
                BCBlockGameState.Soundman.PlaySound("shrink");
            }
            AddScore(gamestate, -5, "Paddle--");
            return true;
        }
        public override bool PerformBlockHit(BCBlockGameState parentstate, cBall ballhit)
        {
            bool nodef = false;
            DefaultHitSound = "";

            if(!Silent) PlayBlockSound(ballhit, "METAL");
            RaiseBlockHit(parentstate, ballhit, ref nodef);

            //temporary code for testing powerup:
            //invincible blocks will now "emerge" a mushroom.
            //MushroomPower mp = new MushroomPower(this);
            //parentstate.GameObjects.AddLast(mp);

            return false;
        }
        public bool PowerUpCallback(BCBlockGameState gamestate)
        {
            //Old code...
            //has the same effect as a frustratorblock.
            //and how do we get the frustrator effect to "engage"?
            //we add a frustrator block, and break it off-screen. couldn't be simpler.
            // FrustratorBlock createblock = new FrustratorBlock(new RectangleF(-500, -500, 50, 50));
            // gamestate.Blocks.AddLast(createblock);
            // BCBlockGameState.Block_Hit(gamestate, createblock);
            //HAHAHA...

            //Change: this powerup now spawns a frustratorball instead...
            FrustratorBall fb = new FrustratorBall(Location, BCBlockGameState.GetRandomVelocity(3, 6));
            gamestate.Balls.AddLast(fb);

            return true;
        }
Exemple #20
0
        public override bool PerformBlockHit(BCBlockGameState parentstate, cBall ballhit, ref List<cBall> ballsadded)
        {
            BASeBlock.BCBlockGameState.Soundman.PlaySound("1UP", 0.9f);
            Block.PlayDefaultSound(ballhit);
            //base.AddScore(parentstate, 40);
            //no idea why the above is broken...
            float useangle = (float)BCBlockGameState.rgen.NextDouble() * (float)(2 * Math.PI);
            PointF spawnlocation = new PointF((float)BlockRectangle.Left+(BlockRectangle.Width/2),(float)BlockRectangle.Top + (BlockRectangle.Height/2));

            float useXSpeed = (float)Math.Sin(useangle) * spawnvelocity;
            float useYSpeed = (float)Math.Cos(useangle) * spawnvelocity;
            PointF spawnvel = new PointF(useXSpeed,useYSpeed);
            ballsadded.Add(new cBall(spawnlocation,spawnvel));
            StandardSpray(parentstate, ballhit);

            return true;
        }
Exemple #21
0
        public override bool PerformBlockHit(BCBlockGameState parentstate, cBall ballhit)
        {
            var ballrel = getBallRelative(ballhit);

            //we only take damage if we are hit on one of the sides...
            if (ballrel == BallRelativeConstants.Relative_Left || ballrel == BallRelativeConstants.Relative_Right)
            {
                Damage++;
                base.PerformBlockHit(parentstate, ballhit);
                return Health < Damage;
            }
            else
            {
                base.PerformBlockHit(parentstate, ballhit);
                return false;

            }
        }
Exemple #22
0
            public FallingCharacterAnimator(char Character, Font fontuse, PointF pPosition, PointF pVelocity, Brush UseBrush, Pen usePen, RectangleF pbounds)
            {
                Position  = pPosition;
                Velocity  = pVelocity;
                usebounds = pbounds;
                SizeF LetterSize = BCBlockGameState.MeasureString(Character.ToString(), fontuse);

                //create letter bitmap...
                DrawBitmap = new Bitmap((int)LetterSize.Width, (int)LetterSize.Height);
                //create the canvas, and draw the character on it.
                DrawCanvas = Graphics.FromImage(DrawBitmap);
                //draw; use a path.
                drawletterpath = new GraphicsPath();
                drawletterpath.AddString(Character.ToString(), fontuse.FontFamily, (int)fontuse.Style,
                                         fontuse.Size, new Point(0, 0), StringFormat.GenericDefault);
                //paint that graphics path onto the bitmap...
                DrawCanvas.FillPath(UseBrush, drawletterpath);
                DrawCanvas.DrawPath(usePen, drawletterpath);
            }
        public bool PowerUpCallback(BCBlockGameState gamestate)
        {
            float randgen = (float)BCBlockGameState.rgen.NextDouble() * Spawnchancesum;
            int useindex = RandomValueToIndex(randgen, spawnchance);
            Type grabtype = spawntypes[useindex];

            SizeF useSize = new SizeF(16, 16);
            PointF useposition =
                new PointF(gamestate.GameArea.Width * (float)BCBlockGameState.rgen.NextDouble(), (gamestate.GameArea.Height - 72) * (float)BCBlockGameState.rgen.NextDouble());

            GameEnemy genenemy = (GameEnemy)Activator.CreateInstance(grabtype, useposition, useSize);
            gamestate.Defer(() =>
                                {
                                    gamestate.GameObjects.AddLast(genenemy);

                                    AddScore(gamestate, 10);
                                });
            return true;
        }
        public bool Callback(BCBlockGameState gamestate)
        {
            BCBlockGameState.Soundman.PlaySound("RANDOMY");
            int numchange = Math.Min(BCBlockGameState.rgen.Next(4, 10),gamestate.Blocks.Count);

            for (int i = 0; i < numchange; i++)
            {
                bool err = true;
                while (err)
                {
                    try
                    {
                        //choose a random block...
                        Block chosenblock = BCBlockGameState.Choose(gamestate.Blocks);
                        //choose a random block type to replace it with.
                        //Type replacewith = BCBlockGameState.Choose(BCBlockGameState.BlockTypes.ManagedTypes);
                        Type replacewith = BCBlockGameState.Choose(PossibleTypes);
                        Block createdblock = (Block)Activator.CreateInstance(replacewith, chosenblock.BlockRectangle);

                        //remove the old block...
                        gamestate.Blocks.Remove(chosenblock);
                        //add the new one (the "swapped" one...
                        gamestate.Blocks.AddLast(createdblock);
                        //set refresh variable to tell the paint routine that it has to refresh the blocks.

                        err = false;
                    }
                    catch
                    {
                        err = true;

                    }
                    //create the new block. remember, block constructor is a single RectangleF. catch errors
                }

            }
            gamestate.Forcerefresh = true;
            gamestate.NextFrameCalls.Enqueue(new BCBlockGameState.NextFrameStartup((a, q) => { gamestate.Forcerefresh = true; return true; },null));

            return true;
        }
Exemple #25
0
        public FallingTextAnimator(String DisplayString, Font fontuse, PointF Position, Brush useBrush, Pen usePen, PointF pGravity, RectangleF pBounds)
        {
            useBounds = pBounds;
            Gravity   = pGravity;
            String BuildString     = "";
            float  currtextwidth   = 0;
            PointF currentPosition = Position;

            foreach (Char loopchar in DisplayString)
            {
                PointF useVelocity             = new PointF(0, (float)rgen.NextDouble() * 3);
                FallingCharacterAnimator Addme = new FallingCharacterAnimator(loopchar, fontuse, currentPosition,
                                                                              useVelocity, useBrush, usePen,
                                                                              useBounds);
                FallingCharacters.Add(Addme);
                currentPosition = new PointF(Position.X + currtextwidth, Position.Y);
                BuildString    += loopchar;
                int currlength = BuildString.Length;
                currtextwidth += (BCBlockGameState.MeasureString(loopchar.ToString(), fontuse).Width / currlength);
            }
        }
        private bool PerformFrameProxy(ProxyObject sourceobject, BCBlockGameState gamestate)
        {
            var pPaddle = gamestate.PlayerPaddle;
            if (pPaddle == null) return true;
            //"bleed"
            RectangleF paddlerect = pPaddle.Getrect();
            for (int i = 0; i < (int) (20f*BCBlockGameState.ParticleGenerationFactor); i++)
            {
                //add a random blood particle...
                PointF randomspot =
                    new PointF((float) (paddlerect.Width*BCBlockGameState.rgen.NextDouble() + paddlerect.Left),
                               (float) (paddlerect.Bottom));

                WaterParticle Bloodparticle = new WaterParticle(randomspot, Color.Red);
                Bloodparticle.Velocity = new PointF((float) BCBlockGameState.rgen.NextDouble()*2 - 1,
                                                    (float) BCBlockGameState.rgen.NextDouble() - 0.5f);

                gamestate.Particles.Add(Bloodparticle);
            }

            return false;
        }
        public override void PerformFrame(BCBlockGameState gamestate, Paddle pPaddle)
        {
            base.PerformFrame(gamestate, pPaddle);

            if (pPaddle.HP > HPCheck)
            {
                //
                if (proxiedObject != null)
                {
                    gamestate.NextFrameCalls.Enqueue(new BCBlockGameState.NextFrameStartup(() =>
                                                                                               {
                                                                                                   gamestate
                                                                                                       .GameObjects
                                                                                                       .Remove(
                                                                                                           proxiedObject);
                                                                                                   gamestate
                                                                                                       .PlayerPaddle
                                                                                                       .Behaviours
                                                                                                       .Remove(this);
                                                                                               }));
                }
            }
        }
Exemple #28
0
        public override bool PerformBlockHit(BCBlockGameState parentstate, cBall ballhit)
        {
            float mindimension = Math.Min(BlockRectangle.Width, BlockRectangle.Height);
            if (mindimension > _MinimumSize)
            {
                //split us in half.
                RectangleF newA, newB; //the "new" block rectangles.
                if (BlockRectangle.Width > BlockRectangle.Height)
                {
                    //split vertically.
                    newA = new RectangleF(BlockRectangle.Left, BlockRectangle.Top, BlockRectangle.Width / 2, BlockRectangle.Height);
                    newB = new RectangleF(BlockRectangle.Left + BlockRectangle.Width / 2, BlockRectangle.Top, BlockRectangle.Width / 2, BlockRectangle.Height);

                }
                else
                {
                    //split horizontally.
                    newA = new RectangleF(BlockRectangle.Left, BlockRectangle.Top, BlockRectangle.Width, BlockRectangle.Height / 2);
                    newB = new RectangleF(BlockRectangle.Left, BlockRectangle.Top + BlockRectangle.Height / 2, BlockRectangle.Width, BlockRectangle.Height / 2);

                }

                parentstate.Blocks.AddLast(new SplitBlock(newA));
                parentstate.Blocks.AddLast(new SplitBlock(newB));
                parentstate.Forcerefresh = true;

                BCBlockGameState.Soundman.PlaySound("bbounce");

            }
            else
            {
                Block.PlayDefaultSound(ballhit);
            }

            return true; //we are destroyed.
        }
        public override bool PerformFrame(BCBlockGameState gamestate)
        {
            /*
                   qcm.RotateHue(0.1f);
                   DrawAttributes.SetColorMatrix(
                    qcm.ToColorMatrix(),
                    ColorMatrixFlag.Default,
                    ColorAdjustType.Bitmap);
                   cmuse = qcm.ToColorMatrix();
                   */

                //TODO: change velocity to go towards paddle, but only if there is a paddle.
                if (gamestate.PlayerPaddle != null)
                {
                    if (Location.Y < gamestate.PlayerPaddle.Position.Y) //only change if we are above the paddle.
                    {
                        //step one: get angle between fireball and the middle of the paddle:
                        double anglebetween = BCBlockGameState.GetAngle(CenterPoint(),
                                                                        gamestate.PlayerPaddle.Getrect().CenterPoint());

                        //also, get the angle of our speed vector.
                        double movementangle = BCBlockGameState.GetAngle(new PointF(0, 0), Velocity);
                        double totalspeed = BCBlockGameState.Distance(0, 0, Velocity.X, Velocity.Y);
                        //now, we want to move from movementangle towards anglebetween. 25% ought to work...

                        //double distancemove = ((anglebetween - movementangle)*0.05);
                        double anglevary = Math.Sign(anglebetween - movementangle) * (Math.PI / 90) * 0.25f;

                        double changedangle = movementangle + anglevary;

                        //now get the new velocity...

                        PointF newspeed = new PointF((float)(Math.Cos(changedangle) * totalspeed),
                                                     (float)(Math.Sin(changedangle) * totalspeed));
                        Velocity = newspeed;
                    }
                }

                return base.PerformFrame(gamestate);
        }
 public BlueFireball(BCBlockGameState currstate, PointF Location, SizeF ObjectSize, float initialsize)
     : base(currstate, Location, ObjectSize, initialsize)
 {
 }
 public BlueFireball(BCBlockGameState currstate, Block originBlock, float initialspeed)
     : this(currstate, originBlock.CenterPoint(), new SizeF(8, 8), initialspeed)
 {
     setattributes();
 }
 public BlueFireball(BCBlockGameState currstate, PointF Location, SizeF ObjectSize, PointF initialSpeed)
     : base(currstate, Location, ObjectSize, initialSpeed)
 {
     Velocity = initialSpeed;
 }
        public override bool PerformFrame(BCBlockGameState gamestate)
        {
            var changeme = from p in gamestate.Blocks
                               where
                                   BCBlockGameState.Distance(Location.X, Location.Y, p.CenterPoint().X,
                                                             p.CenterPoint().Y) < _CurrentRadius && (BlockFindType==null || p.GetType()==BlockFindType)
                               select p;

                foreach (var loopitem in changeme)
                {
                    if (!(loopitem.GetType().Equals(BlockChangeType)))
                    {
                        //if not equal, create a new block with the same rect as loopitem
                        Block createdblock = (Block)Activator.CreateInstance(BlockChangeType, loopitem.BlockRectangle);
                        //remove the old one, and replace it with this one.
                        var nodeitem = gamestate.Blocks.Find(loopitem);
                        //add the new one...
                        var copied = loopitem;
                        //don't change the blocks right away, plonk it to a delegate.
                        //it might also be possible to plonk this entire for loop into a delayed framestartup call, too.
                        gamestate.NextFrameCalls.Enqueue(new BCBlockGameState.NextFrameStartup(() =>
                        {
                            //add a "changed" block...
                            gamestate.Blocks.AddAfter(nodeitem,createdblock);
                            //remove the old one.
                            gamestate.Blocks.Remove(copied);
                        }));

                    }

                }
                gamestate.Forcerefresh = true;

                return base.PerformFrame(gamestate);
        }
        public override bool PerformFrame(BCBlockGameState gamestate)
        {
            numticks++;
                bool dodefault = FrameFunction == null || FrameFunction(this);

                if (dodefault)
                {
                    mPosition = new PointF(mPosition.X + mVelocity.X, mPosition.Y + mVelocity.Y);
                    //mVelocity = new PointF(mVelocity.X,mVelocity.Y*myspeedfalloff);

                    if (XSpeedDelegate != null && YSpeedDelegate != null)
                    {
                        mVelocity = new PointF(XSpeedDelegate(this), YSpeedDelegate(this));

                    }
                    else if ((XSpeedDelegate != null) ^ (YSpeedDelegate != null))
                    {
                        if (XSpeedDelegate != null)
                            mVelocity = new PointF(XSpeedDelegate(this), mVelocity.Y);
                        else
                            mVelocity = new PointF(mVelocity.X, YSpeedDelegate(this));

                    }
                    life++;
                }

                bool retval = life > maxTTL;
                if (measuredsize != null)
                {
                    retval = retval || !(gamestate.GameArea.IntersectsWith(RectFToRect(new RectangleF(mPosition, measuredsize.Value))));

                }
                return (retval);
        }
 public override bool PerformFrame(BCBlockGameState gamestate)
 {
     BCBlockGameState.IncrementLocation(gamestate, ref _Location, Velocity);
         Velocity = new PointF(Velocity.X * VelocityDecay.X, Velocity.Y * VelocityDecay.Y);
         _CurrentRadius = IncrementRoutine(_CurrentRadius, _MaxRadius);
         float usealpha = (1 - (_CurrentRadius / _MaxRadius)) * 255;
         usealpha = BCBlockGameState.ClampValue(usealpha, 0, 255);
         CurrentBrush = new SolidBrush(Color.FromArgb((int)usealpha, _useColor));
         return _CurrentRadius >= _MaxRadius || (usealpha <= 5);
 }
Exemple #36
0
        private void BobberThread()
        {
            int EffectLengthi = 5000;

            if (BobberThreadEffectFinish == null)
            {
                BobberThreadEffectFinish = DateTime.Now;
            }
            const int numeffects = 6;

            while (true)
            {
                lock (ImageBackBufferCanvas)
                {
                    Thread.Sleep(50);
                    Thread.SpinWait(15);
                    while (Form.ActiveForm == null)
                    {
                        Thread.Sleep(0);
                    }
                    if (!this.Visible)
                    {
                        Thread.Sleep(0); //nothing to do, allow other threads to run.
                    }
                    else
                    {
                        DrawFrame();
                    }
                    if (performingEffect)
                    {
                        bool     doflip       = false;
                        TimeSpan EffectLength = DateTime.Now - BobberThreadEffectStart;
                        //currently the only supported "effect" ,draws a bunch of particles across the screen halfway. (Y).


                        imagesdraw.Clear();
                        if (EffectLength.TotalMilliseconds > EffectLengthi)
                        {
                            performingEffect         = false;
                            prevparticlepos          = new PointF(0, 0);
                            BobberThreadEffectFinish = DateTime.Now;
                        }
                        else
                        {
                            double currpercent = (double)EffectLength.TotalMilliseconds / (double)EffectLengthi;
                            int    Xpos        =
                                (int)
                                (((float)(ImageBackBufferbitmap.Width * 1.5) * currpercent) -
                                 ((float)(ImageBackBufferbitmap.Width * 0.2f)));

                            Debug.Print("Effect currpercent=" + currpercent);
                            //                        PointF addparticlepos = new PointF(Xpos, ImageBackBufferbitmap.Height / 2);
                            int effectnumber = EffectCount % numeffects;

                            if (effectnumber % 2 == 0)
                            {
                                Xpos   = ImageBackBufferbitmap.Width - Xpos;
                                doflip = true;
                            }
                            PointF addparticlepos = new PointF(Xpos, 163);
                            if (prevparticlepos.X == 0 && prevparticlepos.Y == 0)
                            {
                                prevparticlepos = addparticlepos;
                            }
                            float               usehue        = (((float)currpercent * 3) % 1) * 240;
                            Color               particlecolor = new HSLColor(usehue, 240, 120);
                            const float         maxoutspeed   = 1f;
                            const int           numparticles  = 25;
                            Image               usepic        = null;
                            System.Drawing.Size?usesize;

                            switch (effectnumber)
                            {
                            case 0:
                            case 2:
                                usepic = rdash.BackgroundImage;
                                if (effectnumber == 2)
                                {
                                    addparticlepos = new PointF(addparticlepos.X,
                                                                ((float)Math.Sin(addparticlepos.X / 16) * 8) +
                                                                addparticlepos.Y);
                                }


                                /*for (int addp = 0; addp < numparticles*2; addp++)
                                 * {
                                 *  Particle addparticle = new DustParticle(addparticlepos, (float) (rg.NextDouble()*4),
                                 *                                          7500, particlecolor);
                                 *
                                 *
                                 *  lock (DrawParticles)
                                 *  {
                                 *      DrawParticles.Add(addparticle);
                                 *  }
                                 * }*/

                                //create a spectrum...
                                const float numlines  = 25;
                                const int   totalsize = 100;
                                for (int i = 0; i < numlines; i++)
                                {
                                    float  useYoffset   = (totalsize / 2) + (((float)i / numlines) * totalsize);
                                    float  pct          = ((float)i / numlines);
                                    float  percenthue   = (pct * 240);
                                    PointF offsetamount = new PointF(addparticlepos.X - prevparticlepos.X,
                                                                     addparticlepos.Y - prevparticlepos.Y);
                                    //PointF firstpoint = new PointF(addparticlepos.X, useYoffset);
                                    //PointF secondpoint = new PointF(firstpoint.X+offsetamount.X,firstpoint.Y+offsetamount.Y);
                                    PointF firstpoint  = addparticlepos;
                                    PointF secondpoint = prevparticlepos;
                                    if (firstpoint.X > secondpoint.X)
                                    {
                                        firstpoint  = new PointF(firstpoint.X + 2, firstpoint.Y);
                                        secondpoint = new PointF(secondpoint.X - 2, secondpoint.Y);
                                    }
                                    else
                                    {
                                        firstpoint  = new PointF(firstpoint.X - 2, firstpoint.Y);
                                        secondpoint = new PointF(secondpoint.X + 2, secondpoint.Y);
                                    }
                                    //float phue = (percenthue + (Xpos/2)%240 )%240;
                                    float        phue         = percenthue % 240;
                                    Color        linecoloruse = new HSLColor(phue, 240, 120);
                                    float        usevel       = (pct - 0.5f) * 5;
                                    DustParticle dust1        = new DustParticle(firstpoint, new PointF(0, usevel));
                                    DustParticle dust2        = new DustParticle(secondpoint, new PointF(0, usevel));
                                    LineParticle lp           = new LineParticle(dust1, dust2, linecoloruse);



                                    lock (DrawParticles)
                                    {
                                        DrawParticles.Add(lp);


                                        if (Math.Truncate((double)Xpos) % 15 == 0)
                                        {
                                            //add a 5-pointed star...
                                            //StarParticle staradd = new StarParticle(addparticlepos, BCBlockGameState.GetRandomVelocity(0,3), 5, 3, 6, Color.Yellow, Color.Black, (float)(rg.NextDouble() * 2));
                                            CharacterDebris staradd = new CharacterDebris(addparticlepos,
                                                                                          BCBlockGameState.
                                                                                          GetRandomVelocity(0, 3),
                                                                                          Color.Yellow, 8, 18);
                                            DrawParticles.Add(staradd);
                                        }
                                    }
                                }



                                /*
                                 * Particle addParticleA = new DustParticle(addparticlepos, new PointF(0, -2));
                                 * Particle addParticleB = new DustParticle(addparticlepos, new PointF(0, 2));
                                 * LineParticle lp = new LineParticle(addParticleA, addParticleB, particlecolor);
                                 *
                                 * lock (DrawParticles)
                                 * {
                                 *  DrawParticles.Add(lp);
                                 * }
                                 *
                                 *
                                 */
                                break;

                            case 1:
                            case 3:
                                usepic = rdash.BackgroundImage;
                                if (effectnumber == 3)
                                {
                                    addparticlepos = new PointF(addparticlepos.X,
                                                                ((float)Math.Sin(addparticlepos.X / 32) * 16) +
                                                                addparticlepos.Y);
                                }
                                for (int addp = 0; addp < numparticles; addp++)
                                {
                                    float  ppercent = (float)addp / (float)numparticles;
                                    float  usespeed = (float)(((maxoutspeed * 2) * ppercent) - maxoutspeed);
                                    PointF speeduse = new PointF((float)(rg.NextDouble() - 0.5d), usespeed);
                                    particlecolor = new HSLColor(ppercent * 240, 240, 120);
                                    //Particle addparticle = new PolyDebris(addparticlepos, rg.NextDouble() * 2, particlecolor, 3, 4, 3, 8);
                                    Particle addparticle = new PolyDebris(addparticlepos, speeduse, particlecolor, 3,
                                                                          4,
                                                                          3, 8);

                                    lock (DrawParticles)
                                    {
                                        DrawParticles.Add(addparticle);
                                    }
                                }
                                break;

                            case 4:
                                usepic = ttoaster.BackgroundImage;
                                for (int addp = 0; addp < numparticles * 2; addp++)
                                {
                                    particlecolor = Color.FromArgb(rg.Next(255), rg.Next(255), 0);
                                    Particle addparticle = new DustParticle(addparticlepos,
                                                                            (float)(rg.NextDouble() * 4),
                                                                            7500, particlecolor);


                                    lock (DrawParticles)
                                    {
                                        DrawParticles.Add(addparticle);
                                    }
                                }
                                break;

                            case 5:
                                /*
                                 *
                                 */
                                //megaman sprites...
                                //since these are loaded

                                if (!mmimagesloaded)
                                {
                                    mmimagesloaded = true;
                                    try
                                    {
                                        mmimages = BCBlockGameState.Imageman.getImageFrames("megaman");
                                    }
                                    catch
                                    {
                                        mmimagesloaded = false;
                                    }
                                }
                                if (mmimagesloaded)
                                {
                                    if ((DateTime.Now - lastmmFrameChange) > mmFrameDelayTime)
                                    {
                                        //advance the frame.
                                        mmimageframe++;
                                    }
                                    mmimageframe = mmimageframe % mmimages.Length;
                                    //they are... or should  be, loaded now.


                                    usepic  = mmimages[mmimageframe];
                                    usesize = new Size(usepic.Size.Width * 3, usepic.Size.Height * 3);
                                }
                                break;



                                /*
                                 * case 3:
                                 *
                                 * addparticlepos = new PointF(addparticlepos.X, ((float)Math.Sin(addparticlepos.X / 16) * 8) + addparticlepos.Y);
                                 * for (int addp = 0; addp < numparticles; addp++)
                                 * {
                                 * Particle addparticle = new PolyDebris(addparticlepos, rg.NextDouble()*2, particlecolor, 3, 4, 3, 8);
                                 *
                                 *
                                 * lock (DrawParticles)
                                 * {
                                 *  DrawParticles.Add(addparticle);
                                 * }
                                 * }
                                 * break;
                                 */
                            }
                            drawimagedata dd = new drawimagedata();
                            dd.DrawImage = (Image)usepic.Clone();

                            if (doflip)
                            {
                                dd.DrawImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
                            }
                            dd.Location = addparticlepos;

                            //imagesdraw.Add(new drawimagedata(BCBlockGameState.Imageman.GetLoadedImage("rdash")

                            double ang = BCBlockGameState.GetAngle(prevparticlepos, addparticlepos);
                            Debug.Print("chosen angle=" + ang);
                            dd.Angle = ang;
                            if (doflip)
                            {
                                dd.Angle += (float)Math.PI;
                            }
                            imagesdraw.Add(dd);
                            prevparticlepos = addparticlepos;
                        }
                    }
                    else if ((DateTime.Now - BobberThreadEffectFinish.Value).TotalSeconds >= 60)
                    {
                        EffectCount++;
                        EffectCount = EffectCount % numeffects;
                        switch (EffectCount)
                        {
                        case 0:
                        case 1:
                        case 2:
                        case 3:
                            EffectLengthi = 5000;
                            if (BCBlockGameState.Soundman != null)     //can be null, if you press shift during startup and take a while on the screen presented...
                            {
                                if (BCBlockGameState.Soundman.HasSound("asboom"))
                                {
                                    BCBlockGameState.Soundman.PlaySound("asboom", 3.0f);
                                }
                            }
                            break;

                        case 4:
                            iSoundSourceObject grabsound;
                            if (BCBlockGameState.Soundman != null)
                            {
                                if (((grabsound = BCBlockGameState.Soundman.GetSoundRnd("TTOASTER")) != null))
                                {
                                    grabsound.Play(false, 3.0f);
                                }
                            }
                            break;

                        case 5:
                            if (BCBlockGameState.Soundman != null)
                            {
                                BCBlockGameState.Soundman.PlaySound("ray");
                            }
                            break;
                        }
                        Debug.Print("invoking effect #" + EffectCount);
                        performingEffect = true;

                        BobberThreadEffectStart = DateTime.Now;
                    }
                }
            }
        }