A world larger than the screen

In both Flood Control and Asteroid Belt Assault, we dealt with game worlds limited to the area of the display window of the game. None of our game objects existed outside the confines of the screen, and, in fact, when we wished to eliminate some objects in Asteroid Belt Assault, we just moved them to an off screen location to allow the appropriate code manager to clean them up.

When dealing with a larger game world, we need to make a few adjustments to the way we think about object positions. Instead of simply tracking the location of a sprite on the screen, we will need to track the location of the object in "world coordinates":

A world larger than the screen

In the previous image, the camera points to the upper left corner of a viewport within a larger game world. Anything inside the viewport will be visible on the screen, while background areas and objects outside the viewport will not be drawn.

Both the viewport and the game objects can move independently, so we can no longer consider objects that are off screen to be ready to be cleaned up and removed from the game. An object that is off screen during the current frame may be moving towards an onscreen location or, alternatively, the camera may be moving towards the object, causing it to appear within the newly moved viewport.

Defining a camera

In order to create our viewport into the game world, we will define a static Camera class that will represent the view the player currently has of the game world. At its most basic, a camera is really nothing more than a vector pointing to the camera's location. In order to provide some additional functionality, we will add several other properties and methods to the Camera class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.93.136