Exemple #1
0
        void CreatePlayer()
        {
            player.Name     = "player";
            player.Position = new CCPoint(VisibleBoundsWorldspace.MinX + player.ContentSize.Width * 1.5f, ContentSize.Height * 0.75f);
            AddChild(player);
            this.ReorderChild(player, 10);

            CCAnimation playerAnimation = new CCAnimation();

            for (int i = 1; i <= 3; i++)
            {
                playerAnimation.AddSpriteFrame(new CCSprite(string.Format("player-{0}", i)));
            }
            playerAnimation.AddSpriteFrame(playerAnimation.Frames[1].SpriteFrame);
            playerAnimation.DelayPerUnit = 0.01f;

            var animate         = new CCAnimate(playerAnimation);
            var animationAction = new CCRepeatForever(animate);

            player.RunAction(animationAction);
        }
Exemple #2
0
        void CreatePipesAndCoins()
        {
            var pipeNode = new CCNode();

            pipeNode.AnchorPoint = CCPoint.Zero;
            pipeNode.Name        = "pipe";

            var bottomPipe = new CCSprite("pipe");

            bottomPipe.AnchorPoint = CCPoint.Zero;
            bottomPipe.ScaleX      = 0.5f;
            bottomPipe.FlipY       = true;
            bottomPipe.Name        = "bottomPipe";
            bottomPipe.Position    = new CCPoint(0, 0);

            var pipeGap = new CCDrawNode();

            pipeGap.AnchorPoint = CCPoint.Zero;
            pipeGap.DrawRect(new CCRect(0, 0, 1, (player.ContentSize.Height * 2.8f) - pipeGapShrink), CCColor4B.Red);
            pipeGap.Name     = "sensorScore";
            pipeGap.Position = new CCPoint(bottomPipe.ScaledContentSize.Width, bottomPipe.ContentSize.Height);
            pipeGap.Visible  = false;

            var topPipe = new CCSprite("pipe");

            topPipe.AnchorPoint = CCPoint.Zero;
            topPipe.ScaleX      = 0.5f;
            topPipe.Name        = "topPipe";
            topPipe.Position    = new CCPoint(0, bottomPipe.ContentSize.Height + pipeGap.ContentSize.Height);

            pipeNode.AddChild(bottomPipe);
            pipeNode.AddChild(pipeGap);
            pipeNode.AddChild(topPipe);


            AddChild(pipeNode);
            this.ReorderChild(pipeNode, -20);

            float xPosition = ContentSize.Width;
            float yPosition = CCRandom.Next(-530, 5);

            pipeNode.Position = new CCPoint(xPosition, yPosition);

            //Create coin
            var coin = new CCSprite("gold_1");

            coin.Name  = "coin";
            coin.Scale = 0.75f;

            int coinPos = CCRandom.Next(0, 3);

            if (coinPos == 0)
            {
                coin.Tag       = 0;
                coin.PositionX = topPipe.PositionX + 190;
                coin.PositionY = topPipe.PositionY + 120;
            }
            else if (coinPos == 1)
            {
                coin.Tag       = 1;
                coin.PositionX = topPipe.PositionX + coin.ContentSize.Width / 3;
                coin.PositionY = topPipe.PositionY - pipeGap.ContentSize.Height / 2;
            }
            else
            {
                coin.Tag       = 2;
                coin.PositionX = topPipe.PositionX + 190;
                coin.PositionY = topPipe.PositionY - pipeGap.ContentSize.Height - 120;
            }


            pipeNode.AddChild(coin);
            this.ReorderChild(coin, 10);

            CCAnimation coinAnimation = new CCAnimation();

            for (int i = 1; i <= 4; i++)
            {
                coinAnimation.AddSpriteFrame(new CCSprite(string.Format("gold_{0}", i)));
            }
            coinAnimation.DelayPerUnit = 0.1f;

            var animate         = new CCAnimate(coinAnimation);
            var animationAction = new CCRepeatForever(animate);

            coin.RunAction(animationAction);



            float endPosition  = ContentSize.Width + (pipeNode.ContentSize.Width * 2) + 190;
            var   moveAction   = new CCMoveBy(6.2f, new CCPoint(-endPosition, 0));
            var   remove       = new CCRemoveSelf();
            var   moveSequence = new CCSequence(moveAction, remove);

            pipeNode.RunAction(moveSequence);
        }
Exemple #3
0
        private void createActions()
        {
            //swing action for health drops
            CCFiniteTimeAction easeSwing = new CCSequence(
                new CCEaseInOut(new CCRotateTo(1.2f, -10), 2),
                new CCEaseInOut(new CCRotateTo(1.2f, 10), 2));

            _swingHealth = new CCRepeatForever(easeSwing);
            //_swingHealth ->retain();

            //action sequence for shockwave: fade out, call back when done
            _shockwaveSequence = new CCSequence(
                new CCFadeOut(1.0f),
                new CCCallFunc(shockwaveDone));
            //_shockwaveSequence->retain();

            //action to grow bomb
            _growBomb = new CCScaleTo(6.0f, 1);
            //_growBomb->retain();

            //action to rotate sprites
            _rotateSprite = new CCRepeatForever(new CCRotateBy(0.5f, -90));
            //_rotateSprite->retain();


            //sprite animations
            CCAnimation animation;

            var spriteFrameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

            animation = new CCAnimation();
            CCSpriteFrame frame;
            int           i;

            //animation for ground hit
            for (i = 1; i <= 10; i++)
            {
                frame = spriteFrameCache[String.Format("boom{0}.png", i)];
                animation.AddSpriteFrame(frame);
            }



            animation.DelayPerUnit         = (1 / 10.0f);
            animation.RestoreOriginalFrame = true;
            _groundHit = new CCSequence(
                new CCMoveBy(0, new CCPoint(0, _screenSize.Height * 0.12f)),
                new CCAnimate(animation),
                new CCCallFuncN(animationDone));
            //_groundHit->retain();

            animation = new CCAnimation();
            //animation for falling object explosion
            for (i = 1; i <= 7; i++)
            {
                frame = spriteFrameCache[String.Format("explosion_small{0}.png", i)];

                animation.AddSpriteFrame(frame);
            }

            animation.DelayPerUnit         = 0.5f / 7.0f;
            animation.RestoreOriginalFrame = true;
            _explosion = new CCSequence(
                new CCAnimate(animation),
                new CCCallFuncN(animationDone)
                );
            ;
            // _explosion->retain();
        }