Electronic fence.
[sdlbotor.git] / Tileset.cpp
blobaf6a1e449d4480d84170507f51e40f8667a3f444
1 #include "Tileset.h"
2 #include "Game.h"
4 namespace botor
7 //template<unsigned int TILE_WIDTH, unsigned int TILE_HEIGHT>
8 void Tileset::unload()
10 if( tileset )
11 SDL_FreeSurface( tileset );
14 //template<unsigned int TILE_WIDTH, unsigned int TILE_HEIGHT>
15 bool Tileset::load( const char* ftile )
17 if( tileset )
18 SDL_FreeSurface( tileset );
20 tileset = SDL_LoadBMP( ftile );
22 if( tileset )
24 SET_WIDTH = tileset->w / TILE_WIDTH;
25 SET_HEIGHT = tileset->h / TILE_HEIGHT;
27 return true;
29 else
30 return false;
33 //template<unsigned int TILE_WIDTH, unsigned int TILE_HEIGHT>
34 void Tileset::Draw( Sint16 x, Sint16 y, unsigned int tileID )
36 SDL_Rect tileRect;
38 if(!tileset)
39 return; //throw error?
42 tileRect.x = (tileID % SET_WIDTH) * TILE_WIDTH;
43 tileRect.y = ((int)(tileID / SET_HEIGHT)) * TILE_HEIGHT;
44 tileRect.w = TILE_WIDTH;
45 tileRect.h = TILE_HEIGHT;
47 Game::getVideo()->Blit( tileset, &tileRect, x, y );