Trabajando en las colisiones

This commit is contained in:
2022-08-16 13:54:22 +02:00
parent 77980a4d70
commit a941f72208
7 changed files with 140 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
// Copia los punteros
setTexture(texture);
setRenderer(renderer);
// Establece el alto y el ancho del sprite
setWidth(w);
setHeight(h);
@@ -15,6 +15,8 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
// Establece la posición X,Y del sprite
setPosX(x);
setPosY(y);
mPosXPrev = x;
mPosYPrev = y;
// Establece la velocidad X,Y del sprite
setVelX(velx);
@@ -43,7 +45,7 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
setSpriteClip(0, 0, w, h);
// Establece el centro de rotación
mCenter = {0,0};
mCenter = {0, 0};
// Establece el tipo de volteado
mFlip = SDL_FLIP_NONE;
@@ -84,6 +86,9 @@ void MovingSprite::move()
{
if (mEnabled)
{
mPosXPrev = mPosX;
mPosYPrev = mPosY;
mPosX += mVelX;
mPosY += mVelY;
@@ -302,4 +307,11 @@ SDL_Rect MovingSprite::getRect()
{
SDL_Rect rect = {(int)getPosX(), (int)getPosY(), getWidth(), getHeight()};
return rect;
}
// Deshace el último movimiento
void MovingSprite::undoMove()
{
mPosX = mPosXPrev;
mPosY = mPosYPrev;
}