Capa de fondo con posibilidad de scroll
This commit is contained in:
@@ -10,6 +10,8 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *it
|
||||
name = file.substr(file.find_last_of("\\/") + 1);
|
||||
enemy_file = "";
|
||||
bgColor1 = bgColor2 = {0, 0, 0};
|
||||
bgScroll = false;
|
||||
counter = 0;
|
||||
|
||||
// Copia los punteros a objetos
|
||||
this->asset = asset;
|
||||
@@ -273,6 +275,7 @@ bool Map::setVars(std::string var, std::string value)
|
||||
{
|
||||
tileset_img = value;
|
||||
}
|
||||
|
||||
else if (var == "bgColor1")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
@@ -285,6 +288,7 @@ bool Map::setVars(std::string var, std::string value)
|
||||
getline(ss, tmp, ',');
|
||||
bgColor1.b = std::stoi(tmp);
|
||||
}
|
||||
|
||||
else if (var == "bgColor2")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
@@ -297,29 +301,41 @@ bool Map::setVars(std::string var, std::string value)
|
||||
getline(ss, tmp, ',');
|
||||
bgColor2.b = std::stoi(tmp);
|
||||
}
|
||||
|
||||
else if (var == "bgScroll")
|
||||
{
|
||||
bgScroll = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "room_up")
|
||||
{
|
||||
room_up = value;
|
||||
}
|
||||
|
||||
else if (var == "room_down")
|
||||
{
|
||||
room_down = value;
|
||||
}
|
||||
|
||||
else if (var == "room_left")
|
||||
{
|
||||
room_left = value;
|
||||
}
|
||||
|
||||
else if (var == "room_right")
|
||||
{
|
||||
room_right = value;
|
||||
}
|
||||
|
||||
else if (var == "enemy_file")
|
||||
{
|
||||
enemy_file = value;
|
||||
}
|
||||
|
||||
else if (var == "")
|
||||
{
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
@@ -338,53 +354,66 @@ bool Map::setActor(actor_t *actor, SDL_Point *p1, SDL_Point *p2, std::string var
|
||||
{
|
||||
actor->tileset = value;
|
||||
}
|
||||
|
||||
else if (var == "animation")
|
||||
{
|
||||
actor->animation = value;
|
||||
}
|
||||
|
||||
else if (var == "width")
|
||||
{
|
||||
actor->w = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "height")
|
||||
{
|
||||
actor->h = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "x")
|
||||
{
|
||||
actor->x = std::stof(value) * tile_size;
|
||||
}
|
||||
|
||||
else if (var == "y")
|
||||
{
|
||||
actor->y = std::stof(value) * tile_size;
|
||||
}
|
||||
|
||||
else if (var == "vx")
|
||||
{
|
||||
actor->vx = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "vy")
|
||||
{
|
||||
actor->vy = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "x1")
|
||||
{
|
||||
p1->x = std::stoi(value) * tile_size;
|
||||
}
|
||||
|
||||
else if (var == "x2")
|
||||
{
|
||||
p2->x = std::stoi(value) * tile_size;
|
||||
}
|
||||
|
||||
else if (var == "y1")
|
||||
{
|
||||
p1->y = std::stoi(value) * tile_size;
|
||||
}
|
||||
|
||||
else if (var == "y2")
|
||||
{
|
||||
p2->y = std::stoi(value) * tile_size;
|
||||
}
|
||||
|
||||
else if ((var == "[/moving platform]") || (var == "[/diamond]"))
|
||||
{
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
@@ -468,8 +497,23 @@ void Map::render()
|
||||
void Map::renderLayer0()
|
||||
{
|
||||
// Dibuja la textura con el mapa en pantalla
|
||||
SDL_Rect rect = {PLAY_AREA_X, PLAY_AREA_Y, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT};
|
||||
SDL_RenderCopy(renderer, map_layer0, NULL, &rect);
|
||||
if (bgScroll)
|
||||
{
|
||||
const int offset = PLAY_AREA_WIDTH - ((counter / 20) % PLAY_AREA_WIDTH);
|
||||
SDL_Rect src1 = {PLAY_AREA_X, PLAY_AREA_Y, offset, PLAY_AREA_HEIGHT};
|
||||
SDL_Rect dst1 = {PLAY_AREA_X + PLAY_AREA_WIDTH - offset, PLAY_AREA_Y, offset, PLAY_AREA_HEIGHT};
|
||||
|
||||
SDL_Rect src2 = {PLAY_AREA_X + offset, PLAY_AREA_Y, PLAY_AREA_WIDTH - offset, PLAY_AREA_HEIGHT};
|
||||
SDL_Rect dst2 = {PLAY_AREA_X, PLAY_AREA_Y, PLAY_AREA_WIDTH - offset, PLAY_AREA_HEIGHT};
|
||||
|
||||
SDL_RenderCopy(renderer, map_layer0, &src1, &dst1);
|
||||
SDL_RenderCopy(renderer, map_layer0, &src2, &dst2);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Rect rect = {PLAY_AREA_X, PLAY_AREA_Y, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT};
|
||||
SDL_RenderCopy(renderer, map_layer0, nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja la capa 1
|
||||
@@ -492,6 +536,8 @@ void Map::renderActors()
|
||||
// Actualiza todas las variables
|
||||
void Map::update()
|
||||
{
|
||||
counter++;
|
||||
|
||||
for (auto actor : actors)
|
||||
{
|
||||
actor->update();
|
||||
|
||||
Reference in New Issue
Block a user