Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is happening because your code increments <code>score</code> any time it detects that ball is inside the goal. Since (by default) <code>Update</code> is called 60 times per second, if your ball is inside the goal score will get incremented by 60 every second.</p> <p>You could rewrite your code so that your game has 2 states: Displaying a message state and playing state:</p> <pre><code>enum GameState { Playing, Message } GameState _gameState = GameState.Playing; String _messageToDisplay = ""; int _score = 0; protected override void Update(GameTime gameTime) { if(_gameState == GameState.Playing) { if(CollideGoalArea()) { if(CollideGoalkeeper()) { _messageToDisplay = "Goalie defends the goal!"; _gameState = GameState.Message; } else { _messageToDisplay = "GOAL!"; score++; _gameState = GameState.Message; } } else { _messageToDisplay = "You missed the goal."; _gameState = GameState.Message; } } else if(_gameState == GameState.Message) { if(Mouse.GetState().RightButton == ButtonState.Pressed) // right click to continue playing _gameState = GameState.Playing; //you should also reset your ball position here } } </code></pre> <p>This way, whenever ball enters the goal area, it will either be a score, miss or hit on the goalkeeper. The game will then instantly change state so that those conditions aren't checked again until you right click with your mouse.</p> <p>You could also put your input detection logic and ball and goalie position update logic inside these if's (you might not want for the player to be able to shoot another ball while the message is being displayed).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload