#include "stdafx.h" Map::Map(void) { height = SCREEN_HEIGHT/TILE_HEIGHT; width = SCREEN_WIDTH/TILE_WIDTH; sx = 0; sy = 0; //Passability tileset[0] = 0; tileset[1] = 0; tileset[2] = 0; tileset[3] = 0; tileset[4] = 0; tileset[5] = 0; tileset[6] = 1; tileset[7] = 1; tileset[8] = 1; tileset[9] = 1; tileset[10] = 1; tileset[11] = 1; tileset[12] = 1; tileset[13] = 1; tileset[14] = 1; //Get the Sheet sheet = IMG_Load("./sprites/tilesheet.gif"); Uint32 colorkey = SDL_MapRGB(sheet->format, 255, 0, 255); SDL_SetColorKey(sheet, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); //le ponemos al buddy el colorkey para las transparencias std::ifstream in("./map0.bin", std::ios::in | std::ios::binary); int length; //get the size in.seekg (0, std::ios::end); length = in.tellg(); in.seekg (0, std::ios::beg); in.read((char *) &tiles, length); // see how many bytes have been read std::cout << in.gcount() << " bytes read\n"; in.close(); } void Map::drawmap(SDL_Surface *viewport){ int x1, x2, y1, y2, tx, ty; tx = sx/TILE_WIDTH; ty = sy/TILE_HEIGHT; x1 = (sx%TILE_WIDTH) * -1; x2 = x1 + SCREEN_WIDTH + (x1 == 0 ? 0 : TILE_WIDTH); y1 = (sy%TILE_HEIGHT) * -1; y2 = y1 + SCREEN_HEIGHT + (y1 == 0 ? 0 : TILE_WIDTH); for(int y = y1; ydraw_tile(viewport, tiles[ty][tx], x, y); tx++; } ty++; } } void Map::draw_tile(SDL_Surface *viewport, int type, int x, int y){ if(type > 14 || type < 0){ type = 0; } int x_tile, y_tile; x_tile = floor(type / 3) * TILE_HEIGHT; y_tile = (type % 3) * TILE_WIDTH; /*Draws a rectangular surface from sx,sy of swxsh dimensions to dx, dy*/ Gfx::drawsurface(y_tile, x_tile, TILE_WIDTH, TILE_HEIGHT, this->sheet, x, y, viewport); // switch (type) { // // // // case 0: // case 1: // case 2: // /*boxRGBA(viewport, // x, y, // x+25, y+25, // 255, 255, 255, 255);*/ // break; // case 3: // case 4: // case 5: // boxRGBA(viewport, // x, y, // x+TILE_WIDTH, y+TILE_HEIGHT, // 238, 0, 139, 255); // break; // case 6: // case 7: // case 8: // boxRGBA(viewport, // x, y, // x+TILE_WIDTH, y+TILE_HEIGHT, // 34, 34, 34, 255); // break; // } } int Map::get_passability(int x, int y){ return tileset[tiles[(sy+y)/TILE_HEIGHT][(sx+x)/TILE_WIDTH]]; } int Map::get_tile(int x, int y){ return tiles[(sy+y)/TILE_HEIGHT][(sx+x)/TILE_WIDTH]; } int Map::get_sx(){ return sx; } int Map::get_sy(){ return sy; } void Map::set_sx(int x){ sx = x; } void Map::set_sy(int y){ sy = y; } Map::~Map(void){ }