Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7845175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:08:30+00:00 2026-06-02T17:08:30+00:00

I am programming a penalty shoout game in xna, my question is how do

  • 0

I am programming a penalty shoout game in xna, my question is how do I count just 1 goal and then let time for a goal message??,

I already solve the collison between the goalkeeper, goal and the goal area, and I keep and score but when the ball touched the goal area, the score always increment when the ball touched the goal area, how do I just count 1 goal and then display a goal message??

this is what I have so far, I think about a delay but its not working, please help I am stucked in this

 if (_gameState == GameState.Playing)
         {

             if (CollideGoalArea())
             {
                 if (CollideGoalKeeper())
                 {
                     _messageToDisplay = "Goalie defends the goal!";
                     this.Window.Title = "Missed!";
                     _gameState = GameState.Message;
                 }
                 else
                 {
                     score++;
                     _messageToDisplay = "GOAL!";

                     this.Window.Title = "Goal!";

                     _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;
                 balonpos.X = 300;
                 balonpos.Y = 350;

             }

         }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:08:32+00:00Added an answer on June 2, 2026 at 5:08 pm

    The problem is happening because your code increments score any time it detects that ball is inside the goal. Since (by default) Update is called 60 times per second, if your ball is inside the goal score will get incremented by 60 every second.

    You could rewrite your code so that your game has 2 states: Displaying a message state and playing state:

    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
        }
    }
    

    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.

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Programming is (so far) just a hobby for me, so I try to find
Programming Question First (from w3 schools) The programming example way below (from W3 schools)
Im programming a little game where two Players have to click some Buttons it
Evolutionary programming seems to be a great way to solve many optimization problems. The
Programming in vim I often go search for something, yank it, then go back
I'm programing a penalty kick off game (javascrit + CSS3) and I need your
Programming noob here. Just wondering what the best way to extract specific bits of
while programming throughout the years I have never posted a question on this website,
While programming in java is there any time that I as the programmer should
In programming you can use the this keyword this.Textbox or just Textbox What is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.