/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); if (level != null) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; KeyboardState ks = Keyboard.GetState(); MouseState ms = Mouse.GetState(); if (level.finished == true) { level.Pause(); if (ks.IsKeyDown(Keys.Enter)) { if (level.Won) { //Next Level level.Finished(); if (level.Id < loader.levelDict.Count) { level = loader.levelDict[level.Id]; Components.Add(level); level.Start(); } else { //If there is no next level level = null; } } else if (level.Lost) { this.Exit(); } } } } // TODO: Add your update logic here base.Update(gameTime); }
/// <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); boxT = Content.Load<Texture2D>(@"Textures/box"); ammoT = Content.Load<Texture2D>(@"Textures/ammo"); sf = Content.Load<SpriteFont>(@"Textures/font"); circleT = Content.Load<Texture2D>(@"Textures/circle"); tiles = Content.Load<Texture2D>(@"Textures/Tiles"); build = Content.Load<Texture2D>(@"Textures/build"); grass = Content.Load<Texture2D>(@"Textures/Grass_3"); trap = Content.Load<Texture2D>(@"Textures/TradPlat"); se = Content.Load<SoundEffect>(@"Audio/fire_laser1"); music = Content.Load<SoundEffect>(@"Audio/Theme"); mountain = Content.Load<Texture2D>(@"Textures/004-Mountain01"); health = Content.Load<Texture2D>(@"Textures/HealthBar2"); // TODO: use this.Content to load your game content here XmlDocument doc = new XmlDocument(); doc.Load("test.xml"); loader = new Loader(doc, Content, this); sourceRectDict.Add("1", new Rectangle(0, 160, 32, 32)); sourceRectDict.Add("2", new Rectangle(32, 160, 32, 32)); sourceRectDict.Add("3", new Rectangle(64, 160, 32, 32)); sourceRectDict.Add("4", new Rectangle(0, 192, 32, 32)); sourceRectDict.Add("5", new Rectangle(0, 0, 32, 32)); sourceRectDict.Add("6", new Rectangle(64, 192, 32, 32)); sourceRectDict.Add("7", new Rectangle(0, 224, 32, 32)); sourceRectDict.Add("8", new Rectangle(32, 224, 32, 32)); sourceRectDict.Add("9", new Rectangle(64, 224, 32, 32)); level = loader.levelDict[0]; Components.Add(level); level.Start(); }