forked from jaildesigner-jailgames/jaildoctors_dilemma
Animatedsprite ya no permite indices fuera de rango
This commit is contained in:
@@ -32,7 +32,7 @@ int AnimatedSprite::getIndex(std::string name)
|
||||
|
||||
for (auto a : animation)
|
||||
{
|
||||
++index;
|
||||
index++;
|
||||
if (a.name == name)
|
||||
{
|
||||
return index;
|
||||
@@ -77,7 +77,7 @@ void AnimatedSprite::animate()
|
||||
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
||||
|
||||
// Incrementa el contador de la animacion
|
||||
++animation[currentAnimation].counter;
|
||||
animation[currentAnimation].counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
int framesPerRow = 0;
|
||||
int frameWidth = 0;
|
||||
int frameHeight = 0;
|
||||
int maxTiles = 0;
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
@@ -192,7 +193,8 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
int numTile = std::stoi(tmp);
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
||||
rect.x = (numTile % framesPerRow) * frameWidth;
|
||||
rect.y = (numTile / framesPerRow) * frameHeight;
|
||||
buffer.frames.push_back(rect);
|
||||
@@ -227,12 +229,6 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
else if (line.substr(0, pos) == "frameWidth")
|
||||
{
|
||||
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
||||
|
||||
// Normaliza valores
|
||||
if (framesPerRow == 0)
|
||||
{
|
||||
framesPerRow = texture->getWidth() / frameWidth;
|
||||
}
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frameHeight")
|
||||
@@ -245,6 +241,19 @@ bool AnimatedSprite::load(std::string filePath)
|
||||
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
if (framesPerRow == 0 && frameWidth > 0)
|
||||
{
|
||||
framesPerRow = texture->getWidth() / frameWidth;
|
||||
}
|
||||
|
||||
if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0)
|
||||
{
|
||||
const int w = texture->getWidth() / frameWidth;
|
||||
const int h = texture->getHeight() / frameHeight;
|
||||
maxTiles = w * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ void Credits::fillTexture()
|
||||
for (auto t:texts)
|
||||
{
|
||||
text->write(0, i * size, t);
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
@@ -134,7 +134,7 @@ void Credits::update()
|
||||
checkEventHandler();
|
||||
|
||||
// Incrementa el contador
|
||||
++counter;
|
||||
counter++;
|
||||
|
||||
// Comprueba si ha terminado la sección
|
||||
if (counter > 1000)
|
||||
|
||||
@@ -18,17 +18,17 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, D
|
||||
// ****
|
||||
// this->debug->setEnabled(true);
|
||||
|
||||
//currentRoom = "11.room";
|
||||
//spawnPoint = {2 * 8, 5 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
// currentRoom = "11.room";
|
||||
// spawnPoint = {2 * 8, 5 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
|
||||
//currentRoom = "06.room";
|
||||
//spawnPoint = {14 * 8, 9 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
// currentRoom = "06.room";
|
||||
// spawnPoint = {14 * 8, 9 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
|
||||
//currentRoom = "60.room";
|
||||
//const int x = 16;
|
||||
//const int y = 13;
|
||||
//spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
// ****
|
||||
// currentRoom = "60.room";
|
||||
// const int x = 16;
|
||||
// const int y = 13;
|
||||
// spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
// ****
|
||||
|
||||
// Crea los objetos
|
||||
scoreboard = new ScoreBoard(renderer, asset, &board);
|
||||
@@ -320,7 +320,7 @@ bool Game::changeRoom(std::string file)
|
||||
board.color = (c.r + c.g + c.b == 0) ? stringToColor("white") : c; // Si el color es negrom cambialo a blanco
|
||||
if (roomTracker->addRoom(file))
|
||||
{ // Incrementa el contador de habitaciones visitadas
|
||||
++board.rooms;
|
||||
board.rooms++;
|
||||
}
|
||||
|
||||
// Pasa la nueva habitación al jugador
|
||||
@@ -422,7 +422,7 @@ void Game::reLoadTextures()
|
||||
void Game::setBlackScreen()
|
||||
{
|
||||
blackScreen = true;
|
||||
//screen->setspectrumFade();
|
||||
// screen->setspectrumFade();
|
||||
}
|
||||
|
||||
// Actualiza las variables relativas a la pantalla en negro
|
||||
@@ -430,18 +430,15 @@ void Game::updateBlackScreen()
|
||||
{
|
||||
if (blackScreen)
|
||||
{
|
||||
//if (screen->spectrumFadeEnded())
|
||||
blackScreenCounter++;
|
||||
if (blackScreenCounter > 10)
|
||||
{
|
||||
++blackScreenCounter;
|
||||
if (blackScreenCounter > 10)
|
||||
{
|
||||
blackScreen = false;
|
||||
blackScreenCounter = 0;
|
||||
blackScreen = false;
|
||||
blackScreenCounter = 0;
|
||||
|
||||
player->resume();
|
||||
room->resume();
|
||||
screen->setBorderColor(room->getBorderColor());
|
||||
}
|
||||
player->resume();
|
||||
room->resume();
|
||||
screen->setBorderColor(room->getBorderColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,15 +41,15 @@ private:
|
||||
Uint8 scancode; // Scancode asociado
|
||||
bool active; // Indica si está activo
|
||||
};
|
||||
keyBindings_t keyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
|
||||
struct GameControllerBindings_t
|
||||
{
|
||||
SDL_GameControllerButton button; // GameControllerButton asociado
|
||||
bool active; // Indica si está activo
|
||||
};
|
||||
GameControllerBindings_t gameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
|
||||
keyBindings_t keyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
GameControllerBindings_t gameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
||||
int numGamepads; // Numero de mandos conectados
|
||||
|
||||
@@ -101,11 +101,11 @@ void Intro::updateCounter()
|
||||
{
|
||||
JA_PlayMusic(loadingSound2);
|
||||
}
|
||||
++counter;
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
++preCounter;
|
||||
preCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ private:
|
||||
int preCounter; // Contador previo para realizar una pausa inicial
|
||||
int counter; // Contador
|
||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
int loadCounter; // Contador para controlar las cargas
|
||||
bool load1, load2;
|
||||
JA_Music loadingSound1, loadingSound2, loadingSound3;
|
||||
|
||||
@@ -58,7 +58,7 @@ void Item::render()
|
||||
// Actualiza las variables del objeto
|
||||
void Item::update()
|
||||
{
|
||||
++counter;
|
||||
counter++;
|
||||
}
|
||||
|
||||
// Obtiene el rectangulo de colision del objeto
|
||||
|
||||
@@ -23,8 +23,8 @@ struct item_t
|
||||
int y; // Posicion del item en pantalla
|
||||
int tile; // Numero de tile dentro de la textura
|
||||
int counter; // Contador inicial. Es el que lo hace cambiar de color
|
||||
color_t color1;
|
||||
color_t color2;
|
||||
color_t color1; // Uno de los dos colores que se utiliza para el item
|
||||
color_t color2; // Uno de los dos colores que se utiliza para el item
|
||||
};
|
||||
|
||||
// Clase Item
|
||||
|
||||
@@ -65,7 +65,7 @@ int ItemTracker::findByName(std::string name)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -82,7 +82,7 @@ int ItemTracker::findByPos(int index, SDL_Point pos)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@@ -227,7 +227,7 @@ void Logo::update()
|
||||
checkEventHandler();
|
||||
|
||||
// Incrementa el contador
|
||||
++counter;
|
||||
counter++;
|
||||
|
||||
// Gestiona el logo de JAILGAME
|
||||
updateJAILGAMES();
|
||||
|
||||
@@ -27,8 +27,8 @@ private:
|
||||
std::vector<color_t> color; // Vector con los colores para el fade
|
||||
int counter; // Contador
|
||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
int initFade; // Tiempo del contador cuando inicia el fade a negro
|
||||
int endLogo; // Tiempo del contador para terminar el logo
|
||||
int postLogo; // Tiempo que dura el logo con el fade al maximo
|
||||
|
||||
@@ -232,7 +232,7 @@ void Player::checkState()
|
||||
{
|
||||
vx = 0.0f;
|
||||
vy = maxVY;
|
||||
++fallCounter;
|
||||
fallCounter++;
|
||||
playFallSound();
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ void Player::checkState()
|
||||
|
||||
else if (state == s_jumping)
|
||||
{
|
||||
++jumpCounter;
|
||||
jumpCounter++;
|
||||
playJumpSound();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,19 +865,19 @@ void Room::setBottomSurfaces()
|
||||
line.x1 = (tile[i] % mapWidth) * tileSize;
|
||||
line.y = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
|
||||
lastOne = i;
|
||||
++i;
|
||||
i++;
|
||||
|
||||
while (tile[i] == tile[i - 1] + 1)
|
||||
{
|
||||
lastOne = i;
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
|
||||
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
||||
bottomSurfaces.push_back(line);
|
||||
if (tile[i] == -1)
|
||||
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -912,19 +912,19 @@ void Room::setTopSurfaces()
|
||||
line.x1 = (tile[i] % mapWidth) * tileSize;
|
||||
line.y = (tile[i] / mapWidth) * tileSize;
|
||||
lastOne = i;
|
||||
++i;
|
||||
i++;
|
||||
|
||||
while (tile[i] == tile[i - 1] + 1)
|
||||
{
|
||||
lastOne = i;
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
|
||||
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
||||
topSurfaces.push_back(line);
|
||||
if (tile[i] == -1)
|
||||
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -959,11 +959,11 @@ void Room::setLeftSurfaces()
|
||||
line.y1 = ((tile[i] / mapWidth) * tileSize);
|
||||
while (tile[i] + mapWidth == tile[i + 1])
|
||||
{
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
|
||||
leftSurfaces.push_back(line);
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -997,11 +997,11 @@ void Room::setRightSurfaces()
|
||||
line.y1 = ((tile[i] / mapWidth) * tileSize);
|
||||
while (tile[i] + mapWidth == tile[i + 1])
|
||||
{
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
|
||||
rightSurfaces.push_back(line);
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1037,7 +1037,7 @@ void Room::setLeftSlopes()
|
||||
lastOneFound = lookingFor;
|
||||
lookingFor += mapWidth + 1;
|
||||
found.erase(found.begin() + i);
|
||||
--i;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
line.x2 = ((lastOneFound % mapWidth) * tileSize) + tileSize - 1;
|
||||
@@ -1078,7 +1078,7 @@ void Room::setRightSlopes()
|
||||
lastOneFound = lookingFor;
|
||||
lookingFor += mapWidth - 1;
|
||||
found.erase(found.begin() + i);
|
||||
--i;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
line.x2 = (lastOneFound % mapWidth) * tileSize;
|
||||
|
||||
@@ -129,7 +129,7 @@ void ScoreBoard::render()
|
||||
// Actualiza las variables del objeto
|
||||
void ScoreBoard::update()
|
||||
{
|
||||
++counter;
|
||||
counter++;
|
||||
sprite->update();
|
||||
|
||||
if (!paused)
|
||||
|
||||
@@ -115,7 +115,7 @@ void Screen::setVideoMode(int fullScreenMode)
|
||||
int scale = 0;
|
||||
while (((gameCanvasWidth * (scale + 1)) <= screenWidth) && ((gameCanvasHeight * (scale + 1)) <= screenHeight))
|
||||
{
|
||||
++scale;
|
||||
scale++;
|
||||
}
|
||||
|
||||
dest.w = gameCanvasWidth * scale;
|
||||
@@ -259,7 +259,7 @@ void Screen::updateFade()
|
||||
return;
|
||||
}
|
||||
|
||||
++fadeCounter;
|
||||
fadeCounter++;
|
||||
if (fadeCounter > fadeLenght)
|
||||
{
|
||||
iniFade();
|
||||
@@ -325,7 +325,7 @@ void Screen::updateSpectrumFade()
|
||||
return;
|
||||
}
|
||||
|
||||
++spectrumFadeCounter;
|
||||
spectrumFadeCounter++;
|
||||
if (spectrumFadeCounter > spectrumFadeLenght)
|
||||
{
|
||||
iniSpectrumFade();
|
||||
|
||||
@@ -26,7 +26,7 @@ Text::~Text()
|
||||
void Text::init()
|
||||
{
|
||||
// Inicializa a cero el vector con las coordenadas
|
||||
for (int i = 0; i < 128; i++)
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = 0;
|
||||
offset[i].y = 0;
|
||||
@@ -44,7 +44,7 @@ void Text::init()
|
||||
sprite->setSpriteClip(0, 0, sprite->getWidth(), sprite->getHeight());
|
||||
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
for (int i = 32; i < 128; i++)
|
||||
for (int i = 32; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = ((i - 32) % 15) * boxWidth;
|
||||
offset[i].y = ((i - 32) / 15) * boxHeight;
|
||||
@@ -131,7 +131,7 @@ int Text::lenght(std::string text, int kerning)
|
||||
{
|
||||
int shift = 0;
|
||||
|
||||
for (int i = 0; i < (int)text.length(); i++)
|
||||
for (int i = 0; i < (int)text.length(); ++i)
|
||||
shift += (offset[int(text[i])].w + kerning);
|
||||
|
||||
// Descuenta el kerning del último caracter
|
||||
@@ -164,7 +164,9 @@ void Text::initOffsetFromFile()
|
||||
{
|
||||
// Almacena solo las lineas impares
|
||||
if (line_read % 2 == 1)
|
||||
{
|
||||
offset[index++].w = std::stoi(buffer);
|
||||
}
|
||||
|
||||
// Limpia el buffer
|
||||
buffer.clear();
|
||||
|
||||
@@ -22,7 +22,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
longText = "HEY JAILERS!! IT'S 2022 AND WE'RE STILL ROCKING LIKE IT'S 1998!!! HAVE YOU HEARD IT? JAILGAMES ARE BACK!! YEEESSS BACK!! MORE THAN 10 TITLES ON JAILDOC'S KITCHEN!! THATS A LOOOOOOT OF JAILGAMES, BUT WHICH ONE WILL STRIKE FIRST? THERE IS ALSO A NEW DEVICE TO COME P.A.C.O. THAT WILL BLOW YOUR MIND WITH JAILGAMES ON THE GO. BUT WAIT! WHAT'S THAT BEAUTY I'M SEEING RIGHT OVER THERE?? OOOH THAT TINY MINIASCII IS PURE LOVE!! I WANT TO LICK EVERY BYTE OF IT!! OH SHIT! AND DON'T FORGET TO BRING BACK THOSE OLD AND FAT MS-DOS JAILGAMES TO GITHUB TO KEEP THEM ALIVE!! WHAT WILL BE THE NEXT JAILDOC RELEASE? WHAT WILL BE THE NEXT PROJECT TO COME ALIVE?? OH BABY WE DON'T KNOW BUT HERE YOU CAN FIND THE ANSWER, YOU JUST HAVE TO COMPLETE JAILDOCTOR'S DILEMMA ... COULD YOU?";
|
||||
for (int i = 0; i < (int)longText.length(); i++)
|
||||
for (int i = 0; i < (int)longText.length(); ++i)
|
||||
{
|
||||
letter_t l;
|
||||
l.letter = longText.substr(i, 1);
|
||||
@@ -108,7 +108,7 @@ void Title::checkEventHandler()
|
||||
// Actualiza la marquesina
|
||||
void Title::updateMarquee()
|
||||
{
|
||||
for (int i = 0; i < (int)letters.size(); i++)
|
||||
for (int i = 0; i < (int)letters.size(); ++i)
|
||||
{
|
||||
if (letters[i].enabled)
|
||||
{
|
||||
|
||||
4
todo.txt
4
todo.txt
@@ -9,7 +9,7 @@ x (A) Decidir un diseño para qué sucede en caso de morir: Recordar el punto po
|
||||
x (A) Crear tiles que maten {cm:2022-08-29}
|
||||
x (A) Modificar el salto para que coincida con el del JSW, no ha de colisionar lateralmente
|
||||
(A) Crear tiles que arrastren, tipo cinta transportadora
|
||||
(A) Tiles animados
|
||||
x (A) Tiles animados
|
||||
x (A) Tile que maten (o enemigos?)
|
||||
x (A) Cuando mueres, pantalla negra entre vida y vida
|
||||
x (A) Morir al caer de alto
|
||||
@@ -44,7 +44,7 @@ x (A) La pantalla de titulo no tiene menu, solo un PRESS ENTER TO PLAY
|
||||
x (A) Poner el mapa/jugador en pausa
|
||||
x (A) El color del borde se pierde al morir por la pantalla negra
|
||||
|
||||
(B) El fichero ani ha de calcular cuantos frames hay a partir del tamaño y ver que no hay ningun indice incorrecto
|
||||
x (B) El fichero ani ha de calcular cuantos frames hay a partir del tamaño y ver que no hay ningun indice incorrecto
|
||||
x (B) Así como no necesitar lo de frames per row
|
||||
(B) Le ha de pasar el w y h al sprite
|
||||
(B) Lo enemigos han de coger el ancho y alto del fichero ani (y si no hay?)
|
||||
|
||||
Reference in New Issue
Block a user