I've been working on my first Xna game, and yes, that's my excuse for the poor coding. I've managed to fix most problems, but not this one. I can't really make scense of this. I'm trying to make the game go back to default when my player dies (called sprite). Can you guys help? To be clear, when my player dies, i want the GameState to go back to MainMenu, and the buttons to go back to normal. Now, when the player dies, the buttons can't be pressed. Thanks in advance. I'll provide everything that has to do with the Menu/buttons. In Game1:
enum GameState
{
MainMenu,
Play,
HighScore,
GameOver,
}
GameState CurrentGameState = GameState.MainMenu;
``
cButtonplay btnPlay;
cButtonHS btnHighScore;
protected override void LoadContent()
{
IsMouseVisible = true;
btnPlay = new cButtonplay(Content.Load<Texture2D>("button_play"), graphics.GraphicsDevice);
btnPlay.setPosition(new Vector2(300, 250));
btnHighScore = new cButtonHS(Content.Load<Texture2D>("button_highscore"), graphics.GraphicsDevice);
btnHighScore.setPosition(new Vector2(300, 300));
}
And my update logic:
protected override void Update(GameTime gameTime)
{
//MENU
isSpriteAlive = true;
MouseState mouse = Mouse.GetState();
switch (CurrentGameState)
{
case GameState.MainMenu:
if (btnPlay.isClicked == true)
{
btnPlay.isClicked = false;
CurrentGameState = GameState.Play;
}
btnPlay.Update(mouse);
if (btnHighScore.isClicked == true)
{
btnHighScore.isClicked = false;
CurrentGameState = GameState.HighScore;
// btnHighScore.Update(mouse);
}
break;
case GameState.Play:
isSpriteAlive = true;
// Here is alot of various code
case GameState.HighScore:
if (btnHighScore.isClicked == true) CurrentGameState = GameState.HighScore;
btnHighScore.Update(mouse);
break;
case GameState.GameOver:
btnHighScore.isClicked = false;
btnHighScore.Update(mouse);
break;
And finally my draw method:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.ForestGreen);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null);
//MENU
switch (CurrentGameState)
{
case GameState.MainMenu:
spriteBatch.Draw(Content.Load<Texture2D>("menu_background"), new Rectangle(0, 0, screenWidth, screenHeight), Color.WhiteSmoke);
btnPlay.playDraw(spriteBatch);
btnHighScore.highScoreDraw(spriteBatch);
printText.PrintMainMenu("By: Felix Claesson\nand Carl Wikstrom", spriteBatch, 250, 500);
//printText.Print("$ " + points * 25, spriteBatch, 0, 0);
break;
case GameState.Play:
if (isSpriteAlive == true)
{
spriteBatch.Draw(backgroundTexture, backgroundPosition, Color.White);
foreach (Enemies enemy in enemies)
enemy.Draw(spriteBatch);
foreach (Bullets bullet in bullets)
bullet.Draw(spriteBatch);
foreach (healthBars healthbar in healthbars)
healthbar.Draw(spriteBatch);
if (isSpriteAlive == true)
spriteBatch.Draw(spriteTexture, spritePosition, new Rectangle(56 * frames, 0, 56, 51), Color.White, playerRotation, spriteOrigin, 1f, SpriteEffects.None, 0);
printText.Print("$ " + points * 25, spriteBatch, 0, 0);
}
else CurrentGameState = GameState.GameOver;
break;
case GameState.HighScore:
printText.Print(":-)", spriteBatch, 350, 300);
break;
case GameState.GameOver:
printText.Print("h", spriteBatch, 350, 300);
btnHighScore.highScoreDraw(spriteBatch);
break;
}
spriteBatch.End();
base.Draw(gameTime);
}
}
Do you have any tips at all? I can't play twice and my buttons won't work twice. Best regards.