Game Development Reference
In-Depth Information
if
-instruction then becomes
if
(Painter.GameWorld.IsOutsideWorld(position))
Reset();
Finally, in order to make the game a bit more challenging, we slightly increase the
minimum velocity that the cans get each time we go through the update loop:
minVelocity += 0.001f;
Because the minimum velocity is slightly increasing all the time, the game gets more
difficult as time progresses.
8.3.5 Drawing the Cans on the Screen
For drawing the paint cans on the screen, we add a
Draw
method to the
PaintCan
class. Inside the
GameWorld
class, we can now call the
Update
and
Draw
methods
on the different game objects. So, the new
Update
method contains the following
instructions:
ball.Update(gameTime);
can1.Update(gameTime);
can2.Update(gameTime);
can3.Update(gameTime);
And the
GameWorld.Draw
method is given as follows:
public void
Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
spriteBatch.Begin();
spriteBatch.Draw(background, Vector2.Zero, Color.White);
ball.Draw(gameTime, spriteBatch);
cannon.Draw(gameTime, spriteBatch);
can1.Draw(gameTime, spriteBatch);
can2.Draw(gameTime, spriteBatch);
can3.Draw(gameTime, spriteBatch);
spriteBatch.End();
}
The complete program (
Painter6
) is available in the example solution belonging to
this chapter.