/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); var backgroundTexture = Content.Load <Texture2D>("bg"); var backgroundSprite = new StaticSprite(backgroundTexture); var backgroundLayer = new ParallaxLayer(this); backgroundLayer.Sprites.Add(backgroundSprite); backgroundLayer.DrawOrder = 0; Components.Add(backgroundLayer); // TODO: use this.Content to load your game content here var spritesheet = Content.Load <Texture2D>("boat"); player = new Player(spritesheet); var playerLayer = new ParallaxLayer(this); playerLayer.Sprites.Add(player); playerLayer.DrawOrder = 2; Components.Add(playerLayer); var midgroundTextures = new Texture2D[] { Content.Load <Texture2D>("mid"), Content.Load <Texture2D>("mid") }; var midgroundSprites = new StaticSprite[] { new StaticSprite(midgroundTextures[0]), new StaticSprite(midgroundTextures[1], new Vector2(3500, 0)) }; var midgroundLayer = new ParallaxLayer(this); midgroundLayer.Sprites.AddRange(midgroundSprites); midgroundLayer.DrawOrder = 1; //var midgroundScrollController = midgroundLayer.ScrollController as AutoScrollController; //midgroundScrollController.Speed = 40f; Components.Add(midgroundLayer); lava = Content.Load <Texture2D>("lava"); var foregroundSprites = new StaticSprite(lava); var foregroundLayer = new ParallaxLayer(this); foregroundLayer.Sprites.Add(foregroundSprites); foregroundLayer.DrawOrder = 4; //var foregroundScrollController = foregroundLayer.ScrollController as AutoScrollController; //foregroundScrollController.Speed = 80f; Components.Add(foregroundLayer); //var playerScrollController = playerLayer.ScrollController as AutoScrollController; //playerScrollController.Speed = 80f; backgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.1f); midgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.4f); playerLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f); foregroundLayer.ScrollController = new LavaScrollController(player, 1.0f); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here // PLAYER //----------------------------------------------------------- var spritesheet = Content.Load <Texture2D>("player"); player = new Player(spritesheet, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); var playerLayer = new ParallaxLayer(this); playerLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f); playerLayer.Sprites.Add(player); playerLayer.DrawOrder = 5; Components.Add(playerLayer); // BACKGROUND //----------------------------------------------------------- var backgroundTexture = Content.Load <Texture2D>("finalNight"); var backgroundSprite = new StaticSprite(backgroundTexture); var backgroundLayer = new ParallaxLayer(this); backgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.1f); backgroundLayer.Sprites.Add(backgroundSprite); backgroundLayer.DrawOrder = 0; Components.Add(backgroundLayer); var midgroundTexture = Content.Load <Texture2D>("sky"); var midgroundSprite = new StaticSprite(midgroundTexture); var midgroundLayer = new ParallaxLayer(this); midgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.2f); midgroundLayer.Sprites.Add(midgroundSprite); midgroundLayer.DrawOrder = 1; Components.Add(midgroundLayer); // Foreground //----------------------------------------------------------- var foregroundTexture = new Texture2D[] { Content.Load <Texture2D>("trees1"), Content.Load <Texture2D>("trees1") }; var foregroundSprite = new StaticSprite[] { new StaticSprite(foregroundTexture[0]), new StaticSprite(foregroundTexture[1], new Vector2(3500, 0)) }; var foregroundLayer = new ParallaxLayer(this); foregroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.5f); foregroundLayer.Sprites.AddRange(foregroundSprite); foregroundLayer.DrawOrder = 2; Components.Add(foregroundLayer); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here var spritesheet = Content.Load <Texture2D>("helicopter"); player = new Player(spritesheet); var backgroundTexture = Content.Load <Texture2D>("background"); var backgroundSprite = new StaticSprite(backgroundTexture); var backgroundLayer = new ParallaxLayer(this); backgroundLayer.Sprites.Add(backgroundSprite); backgroundLayer.DrawOrder = 0; Components.Add(backgroundLayer); var playerLayer = new ParallaxLayer(this); playerLayer.Sprites.Add(player); playerLayer.DrawOrder = 2; Components.Add(playerLayer); var midgroundTextures = new Texture2D[] { Content.Load <Texture2D>("midground1"), Content.Load <Texture2D>("midground2") }; var midgroundSprites = new StaticSprite[] { new StaticSprite(midgroundTextures[0]), new StaticSprite(midgroundTextures[1], new Vector2(3500, 0)) }; var midgroundLayer = new ParallaxLayer(this); midgroundLayer.Sprites.AddRange(midgroundSprites); midgroundLayer.DrawOrder = 1; //var midgroundScrollController = midgroundLayer.ScrollController as AutoScrollController; //midgroundScrollController.Speed = 40f; Components.Add(midgroundLayer); var foregroundTextures = new List <Texture2D>() { Content.Load <Texture2D>("foreground1"), Content.Load <Texture2D>("foreground2"), Content.Load <Texture2D>("foreground3"), Content.Load <Texture2D>("foreground4") }; var foregroundSprites = new List <StaticSprite>(); for (int i = 0; i < foregroundTextures.Count; i++) { var position = new Vector2(i * 3500, 0); var sprite = new StaticSprite(foregroundTextures[i], position); foregroundSprites.Add(sprite); } var foregroundLayer = new ParallaxLayer(this); foreach (var sprite in foregroundSprites) { foregroundLayer.Sprites.Add(sprite); } foregroundLayer.DrawOrder = 4; //var foregroundScrollController = foregroundLayer.ScrollController as AutoScrollController; //foregroundScrollController.Speed = 80f; Components.Add(foregroundLayer); //var playerScrollController = playerLayer.ScrollController as AutoScrollController; //playerScrollController.Speed = 80f; backgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.1f); midgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.4f); playerLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f); foregroundLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here walls.LoadContent(Content); var spritesheet = Content.Load <Texture2D>("character"); player = new Player(spritesheet, this); // Parallax Implementation START // Load Textures var backgroundTexture = Content.Load <Texture2D>("background"); var starsTexture = Content.Load <Texture2D>("stars"); var farPlanetsTexture = Content.Load <Texture2D>("farPlanets"); var bigPlanetTexture = Content.Load <Texture2D>("bigPlanet"); var ringPlanetTexture = Content.Load <Texture2D>("ringPlanet"); var mazeTexture = Content.Load <Texture2D>("wall"); var font = Content.Load <SpriteFont>("Calibri"); // Create corresponding StaticSprites var backgroundSprite = new StaticSprite(backgroundTexture, new Vector2(0, 0)); var starsSprite = new StaticSprite(starsTexture, new Vector2(0, 0)); var farPlanetsSprite = new StaticSprite(farPlanetsTexture, new Vector2(100, 200)); var bigPlanetSprite = new StaticSprite(bigPlanetTexture, new Vector2(300, 300)); var ringPlanetSprite = new StaticSprite(ringPlanetTexture, new Vector2(800, 200)); var mazeSprites = new List <StaticSprite>(); foreach (BoundingRectangle wall in walls.Maze) { // set staticsprite for each wall of the maze and give it corresponding position (mazeTexture, wall.Position) var position = new Vector2(wall.X, wall.Y); var sprite = new StaticSprite(mazeTexture, position, wall.Width, wall.Height); mazeSprites.Add(sprite); } var offset = new Vector2(750, 500); offset.X -= player.bounds.X; offset.Y -= player.bounds.Y; var textOffset1 = offset * -1; textOffset1.X += 5; textOffset1.Y += 5; var textOffset2 = offset * -1; textOffset2.X += 5; textOffset2.Y += 35; var fontSpriteFont1 = new FontSpriteTest(font, "Reach the goal in the bottom-right corner using the arrow keys (or WASD keys)", textOffset1, this.player); var fontSpriteFont2 = new FontSpriteTest(font, "Don't touch the walls", textOffset2, this.player); // Create corresponding Parallax Layers var backgroundLayer = new ParallaxLayer(this); var starsLayer = new ParallaxLayer(this); var farPlanetsLayer = new ParallaxLayer(this); var bigPlanetLayer = new ParallaxLayer(this); var playerLayer = new ParallaxLayer(this); var ringPlanetLayer = new ParallaxLayer(this); var mazeLayer = new ParallaxLayer(this); foreach (var sprite in mazeSprites) { mazeLayer.Sprites.Add(sprite); } var fontLayer = new ParallaxLayer(this); // Add sprites to corresponding layers backgroundLayer.Sprites.Add(backgroundSprite); starsLayer.Sprites.Add(starsSprite); farPlanetsLayer.Sprites.Add(farPlanetsSprite); bigPlanetLayer.Sprites.Add(bigPlanetSprite); playerLayer.Sprites.Add(player); ringPlanetLayer.Sprites.Add(ringPlanetSprite); fontLayer.Sprites.Add(fontSpriteFont1); fontLayer.Sprites.Add(fontSpriteFont2); if (player.gameState == GameState.Over) { var textOffsetGameOver = offset * -1; textOffsetGameOver.X += 750; textOffsetGameOver.Y += 500; var fontSpriteFont3 = new FontSpriteTest(font, "Game Over", textOffsetGameOver, this.player); fontLayer.Sprites.Add(fontSpriteFont3); } else if (player.gameState == GameState.Win) { var textOffsetWin = offset * -1; textOffsetWin.X += 750; textOffsetWin.Y += 500; var fontSpriteFont3 = new FontSpriteTest(font, "You Win", textOffsetWin, this.player); fontLayer.Sprites.Add(fontSpriteFont3); } // Create Draw Order (back to front) backgroundLayer.DrawOrder = 0; starsLayer.DrawOrder = 1; farPlanetsLayer.DrawOrder = 2; bigPlanetLayer.DrawOrder = 3; ringPlanetLayer.DrawOrder = 4; playerLayer.DrawOrder = 5; mazeLayer.DrawOrder = 5; fontLayer.DrawOrder = 6; // Add parallax layers to components Components.Add(backgroundLayer); Components.Add(starsLayer); Components.Add(farPlanetsLayer); Components.Add(bigPlanetLayer); Components.Add(playerLayer); Components.Add(ringPlanetLayer); Components.Add(mazeLayer); Components.Add(fontLayer); // SCROLLING WITH PLAYER (PART 8 IN LAB TUTORIAL) backgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.1f); starsLayer.ScrollController = new PlayerTrackingScrollController(player, 0.2f); farPlanetsLayer.ScrollController = new PlayerTrackingScrollController(player, 0.3f); bigPlanetLayer.ScrollController = new PlayerTrackingScrollController(player, 0.4f); playerLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f); ringPlanetLayer.ScrollController = new PlayerTrackingScrollController(player, 0.5f); mazeLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f); fontLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f); }