const int MaxWaterHeight = 244; const int WaterWidth = 297; Vector2 waterOverlayStart = new Vector2(85, 245); Vector2 waterPosition = new Vector2(478, 338);
Draw()
method of the Game1 class by adding the following right after the SpriteBatch.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));
GameOver
state and, after an 8 second delay, back to the title screen.The two int
values, MaxWaterHeight
, and WaterWidth
refer to the size of the water image hidden inside the game board. It is 297 pixels wide, and the full water image is 244 pixels high.
Two vectors are used to store the location of the filled water image (85, 245) and the location that it will be drawn to on the screen (478, 338).
In order to draw the water in the water tank, the waterHeight
variable, the MaxWaterHeight
is multiplied by the percentage of water currently in the tank. This results in the number of pixels of water that need to be drawn into the tank.
When determining the source and destination rectangles, the X coordinates are dependant only on the location of the overlay and the drawing position, since they will not change.
The Y coordinates must be modified to pull pixels from the bottom of the image and expand upwards. In order to accomplish this, the current waterHeight
is subtracted from the MaxWaterHeight
, and this value is added to the Y coordinate of both vectors.
3.140.198.173