示例#1
0
 public override void Update(float dt)
 {
     elapsed += dt;
     if (elapsed > 1f)
     {
         elapsed = 0f;
         // CCLabelBMFont
         if (label1 != null)
         {
             RemoveChild(label1);
         }
         CCNode node = new CCNode();
         CCSize s    = CCDirector.SharedDirector.WinSize;
         float  x    = s.Width * CCMacros.CCRandomBetween0And1();
         float  y    = s.Height * CCMacros.CCRandomBetween0And1();
         label1 = new CCLabelBMFont(string.Format("{0:N2},{1:N2} @ Mem Leak Ctor", x, y), "fonts/konqa32.fnt", 255f, CCTextAlignment.Right, CCPoint.Zero);
         node.AddChild(label1);
         label1.Position = new CCPoint(x, y);
         AddChild(node);
         label1 = node;
         // Start - test case for memory leak mentioned at https://cocos2dxna.codeplex.com/discussions/544032
         node.Scale = 2f;
         //--> This action causes the leak
         CCScaleTo    acScale   = new CCScaleTo(0.1f, 1);
         CCDelayTime  acShow    = new CCDelayTime(0.1f);
         CCSplitRows  acFadeOut = new CCSplitRows(0.1f, 20);
         CCRemoveSelf acRemove  = new CCRemoveSelf(true);
         CCSequence   seq       = new CCSequence(acScale, acShow, acFadeOut, acRemove);
         node.RunAction(seq);
     }
 }
示例#2
0
        /**********************************************************************
         *********************************************************************/
        //Receiver sends ACK
        public static void SendACKFor(int seqnum)
        {
            if (!stopEverything)
            {
                //define object
                float yPos = 15 + (65 * (28 - seqnum)); //where the box !starts!
                OldPipelineProtocolsACK pp;

                //smaller rectangle at --
                switch (seqnum)
                {
                case -1:
                    pp   = new OldPipelineProtocolsACK(seqnum, 5, 1);
                    yPos = yPos + 12;     //since it's smaller, it has to be a little further up, in order to look pretty
                    break;

                default:
                    pp = new OldPipelineProtocolsACK(seqnum, 0);
                    break;
                }
                pp.Position = new CCPoint(280, yPos);
                layer.AddChild(pp);

                //define action
                float timeToTake        = 5f;
                var   distance          = new CCPoint(80, yPos);              //82 to 278 = 278-82 = 196
                var   sendPackageAction = new CCMoveTo(timeToTake, distance); //this action moves the object 196 in x-direction within 5 seconds
                var   removeAction      = new CCRemoveSelf();                 //this action removes the object*/

                //define sequence of actions and apply to object
                var cc_seq1 = new CCSequence(sendPackageAction, removeAction);
                pp.RunAction(cc_seq1);
            }
        }
示例#3
0
        /**********************************************************************
         *********************************************************************/
        //this method imitates the sender of a packet. It is called by the method invoke
        public static void SendPackageAt(int seqnum)
        {
            if (!stopEverything)
            {
                if (seqnum == nextSeqnum)
                {
                    DrawFillLeft(seqnum);
                }

                //pending if not already acknowledged . Add to list only once
                if (!arrivedAck.Any() && !pendingAck.Contains(seqnum) ||
                    arrivedAck.Any() && !arrivedAck.Contains(seqnum) && !pendingAck.Contains(seqnum))
                {
                    pendingAck.Add(seqnum);
                }

                //define object
                float yPos = 15 + (65 * (28 - seqnum)); //calculate where the box !starts! in the coordinate system
                var   pp   = new OldPipelineProtocolsPack(seqnum, 0);
                pp.Position = new CCPoint(80, yPos);
                layer.AddChild(pp);

                //define actions
                float timeToTake        = 5f;
                var   distance          = new CCPoint(280, yPos);             //82 to 278 = 278-82 = 196
                var   sendPackageAction = new CCMoveTo(timeToTake, distance); //this action moves the object 196 in x-direction within 5 seconds
                var   removeAction      = new CCRemoveSelf();                 //this action removes the object

                //define sequence of actions and apply to object
                var cc_seq1 = new CCSequence(sendPackageAction, removeAction);
                pp.RunAction(cc_seq1);
            }
        }
示例#4
0
        public void ConveyorShushiLeftToRight()
        {
            var sushi = new CCSprite(sushiTexture);

            sushi.PositionX = -50f;
            sushi.PositionY = 210f;
            var moveBy   = new CCMoveBy(4f, new CCPoint(500f, 0));
            var remove   = new CCRemoveSelf();
            var sequence = new CCSequence(moveBy, remove);

            sushi.RunAction(sequence);
            AddChild(sushi);
        }
示例#5
0
        /**********************************************************************
         *********************************************************************/
        public static void SlowDownPack(OldPipelineProtocolsPack pp, int xPos)
        {
            //stop running actions
            pp.StopAllActions();

            //define actions
            float yPos              = 15 + (65 * (28 - pp.seqnum));
            float timeToTake        = 8f;
            var   distance          = new CCPoint(280, yPos);
            var   sendPackageAction = new CCMoveTo(timeToTake, distance); //this action moves the Object to the CCPoint
            var   removeAction      = new CCRemoveSelf();                 //this action removes the object*/

            //define sequence of actions and apply to object
            var cc_seq1 = new CCSequence(sendPackageAction, removeAction);

            pp.RunAction(cc_seq1);
        }
示例#6
0
        /**********************************************************************
         *********************************************************************/
        public static void SlowDownAck(OldPipelineProtocolsACK aa, int xPos)
        {
            //stop running actions
            aa.StopAllActions();

            //define actions
            float timeToTake = 8f; //SET TIME TO TAKE DEPENDING ON xPos?

            float yPos              = 15 + (65 * (28 - aa.seqnum));
            var   distance          = new CCPoint(80, yPos);
            var   sendPackageAction = new CCMoveTo(timeToTake, distance); //this action moves the Object to the CCPoint
            var   removeAction      = new CCRemoveSelf();                 //this action removes the object*/

            //define sequence of actions and apply to object
            var cc_seq1 = new CCSequence(sendPackageAction, removeAction);

            aa.RunAction(cc_seq1);
        }
示例#7
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);
        }
示例#8
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            var backGround = new CCSprite("Images/BackGround/space", null)
            {
                Position = ContentSize.Center
            };

            AddChild(backGround);

            if (_mode == GameMode.Replay)
            {
                playerPoint    = _playData.PlayerPositions;
                enemyPopPointX = new Queue <int>(_playData.EnemyPopPoints_X);
                enemyTypes     = new Queue <MoverType>(_playData.MoverTypes);
                var modeLabel = new CCLabel("リプレイモード", "arial", 30)
                {
                    Color    = new CCColor3B(255, 100, 100),
                    Position = new CCPoint(380, GlobalGameData.Window_Height - 20)
                };
                AddChild(modeLabel);
            }


            player = _mode == GameMode.Normal ? new Player() : new ReplayPlayer(playerPoint);
            AddChild(player.Node);

            enemys        = new List <Enemy>(100);
            playerBullets = new List <IBullet <IShot> >(50);
            enemyBullets  = new List <IBullet <IShot> >(100);

            if (_mode == GameMode.Normal)
            {
                playerPoint    = new List <Point>(10000);
                enemyPopPointX = new Queue <int>(100);
                enemyTypes     = new Queue <MoverType>(100);
            }


            brokenMovers    = new BrokenMover[2];
            brokenMovers[0] = new BrokenMover(new CCPoint(0, 650), (new NormalEnemySkin()).ImgPath, MoverType.NormalEnemy);
            brokenMovers[1] = new BrokenMover(new CCPoint(0, 620), (new StrongEnemySkin()).ImgPath, MoverType.StrongEnemy);

            AddChild(brokenMovers[0].Image);
            AddChild(brokenMovers[1].Image);
            AddChild(brokenMovers[0].Nodes[1]);
            AddChild(brokenMovers[1].Nodes[1]);


            var count3  = new CCSprite("Images/System/Count3");
            var count2  = new CCSprite("Images/System/Count2");
            var count1  = new CCSprite("Images/System/Count1");
            var countGo = new CCSprite("Images/System/CountGo")
            {
                Tag = 0x1919
            };
            var counts = new[] { count3, count2, count1, countGo };

            var countAction = new CCMoveTo(1, ContentSize.Center);

            var countsQueue = new Queue <CCNode>(counts);
            var remove      = new CCRemoveSelf();

            foreach (var count in counts)
            {
                count.Position = new CCPoint(1000, GlobalGameData.Window_Center_Y);
                AddChild(count);
            }

            void s(float f)
            {
                if (!countsQueue.Any())
                {
                    CCAudioEngine.SharedEngine.PlayBackgroundMusic(randomBGM, true);
                    Unschedule(s);
                    Schedule(RunGameLogic);
                    Schedule((_) =>
                    {
                        if (_mode == GameMode.Normal)
                        {
                            Enemy enemy = new Enemy(new EnemySkinFactory(), this);
                            enemyPopPointX.Enqueue(enemy.InitXPoint);
                            enemyTypes.Enqueue(enemy.Type);
                            AddEnemy(enemy);
                        }
                        else if (_mode == GameMode.Replay)
                        {
                            if (!enemyPopPointX.Any() || !enemyTypes.Any())
                            {
                                return;
                            }
                            AddEnemy(new ReplayEnemy(this, enemyPopPointX.Dequeue(), enemyTypes.Dequeue()));
                        }
                    },
                             1.0f);

                    Schedule((_) =>
                    {
                        if (!player.IsEnable)
                        {
                            return;
                        }
                        AddBullets(playerBullets, player.Fire(playerBullets));
                    }, (1.0f / 6.0f));

                    Schedule(_ =>
                    {
                        if (!player.IsEnable)
                        {
                            return;
                        }
                        Score++;
                    }, 1.0f);


                    AddEventListener(player.TouchListener, this);
                }
                else
                {
                    var count = countsQueue.Dequeue();
                    count.RunActions(countAction, remove);
                    if (count.Tag == 0x1919)
                    {
                        CCAudioEngine.SharedEngine.PlayEffect("SE/Countdown01-6");
                    }
                    else
                    {
                        CCAudioEngine.SharedEngine.PlayEffect("SE/Countdown01-5");
                    }
                }
            };
            Schedule(s, 1, 4, 1);

            var button = new CCSprite("Images/System/gear")
            {
                Position = new CCPoint(30, 30),
            };

            var buttontouch = new CCEventListenerTouchOneByOne()
            {
                IsSwallowTouches = true,
                OnTouchBegan     = (touch, _) =>
                {
                    if (button.BoundingBox.ContainsPoint(touch.Location))
                    {
                        isbuttontouch = true;
                        return(true);
                    }
                    return(false);
                },
                OnTouchMoved = (touch, _) =>
                {
                    if (!isbuttontouch)
                    {
                        return;
                    }
                    isbuttontouch = false;
                    if (button.BoundingBox.ContainsPoint(touch.Location))
                    {
                        isbuttontouch = true;
                    }
                },
                OnTouchEnded = (touch, _) =>
                {
                    if (!isbuttontouch)
                    {
                        return;
                    }
                    if (button.BoundingBox.ContainsPoint(touch.Location))
                    {
                        this.Pause();
                        //var dialog = new YesNoDialog("停止なう", "再開しますか",
                        //    ___ =>
                        //    {
                        //        var _dialog = GetChildByTag(YesNoDialog.TAG) as YesNoDialog;
                        //        _dialog.Close();
                        //        RemoveChild(_dialog);
                        //        this.Resume();

                        //    }, null);
                        //AddChild(dialog, 1, YesNoDialog.TAG);
                        var pauseMenu = new ModalMenu()
                        {
                            Position = ContentSize.Center,
                        };
                        var retryGame = new CCMenuItemLabel(new CCLabel("ゲームをやりなおす", "Arials", 50),
                                                            A =>
                        {
                            ChangeScene(new Game(randomBGM));

                            var dialog = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog;
                            dialog.Close();
                        });
                        var goRanking = new CCMenuItemLabel(new CCLabel("ランキングにもどる", "Arial", 50),
                                                            A =>
                        {
                            ChangeScene(new Loading(new RankingAssetsLoader()));
                            var dialog = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog;
                            dialog.Close();
                        });
                        var goTitle = new CCMenuItemLabel(new CCLabel("タイトルにもどる", "Arial", 50),
                                                          A =>
                        {
                            ChangeScene(new Loading(new TitleAssetsLoader()));
                            var dialog = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog;
                            dialog.Close();
                        });
                        var resumeGame = new CCMenuItemLabel(new CCLabel("ゲームをつづける", "Arial", 50),
                                                             A =>
                        {
                            this.Resume();
                            var dialog = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog;
                            dialog.Close();
                            RemoveChild(dialog);
                        });

                        var menuItems = new[] { retryGame, goTitle, resumeGame };


                        foreach (var menuItem in menuItems)
                        {
                            pauseMenu.AddChild(menuItem);
                        }

                        pauseMenu.AlignItemsVertically(20);

                        var modalMenuDialog = new ModalMenuDialog(pauseMenu);

                        AddChild(modalMenuDialog, 1, ModalMenuDialog.TAG);
                    }
                }
            };

            AddChild(button);
            AddEventListener(buttontouch);
        }