Debugando la clase enemy
This commit is contained in:
@@ -1,73 +1,14 @@
|
|||||||
tileset_img=surface.png
|
[path]
|
||||||
bgColor1=234,171,159
|
tileset=walking_eye.png
|
||||||
bgColor2=144,225,231
|
animation=walking_eye.ani
|
||||||
|
|
||||||
room_up=0
|
|
||||||
room_down=0
|
|
||||||
room_left=0
|
|
||||||
room_right=02.map
|
|
||||||
|
|
||||||
[tilemap]
|
|
||||||
01.tmx
|
|
||||||
[/tilemap]
|
|
||||||
|
|
||||||
[actors]
|
|
||||||
|
|
||||||
[moving platform]
|
|
||||||
tileset=moving_platform.png
|
|
||||||
animation=moving_platform.ani
|
|
||||||
width=16
|
width=16
|
||||||
height=8
|
height=16
|
||||||
x=9
|
x=22
|
||||||
y=11
|
y=20
|
||||||
vx=0.3
|
vx=0.4
|
||||||
vy=0
|
vy=0
|
||||||
x1=9
|
x1=22
|
||||||
y1=11
|
y1=20
|
||||||
x2=15
|
x2=27
|
||||||
y2=11
|
y2=20
|
||||||
[/moving platform]
|
[/path]
|
||||||
|
|
||||||
[moving platform]
|
|
||||||
tileset=moving_platform.png
|
|
||||||
animation=moving_platform.ani
|
|
||||||
width=16
|
|
||||||
height=8
|
|
||||||
x=20
|
|
||||||
y=14
|
|
||||||
vx=0
|
|
||||||
vy=0.3
|
|
||||||
x1=20
|
|
||||||
y1=14
|
|
||||||
x2=20
|
|
||||||
y2=21
|
|
||||||
[/moving platform]
|
|
||||||
|
|
||||||
[diamond]
|
|
||||||
tileset=diamond.png
|
|
||||||
animation=diamond.ani
|
|
||||||
width=16
|
|
||||||
height=16
|
|
||||||
x=1
|
|
||||||
y=10
|
|
||||||
[/diamond]
|
|
||||||
|
|
||||||
[diamond]
|
|
||||||
tileset=diamond.png
|
|
||||||
animation=diamond.ani
|
|
||||||
width=16
|
|
||||||
height=16
|
|
||||||
x=24
|
|
||||||
y=10
|
|
||||||
[/diamond]
|
|
||||||
|
|
||||||
[diamond]
|
|
||||||
tileset=diamond.png
|
|
||||||
animation=diamond.ani
|
|
||||||
width=16
|
|
||||||
height=16
|
|
||||||
x=25
|
|
||||||
y=12
|
|
||||||
[/diamond]
|
|
||||||
|
|
||||||
[/actors]
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
tileset_img=surface.png
|
tileset_img=surface.png
|
||||||
|
enemy_file=01.ene
|
||||||
bgColor1=234,171,159
|
bgColor1=234,171,159
|
||||||
bgColor2=144,225,231
|
bgColor2=144,225,231
|
||||||
|
|
||||||
|
|||||||
14
data/map/02.ene
Normal file
14
data/map/02.ene
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[path]
|
||||||
|
tileset=flying_eye.png
|
||||||
|
animation=flying_eye.ani
|
||||||
|
width=16
|
||||||
|
height=16
|
||||||
|
x=9
|
||||||
|
y=12
|
||||||
|
vx=0
|
||||||
|
vy=0.3
|
||||||
|
x1=9
|
||||||
|
y1=12
|
||||||
|
x2=9
|
||||||
|
y2=20
|
||||||
|
[/path]
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
tileset_img=surface.png
|
tileset_img=surface.png
|
||||||
|
enemy_file=02.ene
|
||||||
bgColor1=234,100,159
|
bgColor1=234,100,159
|
||||||
bgColor2=144,235,231
|
bgColor2=144,235,231
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
0,0,0,0,0,0,0,404,395,395,406,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,404,395,395,406,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,112,113,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,112,113,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,109,110,113,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,109,110,113,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,141,142,138,264,263,264,364,0,0,0,0,0,0,0,0,0,0,0,0,161,162,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,141,142,138,113,264,263,264,364,0,0,0,0,0,0,0,0,0,0,0,161,162,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,180,169,170,313,295,296,406,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,180,169,170,138,313,295,296,406,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,372,373,373,264,78,137,138,75,76,145,0,0,0,0,0,0,583,584,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,372,373,373,264,78,137,138,75,76,145,0,0,0,0,0,0,583,584,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,144,86,77,110,169,170,83,108,0,0,0,0,0,0,0,161,162,0,0,0,0,0,159,160,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,144,86,77,110,169,170,83,108,0,0,0,0,0,0,0,161,162,0,0,0,0,0,159,160,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,109,148,137,138,115,0,0,0,0,0,0,583,584,155,156,65,66,0,0,0,191,192,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,109,148,137,138,115,0,0,0,0,0,0,583,584,155,156,65,66,0,0,0,191,192,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
|||||||
@@ -3,17 +3,27 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
EnemyEngine::EnemyEngine(SDL_Renderer *renderer, Asset *asset, Player *player, Map *map)
|
EnemyEngine::EnemyEngine(SDL_Renderer *renderer, Asset *asset, Player *player, Map *map, std::string file)
|
||||||
{
|
{
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
this->player = player;
|
this->player = player;
|
||||||
this->map = map;
|
this->map = map;
|
||||||
|
|
||||||
|
load(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
EnemyEngine::~EnemyEngine()
|
EnemyEngine::~EnemyEngine()
|
||||||
{
|
{
|
||||||
|
// Elimina todos los enemigos anteriores
|
||||||
|
for (auto enemy : enemies)
|
||||||
|
{
|
||||||
|
delete enemy;
|
||||||
|
}
|
||||||
|
enemies.clear();
|
||||||
|
|
||||||
|
delete enemy;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta los enemigos en pantalla
|
// Pinta los enemigos en pantalla
|
||||||
@@ -23,6 +33,7 @@ void EnemyEngine::render()
|
|||||||
{
|
{
|
||||||
enemy->render();
|
enemy->render();
|
||||||
}
|
}
|
||||||
|
enemy->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -32,6 +43,7 @@ void EnemyEngine::update()
|
|||||||
{
|
{
|
||||||
enemy->update();
|
enemy->update();
|
||||||
}
|
}
|
||||||
|
enemy->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga las variables desde un fichero
|
// Carga las variables desde un fichero
|
||||||
@@ -51,133 +63,33 @@ bool EnemyEngine::load(std::string file_path)
|
|||||||
printf("Reading file %s\n", filename.c_str());
|
printf("Reading file %s\n", filename.c_str());
|
||||||
while (std::getline(file, line))
|
while (std::getline(file, line))
|
||||||
{
|
{
|
||||||
// Si la linea contiene el texto [tilemap] se realiza el proceso de carga del fichero tmx
|
|
||||||
if (line == "[tilemap]")
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
std::getline(file, line);
|
|
||||||
if (line.find(".tmx") != std::string::npos)
|
|
||||||
{
|
|
||||||
std::ifstream file2(asset->get(line)); // Abre el fichero tmx
|
|
||||||
if (file2.good())
|
|
||||||
{
|
|
||||||
bool data_read = false;
|
|
||||||
while (std::getline(file2, line)) // Lee el fichero linea a linea
|
|
||||||
{
|
|
||||||
if (!data_read)
|
|
||||||
{ // Lee lineas hasta que encuentre donde empiezan los datos del mapa
|
|
||||||
int pos = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
std::getline(file2, line);
|
|
||||||
pos = line.find("data encoding");
|
|
||||||
} while (pos == std::string::npos);
|
|
||||||
|
|
||||||
do
|
|
||||||
{ // Se introducen los valores separados por comas en un vector
|
|
||||||
data_read = true;
|
|
||||||
std::getline(file2, line);
|
|
||||||
if (line != "</data>")
|
|
||||||
{
|
|
||||||
std::stringstream ss(line);
|
|
||||||
std::string tmp;
|
|
||||||
while (getline(ss, tmp, ','))
|
|
||||||
{
|
|
||||||
tilemap.push_back(std::stoi(tmp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (line != "</data>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (line != "[/tilemap]");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si la linea contiene el texto [actor] se realiza el proceso de carga de los actores
|
// Si la linea contiene el texto [actor] se realiza el proceso de carga de los actores
|
||||||
else if (line == "[actors]")
|
if (line == "[path]")
|
||||||
{
|
{
|
||||||
|
enemy_t enemy;
|
||||||
|
enemy.asset = asset;
|
||||||
|
enemy.renderer = renderer;
|
||||||
|
SDL_Point p1, p2;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::getline(file, line);
|
std::getline(file, line);
|
||||||
|
|
||||||
if (line == "[moving platform]")
|
// Encuentra la posición del caracter '='
|
||||||
|
int pos = line.find("=");
|
||||||
|
|
||||||
|
// Procesa las dos subcadenas
|
||||||
|
if (!setEnemy(&enemy, &p1, &p2, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||||
{
|
{
|
||||||
actor_t actor;
|
printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||||
actor.asset = asset;
|
success = false;
|
||||||
actor.renderer = renderer;
|
|
||||||
actor.name = a_moving_platform;
|
|
||||||
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 moving platform loaded\n\n");
|
|
||||||
actors.push_back(new ActorMovingPlatform(actor, p1, p2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line == "[diamond]")
|
} while (line != "[/path]");
|
||||||
{
|
|
||||||
actor_t actor;
|
|
||||||
actor.asset = asset;
|
|
||||||
actor.renderer = renderer;
|
|
||||||
actor.name = a_diamond;
|
|
||||||
actor.vx = 0.0f;
|
|
||||||
actor.vy = 0.0f;
|
|
||||||
SDL_Point p1, p2;
|
|
||||||
|
|
||||||
do
|
printf("** enemy path loaded\n\n");
|
||||||
{
|
//enemies.push_back(new EnemyPath(enemy, p1, p2));
|
||||||
std::getline(file, line);
|
enemy = new EnemyPath(enemy, p1, p2);
|
||||||
|
|
||||||
// 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 != "[/diamond]");
|
|
||||||
|
|
||||||
// Comprueba si el actor no ha sido recogido previamente
|
|
||||||
if (!itemTracker->hasBeenPicked(name, {(int)actor.x, (int)actor.y}))
|
|
||||||
{
|
|
||||||
printf("** actor diamond loaded\n\n");
|
|
||||||
actors.push_back(new ActorDiamond(actor));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (line != "[/actors]");
|
|
||||||
}
|
|
||||||
|
|
||||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Encuentra la posición del caracter '='
|
|
||||||
int pos = line.find("=");
|
|
||||||
// Procesa las dos subcadenas
|
|
||||||
if (!setVars(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
|
||||||
{
|
|
||||||
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,3 +106,86 @@ bool EnemyEngine::load(std::string file_path)
|
|||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Asigna variables a una estructura enemy_t
|
||||||
|
bool EnemyEngine::setEnemy(enemy_t *enemy, SDL_Point *p1, SDL_Point *p2, std::string var, std::string value)
|
||||||
|
{
|
||||||
|
const int tile_size = 8;
|
||||||
|
|
||||||
|
// Indicador de éxito en la asignación
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
if (var == "tileset")
|
||||||
|
{
|
||||||
|
enemy->tileset = value;
|
||||||
|
}
|
||||||
|
else if (var == "animation")
|
||||||
|
{
|
||||||
|
enemy->animation = value;
|
||||||
|
}
|
||||||
|
else if (var == "width")
|
||||||
|
{
|
||||||
|
enemy->w = std::stof(value);
|
||||||
|
}
|
||||||
|
else if (var == "height")
|
||||||
|
{
|
||||||
|
enemy->h = std::stof(value);
|
||||||
|
}
|
||||||
|
else if (var == "x")
|
||||||
|
{
|
||||||
|
enemy->x = std::stof(value) * tile_size;
|
||||||
|
}
|
||||||
|
else if (var == "y")
|
||||||
|
{
|
||||||
|
enemy->y = std::stof(value) * tile_size;
|
||||||
|
}
|
||||||
|
else if (var == "vx")
|
||||||
|
{
|
||||||
|
enemy->vx = std::stof(value);
|
||||||
|
}
|
||||||
|
else if (var == "vy")
|
||||||
|
{
|
||||||
|
enemy->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 == "[/path]")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga el vector de enemigos
|
||||||
|
//bool EnemyEngine::setEnemies(std::string file)
|
||||||
|
//{
|
||||||
|
// // Elimina todos los enemigos anteriores
|
||||||
|
// for (auto enemy : enemies)
|
||||||
|
// {
|
||||||
|
// delete enemy;
|
||||||
|
// }
|
||||||
|
// enemies.clear();
|
||||||
|
//
|
||||||
|
// // Carga el vector de enemigos desde un fichero
|
||||||
|
// const bool success = load(file);
|
||||||
|
//
|
||||||
|
// return success;
|
||||||
|
//}
|
||||||
@@ -21,14 +21,18 @@ private:
|
|||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
Map *map; // Mapa con la información de la habitación
|
Map *map; // Mapa con la información de la habitación
|
||||||
Player *player; // Puntero con el jugador
|
Player *player; // Puntero con el jugador
|
||||||
std::vector<Enemy *> enemies; // Vector con la lista de enemigos
|
std::vector<EnemyPath *> enemies; // Vector con la lista de enemigos
|
||||||
|
EnemyPath *enemy;
|
||||||
|
|
||||||
// Carga las variables desde un fichero
|
// Carga las variables desde un fichero
|
||||||
bool load(std::string file_path);
|
bool load(std::string file_path);
|
||||||
|
|
||||||
|
// Asigna variables a una estructura enemy_t
|
||||||
|
bool setEnemy(enemy_t *enemy, SDL_Point *p1, SDL_Point *p2, std::string var, std::string value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
EnemyEngine(SDL_Renderer *renderer, Asset *asset, Player *player, Map *map);
|
EnemyEngine(SDL_Renderer *renderer, Asset *asset, Player *player, Map *map, std::string file);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~EnemyEngine();
|
~EnemyEngine();
|
||||||
@@ -38,6 +42,9 @@ public:
|
|||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
// Carga el vector de enemigos
|
||||||
|
//bool setEnemies(std::string file);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
|||||||
itemTracker = new ItemTracker();
|
itemTracker = new ItemTracker();
|
||||||
map = new Map(asset->get("01.map"), renderer, asset, itemTracker);
|
map = new Map(asset->get("01.map"), renderer, asset, itemTracker);
|
||||||
player = new Player(renderer, asset, input, map);
|
player = new Player(renderer, asset, input, map);
|
||||||
enemyEngine = new EnemyEngine(renderer, asset, player, map);
|
enemyEngine = new EnemyEngine(renderer, asset, player, map, asset->get(map->getEnemyFile()));
|
||||||
|
// enemyEngine->setEnemies(asset->get(map->getEnemyFile()));
|
||||||
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||||
music = JA_LoadMusic(asset->get("music_surface.ogg").c_str());
|
music = JA_LoadMusic(asset->get("music_surface.ogg").c_str());
|
||||||
|
|
||||||
@@ -87,6 +88,7 @@ void Game::update()
|
|||||||
|
|
||||||
player->update();
|
player->update();
|
||||||
checkScreenBorders();
|
checkScreenBorders();
|
||||||
|
enemyEngine->update();
|
||||||
map->update();
|
map->update();
|
||||||
checkInput();
|
checkInput();
|
||||||
}
|
}
|
||||||
@@ -101,6 +103,7 @@ void Game::render()
|
|||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
map->render();
|
map->render();
|
||||||
|
enemyEngine->render();
|
||||||
player->render();
|
player->render();
|
||||||
renderDebugInfo();
|
renderDebugInfo();
|
||||||
|
|
||||||
@@ -213,7 +216,7 @@ bool Game::changeMap(std::string file)
|
|||||||
bool success = false;
|
bool success = false;
|
||||||
// En las habitaciones los limites tienen la cadena del fichero o un 0 en caso de no limitar con nada
|
// En las habitaciones los limites tienen la cadena del fichero o un 0 en caso de no limitar con nada
|
||||||
if (file != "0")
|
if (file != "0")
|
||||||
// Verifica que exista el fichero que se va a cargar
|
{ // Verifica que exista el fichero que se va a cargar
|
||||||
if (asset->get(file) != "")
|
if (asset->get(file) != "")
|
||||||
{
|
{
|
||||||
// Elimina la habitación actual
|
// Elimina la habitación actual
|
||||||
@@ -221,9 +224,22 @@ bool Game::changeMap(std::string file)
|
|||||||
|
|
||||||
// Crea un objeto habitación nuevo a partir del fichero
|
// Crea un objeto habitación nuevo a partir del fichero
|
||||||
map = new Map(asset->get(file), renderer, asset, itemTracker);
|
map = new Map(asset->get(file), renderer, asset, itemTracker);
|
||||||
|
|
||||||
|
delete enemyEngine;
|
||||||
|
enemyEngine = new EnemyEngine(renderer, asset, player, map, asset->get(map->getEnemyFile()));
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Carga los enemigos
|
||||||
|
// const std::string enemyFile = asset->get(map->getEnemyFile());
|
||||||
|
// if (enemyFile != "")
|
||||||
|
//{
|
||||||
|
// enemyEngine->setEnemies(enemyFile);
|
||||||
|
// success = true;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, Item_tracker *itemTracker)
|
Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *itemTracker)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
tile_size = 8;
|
tile_size = 8;
|
||||||
@@ -9,6 +9,8 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, Item_tracker *i
|
|||||||
map_height = 26;
|
map_height = 26;
|
||||||
tileset_width = 32;
|
tileset_width = 32;
|
||||||
name = file.substr(file.find_last_of("\\/") + 1);
|
name = file.substr(file.find_last_of("\\/") + 1);
|
||||||
|
enemy_file = "";
|
||||||
|
bgColor1 = bgColor2 = {0, 0, 0};
|
||||||
|
|
||||||
// Copia los punteros a objetos
|
// Copia los punteros a objetos
|
||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
@@ -256,6 +258,10 @@ bool Map::setVars(std::string var, std::string value)
|
|||||||
{
|
{
|
||||||
room_right = value;
|
room_right = value;
|
||||||
}
|
}
|
||||||
|
else if (var == "enemy_file")
|
||||||
|
{
|
||||||
|
enemy_file = value;
|
||||||
|
}
|
||||||
else if (var == "")
|
else if (var == "")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -592,3 +598,9 @@ void Map::getItem(int index)
|
|||||||
const SDL_Rect r = getActorCollider(index);
|
const SDL_Rect r = getActorCollider(index);
|
||||||
itemTracker->addItem(name, {r.x, r.y});
|
itemTracker->addItem(name, {r.x, r.y});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
std::string Map::getEnemyFile()
|
||||||
|
{
|
||||||
|
return enemy_file;
|
||||||
|
}
|
||||||
@@ -42,6 +42,7 @@ private:
|
|||||||
std::string room_down; // Identificador de la habitación que se encuentra abajp
|
std::string room_down; // Identificador de la habitación que se encuentra abajp
|
||||||
std::string room_left; // Identificador de la habitación que se encuentra a la izquierda
|
std::string room_left; // Identificador de la habitación que se encuentra a la izquierda
|
||||||
std::string room_right; // Identificador de la habitación que se encuentra a la derecha
|
std::string room_right; // Identificador de la habitación que se encuentra a la derecha
|
||||||
|
std::string enemy_file; // Fichero con los enemigos para la habitación
|
||||||
std::string tileset_img; // Imagen con los graficos para la habitación
|
std::string tileset_img; // Imagen con los graficos para la habitación
|
||||||
std::vector<int> tilemap; // Indice de los tiles a dibujar en la habitación
|
std::vector<int> tilemap; // Indice de los tiles a dibujar en la habitación
|
||||||
LTexture *texture_tile; // Textura con los graficos de los tiles habitación
|
LTexture *texture_tile; // Textura con los graficos de los tiles habitación
|
||||||
@@ -49,7 +50,7 @@ private:
|
|||||||
std::vector<Actor *> actors; // Listado con los actores de la habitación
|
std::vector<Actor *> actors; // Listado con los actores de la habitación
|
||||||
color_t bgColor1; // Color superior del degradado de fondo
|
color_t bgColor1; // Color superior del degradado de fondo
|
||||||
color_t bgColor2; // Color inferior del degradado de fondo
|
color_t bgColor2; // Color inferior del degradado de fondo
|
||||||
Item_tracker *itemTracker; // Objeto que gestiona los items que ya se han recogido
|
ItemTracker *itemTracker; // Objeto que gestiona los items que ya se han recogido
|
||||||
|
|
||||||
int tile_size; // Ancho del tile en pixels
|
int tile_size; // Ancho del tile en pixels
|
||||||
int map_width; // Ancho del mapa en tiles
|
int map_width; // Ancho del mapa en tiles
|
||||||
@@ -70,7 +71,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Map(std::string file, SDL_Renderer *renderer, Asset *asset, Item_tracker *itemTracker);
|
Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *itemTracker);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Map();
|
~Map();
|
||||||
@@ -116,6 +117,9 @@ public:
|
|||||||
|
|
||||||
// Coge un item
|
// Coge un item
|
||||||
void getItem(int index);
|
void getItem(int index);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
std::string getEnemyFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ bool Prog::setFileList()
|
|||||||
asset->add("/data/map/01.ene", data);
|
asset->add("/data/map/01.ene", data);
|
||||||
asset->add("/data/map/02.map", data);
|
asset->add("/data/map/02.map", data);
|
||||||
asset->add("/data/map/02.tmx", data);
|
asset->add("/data/map/02.tmx", data);
|
||||||
|
asset->add("/data/map/02.ene", data);
|
||||||
asset->add("/data/map/03.map", data);
|
asset->add("/data/map/03.map", data);
|
||||||
asset->add("/data/map/03.tmx", data);
|
asset->add("/data/map/03.tmx", data);
|
||||||
asset->add("/data/map/surface.png", bitmap);
|
asset->add("/data/map/surface.png", bitmap);
|
||||||
|
|||||||
Reference in New Issue
Block a user