private void openExit(GameTime _gameTime) { isDoorOpen = true; if (openDoor.Update(_gameTime, -1, -1, 1)) { setBlank(doorX, doorY); setBlank(doorX, doorY + brickSize); } openDoor.Draw(spriteBatch); }
/// <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) { float check = PlayerVector.Y; loadLevel(currentLevel); duck = false; move = false; // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } float distancePerSecond = 160; float delta = distancePerSecond * (float)gameTime.ElapsedGameTime.TotalSeconds; keyboard = Keyboard.GetState(); if (keyboard.IsKeyDown(Keys.Down)) { duck = true; } if (!playerDead && !lvl.checkWin((int)PlayerVector.X, (int)PlayerVector.Y)) { //jumping logic if (!jumpPeak && keyboard.IsKeyDown(Keys.Up) && jump != 2 && !(jump == 0 && !collideSide((int)PlayerVector.X, (int)(PlayerVector.Y + delta), pHeight, pWidth, "bottom", lvl)) && //used to check if the player tries to jump mid-air from a previous platform jumpPeak == false && !collideSide((int)PlayerVector.X, (int)(PlayerVector.Y - delta), pHeight, pWidth, "top", lvl)) { jump = 1; jumpAm += delta; PlayerVector.Y -= delta; if (jumpAm > 30 * delta) { jumpPeak = true; } } else if (jumpAm > 0 && !collideSide((int)PlayerVector.X, (int)(PlayerVector.Y + delta), pHeight, pWidth, "bottom", lvl)) { jump = 2; PlayerVector.Y += delta; jumpAm -= delta; if (jumpAm == 0) { jumpPeak = false; } } else { jump = 0; } // TODO if (!collideSide((int)PlayerVector.X, (int)(PlayerVector.Y + delta), pHeight, pWidth, "bottom", lvl) && jump == 0) { jump = 2; PlayerVector.Y += delta; } if (!duck && keyboard.IsKeyDown(Keys.Right) && !collideSide((int)(PlayerVector.X + delta), (int)PlayerVector.Y, pHeight, pWidth, "right", lvl)) { faceRight = true; move = true; PlayerVector.X += delta; } if (!duck && keyboard.IsKeyDown(Keys.Left) && !collideSide((int)(PlayerVector.X - delta), (int)PlayerVector.Y, pHeight, pWidth, "left", lvl)) { faceRight = false; move = true; PlayerVector.X -= delta; } if (!duck && keyboard.IsKeyDown(Keys.Right) && keyboard.IsKeyDown(Keys.Left)) { move = false; } if (check == PlayerVector.Y)//needed to fix cases when peaked jump is interrupted by environment { jumpPeak = false; jumpAm = 0; } int facing; if (faceRight == true) { facing = 1; } else if (faceRight == false) { facing = 2; } else { facing = 0; } spriteWalk.Update(gameTime, (int)PlayerVector.X, (int)PlayerVector.Y, -1, facing); } if (lvl.checkWin((int)PlayerVector.X, (int)PlayerVector.Y)) { if (spriteWin.Update(gameTime, (int)PlayerVector.X, (int)PlayerVector.Y, 4, 1)) { currentLevel++; } } if (!playerDead) { playerDead = false; } base.Update(gameTime); }