/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { Paused = false; //Initialize each argument before sending it to contentloader //Controller initialization keyboardController = new KeyboardController(); keyboardController2 = new KeyboardController(); gamePadController = new GamePadController(); keyboardController2.AddCommand((char)Keys.P, new PauseUnpauseGameCommand(this)); keyboardController2.AddCommand((char)Keys.Q, new QuitCommand(this)); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); spriteMaster = new SpriteMaster(new SpriteBatch(GraphicsDevice), new SpriteBatch(GraphicsDevice)); //Collision initialization collisionGrid = new CollisionGrid(); //Load font font = Content.Load <SpriteFont>("Font"); //load hud hud = new HUD(GraphicsDevice, font); //New Contentloader method should make Game1 easier to follow. ContentLoader contentLoader = new ContentLoader(Content, GraphicsDevice, this, graphics, spriteMaster, keyboardController, gamePadController, collisionGrid, hud); contentLoader.LoadGameContents(checkpointCoords); //this.camera = contentLoader.GetCamera(); this.spriteMaster = contentLoader.GetSpriteMaster(); }
public void LoadLevel(string levelXML) { if (songA != null) { songA.Stop(); } Delay = Constants.ZERO; CurrentLevelXML = levelXML; levelLoader = new LevelLoader(); Camera = Camera.Instance; Camera.SetViewport(GraphicsDevice.Viewport); BackgroundControl = new BackgroundControl(GraphicsDevice.Viewport, this.Content); //Load Song SoundEffect song = Content.Load <SoundEffect>("OverworldNormal"); songA = song.CreateInstance(); songA.IsLooped = true; songA.Play(); collisions = new CollisionDetection(); level = levelLoader.LoadLevel(CurrentLevelXML, this.Content, this.GraphicsDevice, collisions, BackgroundControl); collisions.StartDetection(levelLoader.levelWidth, levelLoader.levelHeight); Collections.Instance.SetCollisionRef(ref collisions); Collections.Instance.SetLevelRef(ref level); if (levelXML == "level.xml") { currentGameState = new BeginningState(this); currentGameState.BeginningTransition(); } else { currentGameState = new InitialState(this); } foreach (IEntity e in level.Entities) { if (e is Peach) { peach = (Peach)e; } else if (e is Mario) { mario = (Mario)e; } } if (peachStatsInstance is null) { peach.PlayerStats = new PlayerStats(this.Content, GraphicsDevice, "Peach", this); peachStatsInstance = peach.PlayerStats; } else { peach.PlayerStats = peachStatsInstance; if (peachStatsInstance.StartingPoint != Vector2.Zero) { //Debug.WriteLine("Peach respawn X: " + playerStats.StartingPoint.X); //Debug.WriteLine("Peach respawn Y: " + playerStats.StartingPoint.Y); peach.Location = peachStatsInstance.StartingPoint; } } Controller = new Controller(); #region Add Commands Controller.AddCommand(Keys.Q, new ExitCommand(this)); Controller.AddCommand(Keys.Left, new MoveLeftCommand(peach)); Controller.AddCommand(Keys.Right, new MoveRightCommand(peach)); Controller.AddCommand(Keys.Up, new JumpCommand(peach)); Controller.AddCommand(Keys.Down, new CrouchCommand(peach)); Controller.AddCommand(Keys.A, new MoveLeftCommand(peach)); Controller.AddCommand(Keys.D, new MoveRightCommand(peach)); Controller.AddCommand(Keys.W, new JumpCommand(peach)); Controller.AddCommand(Keys.S, new CrouchCommand(peach)); Controller.AddCommand(Keys.Y, new StandardPowerUpCommand(peach)); Controller.AddCommand(Keys.I, new FirePowerUpCommand(peach)); Controller.AddCommand(Keys.V, new StarPowerUpCommand(peach)); Controller.AddCommand(Keys.O, new TakeDamageCommand(peach)); Controller.AddCommand(Keys.U, new SuperPowerUpCommand(peach)); Controller.AddCommand(Keys.Space, new FireBallCommand(peach)); Controller.AddCommand(Keys.M, new MuteCommand()); Controller.AddCommand(Buttons.Back, new ExitCommand(this)); Controller.AddCommand(Buttons.DPadLeft, new MoveLeftCommand(peach)); Controller.AddCommand(Buttons.DPadRight, new MoveRightCommand(peach)); Controller.AddCommand(Buttons.DPadUp, new JumpCommand(peach)); Controller.AddCommand(Buttons.DPadDown, new CrouchCommand(peach)); Controller.AddCommand(Buttons.B, new FireBallCommand(peach)); Controller.AddCommand(Keys.R, new ResetLevelCommand(this)); Controller.AddCommand(Keys.C, new ToggleBoundingBoxCommand(level.Entities)); #endregion Controller = new Controller(); #region Add Commands Controller.AddCommand(Keys.Q, new ExitCommand(this)); Controller.AddCommand(Keys.Left, new MoveLeftCommand(peach)); Controller.AddCommand(Keys.Right, new MoveRightCommand(peach)); Controller.AddCommand(Keys.Up, new JumpCommand(peach)); Controller.AddCommand(Keys.Down, new CrouchCommand(peach)); Controller.AddCommand(Keys.A, new MoveLeftCommand(peach)); Controller.AddCommand(Keys.D, new MoveRightCommand(peach)); Controller.AddCommand(Keys.W, new JumpCommand(peach)); Controller.AddCommand(Keys.S, new CrouchCommand(peach)); Controller.AddCommand(Keys.Y, new StandardPowerUpCommand(peach)); Controller.AddCommand(Keys.I, new FirePowerUpCommand(peach)); Controller.AddCommand(Keys.V, new StarPowerUpCommand(peach)); Controller.AddCommand(Keys.O, new TakeDamageCommand(peach)); Controller.AddCommand(Keys.U, new SuperPowerUpCommand(peach)); Controller.AddCommand(Keys.Space, new FireBallCommand(peach)); Controller.AddCommand(Keys.M, new MuteCommand()); Controller.AddCommand(Buttons.Back, new ExitCommand(this)); Controller.AddCommand(Buttons.DPadLeft, new MoveLeftCommand(peach)); Controller.AddCommand(Buttons.DPadRight, new MoveRightCommand(peach)); Controller.AddCommand(Buttons.DPadUp, new JumpCommand(peach)); Controller.AddCommand(Buttons.DPadDown, new CrouchCommand(peach)); Controller.AddCommand(Buttons.B, new FireBallCommand(peach)); Controller.AddCommand(Keys.R, new ResetLevelCommand(this)); Controller.AddCommand(Keys.C, new ToggleBoundingBoxCommand(level.Entities)); #endregion }