Añadidos enemigos volteados verticalmente
This commit is contained in:
@@ -49,6 +49,8 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
|
||||
|
||||
// Establece el tipo de volteado
|
||||
currentFlip = SDL_FLIP_NONE;
|
||||
currentFlipH = false;
|
||||
currentFlipV = false;
|
||||
};
|
||||
|
||||
// Reinicia todas las variables
|
||||
@@ -305,16 +307,56 @@ void MovingSprite::switchRotate()
|
||||
rotateAmount *= -1;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setFlip(SDL_RendererFlip flip)
|
||||
// Actualiza el valor de la variable
|
||||
void MovingSprite::updateCurrentFlip()
|
||||
{
|
||||
currentFlip = flip;
|
||||
if (currentFlipH && currentFlipV)
|
||||
{
|
||||
currentFlip = SDL_RendererFlip(SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL);
|
||||
}
|
||||
|
||||
else if (currentFlipH && !currentFlipV)
|
||||
{
|
||||
currentFlip = SDL_FLIP_HORIZONTAL;
|
||||
}
|
||||
|
||||
else if (!currentFlipH && currentFlipV)
|
||||
{
|
||||
currentFlip = SDL_FLIP_VERTICAL;
|
||||
}
|
||||
|
||||
else if (!currentFlipH && !currentFlipV)
|
||||
{
|
||||
currentFlip = SDL_FLIP_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setFlipH(bool flip)
|
||||
{
|
||||
currentFlipH = flip;
|
||||
updateCurrentFlip();
|
||||
}
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void MovingSprite::flip()
|
||||
void MovingSprite::flipH()
|
||||
{
|
||||
currentFlip = (currentFlip == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
||||
currentFlipH = !currentFlipH;
|
||||
updateCurrentFlip();
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setFlipV(bool flip)
|
||||
{
|
||||
currentFlipV = flip;
|
||||
updateCurrentFlip();
|
||||
}
|
||||
|
||||
// Voltea el sprite verticalmente
|
||||
void MovingSprite::flipV()
|
||||
{
|
||||
currentFlipV = !currentFlipV;
|
||||
updateCurrentFlip();
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
@@ -323,6 +365,18 @@ SDL_RendererFlip MovingSprite::getFlip()
|
||||
return currentFlip;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool MovingSprite::getFlipH()
|
||||
{
|
||||
return currentFlipH;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool MovingSprite::getFlipV()
|
||||
{
|
||||
return currentFlipV;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect MovingSprite::getRect()
|
||||
{
|
||||
|
||||
@@ -35,6 +35,8 @@ protected:
|
||||
double rotateAmount; // Cantidad de grados a girar en cada iteración
|
||||
int counter; // Contador interno
|
||||
SDL_RendererFlip currentFlip; // Indica como se voltea el sprite
|
||||
bool currentFlipV;
|
||||
bool currentFlipH;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -139,15 +141,30 @@ public:
|
||||
// Cambia el sentido de la rotación
|
||||
void switchRotate();
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updateCurrentFlip();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFlip(SDL_RendererFlip flip);
|
||||
void setFlipH(bool flip);
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void flip();
|
||||
void flipH();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFlipV(bool flip);
|
||||
|
||||
// Voltea el sprite verticalmente
|
||||
void flipV();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip getFlip();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool getFlipH();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool getFlipV();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
|
||||
@@ -26,9 +26,10 @@ Enemy::Enemy(enemy_t enemy)
|
||||
{
|
||||
if (enemy.vx < 0.0f)
|
||||
{
|
||||
sprite->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
sprite->setFlipH(true);
|
||||
}
|
||||
}
|
||||
sprite->setFlipV(mirror);
|
||||
|
||||
collider = getRect();
|
||||
|
||||
@@ -66,7 +67,7 @@ void Enemy::checkPath()
|
||||
sprite->setVelX(sprite->getVelX() * (-1));
|
||||
if (doFlip)
|
||||
{
|
||||
sprite->flip();
|
||||
sprite->flipH();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ void Enemy::checkPath()
|
||||
sprite->setVelY(sprite->getVelY() * (-1));
|
||||
if (doFlip)
|
||||
{
|
||||
sprite->flip();
|
||||
sprite->flipH();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ Player::Player(player_t player)
|
||||
sprite->setWidth(8);
|
||||
sprite->setHeight(16);
|
||||
|
||||
sprite->setFlip(player.spawn.flip);
|
||||
sprite->setFlipH(player.spawn.flipH);
|
||||
sprite->setCurrentAnimation("walk");
|
||||
sprite->animate();
|
||||
|
||||
@@ -162,13 +162,13 @@ void Player::checkInput()
|
||||
if (input->checkInput(INPUT_LEFT, REPEAT_TRUE))
|
||||
{
|
||||
vx = -0.6f;
|
||||
sprite->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
sprite->setFlipH(true);
|
||||
}
|
||||
|
||||
else if (input->checkInput(INPUT_RIGHT, REPEAT_TRUE))
|
||||
{
|
||||
vx = 0.6f;
|
||||
sprite->setFlip(SDL_FLIP_NONE);
|
||||
sprite->setFlipH(false);
|
||||
}
|
||||
|
||||
else
|
||||
@@ -186,11 +186,11 @@ void Player::checkInput()
|
||||
|
||||
if (vx > 0.0f)
|
||||
{
|
||||
sprite->setFlip(SDL_FLIP_NONE);
|
||||
sprite->setFlipH(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
sprite->setFlipH(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +685,7 @@ playerSpawn_t Player::getSpawnParams()
|
||||
params.vy = vy;
|
||||
params.jumpIni = jumpIni;
|
||||
params.state = state;
|
||||
params.flip = sprite->getFlip();
|
||||
params.flipH = sprite->getFlipH();
|
||||
|
||||
return params;
|
||||
}
|
||||
@@ -694,7 +694,6 @@ playerSpawn_t Player::getSpawnParams()
|
||||
void Player::reLoadTexture()
|
||||
{
|
||||
sprite->getTexture()->reLoad();
|
||||
// texture->reLoad();
|
||||
}
|
||||
|
||||
// Recarga la paleta
|
||||
|
||||
@@ -30,7 +30,7 @@ struct playerSpawn_t
|
||||
float vy;
|
||||
int jumpIni;
|
||||
state_e state;
|
||||
SDL_RendererFlip flip;
|
||||
bool flipH;
|
||||
};
|
||||
|
||||
struct player_t
|
||||
|
||||
Reference in New Issue
Block a user