Main Page   Class Hierarchy   Compound List   File List   Compound Members  

Graphics Class Reference

Graphic system. More...

#include <graphics.h>

Collaboration diagram for Graphics:

Collaboration graph
[legend]
List of all members.

Public Methods

 Graphics ()
 Default constructor. More...

 Graphics (bool fullscreen)
 Constructor with fullscreen option. More...

 ~Graphics ()
 Destructor. More...

void init ()
 You should call this function at the begining of every game.

void drawMenu (Menu &menu)
 Draws a menu. More...

void drawWorld (World &world, const bool updateNow=true)
 Draws the world. More...

TTF_Font * getFont ()
void loadData ()
 Load all necesary data for the graphics module. More...

void updateText (const string *message, const char color, const string *currentText, const bool updateNow=false)
 Update the text in the information panel. More...

void toggleDebugMode ()

Static Public Attributes

const unsigned int SCREEN_WIDTH = 800
 Width of the screen.

const unsigned int SCREEN_HEIGHT = 600
 Height of the screen.

const unsigned int SCREEN_BPP = 32
 Bit per pixel.

const unsigned int STATUS_W = 800
 Width of the Status Panel.

const unsigned int STATUS_H = 173
 Height of the Status Panel.

const unsigned int STATUS_X = 0
 X coordinate of the upper left corner of the Status Panel.

const unsigned int STATUS_Y = 427
 Y coordinate of the upper left corner of the Status Panel.

const unsigned int INVENTORY_W = 96
 Width of the Inventory Panel.

const unsigned int INVENTORY_H = 384
 Height of the Inventory Panel.

const unsigned int INVENTORY_X = 667
 X coordinate of the upper left corner of the Inventory Panel.

const unsigned int INVENTORY_Y = 32
 Y coordinate of the upper left corner of the Inventory Panel.

const unsigned int FONT_SIZE = 18
 Size of font used.

const string FONT_FILE = string("perihelion.ttf")
 Name of the file with the font used.

const unsigned int TILE_SIZE = 48
 Size of one tile. More...

const string TILES_FILE = string("tiles.bmp")
 Name of the file with the list of tiles used.

const unsigned int PLAYER_SIZE = 48
 Size in pixels of a player bitmap. More...

const string PLAYER_FILE = string("pantycian.bmp")
 Name of the file with the player sprites definition.

const unsigned int PLAYER_N_FRAMES = 3
 Number of frames of a player animation.

const unsigned int RESOURCE_SIZE = 18
const string RESOURCES_FILE = string("resources.bmp")
const unsigned int TOOL_SIZE = 96
const string TOOLS_FILE = string("tools.bmp")
const unsigned int BLACK = 4

Private Methods

void commonInit ()
 Common initialization stuff.

void drawDebugInfo (int px, int py, int velocity)
 Draw some debug info. More...

void drawPlayer (Player &player, int cpx, int cpy)
 Draw a player. More...

void drawTiles (int px, int py)
 Draw the level (main part of the screen). More...

bool initVideoMode (const unsigned int width, const unsigned height, const unsigned int bpp, bool fullscreen)
 Set the video mode. More...

void unloadData ()
 Unload all the necesary data. More...

void updateWorldSurface (vector< Tile > &map, unsigned int mapWidth, unsigned int mapHeight, unsigned int px, unsigned int py)
 Draw the world surface. More...

void drawResource (Resource r)

Private Attributes

SDL_Surface * screen
 Main screen. More...

StatusPanel statusPanel
 Status panel. More...

InventoryPanel inventoryPanel
 Inventory panel. More...

TTF_Font * font
 Font used in the game. More...

SDL_Surface * tiles
 Surface with all the tiles.

SDL_Surface * menuSurface
 Surface for drawing the menus.

SDL_Surface * worldSurface
 Surface for drawing the world.

unsigned int ptx
 Player Tile X coordinate.

unsigned int pty
 Player Tile Y coordinate.

SDL_Surface * playerSprites
SDL_Surface * resources
SDL_Surface * tools
Uint32 playerColors [5]
bool debugMode

Detailed Description

Graphic system.

This class contains all the graphics routines for the game. It main job is drawing in the screen an snapshot of the current world. It also handles the gui for the menus in the user interface


Constructor & Destructor Documentation

Graphics::Graphics  
 

Default constructor.

Initialize the video system and load all the resources needed by the graphic system. It assumes that the SDL library has been initialized previously. It tries to set a resolution of 800x600x16. If it can't it set whatever resolution it can, throws an exception. It runs in window mode

Graphics::Graphics bool    fullscreen
 

Constructor with fullscreen option.

Same thing that the default constructor plus an option to choose between full screen mode or window mode.

Parameters:
fullscreen  If true sets the full screen mode

Graphics::~Graphics  
 

Destructor.

Frees all the resources allocated by the constructor. It does not call to SDL_Quit. It's responsability of the main program to do so. It shuts not down the video system because in Windows this seems to hungs the SDL library.


Member Function Documentation

void Graphics::drawDebugInfo int    px,
int    py,
int    velocity
[private]
 

Draw some debug info.

Draw the player position in world and tile coordinates.

Parameters:
px  Current player world X coordinate.
py  Current player world Y coordinate.

void Graphics::drawMenu Menu   menu
 

Draws a menu.

Draws a menu in a pop up transparent window with the selected option of this menu in a different way. It does not redraw the world, so you better call drawWorld before calling drawMenu.

void Graphics::drawPlayer Player &    player,
int    cpx,
int    cpy
[private]
 

Draw a player.

If this player is too far from the current player it will not be seen.

Parameters:
player  the player to draw.
cpx  Current Player X world coordinate
cpy  Current Player y world coordinate

void Graphics::drawTiles int    px,
int    py
[private]
 

Draw the level (main part of the screen).

Draw the tiles, resources, buildings, tools and characters directly to the screen surface.

Parameters:
tiles  array with the tile types of this level.
px  the x coordinate of the player
py  the y coordinate of the player

void Graphics::drawWorld World   world,
const bool    updateNow = true
 

Draws the world.

Pretty obvious, isn't it? Just take a reference to the world object and draw everything as it is supposed to be.

Parameters:
world  the world we want to draw
updateNow  should we update the screen right now?

bool Graphics::initVideoMode const unsigned int    width,
const unsigned    height,
const unsigned int    bpp,
bool    fullscreen
[private]
 

Set the video mode.

Set the video mode to the values specified by the parameters. It tries to use a hardware double buffer non resizable surface. It does not guarantee to use the bpp and fullscreen parameters.

Parameters:
width  width of the screen in pixels
height  height of the screen in pixels
bpp  bits per pixel
fullscreen  If true sets the full screen mode
Returns:
true on succesfull, false otherwise.

void Graphics::loadData  
 

Load all necesary data for the graphics module.

Load the font file.

void Graphics::unloadData   [private]
 

Unload all the necesary data.

Called by the destructor.

void Graphics::updateText const string *    message,
const char    color,
const string *    currentText,
const bool    updateNow = false
 

Update the text in the information panel.

Update the information area of the screen. This section is located in the lower part of the screen. Both the message and the currentText can be 0 if we don't want to update that information.

Parameters:
message  the string with the message to display
color  the color used to display the message. By default black.
currentText  the text located in the editing line
updateNow  if it is true it redraw the status panel right now, if it is false it wait until next call to drawWorld

void Graphics::updateWorldSurface vector< Tile > &    map,
unsigned int    mapWidth,
unsigned int    mapHeight,
unsigned int    px,
unsigned int    py
[private]
 

Draw the world surface.

Checks if the player has moved enough to update the world surface.

Parameters:
map  The map with all the tile types
mapWidth  Number of tiles of the map's width
mapHeight  Number of tiles of the map's height
px  New player world X coordinate
py  New player world Y coordinate


Member Data Documentation

TTF_Font* Graphics::font [private]
 

Font used in the game.

It is defined with the constants FONT_SIZE and FONT_FILE in the file graphics.h.

InventoryPanel Graphics::inventoryPanel [private]
 

Inventory panel.

This class draw the inventory.

const unsigned int Graphics::PLAYER_SIZE = 48 [static]
 

Size in pixels of a player bitmap.

It is equal to the width and height.

SDL_Surface* Graphics::screen [private]
 

Main screen.

This surface represents the main screen. Ultimately all the drawing operations are sent to it

StatusPanel Graphics::statusPanel [private]
 

Status panel.

This class draw the status panel.

const unsigned int Graphics::TILE_SIZE = 48 [static]
 

Size of one tile.

Size in pixels of a tile. It is equal to the width and height.


The documentation for this class was generated from the following files:
Generated on Thu Jun 6 17:22:21 2002 for Perihelion by doxygen1.2.15