Пример #1
0
        public SwitchBlock(SwitchBlock clonethis)
            : base(clonethis)
        {
            base.BlockRectangle = clonethis.BlockRectangle;
            ActiveSound = clonethis.ActiveSound;
            InactiveSound = clonethis.InactiveSound;
            _ActiveColor = clonethis.ActiveColor;
            _InactiveColor = clonethis.InactiveColor;
            _Locked = clonethis.Locked;
            _Active = clonethis.Active;
            _SwitchMode = clonethis.SwitchMode;
            _AllActiveID = clonethis.AllActiveID;
            _AllInactiveID = clonethis.AllInactiveID;

            Active = clonethis.Active;

            OnBlockRectangleChange+=new Action<RectangleF>(SwitchBlock_OnBlockRectangleChange);
        }
Пример #2
0
        public override bool PerformBlockHit(BCBlockGameState parentstate, cBall ballhit)
        {
            if (_Locked) return false;
            Active = !Active;
            _hasChanged = true;

            BCBlockGameState.Soundman.PlaySound(Active ? ActiveSound : InactiveSound);
            int IDcheck = Active ? AllActiveID : AllInactiveID;

            IEnumerable<SwitchBlock> dealblocks=null;
            bool triggered = false;
            bool? triggerbool = null;

            if ((SwitchMode & SwitchModeConstants.SwitchMode_MultipleBlock) != SwitchModeConstants.SwitchMode_MultipleBlock)
            {
                //we need to deal with only this block.
                dealblocks = new SwitchBlock[] { this};
            }
            else if ((SwitchMode & SwitchModeConstants.SwitchMode_MultipleBlock)==SwitchModeConstants.SwitchMode_MultipleBlock)
            {
                //we need to work with all blocks in the set that are SwitchBlocks and have the same ID.

                dealblocks = (from t in parentstate.Blocks where t is SwitchBlock && (t as SwitchBlock).ID(Active) == IDcheck select (SwitchBlock)t);
            }
            if (dealblocks == null || !dealblocks.Any())
            {
                //uhhh...
                return false;

            }
            // are all dealblocks activated?
            if (AllActiveID != 0)
            {
                if (dealblocks.All((t) => t.Active))
                {
                    triggered = true;
                    triggerbool = true; //all active.
                    BCBlockGameState.Soundman.PlaySound("laser2");
                    Trigger.InvokeTriggerID(AllActiveID, parentstate);

                }
            }
            if (AllInactiveID != 0)
            {
                if (dealblocks.All((t) => !t.Active))
                {
                    triggered = true;
                    triggerbool = false;
                    BCBlockGameState.Soundman.PlaySound("laser2");
                    Trigger.InvokeTriggerID(AllInactiveID, parentstate);
                }

            }
            if (triggered) //only destroy or reset if we were triggered.
            {
                if ((SwitchMode & SwitchModeConstants.SwitchMode_MultiTrigger) != SwitchModeConstants.SwitchMode_MultiTrigger)
                {
                    //we fire once. if activated, destroy all the blocks we worked with.

                    parentstate.NextFrameCalls.Enqueue(new BCBlockGameState.NextFrameStartup(() =>
                    {
                        var removethese = dealblocks.ToList();
                        foreach (var destroythis in removethese)
                        {
                            destroythis.StandardSpray(parentstate,null);
                            parentstate.Blocks.Remove(destroythis);

                        }
                        parentstate.Forcerefresh = true;
                    }));

                }
                else if ((SwitchMode & SwitchModeConstants.SwitchMode_MultiTrigger) == SwitchModeConstants.SwitchMode_MultiTrigger)
                {
                    //can fire multiple times. Set the state of all affected blocks to false.
                    //We will do this on a time delay, however, and set their "Locked" property to true, preventing
                    //this routine from changing their active state in the future until the delay expires.
                    foreach (var anullthis in dealblocks)
                    {
                        anullthis.Locked = true;
                    }
                    parentstate.DelayInvoke(new TimeSpan(0, 0, 0, 1), (a) =>
                    {
                        parentstate.NextFrameCalls.Enqueue(new BCBlockGameState.NextFrameStartup(() =>
                        {
                            foreach (var unlockit in dealblocks)
                            {
                                unlockit.Active = !(triggerbool.Value);  //invert to old value.
                                unlockit.Locked = false;

                            }
                            parentstate.Forcerefresh = true;
                        }
                        ));
                    });
                }
            }
            return false; //don't destroy.
        }