Trabajando en los frames iniciales aleatorios de los enemigos

This commit is contained in:
2022-09-20 22:33:40 +02:00
parent 03fedbe3b0
commit bfb2610f6f
24 changed files with 17 additions and 43 deletions

View File

@@ -29,13 +29,7 @@ AnimatedSprite::~AnimatedSprite()
int AnimatedSprite::getIndex(std::string name)
{
int index = -1;
/*for (int i = 0; i < (int)animation.size(); i++)
{
if (animation[i].name == name)
{
index = i;
}
}*/
for (auto a : animation)
{
index++;
@@ -46,7 +40,6 @@ int AnimatedSprite::getIndex(std::string name)
}
printf("** Warning: could not find \"%s\" animation\n", name.c_str());
index = 0;
return -1;
}
@@ -230,17 +223,23 @@ bool AnimatedSprite::load(std::string filePath)
{
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "frame_width")
{
frame_width = std::stoi(line.substr(pos + 1, line.length()));
// Normaliza valores
if (frames_per_row == 0)
{
frames_per_row = texture->getWidth() / frame_width;
}
}
else if (line.substr(0, pos) == "frame_height")
{
frame_height = std::stoi(line.substr(pos + 1, line.length()));
}
else
{
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
@@ -261,12 +260,6 @@ bool AnimatedSprite::load(std::string filePath)
success = false;
}
// Normaliza valores
if (frames_per_row == 0)
{
frames_per_row = texture->getWidth() / frame_width;
}
// Pone un valor por defecto
setPos({0, 0, frame_width, frame_height});

View File

@@ -35,6 +35,9 @@ Enemy::Enemy(enemy_t enemy)
}
collider = getRect();
// Coloca un frame al azar
sprite->setCurrentFrame(rand() % 4);
}
// Destructor
@@ -56,7 +59,6 @@ void Enemy::render()
void Enemy::update()
{
sprite->update();
// sprite->animate();
checkPath();
collider = getRect();
}

View File

@@ -13,14 +13,14 @@ int main(int argc, char *args[])
printf("Starting the game...\n\n");
// Crea el objeto Director
Director *mDirector = new Director(args[0]);
Director *director = new Director(args[0]);
// Bucle principal
mDirector->run();
director->run();
// Destruye el objeto Director
delete mDirector;
mDirector = nullptr;
delete director;
director = nullptr;
printf("\nShutting down the game...\n");