Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Map.h"
- Map::Map(int width, int height, int tileSize) : width(width), height(height), tileSize(tileSize), xtrans(0), ytrans(0) {
- }
- Map::~Map() {
- for(int i = 0; i < surfaces.size(); i++) {
- SDL_FreeSurface(surfaces[i]);
- }
- }
- int Map::getWidth() {
- return width;
- }
- int Map::getHeight() {
- return height;
- }
- Tile Map::getTile(int x, int y) {
- return tiles[x][y];
- }
- void Map::setTile(Tile tile, int x, int y) {
- tiles[x][y] = tile;
- }
- void Map::shiftX(int x) {
- this->xtrans += x;
- }
- void Map::shiftY(int y) {
- this->ytrans += y;
- }
- int Map::currShiftX() {
- return xtrans;
- }
- int Map::currShiftY() {
- return ytrans;
- }
- int Map::getTileSize() {
- return tileSize;
- }
- void Map::setTileSize(int tileSize) {
- this->tileSize = tileSize;
- }
- SDL_Surface* Map::getSheet(int n) {
- if(n < 0) {
- return NULL;
- }
- return surfaces[n];
- }
- void Map::addSheet(SDL_Surface* sheet, char* filename) {
- surfaces.push_back(sheet);
- surfacePaths.push_back(filename);
- }
- char* Map::getSheetPath(int n) {
- return surfacePaths[n];
- }
- int Map::numSheets() {
- return surfaces.size();
- }
- int Map::getSheetNum(int x, int y) {
- SDL_Surface* surface = getTile(x, y).getSheet();
- for(int i = 0; i < surfaces.size(); i++) {
- if(surface == surfaces[i]) {
- return i;
- }
- }
- return -1;
- }
- void Map::render(SDL_Surface* screen) {
- cout << "Map::render" << endl;
- for(int i = 0; i < width; i++) {
- for(int j = 0; j < height; j++) {
- Tile t = tiles[i][j];
- cout << "Map::render got tile" << endl;
- if(t.getSize() != -1)
- tiles[i][j].render(screen, xtrans, ytrans);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment