Example #1
0
        private void performanceScale(CCSprite pSprite)
        {
            CCSize size = CCDirector.SharedDirector.WinSize;

            pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            pSprite.Scale    = CCRandom.Float_0_1() * 100 / 50;
        }
        public CCPhysicsSprite addGrossiniAtPosition(CCPoint location)
        {
            int posx, posy;

            posx = CCRandom.Next() * 200;
            posy = CCRandom.Next() * 200;

            posx = (Math.Abs(posx) % 4) * 85;
            posy = (Math.Abs(posy) % 3) * 121;

            CCPhysicsSprite sp = new CCPhysicsSprite(spriteTexture.Texture, new CCRect(posx, posy, 85, 121));

            cpBB verts = new cpBB(-24, -54, 24, 54);

            var body = new cpBody(1, cp.MomentForBox2(1, new cpBB(-24, -54, 24, 54)));             //);

            body.SetPosition(new cpVect(posx, posy));
            space.AddBody(body);

            var shape = cpPolyShape.BoxShape2(body, verts, 0);

            shape.e = .5f;
            shape.u = .5f;
            space.AddShape(shape);

            sp.Body = body;

            AddChild(sp);
            sp.Position = location;


            return(sp);
        }
Example #3
0
        public override void Update(float time)
        {
            int i, j;

            for (i = 0; i < m_sGridSize.X; ++i)
            {
                for (j = 0; j < m_sGridSize.Y; ++j)
                {
                    CCQuad3 coords = OriginalTile(new CCGridSize(i, j));
                    // X
                    coords.BottomLeft.X  += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                    coords.BottomRight.X += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                    coords.TopLeft.X     += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                    coords.TopRight.X    += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;

                    // Y
                    coords.BottomLeft.Y  += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                    coords.BottomRight.Y += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                    coords.TopLeft.Y     += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                    coords.TopRight.Y    += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;

                    if (m_bShakeZ)
                    {
                        coords.BottomLeft.Z  += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                        coords.BottomRight.Z += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                        coords.TopLeft.Z     += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                        coords.TopRight.Z    += (CCRandom.Next() % (m_nRandrange * 2)) - m_nRandrange;
                    }

                    SetTile(new CCGridSize(i, j), ref coords);
                }
            }
        }
Example #4
0
        private CCColor4B GetRandomColor(int maxColors)
        {
            CCColor4B bubbleColor;

            switch (CCRandom.Next(0, maxColors))
            {
            case 0:
                bubbleColor = Color0;
                break;

            case 1:
                bubbleColor = Color1;
                break;

            case 2:
                bubbleColor = Color2;
                break;

            case 3:
                bubbleColor = Color3;
                break;

            case 4:
                bubbleColor = Color4;
                break;
            }
            return(bubbleColor);
        }
Example #5
0
        private void StartScheduling()
        {
            Schedule(t => {
                if (ShouldEndGame)
                {
                    GameLayer.SetScore(_currentScore);
                    GameLayer.GameOver(_currentScore >= _gameConfiguration.ScoreToReach);
                    return;
                }
                _visibleBubbles.Add(AddBubble());

                if (CCRandom.Next(0, 100) > 90)
                {
                    _visibleBubbles.Add(AddBubble());
                }

                float timeLeft = (_gameConfiguration.MaxDuration - ElapsedTime);
                if (timeLeft < 10 && CCRandom.Next(0, 100) > 30)
                {
                    _visibleBubbles.Add(AddBubble());
                }
            }, .5f);

            Schedule(t => CheckPop());

            Schedule(UpdateLayerGradient, 0.1f);
        }
        public static CCPoint GetRandomPosition(CCSize spriteSize, CCSize visibleBoundsWorldspaceSize)
        {
            var randomX = CCRandom.Next(40, (int)visibleBoundsWorldspaceSize.Width - 40);
            var randomY = CCRandom.Next(40, (int)visibleBoundsWorldspaceSize.Height - 40);

            return(new CCPoint((float)randomX, (float)randomY));
        }
Example #7
0
        private void CreateTheButtons()
        {
            CCNode theLayer = GetChildByTag(kTheLayer);

            theLayer.RemoveAllChildrenByTag(kTheButtons);
            int space = 10; // px

            max_w = 0f;
            max_h = 0f;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    // Add the buttons
                    var button = standardButtonWithTitle(CCRandom.Next(30).ToString());
                    button.SetAdjustBackgroundImage(false);  // Tells the button that the background image must not be adjust
                    // It'll use the prefered size of the background image
                    button.Position = new CCPoint(button.ContentSize.Width / 2 + (button.ContentSize.Width + space) * i,
                                                  button.ContentSize.Height / 2 + (button.ContentSize.Height + space) * j);
                    theLayer.AddChild(button, kTheButtons);

                    max_w = Math.Max(button.ContentSize.Width * (i + 1) + space * i, max_w);
                    max_h = Math.Max(button.ContentSize.Height * (j + 1) + space * j, max_h);
                }
            }
        }
        private void performanceActions20(CCSprite pSprite)
        {
            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            if (CCRandom.Float_0_1() < 0.2f)
            {
                pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            }
            else
            {
                pSprite.Position = new CCPoint(-1000, -1000);
            }

            float      period            = 0.5f + (CCRandom.Next() % 1000) / 500.0f;
            CCRotateBy rot               = new CCRotateBy(period, 360.0f * CCRandom.Float_0_1());
            var        rot_back          = (CCFiniteTimeAction)rot.Reverse();
            CCAction   permanentRotation = new CCRepeatForever(new CCSequence(rot, rot_back));

            pSprite.RunAction(permanentRotation);

            float growDuration      = 0.5f + (CCRandom.Next() % 1000) / 500.0f;
            CCFiniteTimeAction grow = new CCScaleBy(growDuration, 0.5f, 0.5f);
            CCAction           permanentScaleLoop = new CCRepeatForever(new CCSequence(grow, grow.Reverse()));

            pSprite.RunAction(permanentScaleLoop);
        }
Example #9
0
        public override void Update(float time)
        {
            if (Target == null)
            {
                return;
            }

            int i, j;

            for (i = 0; i < (GridSize.X + 1); ++i)
            {
                for (j = 0; j < (GridSize.Y + 1); ++j)
                {
                    CCVertex3F v = OriginalVertex(i, j);
                    v.X += (CCRandom.Next() % (Range * 2)) - Range;
                    v.Y += (CCRandom.Next() % (Range * 2)) - Range;

                    if (Shake)
                    {
                        v.Z += (CCRandom.Next() % (Range * 2)) - Range;
                    }

                    SetVertex(i, j, ref v);
                }
            }
        }
Example #10
0
        public override void updateQuantityOfNodes()
        {
            CCSize s = Layer.VisibleBoundsWorldspace.Size;

            // increase nodes
            if (currentQuantityOfNodes < quantityOfNodes)
            {
                StartTimer();
                for (int i = 0; i < (quantityOfNodes - currentQuantityOfNodes); i++)
                {
                    CCSprite sprite = new CCSprite(batchNode.Texture, new CCRect(0, 0, 32, 32));
                    AddChild(sprite);
                    sprite.Position = new CCPoint(CCRandom.Next() * s.Width, CCRandom.Next() * s.Height);
                }
            }

            // decrease nodes
            else if (currentQuantityOfNodes > quantityOfNodes)
            {
                StartTimer();
                for (int i = 0; i < (currentQuantityOfNodes - quantityOfNodes); i++)
                {
                    int index = currentQuantityOfNodes - i - 1;
                }
            }

            currentQuantityOfNodes = quantityOfNodes;
        }
        private void performanceActions20(CCSprite pSprite)
        {
            CCSize size = CCDirector.SharedDirector.WinSize;

            if (CCRandom.Float_0_1() < 0.2f)
            {
                pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            }
            else
            {
                pSprite.Position = new CCPoint(-1000, -1000);
            }

            float      period            = 0.5f + (CCRandom.Next() % 1000) / 500.0f;
            CCRotateBy rot               = new CCRotateBy(period, 360.0f * CCRandom.Float_0_1());
            var        rot_back          = (CCActionInterval)rot.Reverse();
            CCAction   permanentRotation = new CCRepeatForever(CCSequence.FromActions(rot, rot_back));

            pSprite.RunAction(permanentRotation);

            float            growDuration       = 0.5f + (CCRandom.Next() % 1000) / 500.0f;
            CCActionInterval grow               = new CCScaleBy(growDuration, 0.5f, 0.5f);
            CCAction         permanentScaleLoop = new CCRepeatForever(new CCSequence(grow, grow.Reverse()));

            pSprite.RunAction(permanentScaleLoop);
        }
Example #12
0
        public override void Update(float time)
        {
            int i, j;

            var doubleRange = Range * 2;

            for (i = 0; i < GridSize.X; ++i)
            {
                for (j = 0; j < GridSize.Y; ++j)
                {
                    CCQuad3 coords = OriginalTile(i, j);
                    // X
                    coords.BottomLeft.X  += (CCRandom.Next() % doubleRange) - Range;
                    coords.BottomRight.X += (CCRandom.Next() % doubleRange) - Range;
                    coords.TopLeft.X     += (CCRandom.Next() % doubleRange) - Range;
                    coords.TopRight.X    += (CCRandom.Next() % doubleRange) - Range;

                    // Y
                    coords.BottomLeft.Y  += (CCRandom.Next() % doubleRange) - Range;
                    coords.BottomRight.Y += (CCRandom.Next() % doubleRange) - Range;
                    coords.TopLeft.Y     += (CCRandom.Next() % doubleRange) - Range;
                    coords.TopRight.Y    += (CCRandom.Next() % doubleRange) - Range;

                    if (ShakeZ)
                    {
                        coords.BottomLeft.Z  += (CCRandom.Next() % doubleRange) - Range;
                        coords.BottomRight.Z += (CCRandom.Next() % doubleRange) - Range;
                        coords.TopLeft.Z     += (CCRandom.Next() % doubleRange) - Range;
                        coords.TopRight.Z    += (CCRandom.Next() % doubleRange) - Range;
                    }

                    SetTile(i, j, ref coords);
                }
            }
        }
        private void performanceScale(CCSprite pSprite)
        {
            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            pSprite.Scale    = CCRandom.Float_0_1() * 100 / 50;
        }
Example #14
0
        public void reset()
        {
            int localtag = 0;

            localtag++;

            // TO TRIGGER THE BUG:
            // remove the itself from parent from an action
            // The menu will be removed, but the instance will be alive
            // and then a new node will be allocated occupying the memory.
            // => CRASH BOOM BANG
            CCNode node = GetChildByTag(localtag - 1);

            CCLog.Log("Menu: %p", node);
            RemoveChild(node, false);
            //	[self removeChildByTag:localtag-1 cleanup:NO];

            CCMenuItem item1 = new CCMenuItemFont("One", menuCallback);

            CCLog.Log("MenuItemFont: %p", item1);
            CCMenuItem item2 = new CCMenuItemFont("Two", menuCallback);
            CCMenu     menu  = new CCMenu(item1, item2);

            menu.AlignItemsVertically();

            float x = CCRandom.Next() * 50;
            float y = CCRandom.Next() * 50;

            menu.Position = menu.Position + new CCPoint(x, y);
            AddChild(menu, 0, localtag);

            //[self check:self];
        }
Example #15
0
        public void PlayStackImpactSound()
        {
            if (!soundFXTurnedOff)
            {
                int randomNum = CCRandom.Next(0, 4); //0 to 4
                switch (randomNum)
                {
                case 0:
                    CCSimpleAudioEngine.SharedEngine.PlayEffect(FormatSoundFilePath("impact1"));
                    break;

                case 1:
                    CCSimpleAudioEngine.SharedEngine.PlayEffect(FormatSoundFilePath("impact2"));
                    break;

                case 2:
                    CCSimpleAudioEngine.SharedEngine.PlayEffect(FormatSoundFilePath("impact3"));
                    break;

                case 3:
                    CCSimpleAudioEngine.SharedEngine.PlayEffect(FormatSoundFilePath("impact4"));
                    break;

                case 4:
                    CCSimpleAudioEngine.SharedEngine.PlayEffect(FormatSoundFilePath("impact5"));
                    break;
                }
            }
        }
Example #16
0
        public override void updateQuantityOfNodes()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // increase nodes
            if (currentQuantityOfNodes < quantityOfNodes)
            {
                for (int i = 0; i < (quantityOfNodes - currentQuantityOfNodes); i++)
                {
                    CCSprite sprite = new CCSprite(batchNode.Texture, new CCRect(0, 0, 32, 32));
                    batchNode.AddChild(sprite);
                    sprite.Position = new CCPoint(CCRandom.Next() * s.Width, CCRandom.Next() * s.Height);
                }
            }

            // decrease nodes
            else if (currentQuantityOfNodes > quantityOfNodes)
            {
                for (int i = 0; i < (currentQuantityOfNodes - quantityOfNodes); i++)
                {
                    int index = currentQuantityOfNodes - i - 1;
                    batchNode.RemoveChildAtIndex(index, true);
                }
            }

            currentQuantityOfNodes = quantityOfNodes;
        }
Example #17
0
        public Bubble()
        {
            UniversalId++;
            id     = UniversalId;
            random = new Random();
            Scale  = 0.5f;
            switch (random.Next(0, 5))
            {
            case 0:
                color = color0;
                break;

            case 1:
                color = color1;
                break;

            case 2:
                color = color2;
                break;

            case 3:
                color = color3;
                break;

            case 4:
                color = color4;
                break;
            }

            colorF = new CCColor4F(color);
            var size = CCRandom.Next(25, 50);

            this.ContentSize = new CCSize(size, size);
            this.DrawSolidCircle(this.Position, (float)size, color);
        }
Example #18
0
        void StartScheduling()
        {
            Schedule(t => {
                if (ShouldEndGame())
                {
                    EndGame();
                    return;
                }
                visibleBubbles.Add(AddBubble());

                if (CCRandom.Next(0, 100) > 90)
                {
                    visibleBubbles.Add(AddBubble());
                }

                var left = (GAME_DURATION - elapsedTime);
                if (left < 10 && CCRandom.Next(0, 100) > 30)
                {
                    visibleBubbles.Add(AddBubble());
                }
            }, .5f);

            Schedule(t => CheckPop());

            // Schedule for method to be called every 0.1s
            Schedule(UpdateLayerGradient, 0.1f);
        }
Example #19
0
        void OpenEyes(float delta)
        {
            sprite.Texture = new CCSprite(String.Format("{0}", baseImageName)).Texture;
            Unschedule(OpenEyes);
            var blinkInterval = CCRandom.Next(3, 8);//   random.Next(3,8); // range 3 to 8

            Schedule(Blink, blinkInterval);
        }
Example #20
0
        public void SpriteInStandingState()
        {
            sprite.Texture = new CCSprite(String.Format("{0}_standing", baseImageName)).Texture;

            var blinkInterval = CCRandom.Next(3, 8);            // range 3 to 8

            Schedule(Blink, blinkInterval);
        }
Example #21
0
        public virtual EnemySkin Create()
        {
            EnemySkin _skin = new NormalEnemySkin();

            if (CCRandom.Next(100) < 20)
            {
                _skin = new StrongEnemySkin();
            }
            return(_skin);
        }
Example #22
0
 public void Shuffle(ref int[] pArray, int nLen)
 {
     int i;
     for (i = nLen - 1; i >= 0; i--)
     {
         int j = CCRandom.Next() % (i + 1);
         int v = pArray[i];
         pArray[i] = pArray[j];
         pArray[j] = v;
     }
 }
Example #23
0
        void OnDeleteBackward(object sender, CCIMEKeybardEventArgs e)
        {
            var focusedTextField = sender as CCTextField;

            if (focusedTextField == null || string.IsNullOrEmpty(focusedTextField.Text))
            {
                e.Cancel = true;
                return;
            }

            // Just cancel this if we would backspace over the PlaceHolderText as it would just be
            // replaced anyway and the Action below should not be executed.
            var delText = focusedTextField.Text;

            if (delText == focusedTextField.PlaceHolderText)
            {
                e.Cancel = true;
                return;
            }

            delText = delText.Substring(delText.Length - 1);

            // create a delete text sprite and do some action
            var label = new CCLabel(delText, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE + 3, CCLabelFormat.SpriteFont);

            this.AddChild(label);

            // move the sprite to fly out
            CCPoint beginPos      = focusedTextField.Position;
            CCSize  textfieldSize = focusedTextField.ContentSize;
            CCSize  labelSize     = label.ContentSize;

            beginPos.X += (textfieldSize.Width - labelSize.Width) / 2.0f;

            var nextRandom = (float)CCRandom.Next(RANDOM_MAX);

            CCSize  winSize = VisibleBoundsWorldspace.Size;
            CCPoint endPos  = new CCPoint(-winSize.Width / 4.0f, winSize.Height * (0.5f + nextRandom / (2.0f * RANDOM_MAX)));

            float duration       = 1;
            float rotateDuration = 0.2f;
            int   repeatTime     = 5;

            label.Position = beginPos;

            var delAction = new CCSpawn(new CCMoveTo(duration, endPos),
                                        new CCRepeat(
                                            new CCRotateBy(rotateDuration, (CCRandom.Next() % 2 > 0) ? 360 : -360),
                                            (uint)repeatTime),
                                        new CCFadeOut(duration)
                                        );

            label.RunActionsAsync(delAction, new CCRemoveSelf(true));
        }
Example #24
0
        protected override void AddedToScene()
        {
            base.AddedToScene();
            _bubbleMax  = CCRandom.Next(4, 6);
            _growthTime = CCRandom.Next(3, _maxGrowthTime);
            _scale      = new CCScaleBy(_growthTime, _bubbleMax);
            AddAction(_scale);

            _move1          = new CCMoveBy(.2f, new CCPoint(4, 4));
            _move2          = new CCMoveBy(.24f, new CCPoint(-4, -4));
            _repeatedAction = new CCRepeatForever(_move1, _move2);
        }
Example #25
0
        protected override void AddedToScene()
        {
            base.AddedToScene();
            bubbleMax  = CCRandom.Next(4, 6);
            growthTime = CCRandom.Next(3, 5);
            scale      = new CCScaleBy(growthTime, bubbleMax);
            this.AddAction(scale);

            move1          = new CCMoveBy(.2f, new CCPoint(4, 4));
            move2          = new CCMoveBy(.24f, new CCPoint(-4, -4));
            repeatedAction = new CCRepeatForever(move1, move2);
        }
Example #26
0
        private void performanceout20(CCSprite pSprite)
        {
            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            if (CCRandom.Float_0_1() < 0.2f)
            {
                pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            }
            else
            {
                pSprite.Position = new CCPoint(-1000, -1000);
            }
        }
Example #27
0
        public Bubble(int maxColors, int maxGrowthTime)
        {
            _maxGrowthTime = maxGrowthTime;

            Id          = _universalId++;
            Scale       = 0.5f;
            BubbleColor = GetRandomColor(maxColors);
            ColorF      = new CCColor4F(BubbleColor);
            int randomSize = CCRandom.Next(25, 50);

            ContentSize = new CCSize(randomSize, randomSize);
            DrawSolidCircle(Position, randomSize, BubbleColor);
        }
Example #28
0
        public static void AddJiggle(CCNode targetSprite)
        {
            var swingTime = CCRandom.Next(10, 31) / 100f;

            var rotateLeftAction  = new CCRotateBy(swingTime, 1);
            var rotateRightAction = new CCRotateBy(swingTime * 2, -2);
            var rotateBackAction  = new CCRotateBy(swingTime, 1);

            var rotateSequence = new CCSequence(rotateLeftAction, rotateRightAction, rotateBackAction);
            var repeatAction   = new CCRepeatForever(rotateSequence);

            targetSprite.RunAction(repeatAction);
        }
        private void performanceout20(CCSprite pSprite)
        {
            CCSize size = CCDirector.SharedDirector.WinSize;

            if (CCRandom.Float_0_1() < 0.2f)
            {
                pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            }
            else
            {
                pSprite.Position = new CCPoint(-1000, -1000);
            }
        }
Example #30
0
        void TransitionOut(float delta)
        {
            CCLog.Log("Make Transition to Game Level");

            // Too select a random transition comment the two lines below and uncomment the section below.
            //			var transition = Transition2;
            //			CCDirector.SharedDirector.ReplaceScene(transition);


            // other transition options...

            int diceRoll = CCRandom.Next(0, 6); //0 to 6
            CCTransitionScene transition;

            switch (diceRoll)
            {
            case 0:
                transition = Transition0;
                break;

            case 1:
                transition = Transition1;
                break;

            case 2:
                transition = Transition2;
                break;

            case 3:
                transition = Transition3;
                break;

            case 4:
                transition = Transition4;
                break;

            case 5:
                transition = Transition5;
                break;

            case 6:
                transition = Transition6;
                break;

            default:
                transition = Transition0;
                break;
            }

            Director.ReplaceScene(transition);
        }