Empezando con los actores y polimorfismo. Ya pinta la plataforma movil
This commit is contained in:
@@ -36,11 +36,11 @@ Map::~Map()
|
||||
|
||||
SDL_DestroyTexture(map_texture);
|
||||
|
||||
for (auto enemy : enemy_list)
|
||||
for (auto actor : actors)
|
||||
{
|
||||
delete enemy;
|
||||
delete actor;
|
||||
}
|
||||
enemy_list.clear();
|
||||
actors.clear();
|
||||
}
|
||||
|
||||
// Carga las variables desde un fichero
|
||||
@@ -104,12 +104,44 @@ bool Map::load(std::string file_path)
|
||||
} while (line != "[/tilemap]");
|
||||
}
|
||||
|
||||
// Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
|
||||
else if (line == "[enemy]")
|
||||
// Si la linea contiene el texto [actor] se realiza el proceso de carga de los actores
|
||||
else if (line == "[actors]")
|
||||
{
|
||||
enemy_t enemy;
|
||||
enemy.asset = asset;
|
||||
enemy.renderer = renderer;
|
||||
do
|
||||
{
|
||||
std::getline(file, line);
|
||||
|
||||
if (line == "[moving platform]")
|
||||
{
|
||||
actor_t actor;
|
||||
actor.asset = asset;
|
||||
actor.renderer = renderer;
|
||||
SDL_Point p1, p2;
|
||||
|
||||
do
|
||||
{
|
||||
std::getline(file, line);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (!setActor(&actor, &p1, &p2, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
{
|
||||
printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
}
|
||||
|
||||
} while (line != "[/moving platform]");
|
||||
|
||||
printf("actor loaded\n");
|
||||
actors.push_back(new ActorMovingPlatform(actor, p1, p2));
|
||||
}
|
||||
|
||||
} while (line != "[/actors]");
|
||||
/*actor_t actor;
|
||||
actor.asset = asset;
|
||||
actor.renderer = renderer;
|
||||
|
||||
do
|
||||
{
|
||||
@@ -118,15 +150,15 @@ bool Map::load(std::string file_path)
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
// Procesa las dos subcadenas
|
||||
if (!setEnemy(&enemy, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
if (!setActor(&actor, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
{
|
||||
printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
}
|
||||
} while (line != "[/enemy]");
|
||||
} while (line != "[/actor]");
|
||||
|
||||
// Añade el enemigo al vector de enemigos
|
||||
enemy_list.push_back(new Enemy(enemy));
|
||||
actors.push_back(new ActorMovingPlatform(actor));*/
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
@@ -219,60 +251,60 @@ bool Map::setVars(std::string var, std::string value)
|
||||
}
|
||||
|
||||
// Asigna variables a una estructura enemy_t
|
||||
bool Map::setEnemy(enemy_t *enemy, std::string var, std::string value)
|
||||
bool Map::setActor(actor_t *actor, SDL_Point *p1, SDL_Point *p2, std::string var, std::string value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
|
||||
if (var == "tileset")
|
||||
{
|
||||
enemy->tileset = value;
|
||||
actor->tileset = value;
|
||||
}
|
||||
else if (var == "animation")
|
||||
{
|
||||
enemy->animation = value;
|
||||
actor->animation = value;
|
||||
}
|
||||
else if (var == "width")
|
||||
{
|
||||
enemy->w = std::stof(value);
|
||||
actor->w = std::stof(value);
|
||||
}
|
||||
else if (var == "height")
|
||||
{
|
||||
enemy->h = std::stof(value);
|
||||
actor->h = std::stof(value);
|
||||
}
|
||||
else if (var == "x")
|
||||
{
|
||||
enemy->x = std::stof(value) * tile_size;
|
||||
actor->x = std::stof(value) * tile_size;
|
||||
}
|
||||
else if (var == "y")
|
||||
{
|
||||
enemy->y = std::stof(value) * tile_size;
|
||||
actor->y = std::stof(value) * tile_size;
|
||||
}
|
||||
else if (var == "vx")
|
||||
{
|
||||
enemy->vx = std::stof(value);
|
||||
actor->vx = std::stof(value);
|
||||
}
|
||||
else if (var == "vy")
|
||||
{
|
||||
enemy->vy = std::stof(value);
|
||||
actor->vy = std::stof(value);
|
||||
}
|
||||
else if (var == "x1")
|
||||
{
|
||||
enemy->p1.x = std::stoi(value) * tile_size;
|
||||
p1->x = std::stoi(value) * tile_size;
|
||||
}
|
||||
else if (var == "x2")
|
||||
{
|
||||
enemy->p2.x = std::stoi(value) * tile_size;
|
||||
p2->x = std::stoi(value) * tile_size;
|
||||
}
|
||||
else if (var == "y1")
|
||||
{
|
||||
enemy->p1.y = std::stoi(value) * tile_size;
|
||||
p1->y = std::stoi(value) * tile_size;
|
||||
}
|
||||
else if (var == "y2")
|
||||
{
|
||||
enemy->p2.y = std::stoi(value) * tile_size;
|
||||
p2->y = std::stoi(value) * tile_size;
|
||||
}
|
||||
else if (var == "[/enemy]")
|
||||
else if (var == "[/moving platform]")
|
||||
{
|
||||
}
|
||||
else
|
||||
@@ -343,18 +375,18 @@ void Map::render()
|
||||
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||
SDL_RenderCopy(renderer, map_texture, &rect, NULL);
|
||||
|
||||
for (auto enemy : enemy_list)
|
||||
for (auto actor : actors)
|
||||
{
|
||||
enemy->render();
|
||||
actor->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza todas las variables
|
||||
void Map::update()
|
||||
{
|
||||
for (auto enemy : enemy_list)
|
||||
for (auto actor : actors)
|
||||
{
|
||||
enemy->update();
|
||||
actor->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user