Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am having problems with my snake game, when the snake collides with itself it draws a "game over" image in the background, but only while it's colliding with itself. I want it to behave like the pause function, so that as soon as the snake collides with itself it draws an image on the screen and stops the game play. And then how would you be able to restart or to quit the game?

I just have this for the detection at the moment:

if (snakeHeadRectangle.Intersects(snakeBodyRectangleArray[bodyNumber]))
            {

              spriteBatch.Draw(textureGameOver, gameOverPosition, Color.White);
            }

Thanks

share|improve this question

1 Answer 1

up vote 3 down vote accepted

I had a boolean variable isGameRunning which is set to true if the game is on. Update the game only when this variable is true. After collision, you can set this to false.

For more functionality you can have more states like

enum GameStates
{ Running, Paused, Over, WaitingForKeystrokeToBegin }

instead of just true and false.

To restart the game, create an Initialize() function to reset the settings.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.