public Layer(Camera2D camera) { _camera = camera; Parallax = Vector2.One; Sprites = new List <Sprite>(); }
/// <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"); } gameFont = content.Load <SpriteFont>("gamefont"); //INITIALISING CAMERA _camera = new GameObject.Camera2D(ScreenManager.GraphicsDevice.Viewport) { Limits = new Rectangle(0, 0, 16388, 2860), Zoom = 1.0f }; //INITIALISING PLAYERS playerOne = new GameObject.Player(PlayerIndex.One, "lucas", 9, 6); playerOne.Position = new Vector2(500, 1890); playerOne.Scale = 3.0f; playerOne.FramesPerSecond = 8; playerTwo = new GameObject.Player(PlayerIndex.Two, "lucas", 9, 6); playerTwo.Position = new Vector2(550, 1890); playerTwo.Scale = 3.0f; playerTwo.FramesPerSecond = 8; playerTwo.Colour = Color.Violet; playerThree = new GameObject.Player(PlayerIndex.Three, "lucas", 9, 6); playerThree.Position = new Vector2(600, 1890); playerThree.Scale = 3.0f; playerThree.FramesPerSecond = 8; playerThree.Colour = Color.Green; playerFour = new GameObject.Player(PlayerIndex.Four, "lucas", 9, 6); playerFour.Position = new Vector2(650, 1890); playerFour.Scale = 3.0f; playerFour.FramesPerSecond = 8; playerFour.Colour = Color.Blue; playerList = new List <GameObject.Player>(); playerList.Add(playerOne); //playerList.Add(playerTwo); //playerList.Add(playerThree); //playerList.Add(playerFour); //INITIALISING LAYERS _layerDictionary = new Dictionary <string, int>(); _layerDictionary.Add("back", 0); _layerDictionary.Add("cloud1", 1); _layerDictionary.Add("cloud2", 2); _layerDictionary.Add("cloud3", 3); _layerDictionary.Add("horizon", 4); _layerDictionary.Add("distant", 5); _layerDictionary.Add("far", 6); _layerDictionary.Add("rear", 7); _layerDictionary.Add("mid", 8); _layerDictionary.Add("c", 9); _layerDictionary.Add("interactive", 10); _layerDictionary.Add("player", 11); _layerDictionary.Add("front", 12); _layerDictionary.Add("near", 13); _layerDictionary.Add("fore", 14); // Create 15 layers with parallax ranging from 0% to 100% (only horizontal) _layers = new List <GameObject.Layer> { new GameObject.Layer(_camera) { Parallax = new Vector2(0.0f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(0.1f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(0.2f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(0.3f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(0.6f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(0.7f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(0.8f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(1.0f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(1.0f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(1.0f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(1.0f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(1.0f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(1.0f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(1.1f, 1.0f) }, new GameObject.Layer(_camera) { Parallax = new Vector2(1.2f, 1.0f) }, }; //LevelType level = content.Load<LevelType>("Levels/tutorial2"); LevelType level = new LevelType(); importLayers(level); //ADD THE PLAYERS TO THE LAYER LIST foreach (GameObject.Player player in playerList) { _layers[_layerDictionary["player"]].Sprites.Add(player); } //load content for every sprite in the layers foreach (GameObject.Layer layer in _layers) { for (int i = 0; i < layer.Sprites.Count; i++) { layer.Sprites[i].LoadContent(content, layer.Sprites[i].AssetName); } } //START PLAYING THE LEVEL MUSIC AudioManager.PlayBgmMusic("Tutorial"); //MOVE THE CAMERA TO LOOK AT PLAYER 1 _camera.LookAt(playerList[0].Position, BaseScreenSize); // 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. ScreenManager.Game.ResetElapsedTime(); } }