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



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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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