public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
        {
            application.PreferMultiSampling  = false;
            application.ContentRootDirectory = "Content";

            try
            {
                CCSimpleAudioEngine.SharedEngine.PreloadEffect("Sounds/SplatEffect");
                CCSimpleAudioEngine.SharedEngine.PreloadEffect("Sounds/pew-pew-lei");
                CCSimpleAudioEngine.SharedEngine.PlayBackgroundMusic("Sounds/backgroundSound", true);
                CCSimpleAudioEngine.SharedEngine.BackgroundMusicVolume = 0.9f;
                CCSimpleAudioEngine.SharedEngine.EffectsVolume         = 0.7f;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }


            var winSize = mainWindow.WindowSizeInPixels;

            mainWindow.SetDesignResolutionSize(winSize.Width, winSize.Height, CCSceneResolutionPolicy.ExactFit);
//			CCScene.SetDefaultDesignResolution(winSize.Width, winSize.Height, CCSceneResolutionPolicy.ExactFit);

            // TODO: Set this up when we have a Game Layer
            CCScene scene = GameStartLayer.GameStartLayerScene(mainWindow);

            mainWindow.RunWithScene(scene);
        }
Example #2
0
        public static CCScene GameStartLayerScene(CCWindow mainWindow)
        {
            var scene = new CCScene(mainWindow);
            var layer = new GameStartLayer();

            scene.AddChild(layer);

            return(scene);
        }
        public static CCScene GameStartLayerScene(CCWindow mainWindow)
        {
            var scene = new CCScene(mainWindow);
            var layer = new GameStartLayer();

            scene.AddChild (layer);

            return scene;
        }
Example #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);
            }
        }