updated movingsprite.cpp
This commit is contained in:
@@ -15,7 +15,8 @@ MovingSprite::~MovingSprite()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void MovingSprite::init(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
|
void MovingSprite::init(float x, float y, Uint16 w, Uint16 h, float velx, float vely, float accelx, float accely,
|
||||||
|
LTexture *texture, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
// Establece el alto y el ancho del sprite
|
// Establece el alto y el ancho del sprite
|
||||||
setWidth(w);
|
setWidth(w);
|
||||||
@@ -43,11 +44,17 @@ void MovingSprite::init(float x, float y, int w, int h, float velx, float vely,
|
|||||||
setSpriteClip(0, 0, w, h);
|
setSpriteClip(0, 0, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el sprite
|
// Coloca el sprite en su nueva posición en funcion de la velocidad
|
||||||
void MovingSprite::move()
|
void MovingSprite::move()
|
||||||
{
|
{
|
||||||
mPosX += mVelX;
|
mPosX += mVelX;
|
||||||
mPosY += mVelY;
|
mPosY += mVelY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables internas del sprite: posición y velocidad
|
||||||
|
void MovingSprite::update()
|
||||||
|
{
|
||||||
|
move();
|
||||||
|
|
||||||
mVelX += mAccelX;
|
mVelX += mAccelX;
|
||||||
mVelY += mAccelY;
|
mVelY += mAccelY;
|
||||||
|
|||||||
@@ -16,11 +16,15 @@ public:
|
|||||||
~MovingSprite();
|
~MovingSprite();
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void init(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer);
|
void init(float x, float y, Uint16 w, Uint16 h, float velx, float vely, float accelx, float accely,
|
||||||
|
LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Mueve el sprite
|
// Coloca el sprite en su nueva posición en funcion de la velocidad
|
||||||
void move();
|
void move();
|
||||||
|
|
||||||
|
// Actualiza las variables internas del sprite: posición y velocidad
|
||||||
|
void update();
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
@@ -61,17 +65,14 @@ public:
|
|||||||
void setAccelY(float y);
|
void setAccelY(float y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Posición
|
float mPosX; // Posición en el eje X
|
||||||
float mPosX;
|
float mPosY; // Posición en el eje Y
|
||||||
float mPosY;
|
|
||||||
|
|
||||||
// Velocidad
|
float mVelX; // Velocidad en el eje X
|
||||||
float mVelX;
|
float mVelY; // Velocidad en el eje Y
|
||||||
float mVelY;
|
|
||||||
|
|
||||||
// Aceleración
|
float mAccelX; // Aceleración en el eje X
|
||||||
float mAccelX;
|
float mAccelY; // Aceleración en el eje Y
|
||||||
float mAccelY;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user