#include <graphics.h>
Collaboration diagram for Graphics:
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 |
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
|
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 |
|
Constructor with fullscreen option. Same thing that the default constructor plus an option to choose between full screen mode or window mode.
|
|
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. |
|
Draw some debug info. Draw the player position in world and tile coordinates.
|
|
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. |
|
Draw a player. If this player is too far from the current player it will not be seen.
|
|
Draw the level (main part of the screen). Draw the tiles, resources, buildings, tools and characters directly to the screen surface.
|
|
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.
|
|
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.
|
|
Load all necesary data for the graphics module. Load the font file. |
|
Unload all the necesary data. Called by the destructor. |
|
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.
|
|
Draw the world surface. Checks if the player has moved enough to update the world surface.
|
|
Font used in the game. It is defined with the constants FONT_SIZE and FONT_FILE in the file graphics.h. |
|
Inventory panel. This class draw the inventory. |
|
Size in pixels of a player bitmap. It is equal to the width and height. |
|
Main screen. This surface represents the main screen. Ultimately all the drawing operations are sent to it |
|
Status panel. This class draw the status panel. |
|
Size of one tile. Size in pixels of a tile. It is equal to the width and height. |