Project SDL Part1 Base
Project SDL Part1 Base
1
2.1 SDL API
• SDL Rect Defines a rectangle via its upper left (!) corner as well as its width and
height. We will mainly use this to position textures.
• SDL Surface Basically a rectangular array of pixels representing the screen or a tex-
ture. Note that loading a surface in SDL (using IMG Load) for instance, returns an
OWNING pointer to a surface. This means we need to ensure deletion by “hand” using
SDL FreeSurface.
• SDL FillRect Fills a surface with a single color. Called to clear the screen before
drawing each object.
• SDL BlitScaled Scales and translates a texture to match a given rectangle and “draw”
onto the given surface.
• SDL GetTicks and SDL Delay Can be used to control your framerate. SDL GetTicks
returns the time passed since initialization in milliseconds, SDL Delay(x) blocks the
execution for x milliseconds.
• sheep, wolf etc derived from animal. Needs to load the correct texture, choose an
initial position, destroy the texture on destruction and has to implement the movement
function. Note that for the first part, sheep can simply follow straight lines and bounce
of the edge of the window (Like the old windows screen saver); wolves move randomly
or go to the nearest sheep (bonus)
• A ground object ground representing the “arena”. Members: A counter (of type
unsigned) defining the framerate.
Needs a constructor, destructor and a function called loop() doing the actual work (It
corresponds to the “main” loop of your program). Members: ground Holds a NON-
OWNING ptr to the screen (See main application). A vector of (smart?) pointers with
all the animals currently existing.
• application The main application. Members: The “actual” application SDL Window.
Its surface, SDL Surface, defining what is drawn on the screen. Finally a ground ob-
ject, defining the arena. Needs to call the loop() function of ground and update the
2
screen. In this first part we want to stop the execution after a given period of time
(input in seconds).