Time for action – displaying the flood
Add the following declarations to the Game1 class:
const int MaxWaterHeight = 244; const int WaterWidth = 297; Vector2 waterOverlayStart = new Vector2(85, 245); Vector2 waterPosition = new Vector2(478, 338);
Modify the
Draw()
method of the Game1 class by adding the following right after theSpriteBatch.DrawString()
call that displays the player's score:int waterHeight = (int)(MaxWaterHeight * (floodCount / 100)); spriteBatch.Draw(backgroundScreen, new Rectangle( (int)waterPosition.X, (int)waterPosition.Y + (MaxWaterHeight - waterHeight), WaterWidth, waterHeight), new Rectangle( (int)waterOverlayStart.X, (int)waterOverlayStart.Y + (MaxWaterHeight - waterHeight), WaterWidth, waterHeight), new Color(255, 255, 255, 180));
Try it out! You should now be able to watch the flood slowly increase in the flood tank. When it reaches the top the game should switch to the
GameOver
state and...