From 5234d77e77e4544ec84d230b170181d532ba398b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Thu, 18 Feb 2021 18:50:43 +0100 Subject: [PATCH] updated movingsprite.cpp --- source/movingsprite.cpp | 11 +++++++++-- source/movingsprite.h | 39 ++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/source/movingsprite.cpp b/source/movingsprite.cpp index 8954677..6bd0e5d 100644 --- a/source/movingsprite.cpp +++ b/source/movingsprite.cpp @@ -15,7 +15,8 @@ MovingSprite::~MovingSprite() } // 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 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); } -// Mueve el sprite +// Coloca el sprite en su nueva posición en funcion de la velocidad void MovingSprite::move() { mPosX += mVelX; mPosY += mVelY; +} + +// Actualiza las variables internas del sprite: posición y velocidad +void MovingSprite::update() +{ + move(); mVelX += mAccelX; mVelY += mAccelY; diff --git a/source/movingsprite.h b/source/movingsprite.h index f4bdcd6..bda4de5 100644 --- a/source/movingsprite.h +++ b/source/movingsprite.h @@ -16,62 +16,63 @@ public: ~MovingSprite(); // 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(); + // Actualiza las variables internas del sprite: posición y velocidad + void update(); + // Muestra el sprite por pantalla void render(); // Obten el valor de la variable float getPosX(); - + // Obten el valor de la variable float getPosY(); - + // Obten el valor de la variable float getVelX(); - + // Obten el valor de la variable float getVelY(); // Obten el valor de la variable float getAccelX(); - + // Obten el valor de la variable float getAccelY(); - + // Establece el valor de la variable void setPosX(float x); - + // Establece el valor de la variable void setPosY(float y); // Establece el valor de la variable void setVelX(float x); - + // Establece el valor de la variable void setVelY(float y); // Establece el valor de la variable void setAccelX(float x); - + // Establece el valor de la variable void setAccelY(float y); private: - // Posición - float mPosX; - float mPosY; + float mPosX; // Posición en el eje X + float mPosY; // Posición en el eje Y - // Velocidad - float mVelX; - float mVelY; + float mVelX; // Velocidad en el eje X + float mVelY; // Velocidad en el eje Y - // Aceleración - float mAccelX; - float mAccelY; + float mAccelX; // Aceleración en el eje X + float mAccelY; // Aceleración en el eje Y }; #endif