ajtgarber

Map (Map.cpp)

May 5th, 2011
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include "Map.h"
  2.  
  3. Map::Map(int width, int height, int tileSize) : width(width), height(height), tileSize(tileSize), xtrans(0), ytrans(0) {
  4.    
  5. }
  6. Map::~Map() {
  7.     for(int i = 0; i < surfaces.size(); i++) {
  8.         SDL_FreeSurface(surfaces[i]);
  9.     }
  10. }
  11.  
  12. int Map::getWidth() {
  13.     return width;
  14. }
  15. int Map::getHeight() {
  16.     return height;
  17. }
  18.  
  19. Tile Map::getTile(int x, int y) {
  20.     return tiles[x][y];
  21. }
  22. void Map::setTile(Tile tile, int x, int y) {
  23.     tiles[x][y] = tile;
  24. }
  25.  
  26. void Map::shiftX(int x) {
  27.     this->xtrans += x;
  28. }
  29. void Map::shiftY(int y) {
  30.     this->ytrans += y;
  31. }
  32. int Map::currShiftX() {
  33.     return xtrans;
  34. }
  35. int Map::currShiftY() {
  36.     return ytrans;
  37. }
  38. int Map::getTileSize() {
  39.     return tileSize;
  40. }
  41. void Map::setTileSize(int tileSize) {
  42.     this->tileSize = tileSize;
  43. }
  44.  
  45. SDL_Surface* Map::getSheet(int n) {
  46.     if(n < 0) {
  47.         return NULL;
  48.     }
  49.     return surfaces[n];
  50. }
  51. void Map::addSheet(SDL_Surface* sheet, char* filename) {
  52.     surfaces.push_back(sheet);
  53.     surfacePaths.push_back(filename);
  54. }
  55. char* Map::getSheetPath(int n) {
  56.     return surfacePaths[n];
  57. }
  58. int Map::numSheets() {
  59.     return surfaces.size();
  60. }
  61. int Map::getSheetNum(int x, int y) {
  62.     SDL_Surface* surface = getTile(x, y).getSheet();
  63.     for(int i = 0; i < surfaces.size(); i++) {
  64.         if(surface == surfaces[i]) {
  65.             return i;
  66.         }
  67.     }
  68.     return -1;
  69. }
  70.  
  71. void Map::render(SDL_Surface* screen) {
  72.     cout << "Map::render" << endl;
  73.     for(int i = 0; i < width; i++) {
  74.         for(int j = 0; j < height; j++) {
  75.             Tile t = tiles[i][j];
  76.             cout << "Map::render got tile" << endl;
  77.             if(t.getSize() != -1)
  78.                 tiles[i][j].render(screen, xtrans, ytrans);
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment