Esempio n. 1
0
        /// <summary>
        ///  Implement CCDirector and CCScene init code here.
        /// </summary>
        /// <returns>
        ///  true  Initialize success, app continue.
        ///  false Initialize failed, app terminate.
        /// </returns>
        public override bool ApplicationDidFinishLaunching()
        {
            //initialize director
            CCDirector pDirector = CCDirector.SharedDirector;

            pDirector.SetOpenGlView();


            // 2D projection
            pDirector.Projection = CCDirectorProjection.Projection2D;

            var resPolicy = CCResolutionPolicy.ExactFit; // This will stretch out your game

            CCDrawManager.SetDesignResolutionSize(preferredWidth,
                                                  preferredHeight,
                                                  resPolicy);

            // turn on display FPS
            //pDirector.DisplayStats = true;

            // set FPS. the default value is 1.0/60 if you don't call this
            pDirector.AnimationInterval = 1.0 / 60;

            GameSpriteBatchNode = new CCSpriteBatchNode("sprites/player_sprite_texture.png");

            CCScene pScene = StartGameScene.Scene();

            pDirector.RunWithScene(pScene);
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Constructs a new level.
        /// </summary>
        /// <param name="anindiegame"></param>
        public Level(StartGameScene startGameScene)
        {
            StartGameScene = startGameScene;
            // Load background layer textures. For now, all levels must
            // use the same backgrounds and only use the left-most part of them.
            AppDelegate.GameSpriteBatchNode.RemoveAllChildren();

            PlayerCharacterSheet = AppDelegate.GameSpriteBatchNode;

            layers    = new CCSprite[12];
            layers[0] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 677, 1539, 360));
            layers[1] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 677, 1539, 360));
            layers[2] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 677, 1539, 360));
            layers[3] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1114, 1536, 277));
            layers[4] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1114, 1536, 277));

            layers[5]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 300, 1014, 377));
            layers[6]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 300, 1014, 377));
            layers[7]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 300, 1014, 377));
            layers[8]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1400, 894, 400));
            layers[9]        = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1400, 894, 400));
            layers[9].FlipX  = true;
            layers[10]       = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(920, 1400, 901, 480));
            layers[11]       = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(920, 1400, 901, 480));
            layers[11].FlipX = true;

            frontLayers    = new CCSprite[3];
            frontLayers[0] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1802, 755, 96));
            frontLayers[1] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(800, 1900, 755, 96));
            frontLayers[2] = new CCSprite(PlayerCharacterSheet.Texture, new CCRect(0, 1900, 755, 96));

            _layer1Vector = new CCPoint(0, (AppDelegate.GameHeight / 2) + 70);
            _layer2Vector = new CCPoint(layers[3].BoundingBox.Size.Width / 2, (AppDelegate.GameHeight / 2));
            _layer3Vector = new CCPoint(0, (AppDelegate.GameHeight / 2) - 100);

            _ilayer1Vector = new CCPoint(layers[0].BoundingBox.Size.Width, (AppDelegate.GameHeight / 2) + 70);
            _ilayer2Vector = new CCPoint(layers[3].BoundingBox.Size.Width * 1.5f, AppDelegate.GameHeight / 2);
            _ilayer3Vector = new CCPoint(layers[5].BoundingBox.Size.Width, (AppDelegate.GameHeight / 2) - 100);

            _jlayer1Vector = new CCPoint(layers[0].BoundingBox.Size.Width * 2, (AppDelegate.GameHeight / 2) + 70);
            _jlayer3Vector = new CCPoint(layers[5].BoundingBox.Size.Width * 2, (AppDelegate.GameHeight / 2) - 100);

            _frontLayer1Vector = new CCPoint(0, frontLayers[0].BoundingBox.Size.Height / 2);
            _frontLayer2Vector = new CCPoint(frontLayers[0].BoundingBox.Size.Width, frontLayers[1].BoundingBox.Size.Height / 2);
            _frontLayer3Vector = new CCPoint((frontLayers[0].BoundingBox.Size.Width * 2), frontLayers[2].BoundingBox.Size.Height / 2);


            var playerSpawnPoint = new CCPoint((AppDelegate.GameWidth / 3), 100);

            Ball = new Ball(this, new CCPoint(AppDelegate.GameWidth / 2, AppDelegate.GameHeight + 200));

            Credits   = new List <CreditText>(5);
            Platforms = new List <Platform>(3);
            Walls     = new List <Wall>(2);
            Questions = new List <Question>(7);

            Platforms.Add(new Platform("sprites/platform_big.png", PlatformTypes.Large, new CCPoint(0, -80)));
            Platforms.Add(new Platform("sprites/platform_big.png", PlatformTypes.Large, new CCPoint(AppDelegate.GameWidth, -80)));
            TrapDoor = new Platform("sprites/platform.png", PlatformTypes.YouWin, new CCPoint(AppDelegate.GameWidth / 2, 10));
            Platforms.Add(this.TrapDoor);

            Walls.Add(new Wall("sprites/wall.png", new CCPoint(0, AppDelegate.GameHeight / 2)));
            Walls.Add(new Wall("sprites/wall.png", new CCPoint(AppDelegate.GameWidth, AppDelegate.GameHeight / 2)));

            Questions.Add(new Question("Wait... what is he doing?", new CCPoint(AppDelegate.GameWidth / 2, -200)));
            Questions.Add(new Question("Where is he going?", new CCPoint(AppDelegate.GameWidth / 2, -700)));
            Questions.Add(new Question("The game is over; why is he trying to leave?", new CCPoint(AppDelegate.GameWidth / 2, -1200)));
            Questions.Add(new Question("Is he starting another journey?", new CCPoint(AppDelegate.GameWidth / 2, -1700)));
            Questions.Add(new Question("What do we do now?", new CCPoint(AppDelegate.GameWidth / 2, -2200)));
            Questions.Add(new Question("We can't allow that.", new CCPoint(AppDelegate.GameWidth / 2, -2700)));
            Questions.Add(new Question("Stop him!", new CCPoint(AppDelegate.GameWidth / 2, -3200), 200));

            //setup classic segment platforms
            for (int i = 0; i < TopPlatforms.Capacity; i++)
            {
                var newPlatform = new Platform(this, PlatformTypes.Top);
                if (i > 40)
                {
                    newPlatform.isAlive = false;
                }
                else
                {
                    newPlatform.StopAllActions();
                    newPlatform.Rotation = 0;
                    newPlatform.Position = new CCPoint(((newPlatform.BoundingBox.Size.Width) * (i)) + (newPlatform.BoundingBox.Size.Width / 2), (newPlatform.BoundingBox.Size.Height / 2) + newPlatform.BoundingBox.Size.Height);
                    //if(i != 24)
                    //    newPlatform.reachedSpawnPoint = true;
                }
                TopPlatforms.Add(newPlatform);
            }

            for (int i = 0; i < MidPlatforms.Capacity; i++)
            {
                var newPlatform = new Platform(this, PlatformTypes.Middle);
                MidPlatforms.Add(newPlatform);
                if (i > 40)
                {
                    newPlatform.isAlive = false;
                }
                else
                {
                    newPlatform.StopAllActions();
                    newPlatform.Rotation = 0;
                    newPlatform.Position = new CCPoint(((newPlatform.BoundingBox.Size.Width) * (i)) + (newPlatform.BoundingBox.Size.Width / 2), (newPlatform.BoundingBox.Size.Height / 2));
                }
            }

            for (int i = 0; i < Spikes.Capacity; i++)
            {
                var spike = new Spike(this)
                {
                    isAlive = false
                };
                Spikes.Add(spike);
            }

            for (int i = 0; i < AttackCreditTexts.Capacity; i++)
            {
                var credit = new CreditText(this, new CCPoint(100, AppDelegate.GameWidth + 200), CreditTypes.AttackingFirstLast);
                credit.CreditNames.ForEach(name => name.Color = CCColor3B.Red);
                AttackCreditTexts.Add(credit);
            }

            InitClouds();

            //add elements to screen
            layers[0].Position = _layer1Vector;
            layers[1].Position = _ilayer1Vector;
            layers[2].Position = _jlayer1Vector;

            layers[0].Color = SkyColor;
            layers[1].Color = SkyColor;
            layers[2].Color = SkyColor;


            PlayerCharacterSheet.AddChild(layers[0], 0);
            PlayerCharacterSheet.AddChild(layers[1], 0);
            PlayerCharacterSheet.AddChild(layers[2], 0);

            layers[3].Position = _layer2Vector + new CCPoint(0, -123);
            layers[4].Position = _ilayer2Vector + new CCPoint(0, -123);

            PlayerCharacterSheet.AddChild(layers[3], 2);
            PlayerCharacterSheet.AddChild(layers[4], 2);

            PlayerCharacterSheet.AddChild(layers[8], 2);
            PlayerCharacterSheet.AddChild(layers[9], 2);
            PlayerCharacterSheet.AddChild(layers[10], 2);
            PlayerCharacterSheet.AddChild(layers[11], 2);

            foreach (var cloud in Clouds)
            {
                PlayerCharacterSheet.AddChild(cloud, 3);
                if (!cloud.IsAlive)
                {
                    cloud.Visible = false;
                }
            }

            layers[5].Position = _layer3Vector;
            layers[6].Position = _ilayer3Vector;
            layers[7].Position = _jlayer3Vector;

            PlayerCharacterSheet.AddChild(layers[5], 4);
            PlayerCharacterSheet.AddChild(layers[6], 4);
            PlayerCharacterSheet.AddChild(layers[7], 4);

            Platforms.ForEach(platform => StartGameScene.AddChild(platform, 5));
            Walls.ForEach(wall => StartGameScene.AddChild(wall, 4));
            StartGameScene.AddChild(Ball, 4);
            Questions.ForEach(question => StartGameScene.AddChild(question, 4));

            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -200), CreditTypes.RollingFirstLast));
            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -400), CreditTypes.RollingFirstMiddleLast));
            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -600), CreditTypes.RollingFirstLast));
            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -800), CreditTypes.RollingFirstMiddleLast));
            Credits.Add(new CreditText(this, new CCPoint(AppDelegate.GameWidth / 2, -1000), CreditTypes.RollingFirstLast));

            Ball.Reset(new CCPoint(AppDelegate.GameWidth / 2, AppDelegate.GameHeight + 200));

            foreach (var s in Spikes)
            {
                PlayerCharacterSheet.AddChild(s, 4);
                if (!s.isAlive)
                {
                    s.Visible = false;
                }
            }

            foreach (var p in TopPlatforms)
            {
                PlayerCharacterSheet.AddChild(p, 5);
                if (!p.isAlive)
                {
                    p.Visible = false;
                }
            }

            foreach (var p in MidPlatforms)
            {
                PlayerCharacterSheet.AddChild(p, 5);
                if (!p.isAlive)
                {
                    p.Visible = false;
                }
            }

            frontLayers[0].Position = _frontLayer1Vector;
            frontLayers[1].Position = _frontLayer2Vector;
            frontLayers[2].Position = _frontLayer3Vector;

            PlayerCharacterSheet.AddChild(frontLayers[0], 6);
            PlayerCharacterSheet.AddChild(frontLayers[1], 6);
            PlayerCharacterSheet.AddChild(frontLayers[2], 6);

            StartGameScene.AddChild(PlayerCharacterSheet);

            frontLayers[0].Visible = false;
            frontLayers[1].Visible = false;
            frontLayers[2].Visible = false;

            layers[0].Visible  = false;
            layers[1].Visible  = false;
            layers[2].Visible  = false;
            layers[3].Visible  = false;
            layers[4].Visible  = false;
            layers[5].Visible  = false;
            layers[6].Visible  = false;
            layers[7].Visible  = false;
            layers[8].Visible  = false;
            layers[9].Visible  = false;
            layers[10].Visible = false;
            layers[11].Visible = false;

            TopPlatforms.ForEach(tile => tile.Visible = false);
            MidPlatforms.ForEach(tile => tile.Visible = false);
        }