public void isColliding(Rectangle pos) { // if ((pos.X > xPostion && pos.X < xPostion + width / 2) && (pos.Y > yPostion - height && pos.Y < yPostion + height)) { if (Music.canPlay) { game.goalS.Play(); } save.UnlockNextLvl(save.ReadUnlock()); save.UpdateFile(); save.newHighScore(gameScreen.LevelName, gameScreen.Score); save.UpdateHighScore(); state.EndGame(ls.CurrentLevel); // have the next level unlocked } }
//Constructor public LevelScreen(Game1 game1) { save = new SaveInfo(); game = game1; gameState = new GameState(game); // creates new gamestate object and assigns it to gameState font1 = game.Content.Load <SpriteFont>("Font1"); // loads Font1 lastState = Keyboard.GetState(); levels = save.ReadUnlock(); back = game.Content.Load <Texture2D>("back"); lvl1 = game.Content.Load <Texture2D>("level1"); lvl2 = game.Content.Load <Texture2D>("level2"); lvl3 = game.Content.Load <Texture2D>("level3"); lvl4 = game.Content.Load <Texture2D>("level4"); lvl5 = game.Content.Load <Texture2D>("level5"); lvl6 = game.Content.Load <Texture2D>("level6"); currentLvl = "level1.txt"; nextLvl = "level2.txt"; }
//Update Method public void Update(GameTime gameTime) { levels = save.ReadUnlock(); KeyboardState keyState = Keyboard.GetState(); if (keyState.IsKeyDown(Keys.Back) && lastState.IsKeyDown(Keys.Back)) { gameState.CurrentScreen = Screen.StartScreen; } if (keyState.IsKeyDown(Keys.A) && lastState.IsKeyUp(Keys.A) || keyState.IsKeyDown(Keys.Left) && lastState.IsKeyUp(Keys.Left)) { if (Music.canPlay) { game.grappleS.Play(); } count--; if (count < 0) { count = 5; } } if (keyState.IsKeyDown(Keys.D) && lastState.IsKeyUp(Keys.D) || keyState.IsKeyDown(Keys.Right) && lastState.IsKeyUp(Keys.Right)) { if (Music.canPlay) { game.grappleS.Play(); } count++; if (count > 5) { count = 0; } } if (keyState.IsKeyDown(Keys.Enter) && lastState.IsKeyUp(Keys.Enter) || keyState.IsKeyDown(Keys.Space) && lastState.IsKeyUp(Keys.Space)) { if (Music.canPlay) { game.grappleS.Play(); } if (count == 0) { gameState.StartGame("level1.txt", "level1"); currentLvl = "level1.txt"; nextLvl = "level2.txt"; } else if (count == 1 && levels["level2"] == true) { gameState.StartGame("level2.txt", "level2"); currentLvl = "level2.txt"; } else if (count == 2 && levels["level3"] == true) { gameState.StartGame("level3.txt", "level3"); currentLvl = "level3.txt"; } else if (count == 3 && levels["level4"] == true) { gameState.StartGame("level4.txt", "level4"); currentLvl = "level4.txt"; } else if (count == 4 && levels["level5"] == true) { gameState.StartGame("level5.txt", "level5"); currentLvl = "level5.txt"; } else if (count == 5 && levels["level6"] == true) { gameState.StartGame("level6.txt", "level6"); currentLvl = "level6.txt"; } } font1 = game.Content.Load <SpriteFont>("Font1"); lastState = keyState; lastState = keyState; //assigns current keyboard state to lastState }