migracio a SDL3
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
#include "game.h"
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWwrite
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks, SDL_Delay
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_FOCUS_LOST
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for max, min
|
||||
#include <fstream> // for basic_ifstream
|
||||
@@ -14,7 +11,7 @@
|
||||
#include "fade.h" // for Fade, FADE_CENTER
|
||||
#include "input.h" // for inputs_e, Input, REPEAT_TRUE, REPEAT_FALSE
|
||||
#include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
|
||||
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_LoadSound
|
||||
#include "jail_audio.hpp" // for JA_PlaySound, JA_DeleteSound, JA_LoadSound
|
||||
#include "lang.h" // for Lang
|
||||
#include "menu.h" // for Menu
|
||||
#include "movingsprite.h" // for MovingSprite
|
||||
@@ -624,7 +621,7 @@ bool Game::loadScoreFile()
|
||||
bool success = true;
|
||||
const std::string p = asset->get("score.bin");
|
||||
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "r+b");
|
||||
|
||||
// El fichero no existe
|
||||
if (file == nullptr)
|
||||
@@ -635,7 +632,7 @@ bool Game::loadScoreFile()
|
||||
}
|
||||
|
||||
// Creamos el fichero para escritura
|
||||
file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
file = SDL_IOFromFile(p.c_str(), "w+b");
|
||||
if (file != nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
@@ -647,11 +644,11 @@ bool Game::loadScoreFile()
|
||||
for (int i = 0; i < TOTAL_SCORE_DATA; ++i)
|
||||
{
|
||||
scoreDataFile[i] = 0;
|
||||
SDL_RWwrite(file, &scoreDataFile[i], sizeof(Uint32), 1);
|
||||
SDL_WriteIO(file, &scoreDataFile[i], sizeof(Uint32));
|
||||
}
|
||||
|
||||
// Cerramos el fichero
|
||||
SDL_RWclose(file);
|
||||
SDL_CloseIO(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -671,10 +668,10 @@ bool Game::loadScoreFile()
|
||||
std::cout << "Reading file " << filename.c_str() << std::endl;
|
||||
}
|
||||
for (int i = 0; i < TOTAL_SCORE_DATA; ++i)
|
||||
SDL_RWread(file, &scoreDataFile[i], sizeof(Uint32), 1);
|
||||
SDL_ReadIO(file, &scoreDataFile[i], sizeof(Uint32));
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
SDL_CloseIO(file);
|
||||
}
|
||||
|
||||
// Establece el valor de la máxima puntuación a partir del vector con los datos
|
||||
@@ -702,7 +699,7 @@ bool Game::loadDemoFile()
|
||||
bool success = true;
|
||||
const std::string p = asset->get("demo.bin");
|
||||
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "r+b");
|
||||
|
||||
// El fichero no existe
|
||||
if (file == nullptr)
|
||||
@@ -713,7 +710,7 @@ bool Game::loadDemoFile()
|
||||
}
|
||||
|
||||
// Creamos el fichero para escritura
|
||||
file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
file = SDL_IOFromFile(p.c_str(), "w+b");
|
||||
if (file != nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
@@ -731,11 +728,11 @@ bool Game::loadDemoFile()
|
||||
demo.keys.fireLeft = 0;
|
||||
demo.keys.fireRight = 0;
|
||||
demo.dataFile[i] = demo.keys;
|
||||
SDL_RWwrite(file, &demo.dataFile[i], sizeof(demoKeys_t), 1);
|
||||
SDL_WriteIO(file, &demo.dataFile[i], sizeof(demoKeys_t));
|
||||
}
|
||||
|
||||
// Cerramos el fichero
|
||||
SDL_RWclose(file);
|
||||
SDL_CloseIO(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -755,10 +752,10 @@ bool Game::loadDemoFile()
|
||||
std::cout << "Reading file " << filename.c_str() << std::endl;
|
||||
}
|
||||
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
||||
SDL_RWread(file, &demo.dataFile[i], sizeof(demoKeys_t), 1);
|
||||
SDL_ReadIO(file, &demo.dataFile[i], sizeof(demoKeys_t));
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
SDL_CloseIO(file);
|
||||
}
|
||||
|
||||
return success;
|
||||
@@ -770,13 +767,13 @@ bool Game::saveScoreFile()
|
||||
bool success = true;
|
||||
const std::string p = asset->get("score.bin");
|
||||
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "w+b");
|
||||
if (file != nullptr)
|
||||
{
|
||||
// Guardamos los datos
|
||||
for (int i = 0; i < TOTAL_SCORE_DATA; ++i)
|
||||
{
|
||||
SDL_RWwrite(file, &scoreDataFile[i], sizeof(Uint32), 1);
|
||||
SDL_WriteIO(file, &scoreDataFile[i], sizeof(Uint32));
|
||||
}
|
||||
|
||||
if (options->console)
|
||||
@@ -785,7 +782,7 @@ bool Game::saveScoreFile()
|
||||
}
|
||||
|
||||
// Cerramos el fichero
|
||||
SDL_RWclose(file);
|
||||
SDL_CloseIO(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -805,13 +802,13 @@ bool Game::saveDemoFile()
|
||||
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
if (demo.recording)
|
||||
{
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "w+b");
|
||||
if (file != nullptr)
|
||||
{
|
||||
// Guardamos los datos
|
||||
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
||||
{
|
||||
SDL_RWwrite(file, &demo.dataFile[i], sizeof(demoKeys_t), 1);
|
||||
SDL_WriteIO(file, &demo.dataFile[i], sizeof(demoKeys_t));
|
||||
}
|
||||
|
||||
if (options->console)
|
||||
@@ -820,7 +817,7 @@ bool Game::saveDemoFile()
|
||||
}
|
||||
|
||||
// Cerramos el fichero
|
||||
SDL_RWclose(file);
|
||||
SDL_CloseIO(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1679,12 +1676,12 @@ void Game::renderScoreBoard()
|
||||
{ // Pinta el fondo del marcador del color de la dificultad
|
||||
SDL_SetRenderDrawColor(renderer, difficultyColor.r, difficultyColor.g, difficultyColor.b, 255);
|
||||
}
|
||||
SDL_Rect rect = {0, 160, 256, 32};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
SDL_FRect fRect = {0, 160, 256, 32};
|
||||
SDL_RenderFillRect(renderer, &fRect);
|
||||
|
||||
// Dibuja la linea que separa el marcador de la zona de juego
|
||||
SDL_SetRenderDrawColor(renderer, 13, 26, 43, 255);
|
||||
SDL_RenderDrawLine(renderer, 0, 160, 255, 160);
|
||||
SDL_RenderLine(renderer, 0, 160, 255, 160);
|
||||
|
||||
// Anclas para los elementos
|
||||
const int offset1 = 162;
|
||||
@@ -1867,27 +1864,27 @@ void Game::renderDeathFade(int counter)
|
||||
if (counter < 150)
|
||||
{
|
||||
// 192 / 6 = 32, 6 cuadrados de 32 pixeles
|
||||
SDL_Rect rect[12];
|
||||
Uint8 h = counter / 3;
|
||||
SDL_FRect rect[12];
|
||||
float h = (float)(counter / 3);
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
rect[i].x = 0;
|
||||
rect[i].y = i * 16;
|
||||
rect[i].w = GAMECANVAS_WIDTH;
|
||||
rect[i].y = (float)(i * 16);
|
||||
rect[i].w = (float)GAMECANVAS_WIDTH;
|
||||
if (i == 0)
|
||||
{
|
||||
rect[i].h = h;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect[i].h = std::max(rect[i - 1].h - 3, 0);
|
||||
rect[i].h = std::max(rect[i - 1].h - 3.0f, 0.0f);
|
||||
}
|
||||
SDL_RenderFillRect(renderer, &rect[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||
SDL_FRect rect = {0, 0, (float)GAMECANVAS_WIDTH, (float)GAMECANVAS_HEIGHT};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
}
|
||||
@@ -2773,6 +2770,9 @@ void Game::updateEnemyDeployCounter()
|
||||
// Actualiza el juego
|
||||
void Game::update()
|
||||
{
|
||||
// Actualiza el audio
|
||||
JA_Update();
|
||||
|
||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
{
|
||||
@@ -3581,12 +3581,12 @@ void Game::updateGameOverScreen()
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
if (eventHandler->type == SDL_EVENT_QUIT)
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
}
|
||||
else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
|
||||
else if (eventHandler->type == SDL_EVENT_KEY_DOWN && eventHandler->key.repeat == 0)
|
||||
{
|
||||
if (gameCompleted)
|
||||
{
|
||||
@@ -3842,24 +3842,21 @@ void Game::checkEvents()
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
if (eventHandler->type == SDL_EVENT_QUIT)
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
else if (eventHandler->type == SDL_WINDOWEVENT)
|
||||
else if (eventHandler->type == SDL_EVENT_WINDOW_FOCUS_LOST)
|
||||
{
|
||||
if (eventHandler->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
|
||||
{
|
||||
section->subsection = SUBSECTION_GAME_PAUSE;
|
||||
}
|
||||
section->subsection = SUBSECTION_GAME_PAUSE;
|
||||
}
|
||||
|
||||
#ifdef PAUSE
|
||||
else if (eventHandler->type == SDL_KEYDOWN)
|
||||
else if (eventHandler->type == SDL_EVENT_KEY_DOWN)
|
||||
{
|
||||
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_P)
|
||||
if (eventHandler->key.scancode == SDL_SCANCODE_P)
|
||||
{
|
||||
pause = !pause;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user