diff --git a/media/gfx/bkg_surface.png b/media/gfx/bg_surface.png similarity index 100% rename from media/gfx/bkg_surface.png rename to media/gfx/bg_surface.png diff --git a/source/director.cpp b/source/director.cpp index 395e26b..61d91ab 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -215,7 +215,7 @@ bool Director::setFileList() // Texturas asset->add("/media/gfx/actors.png", bitmap); - asset->add("/media/gfx/bkg_surface.png", bitmap); + asset->add("/media/gfx/bg_surface.png", bitmap); asset->add("/media/gfx/filter.png", bitmap); asset->add("/media/gfx/hud.png", bitmap); asset->add("/media/gfx/menu_animation.png", bitmap); diff --git a/source/map.cpp b/source/map.cpp index c1f4d28..2e9a912 100644 --- a/source/map.cpp +++ b/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); } \ No newline at end of file diff --git a/source/map.h b/source/map.h index 9671330..7360891 100644 --- a/source/map.h +++ b/source/map.h @@ -11,6 +11,7 @@ class Map { private: + SDL_Renderer *renderer; // El renderizador donde se dibuja todo LTexture *texture_tile; // Textura con los gráficos de los tiles LTexture *texture_actor; // Textura con los gráficos de los actores LTexture *texture_bg; // Textura con los gráficos de fondo @@ -26,6 +27,8 @@ private: Uint8 h; // Altura en habitaciones del mapa Uint8 room; // Habitación actual del mapa std::string mapfile; // Ruta con el fichero del mapa + JA_Music music; // La musica del mapa + Uint8 zone; // Zona del mapa public: // Constructor @@ -42,6 +45,30 @@ public: // Dibuja el objeto void render(); + + // Obtiene el valor del tile de la habitación actual + Uint8 getTile(int x, int y); + + // Obtiene el tipo de tile segun su ubicación en la textura + Uint8 readMapTile(Uint8 x, Uint8 y); + + // Obtiene el valor del actor en esa ubicación + Uint8 getActor(Uint8 x, Uint8 y); + + // Establece el valor del actor en esa ubicación + void setActor(Uint8 x, Uint8 y, Uint8 valor); + + // Carga las texturas del mapa en función de la zona + void setMapGFX(Uint8 zone); + + // Carga las musica del juego en función de la zona + void setMapMusic(Uint8 zone); + + // Comprueba si se ha cambiado de zona + bool checkZoneChange(int room); + + // Cambia la zona del mapa + void setZone(int room); }; #endif