Retocados nombres de variables antiguos
This commit is contained in:
@@ -22,12 +22,12 @@ Actor::Actor(actor_t actor)
|
||||
// Obten el resto de valores
|
||||
sprite->setPosX(actor.x);
|
||||
sprite->setPosY(actor.y);
|
||||
sprite->setVelX(actor.vx);
|
||||
sprite->setVelY(actor.vy);
|
||||
|
||||
// Inicializa el sprite con el resto de parametros comunes
|
||||
sprite->setWidth(actor.w);
|
||||
sprite->setHeight(actor.h);
|
||||
|
||||
sprite->setVelX(actor.vx);
|
||||
sprite->setVelY(actor.vy);
|
||||
|
||||
sprite->setFlip(actor.vx>0?SDL_FLIP_NONE:SDL_FLIP_HORIZONTAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,16 @@
|
||||
#ifndef ACTOR_H
|
||||
#define ACTOR_H
|
||||
|
||||
// Tipos de actores
|
||||
enum actor_name_e
|
||||
{
|
||||
a_moving_platform,
|
||||
a_key,
|
||||
a_heart,
|
||||
a_diamond,
|
||||
a_door
|
||||
};
|
||||
|
||||
// Estructura para pasar los datos de un enemigo
|
||||
struct actor_t
|
||||
{
|
||||
@@ -22,6 +32,7 @@ struct actor_t
|
||||
float y; // Posición inicial en el eje Y
|
||||
float vx; // Velocidad en el eje X
|
||||
float vy; // Velocidad en el eje Y
|
||||
actor_name_e name; // Tipo de actor
|
||||
};
|
||||
|
||||
// Clase Actor
|
||||
|
||||
@@ -42,7 +42,7 @@ int AnimatedSprite::getIndex(std::string name)
|
||||
// Calcula el frame correspondiente a la animación
|
||||
void AnimatedSprite::animate()
|
||||
{
|
||||
if (mEnabled)
|
||||
if (enabled)
|
||||
{
|
||||
// Calcula el frame actual a partir del contador
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].counter / animation[currentAnimation].speed;
|
||||
|
||||
@@ -23,7 +23,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||
section.name = SECTION_PROG_GAME;
|
||||
section.subsection = SUBSECTION_GAME_PLAY;
|
||||
|
||||
debug = false;
|
||||
debug = true;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -110,7 +110,7 @@ void Game::checkInput()
|
||||
if (input->checkInput(INPUT_BUTTON_3, REPEAT_FALSE))
|
||||
{
|
||||
delete map;
|
||||
map = new Map(asset->get("01.map"),renderer, asset);
|
||||
map = new Map(asset->get("01.map"), renderer, asset);
|
||||
delete player;
|
||||
player = new Player(renderer, asset, input, map);
|
||||
}
|
||||
@@ -138,14 +138,14 @@ void Game::renderDebugInfo()
|
||||
// Pinta el texto
|
||||
int line = 0;
|
||||
std::string text = "";
|
||||
|
||||
|
||||
text = "R - Reload player and map";
|
||||
debugText->write(1, 210, text, -1);
|
||||
|
||||
text = "D - Toggle debug mode";
|
||||
debugText->write(1, 216, text, -1);
|
||||
|
||||
text = std::to_string((int)player->sprite->getPosX()) + "," + std::to_string((int)player->sprite->getPosY());
|
||||
text = std::to_string((int)player->sprite->getPosX()) + "," + std::to_string((int)player->sprite->getPosY()) + "," + std::to_string((int)player->sprite->getWidth()) + "," + std::to_string((int)player->sprite->getHeight());
|
||||
debugText->write(0, line, text, -1);
|
||||
|
||||
text = "VY " + std::to_string(player->vy) + " " + std::to_string(player->jumpStrenght);
|
||||
@@ -169,8 +169,16 @@ void Game::renderDebugInfo()
|
||||
text = "state " + std::to_string(player->state);
|
||||
debugText->write(0, line += 6, text, -1);
|
||||
|
||||
text = map->getRoomFileName(b_top) + " " +map->getRoomFileName(b_right) + " " +map->getRoomFileName(b_bottom) + " " +map->getRoomFileName(b_left);
|
||||
text = map->getRoomFileName(b_top) + " " + map->getRoomFileName(b_right) + " " + map->getRoomFileName(b_bottom) + " " + map->getRoomFileName(b_left);
|
||||
debugText->write(0, line += 6, text, -1);
|
||||
|
||||
text = "ACTOR = " + std::to_string(player->checkActors());
|
||||
debugText->write(0, line += 6, text, -1);
|
||||
|
||||
// Pinta mascaras
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 128);
|
||||
SDL_Rect rect = player->sprite->getRect();
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
|
||||
// Cambia el mapa
|
||||
|
||||
@@ -116,6 +116,7 @@ bool Map::load(std::string file_path)
|
||||
actor_t actor;
|
||||
actor.asset = asset;
|
||||
actor.renderer = renderer;
|
||||
actor.name = a_moving_platform;
|
||||
SDL_Point p1, p2;
|
||||
|
||||
do
|
||||
@@ -266,11 +267,11 @@ bool Map::setActor(actor_t *actor, SDL_Point *p1, SDL_Point *p2, std::string var
|
||||
}
|
||||
else if (var == "width")
|
||||
{
|
||||
actor->w = std::stof(value);
|
||||
actor->w = std::stoi(value);
|
||||
}
|
||||
else if (var == "height")
|
||||
{
|
||||
actor->h = std::stof(value);
|
||||
actor->h = std::stoi(value);
|
||||
}
|
||||
else if (var == "x")
|
||||
{
|
||||
@@ -486,4 +487,20 @@ std::string Map::getRoomFileName(e_border border)
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
// Indica si hay colision con un actor a partir de un rectangulo
|
||||
int Map::actorCollision(SDL_Rect &rect)
|
||||
{
|
||||
int index = 0;
|
||||
for (auto actor : actors)
|
||||
{
|
||||
if (checkCollision(rect, actor->getCollider()))
|
||||
{
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -91,6 +91,9 @@ public:
|
||||
|
||||
// Devuelve el nombre del fichero de la habitación en funcion del borde
|
||||
std::string getRoomFileName(e_border border);
|
||||
|
||||
// Indica si hay colision con un actor a partir de un rectangulo
|
||||
int actorCollision(SDL_Rect &rect);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,50 +5,50 @@
|
||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Copia los punteros
|
||||
setTexture(texture);
|
||||
setRenderer(renderer);
|
||||
this->texture = texture;
|
||||
this->renderer = renderer;
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
setWidth(w);
|
||||
setHeight(h);
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
// Establece la posición X,Y del sprite
|
||||
setPosX(x);
|
||||
setPosY(y);
|
||||
mPosXPrev = x;
|
||||
mPosYPrev = y;
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
xPrev = x;
|
||||
yPrev = y;
|
||||
|
||||
// Establece la velocidad X,Y del sprite
|
||||
setVelX(velx);
|
||||
setVelY(vely);
|
||||
vx = velx;
|
||||
vy = vely;
|
||||
|
||||
// Establece la aceleración X,Y del sprite
|
||||
setAccelX(accelx);
|
||||
setAccelY(accely);
|
||||
ax = accelx;
|
||||
ay = accely;
|
||||
|
||||
// Establece el zoom W,H del sprite
|
||||
setZoomW(1);
|
||||
setZoomH(1);
|
||||
zoomW = 1;
|
||||
zoomH = 1;
|
||||
|
||||
// Establece el angulo con el que se dibujará
|
||||
setAngle(0.0);
|
||||
angle = (double)0;
|
||||
|
||||
// Establece los valores de rotacion
|
||||
setRotate(false);
|
||||
setRotateSpeed(0);
|
||||
setRotateAmount(0.0);
|
||||
rotateEnabled = false;
|
||||
rotateSpeed = 0;
|
||||
rotateAmount = (double)0;
|
||||
|
||||
// Contador interno
|
||||
mCounter = 0;
|
||||
counter = 0;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
setSpriteClip(0, 0, w, h);
|
||||
spriteClip = {0, 0, w, h};
|
||||
|
||||
// Establece el centro de rotación
|
||||
mCenter = {0, 0};
|
||||
center = {0, 0};
|
||||
|
||||
// Establece el tipo de volteado
|
||||
mFlip = SDL_FLIP_NONE;
|
||||
currentFlip = SDL_FLIP_NONE;
|
||||
};
|
||||
|
||||
// Destructor
|
||||
@@ -59,199 +59,199 @@ MovingSprite::~MovingSprite()
|
||||
// Reinicia todas las variables
|
||||
void MovingSprite::clear()
|
||||
{
|
||||
mPosX = 0.0f; // Posición en el eje X
|
||||
mPosY = 0.0f; // Posición en el eje Y
|
||||
x = 0.0f; // Posición en el eje X
|
||||
y = 0.0f; // Posición en el eje Y
|
||||
|
||||
mVelX = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
mVelY = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
vx = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
vy = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
|
||||
mAccelX = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
||||
mAccelY = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
||||
ax = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
||||
ay = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
mZoomW = 1.0f; // Zoom aplicado a la anchura
|
||||
mZoomH = 1.0f; // Zoom aplicado a la altura
|
||||
zoomW = 1.0f; // Zoom aplicado a la anchura
|
||||
zoomH = 1.0f; // Zoom aplicado a la altura
|
||||
|
||||
mAngle = 0.0; // Angulo para dibujarlo
|
||||
mRotate = false; // Indica si ha de rotar
|
||||
mCenter = {0, 0}; // Centro de rotación
|
||||
mRotateSpeed = 0; // Velocidad de giro
|
||||
mRotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
||||
mCounter = 0; // Contador interno
|
||||
angle = 0.0; // Angulo para dibujarlo
|
||||
rotateEnabled = false; // Indica si ha de rotar
|
||||
center = {0, 0}; // Centro de rotación
|
||||
rotateSpeed = 0; // Velocidad de giro
|
||||
rotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
||||
counter = 0; // Contador interno
|
||||
|
||||
mFlip = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||
currentFlip = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||
}
|
||||
|
||||
// Mueve el sprite
|
||||
void MovingSprite::move()
|
||||
{
|
||||
if (mEnabled)
|
||||
if (enabled)
|
||||
{
|
||||
mPosXPrev = mPosX;
|
||||
mPosYPrev = mPosY;
|
||||
xPrev = x;
|
||||
yPrev = y;
|
||||
|
||||
mPosX += mVelX;
|
||||
mPosY += mVelY;
|
||||
x += vx;
|
||||
y += vy;
|
||||
|
||||
mVelX += mAccelX;
|
||||
mVelY += mAccelY;
|
||||
vx += ax;
|
||||
vy += ay;
|
||||
}
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void MovingSprite::render()
|
||||
{
|
||||
if (mEnabled)
|
||||
mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip, mZoomW, mZoomH, mAngle, &mCenter, mFlip);
|
||||
if (enabled)
|
||||
texture->render(renderer, (int)x, (int)y, &spriteClip, zoomW, zoomH, angle, ¢er, currentFlip);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getPosX()
|
||||
{
|
||||
return mPosX;
|
||||
return x;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getPosY()
|
||||
{
|
||||
return mPosY;
|
||||
return y;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getVelX()
|
||||
{
|
||||
return mVelX;
|
||||
return vx;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getVelY()
|
||||
{
|
||||
return mVelY;
|
||||
return vy;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getAccelX()
|
||||
{
|
||||
return mAccelX;
|
||||
return ax;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getAccelY()
|
||||
{
|
||||
return mAccelY;
|
||||
return ay;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomW()
|
||||
{
|
||||
return mZoomW;
|
||||
return zoomW;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomH()
|
||||
{
|
||||
return mZoomH;
|
||||
return zoomH;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
double MovingSprite::getAngle()
|
||||
{
|
||||
return mAngle;
|
||||
return angle;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void MovingSprite::setPos(SDL_Rect rect)
|
||||
{
|
||||
mPosX = (float)rect.x;
|
||||
mPosY = (float)rect.y;
|
||||
x = (float)rect.x;
|
||||
y = (float)rect.y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosX(float x)
|
||||
void MovingSprite::setPosX(float value)
|
||||
{
|
||||
mPosX = x;
|
||||
x = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosY(float y)
|
||||
void MovingSprite::setPosY(float value)
|
||||
{
|
||||
mPosY = y;
|
||||
y = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelX(float x)
|
||||
void MovingSprite::setVelX(float value)
|
||||
{
|
||||
mVelX = x;
|
||||
vx = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelY(float y)
|
||||
void MovingSprite::setVelY(float value)
|
||||
{
|
||||
mVelY = y;
|
||||
vy = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelX(float x)
|
||||
void MovingSprite::setAccelX(float value)
|
||||
{
|
||||
mAccelX = x;
|
||||
ax = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelY(float y)
|
||||
void MovingSprite::setAccelY(float value)
|
||||
{
|
||||
mAccelY = y;
|
||||
ay = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomW(float w)
|
||||
void MovingSprite::setZoomW(float value)
|
||||
{
|
||||
mZoomW = w;
|
||||
zoomW = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomH(float h)
|
||||
void MovingSprite::setZoomH(float value)
|
||||
{
|
||||
mZoomH = h;
|
||||
zoomH = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAngle(double a)
|
||||
void MovingSprite::setAngle(double value)
|
||||
{
|
||||
mAngle = a;
|
||||
angle = value;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void MovingSprite::incAngle(double inc)
|
||||
void MovingSprite::incAngle(double value)
|
||||
{
|
||||
mAngle += inc;
|
||||
angle += value;
|
||||
}
|
||||
|
||||
// Decrementa el valor de la variable
|
||||
void MovingSprite::decAngle(double dec)
|
||||
void MovingSprite::decAngle(double value)
|
||||
{
|
||||
mAngle -= dec;
|
||||
angle -= value;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool MovingSprite::getRotate()
|
||||
{
|
||||
return mRotate;
|
||||
return rotateEnabled;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 MovingSprite::getRotateSpeed()
|
||||
{
|
||||
return mRotateSpeed;
|
||||
return rotateSpeed;
|
||||
}
|
||||
|
||||
// Establece la rotacion
|
||||
void MovingSprite::rotate()
|
||||
{
|
||||
if (mEnabled)
|
||||
if (mRotate)
|
||||
if (enabled)
|
||||
if (rotateEnabled)
|
||||
{
|
||||
if (mCounter % mRotateSpeed == 0)
|
||||
if (counter % rotateSpeed == 0)
|
||||
{
|
||||
incAngle(mRotateAmount);
|
||||
incAngle(rotateAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,26 +259,26 @@ void MovingSprite::rotate()
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotate(bool value)
|
||||
{
|
||||
mRotate = value;
|
||||
rotateEnabled = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateSpeed(Uint16 value)
|
||||
void MovingSprite::setRotateSpeed(int value)
|
||||
{
|
||||
mRotateSpeed = value;
|
||||
rotateSpeed = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateAmount(double value)
|
||||
{
|
||||
mRotateAmount = value;
|
||||
rotateAmount = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::disableRotate()
|
||||
{
|
||||
mRotate = false;
|
||||
mAngle = 0;
|
||||
rotateEnabled = false;
|
||||
angle = (double)0;
|
||||
}
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
@@ -287,62 +287,73 @@ void MovingSprite::update()
|
||||
move();
|
||||
rotate();
|
||||
|
||||
if (mEnabled)
|
||||
++mCounter %= 60000;
|
||||
if (enabled)
|
||||
{
|
||||
++counter %= 60000;
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void MovingSprite::switchRotate()
|
||||
{
|
||||
mRotateAmount *= -1;
|
||||
rotateAmount *= -1;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setFlip(SDL_RendererFlip flip)
|
||||
{
|
||||
mFlip = flip;
|
||||
currentFlip = flip;
|
||||
}
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void MovingSprite::flip()
|
||||
{
|
||||
mFlip = (mFlip==SDL_FLIP_HORIZONTAL)?SDL_FLIP_NONE:SDL_FLIP_HORIZONTAL;
|
||||
currentFlip = (currentFlip == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip MovingSprite::getFlip()
|
||||
{
|
||||
return mFlip;
|
||||
return currentFlip;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect MovingSprite::getRect()
|
||||
{
|
||||
SDL_Rect rect = {(int)getPosX(), (int)getPosY(), getWidth(), getHeight()};
|
||||
const SDL_Rect rect = {(int)x, (int)y, w, h};
|
||||
return rect;
|
||||
}
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void MovingSprite::setRect(SDL_Rect rect)
|
||||
{
|
||||
x = (float)rect.x;
|
||||
y = (float)rect.y;
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento
|
||||
void MovingSprite::undoMove()
|
||||
{
|
||||
mPosX = mPosXPrev;
|
||||
mPosY = mPosYPrev;
|
||||
x = xPrev;
|
||||
y = yPrev;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento en el eje X
|
||||
void MovingSprite::undoMoveX()
|
||||
{
|
||||
mPosX = mPosXPrev;
|
||||
x = xPrev;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento en el eje Y
|
||||
void MovingSprite::undoMoveY()
|
||||
{
|
||||
mPosY = mPosYPrev;
|
||||
y = yPrev;
|
||||
}
|
||||
|
||||
// Pone a cero las velocidades de desplacamiento
|
||||
void MovingSprite::clearVel()
|
||||
{
|
||||
mVelX = mVelY = 0;
|
||||
vx = vy = 0.0f;
|
||||
}
|
||||
@@ -10,28 +10,28 @@
|
||||
class MovingSprite : public Sprite
|
||||
{
|
||||
protected:
|
||||
float mPosX; // Posición en el eje X
|
||||
float mPosY; // Posición en el eje Y
|
||||
float x; // Posición en el eje X
|
||||
float y; // Posición en el eje Y
|
||||
|
||||
float mPosXPrev; // Posición anterior en el eje X
|
||||
float mPosYPrev; // Posición anterior en el eje Y
|
||||
float xPrev; // Posición anterior en el eje X
|
||||
float yPrev; // Posición anterior en el eje Y
|
||||
|
||||
float mVelX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
float mVelY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
float vx; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
float vy; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
|
||||
float mAccelX; // Aceleración en el eje X. Variación de la velocidad
|
||||
float mAccelY; // Aceleración en el eje Y. Variación de la velocidad
|
||||
float ax; // Aceleración en el eje X. Variación de la velocidad
|
||||
float ay; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
float mZoomW; // Zoom aplicado a la anchura
|
||||
float mZoomH; // Zoom aplicado a la altura
|
||||
float zoomW; // Zoom aplicado a la anchura
|
||||
float zoomH; // Zoom aplicado a la altura
|
||||
|
||||
double mAngle; // Angulo para dibujarlo
|
||||
bool mRotate; // Indica si ha de rotar
|
||||
Uint16 mRotateSpeed; // Velocidad de giro
|
||||
double mRotateAmount; // Cantidad de grados a girar en cada iteración
|
||||
Uint16 mCounter; // Contador interno
|
||||
SDL_Point mCenter; // Centro de rotación
|
||||
SDL_RendererFlip mFlip; // Indica como se voltea el sprite
|
||||
double angle; // Angulo para dibujarlo
|
||||
bool rotateEnabled; // Indica si ha de rotar
|
||||
int rotateSpeed; // Velocidad de giro
|
||||
double rotateAmount; // Cantidad de grados a girar en cada iteración
|
||||
int counter; // Contador interno
|
||||
SDL_Point center; // Centro de rotación
|
||||
SDL_RendererFlip currentFlip; // Indica como se voltea el sprite
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -92,43 +92,43 @@ public:
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float x);
|
||||
void setPosX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(float y);
|
||||
void setPosY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelX(float x);
|
||||
void setVelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelY(float y);
|
||||
void setVelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelX(float x);
|
||||
void setAccelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelY(float y);
|
||||
void setAccelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomW(float w);
|
||||
void setZoomW(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomH(float h);
|
||||
void setZoomH(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double a);
|
||||
void setAngle(double vaue);
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incAngle(double inc);
|
||||
void incAngle(double value);
|
||||
|
||||
// Decrementa el valor de la variable
|
||||
void decAngle(double dec);
|
||||
void decAngle(double value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotate(bool value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateSpeed(Uint16 value);
|
||||
void setRotateSpeed(int value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateAmount(double value);
|
||||
@@ -151,6 +151,9 @@ public:
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
|
||||
// Deshace el último movimiento
|
||||
void undoMove();
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input, Map *map)
|
||||
vx = 0;
|
||||
vy = 0;
|
||||
lastPosition = {(int)x, (int)y};
|
||||
const SDL_Rect rect = {(int)x, (int)y, 16, 24};
|
||||
sprite->setPos(rect);
|
||||
const SDL_Rect rect = {(int)x, (int)y, w, h};
|
||||
sprite->setRect(rect);
|
||||
sprite->setCurrentAnimation("stand");
|
||||
sprite->setFlip(SDL_FLIP_NONE);
|
||||
|
||||
@@ -65,9 +65,9 @@ Player::~Player()
|
||||
void Player::update()
|
||||
{
|
||||
checkInput();
|
||||
// addGravity();
|
||||
move();
|
||||
animate();
|
||||
checkActors();
|
||||
}
|
||||
|
||||
// Dibuja el objeto
|
||||
@@ -372,4 +372,11 @@ void Player::switchBorders()
|
||||
void Player::setMap(Map *map)
|
||||
{
|
||||
this->map = map;
|
||||
}
|
||||
|
||||
// Comprueba las interacciones con los actores
|
||||
int Player::checkActors()
|
||||
{
|
||||
SDL_Rect rect = sprite->getRect();
|
||||
return map->actorCollision(rect);
|
||||
}
|
||||
@@ -83,6 +83,9 @@ public:
|
||||
// Comprueba si el jugador tiene suelo debajo de los pies
|
||||
bool isOnFloor();
|
||||
|
||||
// Comprueba las interacciones con los actores
|
||||
int checkActors();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Player(SDL_Renderer *renderer, Asset *asset, Input *input, Map *map);
|
||||
|
||||
@@ -3,175 +3,181 @@
|
||||
// Constructor
|
||||
Sprite::Sprite(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece el alto y el ancho del sprite
|
||||
setWidth(w);
|
||||
setHeight(h);
|
||||
|
||||
// Establece la posición X,Y del sprite
|
||||
setPosX(x);
|
||||
setPosY(y);
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
// Establece el puntero al renderizador de la ventana
|
||||
setRenderer(renderer);
|
||||
this->renderer = renderer;
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
setTexture(texture);
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
setSpriteClip(x, y, w, h);
|
||||
spriteClip = {x, y, w, h};
|
||||
|
||||
// Inicializa variables
|
||||
setEnabled(true);
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
Sprite::Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece el alto y el ancho del sprite
|
||||
setWidth(rect.w);
|
||||
setHeight(rect.h);
|
||||
|
||||
// Establece la posición X,Y del sprite
|
||||
setPosX(rect.x);
|
||||
setPosY(rect.y);
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
|
||||
// Establece el puntero al renderizador de la ventana
|
||||
setRenderer(renderer);
|
||||
this->renderer = renderer;
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
setTexture(texture);
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
setSpriteClip(rect);
|
||||
spriteClip = {x, y, w, h};
|
||||
|
||||
// Inicializa variables
|
||||
setEnabled(true);
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Sprite::~Sprite()
|
||||
{
|
||||
mTexture = nullptr;
|
||||
mRenderer = nullptr;
|
||||
texture = nullptr;
|
||||
renderer = nullptr;
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render()
|
||||
{
|
||||
if (mEnabled)
|
||||
if (enabled)
|
||||
{
|
||||
mTexture->render(mRenderer, mPosX, mPosY, &mSpriteClip);
|
||||
texture->render(renderer, x, y, &spriteClip);
|
||||
}
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosX()
|
||||
{
|
||||
return mPosX;
|
||||
return x;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosY()
|
||||
{
|
||||
return mPosY;
|
||||
return y;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getWidth()
|
||||
{
|
||||
return mWidth;
|
||||
return w;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getHeight()
|
||||
{
|
||||
return mHeight;
|
||||
return h;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPos(SDL_Rect rect)
|
||||
{
|
||||
mPosX = rect.x;
|
||||
mPosY = rect.y;
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosX(int x)
|
||||
{
|
||||
mPosX = x;
|
||||
this->x = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosY(int y)
|
||||
{
|
||||
mPosY = y;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setWidth(int w)
|
||||
{
|
||||
mWidth = w;
|
||||
this->w = w;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setHeight(int h)
|
||||
{
|
||||
mHeight = h;
|
||||
this->h = h;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect Sprite::getSpriteClip()
|
||||
{
|
||||
return mSpriteClip;
|
||||
return spriteClip;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(SDL_Rect rect)
|
||||
{
|
||||
mSpriteClip = rect;
|
||||
spriteClip = rect;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(int x, int y, int w, int h)
|
||||
{
|
||||
mSpriteClip.x = x;
|
||||
mSpriteClip.y = y;
|
||||
mSpriteClip.w = w;
|
||||
mSpriteClip.h = h;
|
||||
spriteClip = {x, y, w, h};
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
LTexture *Sprite::getTexture()
|
||||
{
|
||||
return mTexture;
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setTexture(LTexture *texture)
|
||||
{
|
||||
mTexture = texture;
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
mRenderer = renderer;
|
||||
this->renderer = renderer;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setEnabled(bool value)
|
||||
{
|
||||
mEnabled = value;
|
||||
enabled = value;
|
||||
}
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool Sprite::isEnabled()
|
||||
{
|
||||
return mEnabled;
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect Sprite::getRect()
|
||||
{
|
||||
SDL_Rect rect = {getPosX(), getPosY(), getWidth(), getHeight()};
|
||||
SDL_Rect rect = {x, y, w, h};
|
||||
return rect;
|
||||
}
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void Sprite::setRect(SDL_Rect rect)
|
||||
{
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
}
|
||||
@@ -10,16 +10,16 @@
|
||||
class Sprite
|
||||
{
|
||||
protected:
|
||||
int mPosX; // Posición en el eje X donde dibujar el sprite
|
||||
int mPosY; // Posición en el eje Y donde dibujar el sprite
|
||||
Uint16 mWidth; // Ancho del sprite
|
||||
Uint16 mHeight; // Alto del sprite
|
||||
int x; // Posición en el eje X donde dibujar el sprite
|
||||
int y; // Posición en el eje Y donde dibujar el sprite
|
||||
int w; // Ancho del sprite
|
||||
int h; // Alto del sprite
|
||||
|
||||
SDL_Renderer *mRenderer; // Puntero al renderizador de la ventana
|
||||
LTexture *mTexture; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect mSpriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||
LTexture *texture; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect spriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
|
||||
bool mEnabled; // Indica si el sprite esta habilitado
|
||||
bool enabled; // Indica si el sprite esta habilitado
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -85,6 +85,9 @@ public:
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user