O'Reilly logo

Beginning 3D Game Programming by Tom Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling Level Updates

What about the level itself? Currently there is no way to render the level, so you should add that now. Add the code from Listing 8.6.

Listing 8.6. Rendering the Level
public void Draw(Device device)
{
    // Render every block
    for each(Block b in blocks)
    {
        // It's possible the block may be null
        if (b != null)
        {
            b.Draw(device);
        }
    }
}

Wow, that's probably the easiest render method yet. You simply loop through every block in the level and, assuming it isn't null, call the Draw method on it. Because the work for rendering the blocks is encapsulated in the Block class, it makes the rendering of the entire level extremely simple. You're still currently missing one important method that the other classes had, namely a way to update ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required