private void UpdateStartMenu(KeyboardState kState, MouseState mState, GameTime gameTime) { if (MediaPlayer.State == MediaState.Stopped) { MediaPlayer.IsRepeating = true; MediaPlayer.Play(mainMenuMusic); } if (kState.IsKeyDown(Keys.Enter)) { MediaPlayer.Stop(); pressed = true; gameState = GameState.Loading; } boutonExit.Update(kState, mState); boutonStart.Update(kState, mState); //Animated ball in background if (balleAnim.getEnable() == false) { balleAnim.setEnable(true); } boutonStart.checkBallCollision(balleAnim); boutonExit.checkBallCollision(balleAnim); balleAnim.checkBallCollision(balleAnim2.getLocation()); balleAnim2.checkBallCollision(balleAnim.getLocation()); soundEngineInstance = balleMur.CreateInstance(); balleAnim.Update(kState, gameTime, soundEngineInstance); if (balleAnim2.getEnable() == false) { balleAnim2.setEnable(true); } boutonExit.checkBallCollision(balleAnim2); boutonStart.checkBallCollision(balleAnim2); balleAnim2.Update(kState, gameTime, soundEngineInstance); }
public void checkBallCollision(Balle ball) { bool inCollision = false; Rectangle up = new Rectangle((int)boutonPosition.X, (int)boutonPosition.Y, bound.Width, 0); Rectangle down = new Rectangle((int)boutonPosition.X, (int)boutonPosition.Y + bound.Height, bound.Width, 0); Rectangle left = new Rectangle((int)boutonPosition.X, (int)boutonPosition.Y, 0, bound.Height); Rectangle right = new Rectangle((int)boutonPosition.X + bound.Width, (int)boutonPosition.Y, 0, bound.Height); if (ball.getLocation().Intersects(up) && !inCollision) { if (ball.getDirection().Y > 0) { ball.setDirection(new Vector2(ball.getDirection().X, -1 * (ball.getDirection().Y))); } else { ball.setDirection(new Vector2(-1 * ball.getDirection().X, ball.getDirection().Y + 1)); } inCollision = true; } else if (ball.getLocation().Intersects(down) && !inCollision) { if (ball.getDirection().Y < 0) { ball.setDirection(new Vector2(ball.getDirection().X, -1 * (ball.getDirection().Y))); } else { ball.setDirection(new Vector2(-1 * ball.getDirection().X, ball.getDirection().Y + 1)); } inCollision = true; } else if (ball.getLocation().Intersects(left) && !inCollision) { if (ball.getDirection().X > 0) { ball.setDirection(new Vector2((-1 * ball.getDirection().X), ball.getDirection().Y)); } else { ball.setDirection(new Vector2(ball.getDirection().X + 1, -1 * ball.getDirection().Y)); } inCollision = true; } else if (ball.getLocation().Intersects(right) && !inCollision) { if (ball.getDirection().X < 0) { ball.setDirection(new Vector2((-1 * ball.getDirection().X), ball.getDirection().Y)); } else { ball.setDirection(new Vector2(ball.getDirection().X + 1, -1 * ball.getDirection().Y)); } inCollision = true; } }