/// <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) { hud = $"Life {Mario.Life}"; Window.Title = "X:" + Mario.Person.X + " Y:" + Mario.Person.Y; if (currentState == GameState.Menu) { if (Keyboard.GetState().GetPressedKeys().Length > 0) { currentState = GameState.Playing; mario_theme.Play(); } } if (currentState == GameState.Playing) { if (Keyboard.GetState().IsKeyDown(Keys.Right)) { Mario.Direction = Side.Right; Mario.Move(); } if (Keyboard.GetState().IsKeyDown(Keys.Left)) { Mario.Direction = Side.Left; Mario.Move(); } if (Keyboard.GetState().IsKeyDown(Keys.Space)) { if (Mario.Person.Y == Mario.MARIO_INITIAL_Y_POSITION) { Mario.IsJump = true; jump_sound.Play(); } } if (Mario.IsJump) { Mario.Jump(); } if (Mario.Person.Intersects(life)) { life_sound.Play(); Mario.Life++; life.Y = 999; } MarioIntersects(ref Goomba.Person); MarioIntersects(ref Goomba2.Person); //Goomba walk Goomba.Walk(); Goomba2.Walk(); } //Game Over if (Mario.Life == 2 && Mario.Person.X == 750) { if (currentState == GameState.Playing) { finish_sound.Play(); } currentState = GameState.GameOver; } if (currentState == GameState.GameOver) { if (Keyboard.GetState().IsKeyDown(Keys.Enter)) { RestartGame(); } } base.Update(gameTime); }