/// <summary> /// Loads and starts the level specified. /// </summary> /// <param name="levelNumber">The level to start.</param> /// <param name="isCustom">Whether the level is a custom level or not.</param> public void BeginLevel(int levelNumber, bool isCustom) { this.CurrentLevelCustom = isCustom; this.Complete = false; this.CurrentLevel = levelNumber > 0 ? levelNumber : 1; this.currentLevelCustom = isCustom; this.scrollingDeath = new ScrollingDeath(ref this.physicsWorld, this.gameDisplayResolution.Y, LevelConstants.MinimumScrollRate, LevelConstants.MaximumScrollRate, LevelConstants.ScrollRate, LevelConstants.ScrollAcceleration, LevelConstants.ScrollDeceleration, this.contentManager); this.scrollStartTimer = 0.0f; this.physicsWorld.ClearForces(); this.levelLoader.LoadLevel(this.CurrentLevel, this.currentLevelCustom); LevelFactory.CreateFloor(this.levelLoader.FloorPoints, ref this.physicsWorld, ref this.floorEdges, ref this.visualFloorEdges, this.gameDisplayResolution.Y); LevelFactory.CreatePlatforms(this.levelLoader.PlatformDescriptions, ref this.physicsWorld, ref this.platforms, this.spriteBatch, this.contentManager); LevelFactory.CreateInteractiveEntities(this.levelLoader.InteractiveDescriptions, ref this.physicsWorld, ref this.interactiveEntities, ref this.mineCart, ref this.cartSwitch, this.spriteBatch, this.contentManager); this.exit = new Exit(this.spriteBatch, this.contentManager, ref this.physicsWorld, this.levelLoader.EndPosition); this.stickman.Reset(this.levelLoader.StartPosition); float startX = this.visualFloorEdges[this.visualFloorEdges.Count - 1].EndPoint.X; float y = this.visualFloorEdges[this.visualFloorEdges.Count - 1].EndPoint.Y - this.gameDisplayResolution.Y; this.visualFloorEdges.Add(new VisualEdge(new Vector2(startX, y), new Vector2(startX + this.gameDisplayResolution.X, y))); this.background.Reset(); AudioManager.PlayBackgroundMusic(true); Camera2D.Y = this.stickman.Position.Y - (this.gameDisplayResolution.Y / 2.0f); this.background.Update(); this.DisplayNotifications(); }
/// <summary> /// Initializes a new instance of the <see cref="LevelManager"/> class. /// </summary> /// <param name="gameDisplayResolution">The resolution the game is set to render at.</param> /// <param name="frameTime">The frame time set for the game.</param> public LevelManager(Vector2 gameDisplayResolution, float frameTime) { this.startText = new RenderableText(); this.Complete = false; this.physicsWorld = null; this.gameDisplayResolution = gameDisplayResolution; this.frameTime = frameTime; this.physicsWorld = null; this.spriteBatch = null; this.floorSprite = new Sprite(); this.contentManager = null; this.levelLoader = null; this.floorEdges = new List <Body>(); this.visualFloorEdges = new List <VisualEdge>(); this.platforms = new List <Platform>(); this.interactiveEntities = new List <InteractiveEntity>(); this.stickman = null; this.exit = null; this.scrollingDeath = null; this.mineCart = null; this.cartSwitch = null; this.scrollStartTimer = 0.0f; this.background = new Background(this.gameDisplayResolution, 0.8f); this.maxScore = 0.0f; }
/// <summary> /// Loads the content used by entities in a level. /// </summary> /// <param name="contentManager">The content manager to load content with.</param> /// <param name="spriteBatch">The sprite batch to render using.</param> public void LoadContent(ContentManager contentManager, SpriteBatch spriteBatch) { this.CurrentLevelCustom = false; this.physicsWorld = new World(ConvertUnits.ToSimUnits(new Vector2(0.0f, 348.8f))); this.contentManager = contentManager; this.spriteBatch = spriteBatch; this.startText.InitializeAndLoad(spriteBatch, this.contentManager, ContentLocations.SegoeUIFontLarge, EntityConstants.GoText); this.InitializeAndLoadSprites(this.spriteBatch, this.contentManager); this.levelLoader = new LevelLoader(this.contentManager); this.stickman = new StickMan(ref this.physicsWorld, 10.0f, 100, -1.0f, this.spriteBatch, this.contentManager); this.exit = new Exit(spriteBatch, contentManager, ref this.physicsWorld, this.levelLoader.EndPosition); this.scrollingDeath = new ScrollingDeath(ref this.physicsWorld, this.gameDisplayResolution.Y, LevelConstants.MinimumScrollRate, LevelConstants.MaximumScrollRate, LevelConstants.ScrollRate, LevelConstants.ScrollAcceleration, LevelConstants.ScrollDeceleration, this.contentManager); this.rockyTerrain = contentManager.Load <Texture2D>(ContentLocations.Scenery + ContentLocations.RockyTerrain); this.background.InitializeAndLoad(this.spriteBatch, this.contentManager, ContentLocations.RockyBackGround); }
/// <summary> /// Loads the content used by entities in a level. /// </summary> /// <param name="contentManager">The content manager to load content with.</param> /// <param name="spriteBatch">The sprite batch to render using.</param> public void LoadContent(ContentManager contentManager, SpriteBatch spriteBatch) { this.CurrentLevelCustom = false; this.physicsWorld = new World(ConvertUnits.ToSimUnits(new Vector2(0.0f, 348.8f))); this.contentManager = contentManager; this.spriteBatch = spriteBatch; this.startText.InitializeAndLoad(spriteBatch, this.contentManager, ContentLocations.SegoeUIFontLarge, EntityConstants.GoText); this.InitializeAndLoadSprites(this.spriteBatch, this.contentManager); this.levelLoader = new LevelLoader(this.contentManager); this.stickman = new StickMan(ref this.physicsWorld, 10.0f, 100, -1.0f, this.spriteBatch, this.contentManager); this.exit = new Exit(spriteBatch, contentManager, ref this.physicsWorld, this.levelLoader.EndPosition); this.scrollingDeath = new ScrollingDeath(ref this.physicsWorld, this.gameDisplayResolution.Y, LevelConstants.MinimumScrollRate, LevelConstants.MaximumScrollRate, LevelConstants.ScrollRate, LevelConstants.ScrollAcceleration, LevelConstants.ScrollDeceleration, this.contentManager); this.rockyTerrain = contentManager.Load<Texture2D>(ContentLocations.Scenery + ContentLocations.RockyTerrain); this.background.InitializeAndLoad(this.spriteBatch, this.contentManager, ContentLocations.RockyBackGround); }
/// <summary> /// Initializes a new instance of the <see cref="LevelManager"/> class. /// </summary> /// <param name="gameDisplayResolution">The resolution the game is set to render at.</param> /// <param name="frameTime">The frame time set for the game.</param> public LevelManager(Vector2 gameDisplayResolution, float frameTime) { this.startText = new RenderableText(); this.Complete = false; this.physicsWorld = null; this.gameDisplayResolution = gameDisplayResolution; this.frameTime = frameTime; this.physicsWorld = null; this.spriteBatch = null; this.floorSprite = new Sprite(); this.contentManager = null; this.levelLoader = null; this.floorEdges = new List<Body>(); this.visualFloorEdges = new List<VisualEdge>(); this.platforms = new List<Platform>(); this.interactiveEntities = new List<InteractiveEntity>(); this.stickman = null; this.exit = null; this.scrollingDeath = null; this.mineCart = null; this.cartSwitch = null; this.scrollStartTimer = 0.0f; this.background = new Background(this.gameDisplayResolution, 0.8f); this.maxScore = 0.0f; }