/// <summary>
        /// Adds a new layer to the LayeredLevelBackground.
        /// </summary>
        /// <param name="layer">The background</param>
        /// <param name="layerDepth">Defines the layer depth of the background layer. 0 is the foremost layer depth.</param>
        /// <param name="scrollSpeedModifier">0 for static background or no scrolling, 1 if you want the background to "follow camera"</param>
        public void AddLayer(LevelBackground layer, int layerDepth, Vector2 parallax)
        {
            BackgroundLayer bgLayer = new BackgroundLayer();
            bgLayer.background = layer;
            bgLayer.layerDepth = layerDepth;
            bgLayer.parallax = parallax;

            layers.Add(bgLayer);
        }
Example #2
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (content == null)
                    content = new ContentManager(ScreenManager.Game.Services, "Content");

                _player = new Player(content);
                XmlReader.Initialize(content, _player);

                inputHandler = new InputHandler();
                inputHandler.InitControls();

                #region Layered Background TESTING

                layeredBackground = new LayeredLevelBackground();

                LevelBackground treeLayer = new LevelBackground("Testilevel2/Background/PuutJaOksat", "Testilevel2PuuJaOksat", 32, content);
                LevelBackground platformLayer = new LevelBackground("Testilevel2/Background/Platform", "Testilevel2Platform", 32, content);
                LevelBackground static1Layer = new LevelBackground("Testilevel2/Background/Static1", "Testilevel2Static1", 32, content);
                LevelBackground static2Layer = new LevelBackground("Testilevel2/Background/Static1Takana", "Testilevel2Static1Takana", 32, content);
                LevelBackground Layer2 = new LevelBackground("Testilevel2/Background/2", "Testilevel2-2", 32, content);
                LevelBackground Layer3 = new LevelBackground("Testilevel2/Background/3", "Testilevel2-3", 32, content);
                LevelBackground Layer4 = new LevelBackground("Testilevel2/Background/4", "Testilevel2-4", 32, content);
                LevelBackground skyLayer = new LevelBackground("Testilevel2/Background/Sky", "Testilevel2Sky", 32, content);

                layeredBackground.AddLayer(platformLayer, 1, new Vector2(0, 0));
                layeredBackground.AddLayer(treeLayer, 3, Vector2.Zero);
                layeredBackground.AddLayer(static2Layer, 2, new Vector2(0, 0));
                layeredBackground.AddLayer(static1Layer, 0, new Vector2(0, 0));
                layeredBackground.AddLayer(Layer2, 4, new Vector2(0.2f, 0));
                layeredBackground.AddLayer(Layer3, 5, new Vector2(0.3f, 0));
                layeredBackground.AddLayer(Layer4, 6, new Vector2(0.55f, 0));
                layeredBackground.AddLayer(skyLayer, 7, new Vector2(1f, 0f));

                layeredBackground.Initialize();

                #endregion

                yellow = content.Load<Texture2D>("Sprites/tosi");
                red = content.Load<Texture2D>("Sprites/red");

                _player.ChangePosition(XmlReader.StartPoint("Levels/Testilevel2/Items/Testilevel2_StartPoint"));

                gameFont = content.Load<SpriteFont>(Constants.GameFont);

                enemies = XmlReader.EnemyList("Levels/Testilevel2/Items/Testilevel2_Enemies");

                SoundEffectManager.Instance.MaxSoundEffectDistance = 750;

                platforms = new List<Platform>();
                Platform plat = new Platform(content, Constants.PlatformType.MovingGrassPlatform, new Vector2(7670, 4900));
                Platform fallingPlat = new Platform(content, Constants.PlatformType.FallingPlatform, new Vector2(7600, 4100));
                Platform fallingPlat2 = new Platform(content, Constants.PlatformType.FallingPlatform, new Vector2(7850, 4100));
                Platform fallingPlat3 = new Platform(content, Constants.PlatformType.FallingPlatform, new Vector2(8100, 4100));
                Platform fallingPlat4 = new Platform(content, Constants.PlatformType.FallingPlatform, new Vector2(8350, 4100));
                fallingPlat.InitCollapse(500);
                fallingPlat2.InitCollapse(500);
                fallingPlat3.InitCollapse(500);
                fallingPlat4.InitCollapse(500);
                plat.InitPatrol(5, 0.2f, 7670, 8400, 200f);
                platforms.Add(plat);
                platforms.Add(fallingPlat);
                platforms.Add(fallingPlat2);
                platforms.Add(fallingPlat3);
                platforms.Add(fallingPlat4);

                /*Enemy worm = new Enemy(Constants.EnemyType.OscillatorWorm, Constants.BehaviourType.Default, 3825, 3333, _player, 0, 0, 0, content);
                Enemy worm2 = new Enemy(Constants.EnemyType.OscillatorWorm, Constants.BehaviourType.Default, 3925, 3233, _player, 0, 0, 0, content);
                Enemy worm3 = new Enemy(Constants.EnemyType.OscillatorWorm, Constants.BehaviourType.Default, 4025, 3133, _player, 0, 0, 0, content);
                Enemy worm4 = new Enemy(Constants.EnemyType.OscillatorWorm, Constants.BehaviourType.Default, 4125, 3033, _player, 0, 0, 0, content);
                enemies.Add(worm);
                enemies.Add(worm2);
                enemies.Add(worm3);
                enemies.Add(worm4);
                */

                #region SPAWNER TESTING
                spawners = new List<GameObjectSpawner>();

                GameObjectSpawner badgerSpawner = new GameObjectSpawner(null, new Vector2(3730, 3340), enemies, 3000f, _player, content);
                badgerSpawner.AddEffect(new VisualEffect("VisualEffects/spawnTest"));
                badgerSpawner.AddSoundEffect(SoundEffectManager.Instance.SpawnerSound);
                badgerSpawner.SetActivation(Constants.SpawnerActivationType.Proximity);
                badgerSpawner.ActivationDistance = 200;
                badgerSpawner.AddObject(Constants.EnemyType.BlackMetalBadger, 1, new Vector2(0, -10));
                badgerSpawner.SetScaleModifier(0.25f, 1.2f, 0.1f);

                spawners.Add(badgerSpawner);

                GameObjectSpawner badgerSpawner2 = new GameObjectSpawner(null, new Vector2(3690, 4040), enemies, 3000f, _player, content);
                badgerSpawner2.AddEffect(new VisualEffect("VisualEffects/spawnTest"));
                badgerSpawner2.AddSoundEffect(SoundEffectManager.Instance.SpawnerSound);
                badgerSpawner2.SetActivation(Constants.SpawnerActivationType.Proximity);
                badgerSpawner2.ActivationDistance = 400;
                badgerSpawner2.AddObject(Constants.EnemyType.BlackMetalBadger, 1, new Vector2(0, -10));
                badgerSpawner2.SetScaleModifier(0.25f, 1.2f, 0.1f);

                spawners.Add(badgerSpawner2);

                GameObjectSpawner badgerSpawner3 = new GameObjectSpawner(null, new Vector2(3925, 4040), enemies, 3000f, _player, content);
                badgerSpawner3.AddEffect(new VisualEffect("VisualEffects/spawnTest"));
                badgerSpawner3.AddSoundEffect(SoundEffectManager.Instance.SpawnerSound);
                badgerSpawner3.SetActivation(Constants.SpawnerActivationType.Proximity);
                badgerSpawner3.ActivationDistance = 400;
                badgerSpawner3.AddObject(Constants.EnemyType.BlackMetalBadger, 1, new Vector2(0, -10));
                badgerSpawner3.SetScaleModifier(0.25f, 1.2f, 0.1f);

                spawners.Add(badgerSpawner3);

                GameObjectSpawner badgerSpawner4 = new GameObjectSpawner(null, new Vector2(4420, 4170), enemies, 3000f, _player, content);
                badgerSpawner4.AddEffect(new VisualEffect("VisualEffects/spawnTest"));
                badgerSpawner4.AddSoundEffect(SoundEffectManager.Instance.SpawnerSound);
                badgerSpawner4.SetActivation(Constants.SpawnerActivationType.Proximity);
                badgerSpawner4.ActivationDistance = 400;
                badgerSpawner4.AddObject(Constants.EnemyType.BlackMetalBadger, 1, new Vector2(0, -10));
                badgerSpawner4.SetScaleModifier(0.25f, 1.2f, 0.1f);

                spawners.Add(badgerSpawner4);

                //Animation worm = new Animation(content.Load<Texture2D>("Sprites/matoallas"), 0, 612, 264, 0, 5, 30);

                //GameObjectSpawner wormPool = new GameObjectSpawner(worm, new Vector2(8100, 5000), enemies, 500, _player, content);
                //spawners.Add(wormPool);
                #endregion

                ladders = new List<Ladder>();
                ladders.Add(new Ladder(content, Constants.LadderType.Wooden, new Vector2(3050, 3550)));
                ladders.Add(new Ladder(content, Constants.LadderType.Wooden, new Vector2(3050, 3788)));

                CombatManager.Instance.Initialize(_player, enemies, content);
                //hud = new HeadsUpDisplay();
                //hud.Initialize(content, ResolutionManager.graphicsDevice, enemies, _player);
                cameraController = new CameraController();
                cameraController.AssingTo(_player);

                Texture2D[] collisionMap = new Texture2D[layeredBackground.Fractions];

                CollisionHandler.Initialize(new CollisionMap("Levels/Testilevel2/CollisionMap/Testilevel2CollisionMap_", 8, 2), enemies, _player, platforms, ladders, content);

                CharacterPhysics.Gravity = 1.5f;

                MusicManager.Instance.LoadContent(content);
                camera = new Camera(ScreenManager.GraphicsDevice.Viewport, new Vector2(layeredBackground.LevelWidth, layeredBackground.LevelHeight));

                MusicManager.Instance.PlayLevel1Music();

                VisualEffectManager.Instance.Initialize(content, ResolutionManager.graphicsDevice);
                VisualEffectManager.Instance.InitializeTerrainEffects(_player, enemies);
                // once the load has finished, we use ResetElapsedTime to tell the game's
                // timing mechanism that we have just finished a very long frame, and that
                // it should not try to catch up.s
                ScreenManager.Game.ResetElapsedTime();
                hudScreen = new HUDScreen(content, _player, enemies, camera);
                ScreenManager.AddScreen(new HUDScreen(content, _player, enemies, camera), null);
                hudScreen.Activate();

            }

            #if WINDOWS_PHONE
            if (Microsoft.Phone.Shell.PhoneApplicationService.Current.State.ContainsKey("PlayerPosition"))
            {
                playerPosition = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["PlayerPosition"];
                enemyPosition = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["EnemyPosition"];
            }
            #endif
        }