Añadiendo funciones viejas a la clase Map
This commit is contained in:
121
source/map.cpp
121
source/map.cpp
@@ -5,6 +5,7 @@
|
||||
Map::Map(SDL_Renderer *renderer, std::string file, Asset *asset)
|
||||
{
|
||||
this->asset = asset;
|
||||
this->renderer = renderer;
|
||||
|
||||
texture_tile = new LTexture();
|
||||
texture_actor = new LTexture();
|
||||
@@ -20,6 +21,8 @@ Map::Map(SDL_Renderer *renderer, std::string file, Asset *asset)
|
||||
const SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||
background = new Sprite(rect, texture_bg, renderer);
|
||||
|
||||
music = JA_LoadMusic(asset->get("music_surface.ogg").c_str());
|
||||
|
||||
src_rect = {0, 0, 0, 0};
|
||||
dst_rect = {0, 0, 0, 0};
|
||||
w = 0;
|
||||
@@ -54,6 +57,8 @@ Map::~Map()
|
||||
|
||||
delete[] tile;
|
||||
delete[] actor;
|
||||
|
||||
JA_DeleteMusic(music);
|
||||
}
|
||||
|
||||
// Carga el mapa a partir de un fichero
|
||||
@@ -100,4 +105,120 @@ void Map::update()
|
||||
void Map::render()
|
||||
{
|
||||
background->render();
|
||||
}
|
||||
|
||||
// Obtiene el valor del tile de la habitación actual
|
||||
Uint8 Map::getTile(int x, int y)
|
||||
{
|
||||
const long room_x = (room % 12) * ROOM_WIDTH_IN_TILES;
|
||||
const long room_y = (room / 12) * ROOM_HEIGHT_IN_TILES;
|
||||
return tile[(room_x + x) + (room_y + y) * w];
|
||||
}
|
||||
|
||||
// Obtiene el tipo de tile segun su ubicación en la textura
|
||||
Uint8 Map::readMapTile(Uint8 x, Uint8 y)
|
||||
{
|
||||
const Uint8 tile = getTile(x, y);
|
||||
|
||||
if (tile >= 0 && tile <= 63)
|
||||
{
|
||||
return TILE_BACKGROUND;
|
||||
}
|
||||
else if (tile >= 64 && tile <= 143)
|
||||
{
|
||||
return TILE_PLATFORM;
|
||||
}
|
||||
else if (tile >= 144 && tile <= 175)
|
||||
{
|
||||
return TILE_TRAVESABLE_PLATFORM;
|
||||
}
|
||||
else if (tile >= 176 && tile <= 207)
|
||||
{
|
||||
return TILE_KILLING_PLATFORM;
|
||||
}
|
||||
else if (tile >= 208 && tile <= 255)
|
||||
{
|
||||
return TILE_ACTOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor del actor en esa ubicación
|
||||
Uint8 Map::getActor(Uint8 x, Uint8 y)
|
||||
{
|
||||
long room_x = (room % 12) * ROOM_WIDTH_IN_TILES;
|
||||
long room_y = (room / 12) * ROOM_HEIGHT_IN_TILES;
|
||||
return actor[(room_x + x) + (room_y + y) * w];
|
||||
}
|
||||
|
||||
// Establece el valor del actor en esa ubicación
|
||||
void Map::setActor(Uint8 x, Uint8 y, Uint8 valor)
|
||||
{
|
||||
long room_x = (room % 12) * ROOM_WIDTH_IN_TILES;
|
||||
long room_y = (room / 12) * ROOM_HEIGHT_IN_TILES;
|
||||
actor[(room_x + x) + (room_y + y) * w] = valor;
|
||||
}
|
||||
|
||||
// Carga las texturas del mapa en función de la zona
|
||||
void Map::setMapGFX(Uint8 zone)
|
||||
{
|
||||
switch (zone)
|
||||
{
|
||||
case ZONE_SURFACE:
|
||||
loadTextureFromFile(texture_tile, asset->get("tiles_surface.png").c_str(), renderer);
|
||||
loadTextureFromFile(texture_bg, asset->get("bg_surface.png").c_str(), renderer);
|
||||
break;
|
||||
|
||||
case ZONE_VOLCANO:
|
||||
loadTextureFromFile(texture_tile, asset->get("tiles_volcano.png").c_str(), renderer);
|
||||
loadTextureFromFile(texture_bg, asset->get("bg_surface.png").c_str(), renderer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las musica del juego en función de la zona
|
||||
void Map::setMapMusic(Uint8 zone)
|
||||
{
|
||||
switch (zone)
|
||||
{
|
||||
case ZONE_SURFACE:
|
||||
music = JA_LoadMusic(asset->get("music_surface.ogg").c_str());
|
||||
break;
|
||||
|
||||
case ZONE_VOLCANO:
|
||||
music = JA_LoadMusic(asset->get("music_volcano.ogg").c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si se ha cambiado de zona
|
||||
bool Map::checkZoneChange(int room)
|
||||
{
|
||||
Uint8 _zone = 0;
|
||||
|
||||
if ((room >= 0) && (room <= 23))
|
||||
_zone = ZONE_SURFACE;
|
||||
else if ((room >= 24) && (room <= 255))
|
||||
_zone = ZONE_VOLCANO;
|
||||
|
||||
if (_zone == zone)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cambia la zona del mapa
|
||||
void Map::setZone(int room)
|
||||
{
|
||||
if ((room >= 0) && (room <= 23))
|
||||
zone = ZONE_SURFACE;
|
||||
else if ((room >= 24) && (room <= 255))
|
||||
zone = ZONE_VOLCANO;
|
||||
|
||||
setMapGFX(zone);
|
||||
setMapMusic(zone);
|
||||
JA_PlayMusic(music, -1);
|
||||
}
|
||||
Reference in New Issue
Block a user