예제 #1
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCSprite child = new CCSprite(s_pPathGrossini);
			child.Position = Layer.VisibleBoundsWorldspace.Size.Center;
            AddChild(child, 1);

            //Sum of all action's duration is 1.5 second.
            child.RunAction(new CCRotateBy (1.5f, 90));
			child.RunActions (new CCDelayTime (1.4f), new CCFadeOut (1.1f));

            //After 1.5 second, self will be removed.
			RunActions (new CCDelayTime (1.4f), new CCCallFunc ((removeThis)));
        }
예제 #2
0
		CCSprite AddBanana ()
		{
			var banana = new CCSprite ("Banana");

			double rnd = new Random ().NextDouble ();
			double randomX = (rnd > 0) 
				? rnd * CCDirector.SharedDirector.WinSize.Width - banana.ContentSize.Width / 2 
				: banana.ContentSize.Width / 2;
	
			banana.Position = new CCPoint ((float)randomX, CCDirector.SharedDirector.WinSize.Height - banana.ContentSize.Height / 2);

			AddChild (banana);

			var moveBanana = new CCMoveTo (5.0f, new CCPoint (banana.Position.X, 0));

			banana.RunActions (moveBanana, moveBananaComplete);

			banana.RepeatForever (rotateBanana);

			return banana;
		}
예제 #3
0
        CCSprite AddBanana()
        {
            var spriteSheet = new CCSpriteSheet ("animations/monkey.plist");
            var banana = new CCSprite (spriteSheet.Frames.Find ((x) => x.TextureFilename.StartsWith ("Banana")));

            var p = GetRandomPosition (banana.ContentSize);
            banana.Position = p;
            banana.Scale = 0.5f;

            AddChild (banana);

            var moveBanana = new CCMoveTo (5.0f, new CCPoint (banana.Position.X, 0));
            banana.RunActions (moveBanana, moveBananaComplete);
            banana.RepeatForever (rotateBanana);

            return banana;
        }
예제 #4
0
        private void AddMonster(float time)
        {
            var selectedMonster = new Random().Next() % _monsters.Count;

            var monster = _monsters[selectedMonster];
            var m = monster.Movement;

            //!IMPORTANT -- Every Sprite in Screen must be an new CCSprite! Each Sprite can only be one time on screen
            var spriteMonster = new CCSprite(monster.MonsterSprite);
            spriteMonster.Scale = _appScale;
            spriteMonster.Tag = monster.Tag;

            //BLOCK 1 - Determine where to spawn the monster along the Y axis
            var winSize = Window.WindowSizeInPixels;
            var minX = (spriteMonster.ContentSize.Width / 2);
            var maxX = winSize.Width - spriteMonster.ContentSize.Width / 2;
            var rangeX = maxX - minX;
            var actualY = (new Random().Next() % rangeX) + minX;

            //BLOCK 2 - Determine speed of the monster
            var minDuration = monster.MinVelocity;
            var maxDuration = monster.MaxVelocity;
            var rangeDuration = maxDuration - minDuration;
            var actualDuration = (new Random().Next() % rangeDuration) + minDuration;

            if(m == 1)
            {
                spriteMonster.Position = new CCPoint(actualY, winSize.Height + spriteMonster.ContentSize.Height/2);
                AddChild(spriteMonster);

                var actionMove = new CCMoveTo(actualDuration, new CCPoint(actualY, -spriteMonster.ContentSize.Height/2));
                var actionMoveComplete = new CCCallFuncN (node =>
                    {
                        _monstersOnScreen.Remove(node);
                        node.RemoveFromParent();

                        _lives--;
                        var index = _hearths.Count - 1;
                        RemoveChild(_hearths[index]);
                        _hearths.RemoveAt(index);
                        if(_lives == 0)
                        {
                            Window.DefaultDirector.ReplaceScene(GameStartLayer.GameStartLayerScene(Window));
                        }
                    });

                spriteMonster.RunActions(actionMove, actionMoveComplete);
                _monstersOnScreen.Add(spriteMonster);
            }
            else if(m == 2)
            {
                spriteMonster.Position = new CCPoint(actualY, winSize.Height + spriteMonster.ContentSize.Height/2);
                AddChild(spriteMonster);

                var actionMoveComplete = new CCCallFuncN (node =>
                    {
                        _monstersOnScreen.Remove(node);
                        node.RemoveFromParent();

                        _lives--;
                        var index = _hearths.Count - 1;
                        RemoveChild(_hearths[index]);
                        _hearths.RemoveAt(index);
                        if(_lives == 0)
                        {
                            Window.DefaultDirector.ReplaceScene(GameStartLayer.GameStartLayerScene(Window));
                        }
                    });

                var bezierList = new List<CCFiniteTimeAction>();
                var bezier = new CCBezierConfig();
                var splitDuration = actualDuration / 6.0f;
                CCBezierTo bezierAction;

                for(int i = 0; i < 6; i++)
                {
                    if(i % 2 == 0)
                    {
                        bezier.ControlPoint1 = new CCPoint(actualY + 100, winSize.Height - (100 + (i * 200)));
                        bezier.ControlPoint2 = new CCPoint(actualY + 100, winSize.Height - (100 + (i * 200)));
                        bezier.EndPosition = new CCPoint(actualY, winSize.Height - (200 + (i * 200)));
                        bezierAction = new CCBezierTo(splitDuration, bezier);
                    }
                    else
                    {
                        bezier.ControlPoint1 = new CCPoint(actualY - 100, winSize.Height - (100 + (i * 200)));
                        bezier.ControlPoint2 = new CCPoint(actualY - 100, winSize.Height - (100 + (i * 200)));
                        bezier.EndPosition = new CCPoint(actualY, winSize.Height - (200 + (i * 200)));
                        bezierAction = new CCBezierTo(splitDuration, bezier);
                    }

                    bezierList.Add(bezierAction);
                }

                bezierList.Add(actionMoveComplete);

                var seq = new CCSequence(bezierList.ToArray());
                spriteMonster.RunAction(seq);

                _monstersOnScreen.Add(spriteMonster);
            }
        }