Los enemigos ya hacen flip
This commit is contained in:
@@ -25,6 +25,7 @@ y1=2
|
||||
x2=4
|
||||
y2=12
|
||||
color=yellow
|
||||
flip=true
|
||||
[/enemy]
|
||||
|
||||
[enemy]
|
||||
|
||||
@@ -25,6 +25,14 @@ Enemy::Enemy(enemy_t enemy)
|
||||
sprite->setVelY(enemy.vy);
|
||||
sprite->setWidth(enemy.w);
|
||||
sprite->setHeight(enemy.h);
|
||||
doFlip = enemy.flip;
|
||||
if (doFlip)
|
||||
{
|
||||
if (enemy.vx < 0.0f)
|
||||
{
|
||||
sprite->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
}
|
||||
}
|
||||
|
||||
collider = getRect();
|
||||
}
|
||||
@@ -59,11 +67,19 @@ void Enemy::checkPath()
|
||||
if (sprite->getPosX() > x2 || sprite->getPosX() < x1)
|
||||
{
|
||||
sprite->setVelX(sprite->getVelX() * (-1));
|
||||
if (doFlip)
|
||||
{
|
||||
sprite->flip();
|
||||
}
|
||||
}
|
||||
|
||||
if (sprite->getPosY() > y2 || sprite->getPosY() < y1)
|
||||
{
|
||||
sprite->setVelY(sprite->getVelY() * (-1));
|
||||
if (doFlip)
|
||||
{
|
||||
sprite->flip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ struct enemy_t
|
||||
int x2; // Limite derecho de la ruta en el eje X
|
||||
int y1; // Limite superior de la ruta en el eje Y
|
||||
int y2; // Limite inferior de la ruta en el eje Y
|
||||
bool flip; // Indica si el enemigo hace flip al terminar su ruta
|
||||
color_t color; // Color del enemigo
|
||||
};
|
||||
|
||||
@@ -58,6 +59,7 @@ private:
|
||||
int y1; // Limite superior de la ruta en el eje Y
|
||||
int y2; // Limite inferior de la ruta en el eje Y
|
||||
SDL_Rect collider; // Caja de colisión
|
||||
bool doFlip; // Indica si el enemigo hace flip al terminar su ruta
|
||||
|
||||
// Comprueba si ha llegado al limite del recorrido para darse media vuelta
|
||||
void checkPath();
|
||||
|
||||
@@ -25,8 +25,8 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset
|
||||
texture = new LTexture(renderer, asset->get(tileset));
|
||||
itemSound = JA_LoadSound(asset->get("item.wav").c_str());
|
||||
|
||||
debug->clearLog();
|
||||
debug->addToLog(tileset);
|
||||
//debug->clearLog();
|
||||
//debug->addToLog(tileset);
|
||||
// Calcula las superficies
|
||||
setBottomSurfaces();
|
||||
setTopSurfaces();
|
||||
@@ -89,6 +89,7 @@ bool Room::load(std::string file_path)
|
||||
enemy_t enemy;
|
||||
enemy.asset = asset;
|
||||
enemy.renderer = renderer;
|
||||
enemy.flip = false;
|
||||
|
||||
do
|
||||
{
|
||||
@@ -350,6 +351,11 @@ bool Room::setEnemy(enemy_t *enemy, std::string var, std::string value)
|
||||
enemy->y2 = std::stoi(value) * BLOCK;
|
||||
}
|
||||
|
||||
else if (var == "flip")
|
||||
{
|
||||
enemy->flip = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "color")
|
||||
{
|
||||
enemy->color = stringToColor(value);
|
||||
@@ -775,7 +781,7 @@ void Room::setBottomSurfaces()
|
||||
i++;
|
||||
}
|
||||
|
||||
debug->addToLog("B: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y));
|
||||
//debug->addToLog("B: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -784,7 +790,7 @@ void Room::setTopSurfaces()
|
||||
{
|
||||
std::vector<int> tile;
|
||||
|
||||
debug->addToLog(std::to_string(tilemap.size()));
|
||||
//debug->addToLog(std::to_string(tilemap.size()));
|
||||
|
||||
// Busca todos los tiles de tipo muro o pasable que no tengan encima un muro
|
||||
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
|
||||
@@ -826,7 +832,7 @@ void Room::setTopSurfaces()
|
||||
i++;
|
||||
}
|
||||
|
||||
debug->addToLog("T: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y));
|
||||
//debug->addToLog("T: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
todo.txt
2
todo.txt
@@ -11,7 +11,7 @@ x (A) Modificar el salto para que coincida con el del JSW, no ha de colisionar l
|
||||
|
||||
(A) Crear tiles que arrastren, tipo cinta transportadora
|
||||
(A) Tiles animados
|
||||
(A) Tile que maten (o enemigos?)
|
||||
x (A) Tile que maten (o enemigos?)
|
||||
(A) Cuando mueres, pantalla negra entre vida y vida
|
||||
x (A) Morir al caer de alto
|
||||
x (A) Crear ascensores (NO SE VA A HACER POR DISEÑO)
|
||||
|
||||
Reference in New Issue
Block a user