Muntat a c++14 per a make_unique

Mes autos, const i constexpr perl codi
Ara la classe Screen es un poc pitjor
This commit is contained in:
2024-10-06 14:58:00 +02:00
parent 25a2753b13
commit afe092c742
16 changed files with 290 additions and 381 deletions

View File

@@ -1,20 +1,9 @@
#include "sprite.h"
#include "texture.h" // for Texture
#include "texture.h" // for Texture
// Constructor
Sprite::Sprite(int x, int y, int w, int h, Texture *texture)
Sprite::Sprite(int x, int y, int w, int h, Texture *texture) : x(x), y(y), w(w), h(h), texture(texture)
{
// Establece la posición X,Y del sprite
this->x = x;
this->y = y;
// Establece el alto y el ancho del sprite
this->w = w;
this->h = h;
// Establece la textura donde están los gráficos para el sprite
this->texture = texture;
// Establece el rectangulo de donde coger la imagen
spriteClip = {0, 0, w, h};
@@ -22,19 +11,8 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture)
enabled = true;
}
Sprite::Sprite(SDL_Rect rect, Texture *texture)
Sprite::Sprite(SDL_Rect rect, Texture *texture): x(rect.x), y(rect.y), w(rect.w), h(rect.h), texture(texture)
{
// Establece la posición X,Y del sprite
x = rect.x;
y = rect.y;
// Establece el alto y el ancho del sprite
w = rect.w;
h = rect.h;
// Establece la textura donde están los gráficos para el sprite
this->texture = texture;
// Establece el rectangulo de donde coger la imagen
spriteClip = {0, 0, w, h};
@@ -58,25 +36,25 @@ void Sprite::render()
}
// Obten el valor de la variable
int Sprite::getPosX()
int Sprite::getPosX() const
{
return x;
}
// Obten el valor de la variable
int Sprite::getPosY()
int Sprite::getPosY() const
{
return y;
}
// Obten el valor de la variable
int Sprite::getWidth()
int Sprite::getWidth() const
{
return w;
}
// Obten el valor de la variable
int Sprite::getHeight()
int Sprite::getHeight() const
{
return h;
}
@@ -122,7 +100,7 @@ void Sprite::setHeight(int h)
}
// Obten el valor de la variable
SDL_Rect Sprite::getSpriteClip()
SDL_Rect Sprite::getSpriteClip() const
{
return spriteClip;
}
@@ -158,16 +136,15 @@ void Sprite::setEnabled(bool value)
}
// Comprueba si el objeto está habilitado
bool Sprite::isEnabled()
bool Sprite::isEnabled() const
{
return enabled;
}
// Devuelve el rectangulo donde está el sprite
SDL_Rect Sprite::getRect()
SDL_Rect Sprite::getRect() const
{
SDL_Rect rect = {x, y, w, h};
return rect;
return (SDL_Rect){x, y, w, h};
}
// Establece los valores de posición y tamaño del sprite