Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cf19194e7a | |||
| 8a43e7cd65 | |||
| 370120345e | |||
| 134b679a75 | |||
| 788aec0dab | |||
| a08da3b983 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ SDL2.dll
|
||||
libwinpthread-1.dll
|
||||
libstdc++-6.dll
|
||||
libgcc_s_seh-1.dll
|
||||
linux_utils/
|
||||
@@ -1,7 +1,7 @@
|
||||
# CMakeLists.txt
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(coffee_crisis)
|
||||
project(coffee_crisis VERSION 1.00)
|
||||
|
||||
# Configuración de compilador para MinGW en Windows, si es necesario
|
||||
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
@@ -10,7 +10,7 @@ if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
endif()
|
||||
|
||||
# Establecer estándar de C++
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
# Configuración global de flags de compilación
|
||||
@@ -20,8 +20,8 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os -ffunction-sections
|
||||
# Define el directorio de los archivos fuente
|
||||
set(DIR_SOURCES "${CMAKE_SOURCE_DIR}/source")
|
||||
|
||||
# Cargar todos los archivos fuente en DIR_SOURCES de manera recursiva
|
||||
file(GLOB_RECURSE SOURCES "${DIR_SOURCES}/*.cpp")
|
||||
# Cargar todos los archivos fuente en DIR_SOURCES
|
||||
file(GLOB SOURCES "${DIR_SOURCES}/*.cpp")
|
||||
|
||||
# Verificar si se encontraron archivos fuente
|
||||
if(NOT SOURCES)
|
||||
@@ -60,26 +60,12 @@ target_link_libraries(${PROJECT_NAME} ${LIBS})
|
||||
# Configuración específica para cada plataforma
|
||||
if(WIN32)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE WINDOWS_BUILD)
|
||||
target_link_libraries(${PROJECT_NAME} mingw32 opengl32 gdi32 winmm imm32 ole32 version)
|
||||
target_link_libraries(${PROJECT_NAME} mingw32 gdi32 winmm imm32 ole32 version)
|
||||
elseif(APPLE)
|
||||
set(LIBS ${LIBS} "-framework OpenGL")
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE MACOS_BUILD)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
|
||||
# Configurar compilación para Apple Silicon
|
||||
set(CMAKE_OSX_ARCHITECTURES "arm64")
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
set(LIBS ${LIBS} GL)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE LINUX_BUILD)
|
||||
target_link_libraries(${PROJECT_NAME} ${LIBS})
|
||||
endif()
|
||||
|
||||
# Añadir OpenGL a las bibliotecas enlazadas
|
||||
if(NOT WIN32)
|
||||
find_package(OpenGL REQUIRED)
|
||||
if(OPENGL_FOUND)
|
||||
message(STATUS "OpenGL encontrado: ${OPENGL_LIBRARIES}")
|
||||
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
|
||||
else()
|
||||
message(FATAL_ERROR "OpenGL no encontrado")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
4
Makefile
4
Makefile
@@ -1,8 +1,8 @@
|
||||
executable = coffee_crisis
|
||||
source = source/*.cpp source/common/*.cpp
|
||||
source = source/*.cpp
|
||||
appName = Coffee Crisis
|
||||
releaseFolder = cc_release
|
||||
version = v2.3.1
|
||||
version = v2.3.2
|
||||
resource_file = release/coffee.res
|
||||
|
||||
# Release names
|
||||
|
||||
@@ -101,18 +101,7 @@ line=true
|
||||
|
||||
[item]
|
||||
text=HOW TO PLAY
|
||||
hPaddingDown=2
|
||||
[/item]
|
||||
|
||||
[item]
|
||||
text=HISCORE TABLE
|
||||
hPaddingDown=2
|
||||
[/item]
|
||||
|
||||
[item]
|
||||
text=JAILERID:
|
||||
hPaddingDown=6
|
||||
line=true
|
||||
hPaddingDown=10
|
||||
[/item]
|
||||
|
||||
[item]
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
@@ -21,11 +21,11 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.2a</string>
|
||||
<string>2.3.2</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2.3</string>
|
||||
<string>2.3.2</string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#include "animatedsprite.h"
|
||||
#include <fstream> // for basic_ostream, operator<<, basic_istream, basic...
|
||||
#include <iostream> // for cout
|
||||
#include <sstream> // for basic_stringstream
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose)
|
||||
@@ -1,15 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "movingsprite.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef ANIMATEDSPRITE_H
|
||||
#define ANIMATEDSPRITE_H
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "movingsprite.h" // for MovingSprite
|
||||
class Texture;
|
||||
|
||||
struct animation_t
|
||||
{
|
||||
@@ -99,5 +96,3 @@ public:
|
||||
// Reinicia la animación
|
||||
void resetAnimation();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "asset.h"
|
||||
#include <iostream>
|
||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWops
|
||||
#include <SDL2/SDL_stdinc.h> // for SDL_max
|
||||
#include <stddef.h> // for size_t
|
||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||
|
||||
// Constructor
|
||||
Asset::Asset(std::string executablePath)
|
||||
@@ -1,11 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef ASSET_H
|
||||
#define ASSET_H
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
enum assetType
|
||||
{
|
||||
@@ -62,5 +58,3 @@ public:
|
||||
// Establece si ha de mostrar texto por pantalla
|
||||
void setVerbose(bool value);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,10 @@
|
||||
#include "const.h"
|
||||
#include "balloon.h"
|
||||
#include <math.h> // for abs
|
||||
#include "animatedsprite.h" // for AnimatedSprite
|
||||
#include "const.h" // for PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_AR...
|
||||
#include "movingsprite.h" // for MovingSprite
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer)
|
||||
|
||||
@@ -1,72 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/utils.h"
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#ifndef BALLOON_H
|
||||
#define BALLOON_H
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for circle_t
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||
#define MAX_BOUNCE 10
|
||||
constexpr int MAX_BOUNCE = 10;
|
||||
|
||||
// Tipos de globo
|
||||
#define BALLOON_1 1
|
||||
#define BALLOON_2 2
|
||||
#define BALLOON_3 3
|
||||
#define BALLOON_4 4
|
||||
#define HEXAGON_1 5
|
||||
#define HEXAGON_2 6
|
||||
#define HEXAGON_3 7
|
||||
#define HEXAGON_4 8
|
||||
#define POWER_BALL 9
|
||||
constexpr int BALLOON_1 = 1;
|
||||
constexpr int BALLOON_2 = 2;
|
||||
constexpr int BALLOON_3 = 3;
|
||||
constexpr int BALLOON_4 = 4;
|
||||
constexpr int HEXAGON_1 = 5;
|
||||
constexpr int HEXAGON_2 = 6;
|
||||
constexpr int HEXAGON_3 = 7;
|
||||
constexpr int HEXAGON_4 = 8;
|
||||
constexpr int POWER_BALL = 9;
|
||||
|
||||
// Puntos de globo
|
||||
#define BALLOON_SCORE_1 50
|
||||
#define BALLOON_SCORE_2 100
|
||||
#define BALLOON_SCORE_3 200
|
||||
#define BALLOON_SCORE_4 400
|
||||
constexpr int BALLOON_SCORE_1 = 50;
|
||||
constexpr int BALLOON_SCORE_2 = 100;
|
||||
constexpr int BALLOON_SCORE_3 = 200;
|
||||
constexpr int BALLOON_SCORE_4 = 400;
|
||||
|
||||
// Tamaños de globo
|
||||
#define BALLOON_SIZE_1 1
|
||||
#define BALLOON_SIZE_2 2
|
||||
#define BALLOON_SIZE_3 3
|
||||
#define BALLOON_SIZE_4 4
|
||||
constexpr int BALLOON_SIZE_1 = 1;
|
||||
constexpr int BALLOON_SIZE_2 = 2;
|
||||
constexpr int BALLOON_SIZE_3 = 3;
|
||||
constexpr int BALLOON_SIZE_4 = 4;
|
||||
|
||||
// Clases de globo
|
||||
#define BALLOON_CLASS 0
|
||||
#define HEXAGON_CLASS 1
|
||||
constexpr int BALLOON_CLASS = 0;
|
||||
constexpr int HEXAGON_CLASS = 1;
|
||||
|
||||
// Velocidad del globo
|
||||
#define BALLOON_VELX_POSITIVE 0.7f
|
||||
#define BALLOON_VELX_NEGATIVE -0.7f
|
||||
constexpr float BALLOON_VELX_POSITIVE = 0.7f;
|
||||
constexpr float BALLOON_VELX_NEGATIVE = -0.7f;
|
||||
|
||||
// Indice para las animaciones de los globos
|
||||
#define BALLOON_MOVING_ANIMATION 0
|
||||
#define BALLOON_POP_ANIMATION 1
|
||||
#define BALLOON_BORN_ANIMATION 2
|
||||
// Índice para las animaciones de los globos
|
||||
constexpr int BALLOON_MOVING_ANIMATION = 0;
|
||||
constexpr int BALLOON_POP_ANIMATION = 1;
|
||||
constexpr int BALLOON_BORN_ANIMATION = 2;
|
||||
|
||||
// Cantidad posible de globos
|
||||
#define MAX_BALLOONS 100
|
||||
constexpr int MAX_BALLOONS = 100;
|
||||
|
||||
// Velocidades a las que se mueven los globos
|
||||
#define BALLOON_SPEED_1 0.60f
|
||||
#define BALLOON_SPEED_2 0.70f
|
||||
#define BALLOON_SPEED_3 0.80f
|
||||
#define BALLOON_SPEED_4 0.90f
|
||||
#define BALLOON_SPEED_5 1.00f
|
||||
constexpr float BALLOON_SPEED_1 = 0.60f;
|
||||
constexpr float BALLOON_SPEED_2 = 0.70f;
|
||||
constexpr float BALLOON_SPEED_3 = 0.80f;
|
||||
constexpr float BALLOON_SPEED_4 = 0.90f;
|
||||
constexpr float BALLOON_SPEED_5 = 1.00f;
|
||||
|
||||
// Tamaño de los globos
|
||||
#define BALLOON_WIDTH_1 8
|
||||
#define BALLOON_WIDTH_2 13
|
||||
#define BALLOON_WIDTH_3 21
|
||||
#define BALLOON_WIDTH_4 37
|
||||
constexpr int BALLOON_WIDTH_1 = 8;
|
||||
constexpr int BALLOON_WIDTH_2 = 13;
|
||||
constexpr int BALLOON_WIDTH_3 = 21;
|
||||
constexpr int BALLOON_WIDTH_4 = 37;
|
||||
|
||||
// PowerBall
|
||||
#define POWERBALL_SCREENPOWER_MINIMUM 10
|
||||
#define POWERBALL_COUNTER 8
|
||||
constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
|
||||
constexpr int POWERBALL_COUNTER = 8;
|
||||
|
||||
// Clase Balloon
|
||||
class Balloon
|
||||
@@ -250,5 +249,3 @@ public:
|
||||
// Obtiene le valor de la variable
|
||||
Uint8 getPower();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "const.h"
|
||||
#include "bullet.h"
|
||||
#include "const.h" // for NO_KIND, PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_A...
|
||||
#include "sprite.h" // for Sprite
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture, SDL_Renderer *renderer)
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/sprite.h"
|
||||
#include "common/utils.h"
|
||||
|
||||
#ifndef BULLET_H
|
||||
#define BULLET_H
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include "utils.h" // for circle_t
|
||||
class Sprite;
|
||||
class Texture;
|
||||
|
||||
// Tipos de bala
|
||||
#define BULLET_UP 1
|
||||
#define BULLET_LEFT 2
|
||||
#define BULLET_RIGHT 3
|
||||
constexpr int BULLET_UP = 1;
|
||||
constexpr int BULLET_LEFT = 2;
|
||||
constexpr int BULLET_RIGHT = 3;
|
||||
|
||||
// Tipos de retorno de la funcion move de la bala
|
||||
#define BULLET_MOVE_OK 0
|
||||
#define BULLET_MOVE_OUT 1
|
||||
// Tipos de retorno de la función move de la bala
|
||||
constexpr int BULLET_MOVE_OK = 0;
|
||||
constexpr int BULLET_MOVE_OUT = 1;
|
||||
|
||||
// Clase Bullet
|
||||
class Bullet
|
||||
@@ -80,5 +79,3 @@ public:
|
||||
// Obtiene el circulo de colisión
|
||||
circle_t &getCollider();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
#ifdef JA_USESDLMIXER
|
||||
#include "jail_audio.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct JA_Sound_t {}; // Dummy structs
|
||||
struct JA_Music_t {};
|
||||
|
||||
int JA_freq {48000};
|
||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
||||
Uint8 JA_channels {2};
|
||||
|
||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
||||
JA_freq = freq;
|
||||
JA_format = format;
|
||||
JA_channels = channels;
|
||||
Mix_OpenAudio(JA_freq, JA_format, JA_channels, 1024);
|
||||
}
|
||||
|
||||
void JA_Quit() {
|
||||
Mix_CloseAudio();
|
||||
}
|
||||
|
||||
JA_Music_t *JA_LoadMusic(const char* filename) {
|
||||
return (JA_Music_t*)Mix_LoadMUS(filename);
|
||||
}
|
||||
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
||||
Mix_PlayMusic((Mix_Music*)music, loop);
|
||||
}
|
||||
|
||||
void JA_PauseMusic() {
|
||||
Mix_PauseMusic();
|
||||
}
|
||||
|
||||
void JA_ResumeMusic() {
|
||||
Mix_ResumeMusic();
|
||||
}
|
||||
|
||||
void JA_StopMusic() {
|
||||
Mix_HaltMusic();
|
||||
}
|
||||
|
||||
JA_Music_state JA_GetMusicState() {
|
||||
if (Mix_PausedMusic()) {
|
||||
return JA_MUSIC_PAUSED;
|
||||
} else if (Mix_PlayingMusic()) {
|
||||
return JA_MUSIC_PLAYING;
|
||||
} else {
|
||||
return JA_MUSIC_STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
void JA_DeleteMusic(JA_Music_t *music) {
|
||||
Mix_FreeMusic((Mix_Music*)music);
|
||||
}
|
||||
|
||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JA_Sound_t *JA_LoadSound(const char* filename) {
|
||||
JA_Sound_t *sound = (JA_Sound_t*)Mix_LoadWAV(filename);
|
||||
return sound;
|
||||
}
|
||||
|
||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
||||
return Mix_PlayChannel(-1, (Mix_Chunk*)sound, loop);
|
||||
}
|
||||
|
||||
void JA_DeleteSound(JA_Sound_t *sound) {
|
||||
Mix_FreeChunk((Mix_Chunk*)sound);
|
||||
}
|
||||
|
||||
void JA_PauseChannel(const int channel) {
|
||||
Mix_Pause(channel);
|
||||
}
|
||||
|
||||
void JA_ResumeChannel(const int channel) {
|
||||
Mix_Resume(channel);
|
||||
}
|
||||
|
||||
void JA_StopChannel(const int channel) {
|
||||
Mix_HaltChannel(channel);
|
||||
}
|
||||
|
||||
JA_Channel_state JA_GetChannelState(const int channel) {
|
||||
if (Mix_Paused(channel)) {
|
||||
return JA_CHANNEL_PAUSED;
|
||||
} else if (Mix_Playing(channel)) {
|
||||
return JA_CHANNEL_PLAYING;
|
||||
} else {
|
||||
return JA_CHANNEL_FREE;
|
||||
}
|
||||
}
|
||||
|
||||
int JA_SetVolume(int volume) {
|
||||
return Mix_Volume(-1, volume);
|
||||
}
|
||||
#endif
|
||||
@@ -1,154 +0,0 @@
|
||||
#include "jscore.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace jscore {
|
||||
|
||||
using namespace std;
|
||||
struct user {
|
||||
string name;
|
||||
int points;
|
||||
};
|
||||
vector<user> score;
|
||||
|
||||
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
||||
int sock;
|
||||
struct sockaddr_in client;
|
||||
|
||||
int PORT = 9911;
|
||||
string HOST = "jaildoctor.duckdns.org";
|
||||
|
||||
#ifdef WIN32
|
||||
WSADATA WsaData;
|
||||
#endif
|
||||
|
||||
bool jscore_error = false;
|
||||
string error_message;
|
||||
|
||||
void init(std::string host, const int port) {
|
||||
PORT = port;
|
||||
HOST = host;
|
||||
}
|
||||
|
||||
void setErrorMessage(string message) {
|
||||
jscore_error = true;
|
||||
error_message = message;
|
||||
}
|
||||
|
||||
string sendRequest(const string request) {
|
||||
#ifdef WIN32
|
||||
int ret = WSAStartup(0x101,&WsaData);
|
||||
if (ret != 0) return 0;
|
||||
#endif
|
||||
struct hostent * host = gethostbyname(HOST.c_str());
|
||||
|
||||
if ( (host == NULL) || (host->h_addr == NULL) ) {
|
||||
setErrorMessage("Error retrieving DNS information.\n");
|
||||
return "";
|
||||
}
|
||||
|
||||
bzero(&client, sizeof(client));
|
||||
client.sin_family = AF_INET;
|
||||
client.sin_port = htons( PORT );
|
||||
memcpy(&client.sin_addr, host->h_addr, host->h_length);
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (sock < 0) {
|
||||
setErrorMessage("Error creating socket.\n");
|
||||
return "";
|
||||
}
|
||||
|
||||
if ( connect(sock, (struct sockaddr *)&client, sizeof(client)) < 0 ) {
|
||||
close(sock);
|
||||
setErrorMessage("Could not connect\n");
|
||||
return "";
|
||||
}
|
||||
|
||||
string r = request + " HTTP/1.1\r\nHost: "+HOST+"\r\nConnection: close\r\n\r\n\r\n";
|
||||
if (send(sock, r.c_str(), r.length(), 0) != (int)r.length()) {
|
||||
setErrorMessage("Error sending request.\n");
|
||||
return "";
|
||||
}
|
||||
|
||||
char cur;
|
||||
char start[5]="\r\n\r\n";
|
||||
int pos = 0;
|
||||
while ( recv(sock, &cur, 1,0) > 0 ) {
|
||||
if (cur==start[pos]) { pos++; if (pos == 4) break; } else { pos = 0; }
|
||||
}
|
||||
|
||||
char buffer[1024]; buffer[0]=0; pos=0;
|
||||
while ( recv(sock, &cur, 1,0) > 0 ) {
|
||||
buffer[pos] = cur;
|
||||
pos++;
|
||||
}
|
||||
#ifdef WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
buffer[pos]=0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
const bool initOnlineScore(string game) {
|
||||
string strbuff = sendRequest("GET /score-list.php?game=" + game);
|
||||
if (jscore_error) return not jscore_error;
|
||||
|
||||
user u;
|
||||
char buffer[1024];
|
||||
strcpy(buffer, strbuff.c_str());
|
||||
char *str = buffer;
|
||||
char *p = str;
|
||||
score.clear();
|
||||
while (*p!=0) {
|
||||
while (*p!=',') {p++;}
|
||||
*p=0; u.name = str; p++; str=p;
|
||||
while (*p!='\n') {p++;}
|
||||
*p=0; u.points = atoi(str); p++; str=p;
|
||||
score.push_back(u);
|
||||
}
|
||||
return not jscore_error;
|
||||
}
|
||||
|
||||
const int getNumUsers() {
|
||||
return score.size();
|
||||
}
|
||||
string getUserName(const int index) {
|
||||
return score[index].name;
|
||||
}
|
||||
const int getPoints(const int index) {
|
||||
return score[index].points;
|
||||
}
|
||||
|
||||
const bool updateUserPoints(string game, string user, const int points) {
|
||||
string strbuff = sendRequest("GET /score-update.php?game=" + game + "&user=" + user + "&points=" + to_string(points));
|
||||
initOnlineScore(game);
|
||||
return not jscore_error;
|
||||
}
|
||||
|
||||
const int getUserPoints(string game, std::string user) {
|
||||
return atoi(sendRequest("GET /getuserpoints.php?game=" + game + "&user=" + user).c_str());
|
||||
}
|
||||
|
||||
string getUserData(string game, string user) {
|
||||
return sendRequest("GET /getuserdata.php?game=" + game + "&user=" + user);
|
||||
}
|
||||
|
||||
void setUserData(string game, string user, string data) {
|
||||
sendRequest("GET /setuserdata.php?game=" + game + "&user=" + user + "&data=" + data);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace jscore {
|
||||
void init(std::string host, const int port);
|
||||
const bool initOnlineScore(std::string game);
|
||||
const int getNumUsers();
|
||||
std::string getUserName(const int index);
|
||||
const int getPoints(const int index);
|
||||
const int getUserPoints(std::string game, std::string user);
|
||||
|
||||
const bool updateUserPoints(std::string game, std::string user, const int points);
|
||||
std::string getUserData(std::string game, std::string user);
|
||||
void setUserData(std::string game, std::string user, std::string data);
|
||||
};
|
||||
|
||||
@@ -1,285 +0,0 @@
|
||||
#include "notify.h"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
||||
{
|
||||
// Inicializa variables
|
||||
this->renderer = renderer;
|
||||
this->options = options;
|
||||
bgColor = options->notifications.color;
|
||||
waitTime = 300;
|
||||
|
||||
// Crea objetos
|
||||
iconTexture = new Texture(renderer, iconFile);
|
||||
textTexture = new Texture(renderer, bitmapFile);
|
||||
text = new Text(textFile, textTexture, renderer);
|
||||
sound = JA_LoadSound(soundFile.c_str());
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Notify::~Notify()
|
||||
{
|
||||
// Libera la memoria de los objetos
|
||||
delete textTexture;
|
||||
delete iconTexture;
|
||||
delete text;
|
||||
JA_DeleteSound(sound);
|
||||
|
||||
for (auto notification : notifications)
|
||||
{
|
||||
delete notification.sprite;
|
||||
delete notification.texture;
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void Notify::render()
|
||||
{
|
||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||
{
|
||||
notifications[i].sprite->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void Notify::update()
|
||||
{
|
||||
for (int i = 0; i < (int)notifications.size(); ++i)
|
||||
{
|
||||
// Si la notificación anterior está "saliendo", no hagas nada
|
||||
if (i > 0)
|
||||
{
|
||||
if (notifications[i - 1].state == ns_rising)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
notifications[i].counter++;
|
||||
|
||||
// Hace sonar la notificación en el primer frame
|
||||
if (notifications[i].counter == 1)
|
||||
{
|
||||
if (options->notifications.sound)
|
||||
{
|
||||
if (notifications[i].state == ns_rising)
|
||||
{ // Reproduce el sonido de la notificación
|
||||
JA_PlaySound(sound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los estados
|
||||
if (notifications[i].state == ns_rising)
|
||||
{
|
||||
const float step = ((float)notifications[i].counter / notifications[i].travelDist);
|
||||
const int alpha = 255 * step;
|
||||
|
||||
if (options->notifications.posV == pos_top)
|
||||
{
|
||||
notifications[i].rect.y++;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifications[i].rect.y--;
|
||||
}
|
||||
notifications[i].texture->setAlpha(alpha);
|
||||
|
||||
if (notifications[i].rect.y == notifications[i].y)
|
||||
{
|
||||
notifications[i].state = ns_stay;
|
||||
notifications[i].texture->setAlpha(255);
|
||||
notifications[i].counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (notifications[i].state == ns_stay)
|
||||
{
|
||||
if (notifications[i].counter == waitTime)
|
||||
{
|
||||
notifications[i].state = ns_vanishing;
|
||||
notifications[i].counter = 0;
|
||||
}
|
||||
}
|
||||
else if (notifications[i].state == ns_vanishing)
|
||||
{
|
||||
|
||||
const float step = (notifications[i].counter / (float)notifications[i].travelDist);
|
||||
const int alpha = 255 * (1 - step);
|
||||
|
||||
if (options->notifications.posV == pos_top)
|
||||
{
|
||||
notifications[i].rect.y--;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifications[i].rect.y++;
|
||||
}
|
||||
notifications[i].texture->setAlpha(alpha);
|
||||
|
||||
if (notifications[i].rect.y == notifications[i].y - notifications[i].travelDist)
|
||||
{
|
||||
notifications[i].state = ns_finished;
|
||||
}
|
||||
}
|
||||
|
||||
notifications[i].sprite->setRect(notifications[i].rect);
|
||||
}
|
||||
|
||||
clearFinishedNotifications();
|
||||
}
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void Notify::clearFinishedNotifications()
|
||||
{
|
||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (notifications[i].state == ns_finished)
|
||||
{
|
||||
delete notifications[i].sprite;
|
||||
delete notifications[i].texture;
|
||||
notifications.erase(notifications.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
{
|
||||
// Inicializa variables
|
||||
const int iconSize = 16;
|
||||
const int padding = text->getCharacterSize();
|
||||
const int iconSpace = icon >= 0 ? iconSize + padding : 0;
|
||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||
const int width = text->lenght(txt) + (padding * 2) + iconSpace;
|
||||
const int height = (text->getCharacterSize() * 2) + (padding * 2);
|
||||
|
||||
// Posición horizontal
|
||||
int despH = 0;
|
||||
if (options->notifications.posH == pos_left)
|
||||
{
|
||||
despH = padding;
|
||||
}
|
||||
else if (options->notifications.posH == pos_middle)
|
||||
{
|
||||
despH = ((options->screen.windowWidth * options->windowSize) / 2 - (width / 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
despH = (options->screen.windowWidth * options->windowSize) - width - padding;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
int despV = 0;
|
||||
if (options->notifications.posV == pos_top)
|
||||
{
|
||||
despV = padding;
|
||||
}
|
||||
else
|
||||
{
|
||||
despV = (options->screen.windowHeight * options->windowSize) - height - padding;
|
||||
}
|
||||
|
||||
const int travelDist = height + padding;
|
||||
|
||||
// Offset
|
||||
int offset = 0;
|
||||
if (options->notifications.posV == pos_top)
|
||||
{
|
||||
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = (int)notifications.size() > 0 ? notifications.back().y - travelDist : despV;
|
||||
}
|
||||
|
||||
// Crea la notificacion
|
||||
notification_t n;
|
||||
|
||||
// Inicializa variables
|
||||
n.y = offset;
|
||||
n.travelDist = travelDist;
|
||||
n.counter = 0;
|
||||
n.state = ns_rising;
|
||||
n.text1 = text1;
|
||||
n.text2 = text2;
|
||||
if (options->notifications.posV == pos_top)
|
||||
{
|
||||
n.rect = {despH, offset - travelDist, width, height};
|
||||
}
|
||||
else
|
||||
{
|
||||
n.rect = {despH, offset + travelDist, width, height};
|
||||
}
|
||||
|
||||
// Crea la textura
|
||||
n.texture = new Texture(renderer);
|
||||
n.texture->createBlank(renderer, width, height, SDL_TEXTUREACCESS_TARGET);
|
||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Prepara para dibujar en la textura
|
||||
n.texture->setAsRenderTarget(renderer);
|
||||
|
||||
// Dibuja el fondo de la notificación
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_Rect rect;
|
||||
rect = {4, 0, width - (4 * 2), height};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
rect = {4 / 2, 1, width - 4, height - 2};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
rect = {1, 4 / 2, width - 2, height - 4};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
rect = {0, 4, width, height - (4 * 2)};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
// Dibuja el icono de la notificación
|
||||
if (icon >= 0)
|
||||
{
|
||||
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, iconTexture, renderer);
|
||||
sp->setPos({padding, padding, iconSize, iconSize});
|
||||
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
|
||||
sp->render();
|
||||
delete sp;
|
||||
}
|
||||
|
||||
// Escribe el texto de la notificación
|
||||
color_t color = {255, 255, 255};
|
||||
if (text2 != "")
|
||||
{ // Dos lineas de texto
|
||||
text->writeColored(padding + iconSpace, padding, text1, color);
|
||||
text->writeColored(padding + iconSpace, padding + text->getCharacterSize() + 1, text2, color);
|
||||
}
|
||||
else
|
||||
{ // Una linea de texto
|
||||
text->writeColored(padding + iconSpace, (height / 2) - (text->getCharacterSize() / 2), text1, color);
|
||||
}
|
||||
|
||||
// Deja de dibujar en la textura
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
// Crea el sprite de la notificación
|
||||
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
||||
|
||||
// Deja la notificación invisible
|
||||
n.texture->setAlpha(0);
|
||||
|
||||
// Añade la notificación a la lista
|
||||
notifications.push_back(n);
|
||||
}
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool Notify::active()
|
||||
{
|
||||
if ((int)notifications.size() > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "jail_audio.h"
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "texture.h"
|
||||
#include "utils.h"
|
||||
#include <vector>
|
||||
|
||||
#ifndef NOTIFY_H
|
||||
#define NOTIFY_H
|
||||
|
||||
class Notify
|
||||
{
|
||||
private:
|
||||
enum notification_state_e
|
||||
{
|
||||
ns_rising,
|
||||
ns_stay,
|
||||
ns_vanishing,
|
||||
ns_finished
|
||||
};
|
||||
|
||||
enum notification_position_e
|
||||
{
|
||||
upperLeft,
|
||||
upperCenter,
|
||||
upperRight,
|
||||
middleLeft,
|
||||
middleRight,
|
||||
bottomLeft,
|
||||
bottomCenter,
|
||||
bottomRight
|
||||
};
|
||||
|
||||
struct notification_t
|
||||
{
|
||||
std::string text1;
|
||||
std::string text2;
|
||||
int counter;
|
||||
notification_state_e state;
|
||||
notification_position_e position;
|
||||
Texture *texture;
|
||||
Sprite *sprite;
|
||||
SDL_Rect rect;
|
||||
int y;
|
||||
int travelDist;
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Texture *textTexture; // Textura para la fuente de las notificaciones
|
||||
Texture *iconTexture; // Textura para los iconos de las notificaciones
|
||||
Text *text; // Objeto para dibujar texto
|
||||
options_t *options; // Variable con todas las opciones del programa
|
||||
|
||||
// Variables
|
||||
color_t bgColor; // Color de fondo de las notificaciones
|
||||
int waitTime; // Tiempo que se ve la notificación
|
||||
std::vector<notification_t> notifications; // La lista de notificaciones activas
|
||||
JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void clearFinishedNotifications();
|
||||
|
||||
public:
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void render();
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void update();
|
||||
|
||||
// Constructor
|
||||
Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
|
||||
|
||||
// Destructor
|
||||
~Notify();
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void showText(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool active();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,65 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/utils.h"
|
||||
#include "utils.h"
|
||||
#include "lang.h"
|
||||
|
||||
#ifndef CONST_H
|
||||
#define CONST_H
|
||||
|
||||
// Tamaño de bloque
|
||||
#define BLOCK 8
|
||||
#define HALF_BLOCK BLOCK / 2
|
||||
constexpr int BLOCK = 8;
|
||||
constexpr int HALF_BLOCK = BLOCK / 2;
|
||||
|
||||
// Tamaño de la pantalla virtual
|
||||
#define GAMECANVAS_WIDTH 256
|
||||
#define GAMECANVAS_HEIGHT 192
|
||||
constexpr int GAMECANVAS_WIDTH = 256;
|
||||
constexpr int GAMECANVAS_HEIGHT = 192;
|
||||
|
||||
// Zona de juego
|
||||
const int PLAY_AREA_TOP = (0 * BLOCK);
|
||||
const int PLAY_AREA_BOTTOM = GAMECANVAS_HEIGHT - (4 * BLOCK);
|
||||
const int PLAY_AREA_LEFT = (0 * BLOCK);
|
||||
const int PLAY_AREA_RIGHT = GAMECANVAS_WIDTH - (0 * BLOCK);
|
||||
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
||||
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
||||
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
||||
const int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
|
||||
const int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
|
||||
const int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
|
||||
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
|
||||
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
||||
constexpr int PLAY_AREA_TOP = (0 * BLOCK);
|
||||
constexpr int PLAY_AREA_BOTTOM = GAMECANVAS_HEIGHT - (4 * BLOCK);
|
||||
constexpr int PLAY_AREA_LEFT = (0 * BLOCK);
|
||||
constexpr int PLAY_AREA_RIGHT = GAMECANVAS_WIDTH - (0 * BLOCK);
|
||||
constexpr int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
||||
constexpr int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
||||
constexpr int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
||||
constexpr int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
|
||||
constexpr int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
|
||||
constexpr int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
|
||||
constexpr int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
|
||||
constexpr int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
||||
|
||||
// Anclajes de pantalla
|
||||
const int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
|
||||
const int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
|
||||
const int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
|
||||
const int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
|
||||
const int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
||||
const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
||||
constexpr int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
|
||||
constexpr int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
|
||||
constexpr int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
|
||||
constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
|
||||
constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
||||
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
||||
|
||||
// Secciones del programa
|
||||
#define SECTION_PROG_LOGO 0
|
||||
#define SECTION_PROG_INTRO 1
|
||||
#define SECTION_PROG_TITLE 2
|
||||
#define SECTION_PROG_GAME 3
|
||||
#define SECTION_PROG_QUIT 4
|
||||
constexpr int SECTION_PROG_LOGO = 0;
|
||||
constexpr int SECTION_PROG_INTRO = 1;
|
||||
constexpr int SECTION_PROG_TITLE = 2;
|
||||
constexpr int SECTION_PROG_GAME = 3;
|
||||
constexpr int SECTION_PROG_QUIT = 4;
|
||||
|
||||
// Subsecciones
|
||||
#define SUBSECTION_GAME_PLAY_1P 0
|
||||
#define SUBSECTION_GAME_PLAY_2P 1
|
||||
#define SUBSECTION_GAME_PAUSE 2
|
||||
#define SUBSECTION_GAME_GAMEOVER 3
|
||||
#define SUBSECTION_TITLE_1 3
|
||||
#define SUBSECTION_TITLE_2 4
|
||||
#define SUBSECTION_TITLE_3 5
|
||||
#define SUBSECTION_TITLE_INSTRUCTIONS 6
|
||||
constexpr int SUBSECTION_GAME_PLAY_1P = 0;
|
||||
constexpr int SUBSECTION_GAME_PLAY_2P = 1;
|
||||
constexpr int SUBSECTION_GAME_PAUSE = 2;
|
||||
constexpr int SUBSECTION_GAME_GAMEOVER = 3;
|
||||
constexpr int SUBSECTION_TITLE_1 = 3;
|
||||
constexpr int SUBSECTION_TITLE_2 = 4;
|
||||
constexpr int SUBSECTION_TITLE_3 = 5;
|
||||
constexpr int SUBSECTION_TITLE_INSTRUCTIONS = 6;
|
||||
|
||||
// Ningun tipo
|
||||
#define NO_KIND 0
|
||||
constexpr int NO_KIND = 0;
|
||||
|
||||
// Colores
|
||||
const color_t bgColor = {0x27, 0x27, 0x36};
|
||||
const color_t noColor = {0xFF, 0xFF, 0xFF};
|
||||
const color_t shdwTxtColor = {0x43, 0x43, 0x4F};
|
||||
|
||||
#endif
|
||||
@@ -1,12 +1,34 @@
|
||||
#include "common/jscore.h"
|
||||
#include "common/utils.h"
|
||||
#include "const.h"
|
||||
#include "director.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <SDL2/SDL.h> // for SDL_Init, SDL_Quit, SDL_INIT_EV...
|
||||
#include <SDL2/SDL_audio.h> // for AUDIO_S16
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_CONTROLLER_BUTTON_B, SDL_CO...
|
||||
#include <SDL2/SDL_hints.h> // for SDL_SetHint, SDL_HINT_RENDER_SC...
|
||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_ESCAPE, SDL_SCANCO...
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <errno.h> // for errno, EEXIST, EACCES, ENAMETOO...
|
||||
#include <stdio.h> // for printf, perror
|
||||
#include <string.h> // for strcmp
|
||||
#include <sys/stat.h> // for mkdir, stat, S_IRWXU
|
||||
#include <unistd.h> // for getuid
|
||||
#include <cstdlib> // for exit, EXIT_FAILURE, srand
|
||||
#include <fstream> // for basic_ostream, operator<<, basi...
|
||||
#include <iostream> // for cout
|
||||
#include <string> // for basic_string, operator+, char_t...
|
||||
#include <vector> // for vector
|
||||
#include "asset.h" // for Asset, assetType
|
||||
#include "const.h" // for SECTION_PROG_LOGO, GAMECANVAS_H...
|
||||
#include "game.h" // for Game
|
||||
#include "input.h" // for Input, inputs_e, INPUT_USE_GAME...
|
||||
#include "intro.h" // for Intro
|
||||
#include "jail_audio.h" // for JA_Init
|
||||
#include "lang.h" // for Lang, MAX_LANGUAGES, ba_BA, en_UK
|
||||
#include "logo.h" // for Logo
|
||||
#include "screen.h" // for FILTER_NEAREST, Screen, FILTER_...
|
||||
#include "title.h" // for Title
|
||||
#include "utils.h" // for options_t, input_t, boolToString
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h>
|
||||
@@ -60,9 +82,6 @@ Director::Director(int argc, char *argv[])
|
||||
initInput();
|
||||
|
||||
screen = new Screen(window, renderer, asset, options);
|
||||
|
||||
// Inicializa los servicios online
|
||||
initOnline();
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
@@ -240,9 +259,6 @@ bool Director::setFileList()
|
||||
asset->add(prefix + "/data/config/demo.bin", t_data);
|
||||
asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data);
|
||||
|
||||
// Notificaciones
|
||||
asset->add(prefix + "/data/notifications/notify.png", t_bitmap);
|
||||
|
||||
// Musicas
|
||||
asset->add(prefix + "/data/music/intro.ogg", t_music);
|
||||
asset->add(prefix + "/data/music/playing.ogg", t_music);
|
||||
@@ -266,7 +282,6 @@ bool Director::setFileList()
|
||||
asset->add(prefix + "/data/sound/title.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/clock.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/powerball.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/notify.wav", t_sound);
|
||||
|
||||
// Texturas
|
||||
asset->add(prefix + "/data/gfx/balloon1.png", t_bitmap);
|
||||
@@ -398,24 +413,6 @@ void Director::initOptions()
|
||||
options->difficulty = DIFFICULTY_NORMAL;
|
||||
options->language = ba_BA;
|
||||
options->console = false;
|
||||
|
||||
// Opciones online
|
||||
options->online.enabled = false;
|
||||
options->online.server = "jaildoctor.duckdns.org";
|
||||
options->online.port = 9911;
|
||||
#ifdef DEBUG
|
||||
options->online.gameID = "coffee_crisis_test2";
|
||||
#else
|
||||
options->online.gameID = "coffee_crisis";
|
||||
#endif
|
||||
options->online.jailerID = "";
|
||||
options->online.score = 0;
|
||||
|
||||
// Opciones de las notificaciones
|
||||
options->notifications.posV = pos_top;
|
||||
options->notifications.posH = pos_left;
|
||||
options->notifications.sound = true;
|
||||
options->notifications.color = {48, 48, 48};
|
||||
}
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
@@ -634,41 +631,6 @@ bool Director::saveConfigFile()
|
||||
file << "input0=" + std::to_string(options->input[0].deviceType) + "\n";
|
||||
file << "input1=" + std::to_string(options->input[1].deviceType) + "\n";
|
||||
|
||||
// Opciones sobre la conexión online
|
||||
file << "\n## ONLINE OPTIONS\n";
|
||||
file << "enabled=" + boolToString(options->online.enabled) + "\n";
|
||||
file << "server=" + options->online.server + "\n";
|
||||
file << "port=" + std::to_string(options->online.port) + "\n";
|
||||
file << "jailerID=" + options->online.jailerID + "\n";
|
||||
|
||||
// Opciones de las notificaciones
|
||||
file << "\n## NOTIFICATION OPTIONS\n";
|
||||
file << "## notifications.posV = pos_top | pos_bottom\n";
|
||||
if (options->notifications.posV == pos_top)
|
||||
{
|
||||
file << "notifications.posV=pos_top\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
file << "notifications.posV=pos_bottom\n";
|
||||
}
|
||||
|
||||
file << "## notifications.posH = pos_left | pos_middle | pos_right\n";
|
||||
if (options->notifications.posH == pos_left)
|
||||
{
|
||||
file << "notifications.posH=pos_left\n";
|
||||
}
|
||||
else if (options->notifications.posH == pos_middle)
|
||||
{
|
||||
file << "notifications.posH=pos_middle\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
file << "notifications.posH=pos_right\n";
|
||||
}
|
||||
|
||||
file << "notifications.sound=" + boolToString(options->notifications.sound) + "\n";
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
|
||||
@@ -730,66 +692,6 @@ void Director::run()
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa los servicios online
|
||||
void Director::initOnline()
|
||||
{
|
||||
if (options->online.sessionEnabled)
|
||||
{ // Si ya ha iniciado la sesión, que no continue
|
||||
return;
|
||||
}
|
||||
|
||||
if (options->online.jailerID == "")
|
||||
{ // Jailer ID no definido
|
||||
options->online.enabled = false;
|
||||
}
|
||||
else
|
||||
{ // Jailer ID iniciado
|
||||
options->online.enabled = options->online.sessionEnabled = true;
|
||||
// Establece el servidor y el puerto
|
||||
jscore::init(options->online.server, options->online.port);
|
||||
#ifdef DEBUG
|
||||
const std::string caption = options->online.jailerID + " (DEBUG)";
|
||||
#else
|
||||
const std::string caption = options->online.jailerID;
|
||||
#endif
|
||||
// screen->showNotification(caption, lang->getText(85), 12);
|
||||
screen->showNotification(caption, lang->getText(85));
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << caption << std::endl;
|
||||
}
|
||||
|
||||
// Obtiene la información de puntuaciones online
|
||||
if (!jscore::initOnlineScore(options->online.gameID))
|
||||
{
|
||||
screen->showNotification(lang->getText(80), options->online.server);
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Can't connect to " << options->online.server << std::endl;
|
||||
}
|
||||
|
||||
options->online.enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Obten la puntuación online para el jailerID
|
||||
const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID);
|
||||
if (points == 0)
|
||||
{ // Fallo de conexión o no hay registros
|
||||
screen->showNotification(lang->getText(81), lang->getText(82));
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Can't get online scores" << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
options->online.score = points;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool Director::setOptions(options_t *options, std::string var, std::string value)
|
||||
{
|
||||
@@ -885,65 +787,6 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
||||
options->input[1].deviceType = std::stoi(value);
|
||||
}
|
||||
|
||||
// Opciones onlince
|
||||
else if (var == "enabled")
|
||||
{
|
||||
options->online.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "server")
|
||||
{
|
||||
options->online.server = value;
|
||||
}
|
||||
|
||||
else if (var == "port")
|
||||
{
|
||||
if (value == "")
|
||||
{
|
||||
value = "0";
|
||||
}
|
||||
options->online.port = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "jailerID")
|
||||
{
|
||||
options->online.jailerID = toLower(value);
|
||||
}
|
||||
|
||||
// Opciones de notificaciones
|
||||
else if (var == "notifications.posH")
|
||||
{
|
||||
if (value == "pos_left")
|
||||
{
|
||||
options->notifications.posH = pos_left;
|
||||
}
|
||||
else if (value == "pos_middle")
|
||||
{
|
||||
options->notifications.posH = pos_middle;
|
||||
}
|
||||
else
|
||||
{
|
||||
options->notifications.posH = pos_right;
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "notifications.posV")
|
||||
{
|
||||
if (value == "pos_top")
|
||||
{
|
||||
options->notifications.posV = pos_top;
|
||||
}
|
||||
else
|
||||
{
|
||||
options->notifications.posV = pos_bottom;
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "notifications.sound")
|
||||
{
|
||||
options->notifications.sound = stringToBool(value);
|
||||
}
|
||||
|
||||
// Lineas vacias o que empiezan por comentario
|
||||
else if (var == "" || var.substr(0, 1) == "#")
|
||||
{
|
||||
|
||||
@@ -1,33 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "balloon.h"
|
||||
#include "bullet.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/input.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/menu.h"
|
||||
#include "common/movingsprite.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/smartsprite.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/text.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/writer.h"
|
||||
#include "const.h"
|
||||
#include "fade.h"
|
||||
#include "game.h"
|
||||
#include "intro.h"
|
||||
#include "item.h"
|
||||
#include "logo.h"
|
||||
#include "player.h"
|
||||
#include "title.h"
|
||||
|
||||
#ifndef DIRECTOR_H
|
||||
#define DIRECTOR_H
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||
#include <string> // for string, basic_string
|
||||
class Asset;
|
||||
class Game;
|
||||
class Input;
|
||||
class Intro;
|
||||
class Lang;
|
||||
class Logo;
|
||||
class Screen;
|
||||
class Title;
|
||||
struct options_t;
|
||||
struct section_t;
|
||||
|
||||
// Textos
|
||||
#define WINDOW_CAPTION "Coffee Crisis"
|
||||
constexpr const char* WINDOW_CAPTION = "Coffee Crisis";
|
||||
|
||||
class Director
|
||||
{
|
||||
@@ -59,9 +47,6 @@ private:
|
||||
// Inicializa el objeto input
|
||||
void initInput();
|
||||
|
||||
// Inicializa los servicios online
|
||||
void initOnline();
|
||||
|
||||
// Inicializa las opciones del programa
|
||||
void initOptions();
|
||||
|
||||
@@ -105,5 +90,3 @@ public:
|
||||
// Bucle principal
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,348 +0,0 @@
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/jscore.h"
|
||||
#include "const.h"
|
||||
#include "enter_id.h"
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options, section_t *section)
|
||||
{
|
||||
// Copia la dirección de los objetos
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->lang = lang;
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
eventHandler = new SDL_Event();
|
||||
texture = new Texture(renderer, asset->get("smb2.png"));
|
||||
text = new Text(asset->get("smb2.txt"), texture, renderer);
|
||||
|
||||
// Crea la textura para el texto que se escribe en pantalla
|
||||
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
if (textTexture == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa variables
|
||||
oldJailerID = options->online.jailerID;
|
||||
loopRunning = true;
|
||||
counter = 0;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
jailerIDPos = 0;
|
||||
initName();
|
||||
|
||||
// Escribe el texto en la textura
|
||||
fillTexture();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
EnterID::~EnterID()
|
||||
{
|
||||
delete eventHandler;
|
||||
delete text;
|
||||
delete texture;
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void EnterID::run()
|
||||
{
|
||||
while (loopRunning)
|
||||
{
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void EnterID::checkEvents()
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
loopRunning = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba las teclas que se han pulsado
|
||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN)
|
||||
{
|
||||
options->online.jailerID = toLower((std::string)name);
|
||||
endSection();
|
||||
break;
|
||||
}
|
||||
|
||||
if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_A && eventHandler->key.keysym.scancode <= SDL_SCANCODE_Z)
|
||||
{ // Si pulsa una letra
|
||||
if (pos < maxLenght)
|
||||
{
|
||||
name[pos++] = eventHandler->key.keysym.scancode + 61;
|
||||
name[pos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_1 && eventHandler->key.keysym.scancode <= SDL_SCANCODE_9)
|
||||
{ // Si pulsa un número
|
||||
if (pos < maxLenght)
|
||||
{ // En ascii el '0' va antes del '1', pero en scancode el '0' va despues de '9'
|
||||
name[pos++] = eventHandler->key.keysym.scancode + 19;
|
||||
name[pos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_0)
|
||||
{
|
||||
if (pos < maxLenght)
|
||||
{
|
||||
name[pos++] = 48;
|
||||
name[pos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_BACKSPACE)
|
||||
{
|
||||
if (pos > 0)
|
||||
{
|
||||
name[--pos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
loopRunning = false;
|
||||
break;
|
||||
}
|
||||
|
||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F1)
|
||||
{
|
||||
screen->setWindowSize(1);
|
||||
break;
|
||||
}
|
||||
|
||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F2)
|
||||
{
|
||||
screen->setWindowSize(2);
|
||||
break;
|
||||
}
|
||||
|
||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F3)
|
||||
{
|
||||
screen->setWindowSize(3);
|
||||
break;
|
||||
}
|
||||
|
||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F4)
|
||||
{
|
||||
screen->setWindowSize(4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void EnterID::update()
|
||||
{
|
||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza el contador
|
||||
counter++;
|
||||
|
||||
// Actualiza el cursor
|
||||
cursor = (counter % 20 >= 10) ? " " : "_";
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja en pantalla
|
||||
void EnterID::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
|
||||
// Dibuja la textura con el texto en pantalla
|
||||
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
|
||||
|
||||
// Escribe el jailerID
|
||||
const std::string jailerID = (std::string)name + cursor;
|
||||
const color_t color = stringToColor(options->palette, "white");
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, jailerIDPos, jailerID, 1, color);
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Inicializa los textos
|
||||
void EnterID::iniTexts()
|
||||
{
|
||||
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
||||
const color_t noColor = {0xFF, 0xFF, 0xFF};
|
||||
|
||||
texts.clear();
|
||||
texts.push_back({lang->getText(89), orangeColor});
|
||||
texts.push_back({"", noColor});
|
||||
texts.push_back({lang->getText(90), noColor});
|
||||
texts.push_back({lang->getText(91), noColor});
|
||||
texts.push_back({lang->getText(92), noColor});
|
||||
texts.push_back({"", noColor});
|
||||
texts.push_back({"", noColor});
|
||||
texts.push_back({"", noColor});
|
||||
texts.push_back({"JAILER_ID:", orangeColor});
|
||||
}
|
||||
|
||||
// Escribe el texto en la textura
|
||||
void EnterID::fillTexture()
|
||||
{
|
||||
const color_t shdwTxtColor = {0x43, 0x43, 0x4F};
|
||||
|
||||
// Inicializa los textos
|
||||
iniTexts();
|
||||
|
||||
// Rellena la textura con un color de fondo
|
||||
SDL_SetRenderTarget(renderer, textTexture);
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Añade el efecto de degradado en el fondo
|
||||
//Texture *gradient = new Texture(renderer, asset->get("title_gradient.png"));
|
||||
//SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||
//gradient->render(renderer, 0, 0, &rect);
|
||||
//delete gradient;
|
||||
|
||||
// Escribe el texto en la textura
|
||||
const int desp = 40;
|
||||
const int size = text->getCharacterSize() + 2;
|
||||
int i = 0;
|
||||
|
||||
for (auto t : texts)
|
||||
{
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, PLAY_AREA_CENTER_X, (i * size) + desp, t.label, 1, t.color, 1, shdwTxtColor);
|
||||
i++;
|
||||
}
|
||||
jailerIDPos = ((i + 1) * size) + desp;
|
||||
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
}
|
||||
|
||||
// Inicializa los servicios online
|
||||
void EnterID::initOnline()
|
||||
{
|
||||
// Si ya ha iniciado la sesión y no ha cambiado el jailerID, que no continue
|
||||
if (options->online.sessionEnabled)
|
||||
{
|
||||
if (oldJailerID == options->online.jailerID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (options->online.jailerID == "")
|
||||
{ // Jailer ID no definido
|
||||
options->online.enabled = false;
|
||||
options->online.sessionEnabled = false;
|
||||
}
|
||||
else
|
||||
{ // Jailer ID iniciado
|
||||
options->online.enabled = options->online.sessionEnabled = true;
|
||||
// Establece el servidor y el puerto
|
||||
jscore::init(options->online.server, options->online.port);
|
||||
#ifdef DEBUG
|
||||
const std::string caption = options->online.jailerID + " (DEBUG)";
|
||||
#else
|
||||
const std::string caption = options->online.jailerID;
|
||||
#endif
|
||||
// screen->showNotification(caption, lang->getText(85), 12);
|
||||
screen->showNotification(caption, lang->getText(85));
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << caption << std::endl;
|
||||
}
|
||||
|
||||
// Obtiene la información de puntuaciones online
|
||||
if (!jscore::initOnlineScore(options->online.gameID))
|
||||
{
|
||||
screen->showNotification(lang->getText(80), options->online.server);
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Can't connect to " << options->online.server << std::endl;
|
||||
}
|
||||
|
||||
options->online.enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Obten la puntuación online para el jailerID
|
||||
const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID);
|
||||
if (points == 0)
|
||||
{ // Fallo de conexión o no hay registros
|
||||
screen->showNotification(lang->getText(81), lang->getText(82));
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Can't get online scores" << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
options->online.score = points;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Termina la sección
|
||||
void EnterID::endSection()
|
||||
{
|
||||
loopRunning = false;
|
||||
initOnline();
|
||||
}
|
||||
|
||||
// Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla
|
||||
void EnterID::initName()
|
||||
{
|
||||
// Calcula el tamaño del vector
|
||||
name[0] = 0;
|
||||
maxLenght = sizeof(name) / sizeof(name[pos]);
|
||||
|
||||
// Inicializa el vector con ceros
|
||||
for (int i = 0; i < maxLenght; ++i)
|
||||
{
|
||||
name[i] = 0;
|
||||
}
|
||||
|
||||
// Si no hay definido ningun JailerID, coloca el cursor en primera posición
|
||||
if (options->online.jailerID == "")
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
else
|
||||
{ // En caso contrario, copia el texto al vector y coloca el cursor en posición
|
||||
const int len = std::min((int)options->online.jailerID.size(), maxLenght);
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
name[i] = (char)options->online.jailerID[i];
|
||||
}
|
||||
pos = len;
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/asset.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/text.h"
|
||||
#include "common/texture.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef ENTER_ID_H
|
||||
#define ENTER_ID_H
|
||||
|
||||
class EnterID
|
||||
{
|
||||
private:
|
||||
struct captions_t
|
||||
{
|
||||
std::string label; // Texto a escribir
|
||||
color_t color; // Color del texto
|
||||
};
|
||||
|
||||
// Punteros y objetos
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
SDL_Texture *textTexture; // Textura para dibujar el texto
|
||||
Text *text; // Objeto para escribir texto en pantalla
|
||||
Texture *texture; // Textura para la fuente para el texto
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
// Variables
|
||||
bool loopRunning; // Indica si ha de terminar el bucle principal
|
||||
int counter; // Contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::vector<captions_t> texts; // Vector con los textos
|
||||
std::string cursor; // Contiene el caracter que se muestra como cursor
|
||||
|
||||
char name[15]; // Aqui se guardan los caracteres de las teclas que se van pulsando
|
||||
int pos; // Posición actual en el vector name
|
||||
int maxLenght; // Tamaño máximo del jailerID
|
||||
std::string oldJailerID; // Almacena el valor de jailerID al inicio para ver si se ha modificado
|
||||
int jailerIDPos; // Posición en el eje Y donde ser va a escribir el texto
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
|
||||
// Dibuja en pantalla
|
||||
void render();
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void checkEvents();
|
||||
|
||||
// Inicializa los textos
|
||||
void iniTexts();
|
||||
|
||||
// Escribe el texto en la textura
|
||||
void fillTexture();
|
||||
|
||||
// Inicializa los servicios online
|
||||
void initOnline();
|
||||
|
||||
// Termina la sección
|
||||
void endSection();
|
||||
|
||||
// Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla
|
||||
void initName();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~EnterID();
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,10 @@
|
||||
#include "fade.h"
|
||||
#include "const.h"
|
||||
#include <iostream>
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_timer.h> // for SDL_Delay
|
||||
#include <stdlib.h> // for rand
|
||||
#include <iostream> // for char_traits, basic_ostream, operator<<
|
||||
#include "const.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
||||
|
||||
// Constructor
|
||||
Fade::Fade(SDL_Renderer *renderer)
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/texture.h"
|
||||
|
||||
#ifndef FADE_H
|
||||
#define FADE_H
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16
|
||||
|
||||
// Tipos de fundido
|
||||
#define FADE_FULLSCREEN 0
|
||||
#define FADE_CENTER 1
|
||||
#define FADE_RANDOM_SQUARE 2
|
||||
constexpr int FADE_FULLSCREEN = 0;
|
||||
constexpr int FADE_CENTER = 1;
|
||||
constexpr int FADE_RANDOM_SQUARE = 2;
|
||||
|
||||
// Clase Fade
|
||||
class Fade
|
||||
@@ -52,6 +50,4 @@ public:
|
||||
|
||||
// Establece el tipo de fade
|
||||
void setFadeType(Uint8 fadeType);
|
||||
};
|
||||
|
||||
#endif
|
||||
};
|
||||
@@ -1,5 +1,30 @@
|
||||
#include "game.h"
|
||||
#include "common/jscore.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 <stdlib.h> // for rand
|
||||
#include <algorithm> // for max, min
|
||||
#include <fstream> // for basic_ifstream
|
||||
#include <iostream> // for basic_ostream, char_traits, operator<<
|
||||
#include "asset.h" // for Asset
|
||||
#include "balloon.h" // for Balloon, BALLOON_VELX_NEGATIVE, BALLOON_...
|
||||
#include "bullet.h" // for Bullet, BULLET_LEFT, BULLET_RIGHT, BULLE...
|
||||
#include "const.h" // for PLAY_AREA_CENTER_X, BLOCK, PLAY_AREA_CEN...
|
||||
#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 "lang.h" // for Lang
|
||||
#include "menu.h" // for Menu
|
||||
#include "movingsprite.h" // for MovingSprite
|
||||
#include "player.h" // for Player, DEATH_COUNTER
|
||||
#include "screen.h" // for Screen
|
||||
#include "smartsprite.h" // for SmartSprite
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text, TXT_CENTER
|
||||
#include "texture.h" // for Texture
|
||||
struct JA_Sound_t;
|
||||
|
||||
// Constructor
|
||||
Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section)
|
||||
@@ -69,7 +94,6 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
||||
Game::~Game()
|
||||
{
|
||||
saveScoreFile();
|
||||
sendOnlineScore();
|
||||
saveDemoFile();
|
||||
|
||||
// Restaura el metodo de control
|
||||
@@ -773,38 +797,6 @@ bool Game::saveScoreFile()
|
||||
return success;
|
||||
}
|
||||
|
||||
// Sube la puntuación online
|
||||
bool Game::sendOnlineScore()
|
||||
{
|
||||
if (!options->online.enabled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (demo.enabled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
const int score = players[0]->getScore();
|
||||
if (score <= options->online.score)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (jscore::updateUserPoints(options->online.gameID, options->online.jailerID, score))
|
||||
{
|
||||
options->online.score = score;
|
||||
screen->showNotification(lang->getText(86) + std::to_string(score), "", 2);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
screen->showNotification(lang->getText(86), lang->getText(87));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool Game::saveDemoFile()
|
||||
{
|
||||
@@ -1621,12 +1613,6 @@ void Game::updateHiScore()
|
||||
// Actualiza la máxima puntuación
|
||||
hiScore = player->getScore();
|
||||
|
||||
// Cambia el nombre del jugador con la máxima puntuación
|
||||
if (options->online.enabled)
|
||||
{
|
||||
hiScoreName = options->online.jailerID.substr(0, 12) + " - ";
|
||||
}
|
||||
|
||||
// Almacena la máxima puntuación en el fichero junto con un checksum
|
||||
scoreDataFile[0] = hiScore;
|
||||
scoreDataFile[1] = hiScore % 43;
|
||||
@@ -2793,9 +2779,6 @@ void Game::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
|
||||
// Actualiza el contador de juego
|
||||
counter++;
|
||||
|
||||
@@ -3400,9 +3383,6 @@ void Game::updatePausedGame()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
|
||||
if (leavingPauseMenu)
|
||||
{
|
||||
if (pauseCounter > 0)
|
||||
@@ -3545,9 +3525,6 @@ void Game::updateGameOverScreen()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
|
||||
// Actualiza la lógica del menu
|
||||
gameOverMenu->update();
|
||||
|
||||
@@ -3693,9 +3670,6 @@ void Game::runGameOverScreen()
|
||||
// Guarda los puntos
|
||||
saveScoreFile();
|
||||
|
||||
// Sube la puntuación online
|
||||
sendOnlineScore();
|
||||
|
||||
// Reinicia el menu
|
||||
gameOverMenu->reset();
|
||||
|
||||
@@ -3985,23 +3959,5 @@ void Game::setHiScore()
|
||||
{
|
||||
// Carga el fichero de puntos
|
||||
loadScoreFile();
|
||||
|
||||
// Establece el resto de variables
|
||||
if (options->online.enabled)
|
||||
{
|
||||
if (jscore::getNumUsers() > 0)
|
||||
{
|
||||
hiScoreName = jscore::getUserName(0).substr(0, 12) + " - ";
|
||||
hiScore = (Uint32)jscore::getPoints(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
hiScoreName = "Bacteriol - ";
|
||||
hiScore = 10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hiScoreName = "";
|
||||
}
|
||||
hiScoreName = "";
|
||||
}
|
||||
@@ -1,54 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "balloon.h"
|
||||
#include "bullet.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/input.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/menu.h"
|
||||
#include "common/movingsprite.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/smartsprite.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/text.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/writer.h"
|
||||
#include "const.h"
|
||||
#include "fade.h"
|
||||
#include "item.h"
|
||||
#include "player.h"
|
||||
#include <iostream>
|
||||
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for demoKeys_t, color_t
|
||||
class Asset;
|
||||
class Balloon;
|
||||
class Bullet;
|
||||
class Fade;
|
||||
class Input;
|
||||
class Item;
|
||||
class Lang;
|
||||
class Menu;
|
||||
class MovingSprite;
|
||||
class Player;
|
||||
class Screen;
|
||||
class SmartSprite;
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
|
||||
// Cantidad de elementos a escribir en los ficheros de datos
|
||||
#define TOTAL_SCORE_DATA 3
|
||||
#define TOTAL_DEMO_DATA 2000
|
||||
constexpr int TOTAL_SCORE_DATA = 3;
|
||||
constexpr int TOTAL_DEMO_DATA = 2000;
|
||||
|
||||
// Contadores
|
||||
#define STAGE_COUNTER 200
|
||||
#define SHAKE_COUNTER 10
|
||||
#define HELP_COUNTER 1000
|
||||
#define GAME_COMPLETED_START_FADE 500
|
||||
#define GAME_COMPLETED_END 700
|
||||
constexpr int STAGE_COUNTER = 200;
|
||||
constexpr int SHAKE_COUNTER = 10;
|
||||
constexpr int HELP_COUNTER = 1000;
|
||||
constexpr int GAME_COMPLETED_START_FADE = 500;
|
||||
constexpr int GAME_COMPLETED_END = 700;
|
||||
|
||||
// Formaciones enemigas
|
||||
#define NUMBER_OF_ENEMY_FORMATIONS 100
|
||||
#define MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION 50
|
||||
constexpr int NUMBER_OF_ENEMY_FORMATIONS = 100;
|
||||
constexpr int MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION = 50;
|
||||
|
||||
// Porcentaje de aparición de los objetos
|
||||
#define ITEM_POINTS_1_DISK_ODDS 10
|
||||
#define ITEM_POINTS_2_GAVINA_ODDS 6
|
||||
#define ITEM_POINTS_3_PACMAR_ODDS 3
|
||||
#define ITEM_CLOCK_ODDS 5
|
||||
#define ITEM_COFFEE_ODDS 5
|
||||
#define ITEM_POWER_BALL_ODDS 0
|
||||
#define ITEM_COFFEE_MACHINE_ODDS 4
|
||||
constexpr int ITEM_POINTS_1_DISK_ODDS = 10;
|
||||
constexpr int ITEM_POINTS_2_GAVINA_ODDS = 6;
|
||||
constexpr int ITEM_POINTS_3_PACMAR_ODDS = 3;
|
||||
constexpr int ITEM_CLOCK_ODDS = 5;
|
||||
constexpr int ITEM_COFFEE_ODDS = 5;
|
||||
constexpr int ITEM_POWER_BALL_ODDS = 0;
|
||||
constexpr int ITEM_COFFEE_MACHINE_ODDS = 4;
|
||||
|
||||
// Valores para las variables asociadas a los objetos
|
||||
#define TIME_STOPPED_COUNTER 300
|
||||
constexpr int TIME_STOPPED_COUNTER = 300;
|
||||
|
||||
// Clase Game
|
||||
class Game
|
||||
@@ -266,9 +268,6 @@ private:
|
||||
// Guarda el fichero de puntos
|
||||
bool saveScoreFile();
|
||||
|
||||
// Sube la puntuación online
|
||||
bool sendOnlineScore();
|
||||
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool saveDemoFile();
|
||||
|
||||
@@ -528,5 +527,3 @@ public:
|
||||
// Bucle para el juego
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,286 +0,0 @@
|
||||
#include "hiscore_table.h"
|
||||
#include "common/jscore.h"
|
||||
#include <iostream>
|
||||
|
||||
const Uint8 SELF = 0;
|
||||
|
||||
// Constructor
|
||||
HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->lang = lang;
|
||||
this->section = section;
|
||||
this->options = options;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
eventHandler = new SDL_Event();
|
||||
|
||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||
|
||||
// Crea un backbuffer para el renderizador
|
||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
if (backbuffer == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
section->name = SELF;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
manualQuit = false;
|
||||
counter = 0;
|
||||
counterEnd = 600;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
HiScoreTable::~HiScoreTable()
|
||||
{
|
||||
delete eventHandler;
|
||||
delete text;
|
||||
|
||||
SDL_DestroyTexture(backbuffer);
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void HiScoreTable::update()
|
||||
{
|
||||
// Comprueba los eventos
|
||||
checkEventHandler();
|
||||
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
|
||||
// Actualiza las variables
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
|
||||
if (mode == mhst_auto)
|
||||
{ // Modo automático
|
||||
counter++;
|
||||
|
||||
if (counter == counterEnd)
|
||||
{
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
section->subsection = SUBSECTION_TITLE_1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // Modo manual
|
||||
++counter %= 60000;
|
||||
|
||||
if (manualQuit)
|
||||
{
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
section->subsection = SUBSECTION_TITLE_3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta en pantalla
|
||||
void HiScoreTable::render()
|
||||
{
|
||||
// Pinta en pantalla
|
||||
SDL_Rect window = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||
|
||||
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots
|
||||
const int spaceBetweenHeader = 32;
|
||||
const int spaceBetweenLines = text->getCharacterSize() * 1.8f;
|
||||
|
||||
// Pinta en el backbuffer el texto y los sprites
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Escribe el texto: Mejores puntuaciones
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 8, lang->getText(42), 1, orangeColor, 1, shdwTxtColor);
|
||||
|
||||
// Escribe la lista de jugadores
|
||||
int numUsers = jscore::getNumUsers();
|
||||
for (int i = 0; i < numUsers; ++i)
|
||||
{
|
||||
const std::string userName = jscore::getUserName(i).substr(0, 17);
|
||||
const int nameLenght = (int)userName.length();
|
||||
const int numDots = 20 - nameLenght;
|
||||
std::string dots = "";
|
||||
for (int j = 0; j < numDots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const std::string line = userName + dots + scoreToString(jscore::getPoints(i));
|
||||
text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
||||
}
|
||||
|
||||
// Rellena la lista con otros nombres
|
||||
if (numUsers < 10)
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
names.insert(names.end(), {"Bry", "Usufondo", "G.Lucas", "P.Delgat", "P.Arrabalera", "Pelechano", "Sahuquillo", "Bacteriol", "Pepe", "Rosita"});
|
||||
|
||||
for (int i = numUsers; i < 10; ++i)
|
||||
{
|
||||
const int nameLenght = names[i - numUsers].length();
|
||||
const int numDots = 20 - nameLenght;
|
||||
std::string dots = "";
|
||||
for (int j = 0; j < numDots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const std::string line = names[i - numUsers] + dots + "0000000";
|
||||
text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
||||
}
|
||||
}
|
||||
|
||||
if ((mode == mhst_manual) && (counter % 50 > 14))
|
||||
{
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_HEIGHT - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
||||
}
|
||||
|
||||
// Cambia el destino de renderizado
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bgColor);
|
||||
|
||||
// Establece la ventana del backbuffer
|
||||
if (mode == mhst_auto)
|
||||
{
|
||||
window.y = std::max(8, GAMECANVAS_HEIGHT - counter + 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.y = 0;
|
||||
}
|
||||
|
||||
// Copia el backbuffer al renderizador
|
||||
SDL_RenderCopy(renderer, backbuffer, nullptr, &window);
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
void HiScoreTable::checkEventHandler()
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void HiScoreTable::checkInput()
|
||||
{
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
|
||||
{
|
||||
screen->switchVideoMode();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
{
|
||||
screen->decWindowSize();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
{
|
||||
screen->incWindowSize();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
||||
{
|
||||
if (mode == mhst_auto)
|
||||
{
|
||||
JA_StopMusic();
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
section->subsection = SUBSECTION_TITLE_1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (counter > 30)
|
||||
{
|
||||
manualQuit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bucle para la pantalla de instrucciones
|
||||
void HiScoreTable::run(mode_hiScoreTable_e mode)
|
||||
{
|
||||
this->mode = mode;
|
||||
|
||||
while (section->name == SELF)
|
||||
{
|
||||
update();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Transforma un valor numérico en una cadena de 6 cifras
|
||||
std::string HiScoreTable::scoreToString(Uint32 num)
|
||||
{
|
||||
if ((num >= 0) && (num <= 9))
|
||||
{
|
||||
return ("000000" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 10) && (num <= 99))
|
||||
{
|
||||
return ("00000" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 100) && (num <= 999))
|
||||
{
|
||||
return ("0000" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 1000) && (num <= 9999))
|
||||
{
|
||||
return ("000" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 010000) && (num <= 99999))
|
||||
{
|
||||
return ("00" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 100000) && (num <= 999999))
|
||||
{
|
||||
return ("0" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 1000000) && (num <= 9999999))
|
||||
{
|
||||
return (std::to_string(num));
|
||||
}
|
||||
|
||||
return (std::to_string(num));
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/asset.h"
|
||||
#include "common/input.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/text.h"
|
||||
#include "common/utils.h"
|
||||
#include "const.h"
|
||||
|
||||
#ifndef HISCORE_TABLE_H
|
||||
#define HISCORE_TABLE_H
|
||||
|
||||
enum mode_hiScoreTable_e
|
||||
{
|
||||
mhst_manual,
|
||||
mhst_auto
|
||||
};
|
||||
|
||||
class HiScoreTable
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
Text *text; // Objeto para escribir texto
|
||||
options_t *options; // Opciones y parametros del programa
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
// Variables
|
||||
Uint16 counter; // Contador
|
||||
Uint16 counterEnd; // Valor final para el contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
bool manualQuit; // Indica si se quiere salir del modo manual
|
||||
mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
|
||||
// Pinta en pantalla
|
||||
void render();
|
||||
|
||||
// Comprueba los eventos
|
||||
void checkEventHandler();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
// Transforma un valor numérico en una cadena de 6 cifras
|
||||
std::string scoreToString(Uint32 num);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~HiScoreTable();
|
||||
|
||||
// Bucle principal
|
||||
void run(mode_hiScoreTable_e mode);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,10 @@
|
||||
#include "input.h"
|
||||
#include <iostream>
|
||||
#include <SDL2/SDL.h> // for SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // for SDL_ENABLE
|
||||
#include <SDL2/SDL_joystick.h> // for SDL_NumJoysticks
|
||||
#include <SDL2/SDL_keyboard.h> // for SDL_GetKeyboardState
|
||||
#include <iostream> // for basic_ostream, operator<<, cout, basi...
|
||||
|
||||
// Constructor
|
||||
Input::Input(std::string file)
|
||||
@@ -1,11 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton, SDL_G...
|
||||
#include <SDL2/SDL_scancode.h> // for SDL_Scancode
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
// Valores de repetición
|
||||
constexpr bool REPEAT_TRUE = true;
|
||||
constexpr bool REPEAT_FALSE = false;
|
||||
|
||||
// Métodos de entrada
|
||||
constexpr int INPUT_USE_KEYBOARD = 0;
|
||||
constexpr int INPUT_USE_GAMECONTROLLER = 1;
|
||||
constexpr int INPUT_USE_ANY = 2;
|
||||
|
||||
enum inputs_e
|
||||
{
|
||||
@@ -32,13 +40,6 @@ enum inputs_e
|
||||
input_number_of_inputs
|
||||
};
|
||||
|
||||
#define REPEAT_TRUE true
|
||||
#define REPEAT_FALSE false
|
||||
|
||||
#define INPUT_USE_KEYBOARD 0
|
||||
#define INPUT_USE_GAMECONTROLLER 1
|
||||
#define INPUT_USE_ANY 2
|
||||
|
||||
enum i_disable_e
|
||||
{
|
||||
d_notDisabled,
|
||||
@@ -113,6 +114,4 @@ public:
|
||||
|
||||
// Hablita las entradas
|
||||
void enable();
|
||||
};
|
||||
|
||||
#endif
|
||||
};
|
||||
@@ -1,5 +1,21 @@
|
||||
#include "instructions.h"
|
||||
#include <iostream>
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // for max
|
||||
#include <iostream> // for char_traits, basic_ostream, operator<<
|
||||
#include <string> // for basic_string
|
||||
#include "asset.h" // for Asset
|
||||
#include "const.h" // for shdwTxtColor, GAMECANVAS_CENTER_X, GAME...
|
||||
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "jail_audio.h" // for JA_StopMusic
|
||||
#include "lang.h" // for Lang
|
||||
#include "screen.h" // for Screen
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for color_t, section_t
|
||||
|
||||
const Uint8 SELF = 0;
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/asset.h"
|
||||
#include "common/input.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/text.h"
|
||||
#include "common/utils.h"
|
||||
#include "const.h"
|
||||
|
||||
#ifndef INSTRUCTIONS_H
|
||||
#define INSTRUCTIONS_H
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16, Uint32
|
||||
#include <vector> // for vector
|
||||
class Asset;
|
||||
class Input;
|
||||
class Lang;
|
||||
class Screen;
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
struct section_t;
|
||||
|
||||
enum mode_e
|
||||
{
|
||||
@@ -65,6 +65,4 @@ public:
|
||||
|
||||
// Bucle principal
|
||||
void run(mode_e mode);
|
||||
};
|
||||
|
||||
#endif
|
||||
};
|
||||
@@ -1,4 +1,17 @@
|
||||
#include "intro.h"
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <string> // for basic_string
|
||||
#include "asset.h" // for Asset
|
||||
#include "const.h" // for GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QU...
|
||||
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "jail_audio.h" // for JA_StopMusic, JA_DeleteMusic, JA_LoadMusic
|
||||
#include "lang.h" // for Lang
|
||||
#include "screen.h" // for Screen
|
||||
#include "smartsprite.h" // for SmartSprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for section_t, color_t
|
||||
#include "writer.h" // for Writer
|
||||
|
||||
// Constructor
|
||||
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section)
|
||||
@@ -398,9 +411,6 @@ void Intro::update()
|
||||
|
||||
// Actualiza las escenas de la intro
|
||||
updateScenes();
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/asset.h"
|
||||
#include "common/input.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/smartsprite.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/writer.h"
|
||||
#include "const.h"
|
||||
#include <vector>
|
||||
|
||||
#ifndef INTRO_H
|
||||
#define INTRO_H
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||
#include <vector> // for vector
|
||||
class Asset;
|
||||
class Input;
|
||||
class Lang;
|
||||
class Screen;
|
||||
class SmartSprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
class Writer;
|
||||
struct JA_Music_t;
|
||||
struct section_t;
|
||||
|
||||
// Clase Intro
|
||||
class Intro
|
||||
@@ -65,5 +66,3 @@ public:
|
||||
// Bucle principal
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "const.h"
|
||||
#include "item.h"
|
||||
#include <stdlib.h> // for rand
|
||||
#include "animatedsprite.h" // for AnimatedSprite
|
||||
#include "const.h" // for PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_AR...
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
Item::Item(Uint8 kind, float x, float y, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer)
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/utils.h"
|
||||
|
||||
#ifndef ITEM_H
|
||||
#define ITEM_H
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for circle_t
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
// Tipos de objetos
|
||||
#define ITEM_POINTS_1_DISK 1
|
||||
#define ITEM_POINTS_2_GAVINA 2
|
||||
#define ITEM_POINTS_3_PACMAR 3
|
||||
#define ITEM_CLOCK 4
|
||||
#define ITEM_COFFEE 5
|
||||
#define ITEM_COFFEE_MACHINE 6
|
||||
constexpr int ITEM_POINTS_1_DISK = 1;
|
||||
constexpr int ITEM_POINTS_2_GAVINA = 2;
|
||||
constexpr int ITEM_POINTS_3_PACMAR = 3;
|
||||
constexpr int ITEM_CLOCK = 4;
|
||||
constexpr int ITEM_COFFEE = 5;
|
||||
constexpr int ITEM_COFFEE_MACHINE = 6;
|
||||
|
||||
// Clase Item
|
||||
class Item
|
||||
@@ -41,6 +42,7 @@ private:
|
||||
|
||||
// Actualiza la posición y estados del objeto
|
||||
void move();
|
||||
|
||||
public:
|
||||
Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente
|
||||
|
||||
@@ -56,7 +58,6 @@ public:
|
||||
// Pinta el objeto en la pantalla
|
||||
void render();
|
||||
|
||||
|
||||
// Pone a cero todos los valores del objeto
|
||||
void disable();
|
||||
|
||||
@@ -93,5 +94,3 @@ public:
|
||||
// Informa si el objeto ha colisionado con el suelo
|
||||
bool isOnFloor();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
#ifndef JA_USESDLMIXER
|
||||
#include "jail_audio.h"
|
||||
#include "stb_vorbis.c"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL2/SDL_log.h> // for SDL_Log, SDL_LogSetPriority, SDL_LOG_CAT...
|
||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromMem
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <stdint.h> // for uint8_t, uint32_t
|
||||
#include <stdio.h> // for NULL, fseek, fclose, fopen, fread, ftell
|
||||
#include <stdlib.h> // for free, malloc
|
||||
#include "stb_vorbis.c" // for stb_vorbis_decode_memory
|
||||
|
||||
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
||||
constexpr int JA_MAX_SIMULTANEOUS_CHANNELS = 20;
|
||||
|
||||
struct JA_Sound_t {
|
||||
Uint32 length {0};
|
||||
@@ -20,6 +24,7 @@ struct JA_Channel_t {
|
||||
|
||||
struct JA_Music_t {
|
||||
int samples {0};
|
||||
Uint32 length {0};
|
||||
int pos {0};
|
||||
int times {0};
|
||||
short* output {NULL};
|
||||
@@ -32,19 +37,41 @@ JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
||||
int JA_freq {48000};
|
||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
||||
Uint8 JA_channels {2};
|
||||
int JA_volume = 128;
|
||||
int JA_musicVolume = 128;
|
||||
int JA_soundVolume = 64;
|
||||
bool JA_musicEnabled = true;
|
||||
bool JA_soundEnabled = true;
|
||||
SDL_AudioDeviceID sdlAudioDevice = 0;
|
||||
|
||||
bool fading = false;
|
||||
int fade_start_time;
|
||||
int fade_duration;
|
||||
int fade_initial_volume;
|
||||
|
||||
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||
SDL_memset(stream, 0, len);
|
||||
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
||||
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
|
||||
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_volume);
|
||||
current_music->pos += size/2;
|
||||
int volume = JA_musicVolume;
|
||||
if (fading) {
|
||||
int time = SDL_GetTicks();
|
||||
if (time > (fade_start_time+fade_duration)) {
|
||||
fading = false;
|
||||
current_music->pos = 0;
|
||||
current_music->state = JA_MUSIC_STOPPED;
|
||||
volume = 0;
|
||||
} else {
|
||||
const int time_passed = time - fade_start_time;
|
||||
const float percent = (float)time_passed / (float)fade_duration;
|
||||
volume = JA_musicVolume * (1.0 - percent);
|
||||
}
|
||||
}
|
||||
const int size = SDL_min(len, current_music->length - current_music->pos);
|
||||
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output)+current_music->pos, AUDIO_S16, size, volume);
|
||||
current_music->pos += size;
|
||||
if (size < len) {
|
||||
if (current_music->times != 0) {
|
||||
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_volume);
|
||||
current_music->pos = (len-size)/2;
|
||||
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, volume);
|
||||
current_music->pos = len-size;
|
||||
if (current_music->times > 0) current_music->times--;
|
||||
} else {
|
||||
current_music->pos = 0;
|
||||
@@ -56,11 +83,11 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
||||
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
||||
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2);
|
||||
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_soundVolume);
|
||||
channels[i].pos += size;
|
||||
if (size < len) {
|
||||
if (channels[i].times != 0) {
|
||||
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2);
|
||||
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_soundVolume);
|
||||
channels[i].pos = len-size;
|
||||
if (channels[i].times > 0) channels[i].times--;
|
||||
} else {
|
||||
@@ -71,13 +98,19 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||
}
|
||||
}
|
||||
|
||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
|
||||
#endif
|
||||
|
||||
JA_freq = freq;
|
||||
JA_format = format;
|
||||
JA_channels = channels;
|
||||
SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL};
|
||||
if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice);
|
||||
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
||||
|
||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
||||
}
|
||||
|
||||
@@ -87,9 +120,35 @@ void JA_Quit() {
|
||||
sdlAudioDevice = 0;
|
||||
}
|
||||
|
||||
JA_Music_t *JA_LoadMusic(const char* filename) {
|
||||
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length)
|
||||
{
|
||||
int chan, samplerate;
|
||||
JA_Music_t *music = new JA_Music_t();
|
||||
|
||||
music->samples = stb_vorbis_decode_memory(buffer, length, &chan, &samplerate, &music->output);
|
||||
// [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert
|
||||
// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
||||
|
||||
SDL_AudioCVT cvt;
|
||||
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
||||
if (cvt.needed) {
|
||||
cvt.len = music->samples * chan * 2;
|
||||
music->length = cvt.len;
|
||||
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
||||
SDL_memcpy(cvt.buf, music->output, cvt.len);
|
||||
SDL_ConvertAudio(&cvt);
|
||||
free(music->output);
|
||||
music->output = (short*)cvt.buf;
|
||||
}
|
||||
music->length = music->samples * chan * 2;
|
||||
music->pos = 0;
|
||||
music->state = JA_MUSIC_STOPPED;
|
||||
|
||||
return music;
|
||||
}
|
||||
|
||||
JA_Music_t *JA_LoadMusic(const char* filename)
|
||||
{
|
||||
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
||||
FILE *f = fopen(filename, "rb");
|
||||
fseek(f, 0, SEEK_END);
|
||||
@@ -99,30 +158,17 @@ JA_Music_t *JA_LoadMusic(const char* filename) {
|
||||
if (fread(buffer, fsize, 1, f)!=1) return NULL;
|
||||
fclose(f);
|
||||
|
||||
JA_Music_t *music = new JA_Music_t();
|
||||
JA_Music_t *music = JA_LoadMusic(buffer, fsize);
|
||||
|
||||
music->samples = stb_vorbis_decode_memory(buffer, fsize, &chan, &samplerate, &music->output);
|
||||
free(buffer);
|
||||
// [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert
|
||||
// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
||||
|
||||
SDL_AudioCVT cvt;
|
||||
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
||||
if (cvt.needed) {
|
||||
cvt.len = music->samples * chan * 2;
|
||||
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
||||
SDL_memcpy(cvt.buf, music->output, cvt.len);
|
||||
SDL_ConvertAudio(&cvt);
|
||||
free(music->output);
|
||||
music->output = (short*)cvt.buf;
|
||||
}
|
||||
music->pos = 0;
|
||||
music->state = JA_MUSIC_STOPPED;
|
||||
|
||||
return music;
|
||||
}
|
||||
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop)
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
|
||||
if (current_music != NULL) {
|
||||
current_music->pos = 0;
|
||||
current_music->state = JA_MUSIC_STOPPED;
|
||||
@@ -133,23 +179,45 @@ void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
||||
current_music->times = loop;
|
||||
}
|
||||
|
||||
void JA_PauseMusic() {
|
||||
void JA_PauseMusic()
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
|
||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||
current_music->state = JA_MUSIC_PAUSED;
|
||||
}
|
||||
|
||||
void JA_ResumeMusic() {
|
||||
void JA_ResumeMusic()
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
|
||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||
current_music->state = JA_MUSIC_PLAYING;
|
||||
}
|
||||
|
||||
void JA_StopMusic() {
|
||||
void JA_StopMusic()
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
|
||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||
current_music->pos = 0;
|
||||
current_music->state = JA_MUSIC_STOPPED;
|
||||
}
|
||||
|
||||
void JA_FadeOutMusic(const int milliseconds)
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||
|
||||
fading = true;
|
||||
fade_start_time = SDL_GetTicks();
|
||||
fade_duration = milliseconds;
|
||||
fade_initial_volume = JA_musicVolume;
|
||||
}
|
||||
|
||||
JA_Music_state JA_GetMusicState() {
|
||||
if (!JA_musicEnabled) return JA_MUSIC_DISABLED;
|
||||
|
||||
if (current_music == NULL) return JA_MUSIC_INVALID;
|
||||
return current_music->state;
|
||||
}
|
||||
@@ -160,6 +228,35 @@ void JA_DeleteMusic(JA_Music_t *music) {
|
||||
delete music;
|
||||
}
|
||||
|
||||
int JA_SetMusicVolume(int volume)
|
||||
{
|
||||
JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||
return JA_musicVolume;
|
||||
}
|
||||
|
||||
void JA_SetMusicPosition(float value)
|
||||
{
|
||||
if (!current_music) return;
|
||||
current_music->pos = value * JA_freq;
|
||||
}
|
||||
|
||||
float JA_GetMusicPosition()
|
||||
{
|
||||
if (!current_music) return 0;
|
||||
return float(current_music->pos)/float(JA_freq);
|
||||
}
|
||||
|
||||
void JA_EnableMusic(const bool value)
|
||||
{
|
||||
if (!value && current_music != NULL && current_music->state==JA_MUSIC_PLAYING) JA_StopMusic();
|
||||
|
||||
JA_musicEnabled = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||
JA_Sound_t *sound = new JA_Sound_t();
|
||||
sound->buffer = buffer;
|
||||
@@ -167,6 +264,24 @@ JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||
return sound;
|
||||
}
|
||||
|
||||
JA_Sound_t *JA_LoadSound(uint8_t* buffer, uint32_t size) {
|
||||
JA_Sound_t *sound = new JA_Sound_t();
|
||||
SDL_AudioSpec wavSpec;
|
||||
SDL_LoadWAV_RW(SDL_RWFromMem(buffer, size),1, &wavSpec, &sound->buffer, &sound->length);
|
||||
|
||||
SDL_AudioCVT cvt;
|
||||
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
|
||||
cvt.len = sound->length;
|
||||
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
||||
SDL_memcpy(cvt.buf, sound->buffer, sound->length);
|
||||
SDL_ConvertAudio(&cvt);
|
||||
SDL_FreeWAV(sound->buffer);
|
||||
sound->buffer = cvt.buf;
|
||||
sound->length = cvt.len_cvt;
|
||||
|
||||
return sound;
|
||||
}
|
||||
|
||||
JA_Sound_t *JA_LoadSound(const char* filename) {
|
||||
JA_Sound_t *sound = new JA_Sound_t();
|
||||
SDL_AudioSpec wavSpec;
|
||||
@@ -185,7 +300,10 @@ JA_Sound_t *JA_LoadSound(const char* filename) {
|
||||
return sound;
|
||||
}
|
||||
|
||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
||||
int JA_PlaySound(JA_Sound_t *sound, const int loop)
|
||||
{
|
||||
if (!JA_soundEnabled) return -1;
|
||||
|
||||
int channel = 0;
|
||||
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
||||
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0;
|
||||
@@ -197,7 +315,21 @@ int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
||||
return channel;
|
||||
}
|
||||
|
||||
void JA_DeleteSound(JA_Sound_t *sound) {
|
||||
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop)
|
||||
{
|
||||
if (!JA_soundEnabled) return -1;
|
||||
|
||||
if (channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return -1;
|
||||
|
||||
channels[channel].sound = sound;
|
||||
channels[channel].times = loop;
|
||||
channels[channel].pos = 0;
|
||||
channels[channel].state = JA_CHANNEL_PLAYING;
|
||||
return channel;
|
||||
}
|
||||
|
||||
void JA_DeleteSound(JA_Sound_t *sound)
|
||||
{
|
||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||
if (channels[i].sound == sound) JA_StopChannel(i);
|
||||
}
|
||||
@@ -205,7 +337,10 @@ void JA_DeleteSound(JA_Sound_t *sound) {
|
||||
delete sound;
|
||||
}
|
||||
|
||||
void JA_PauseChannel(const int channel) {
|
||||
void JA_PauseChannel(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return;
|
||||
|
||||
if (channel == -1) {
|
||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||
if (channels[i].state == JA_CHANNEL_PLAYING) channels[i].state = JA_CHANNEL_PAUSED;
|
||||
@@ -215,7 +350,10 @@ void JA_PauseChannel(const int channel) {
|
||||
}
|
||||
}
|
||||
|
||||
void JA_ResumeChannel(const int channel) {
|
||||
void JA_ResumeChannel(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return;
|
||||
|
||||
if (channel == -1) {
|
||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||
if (channels[i].state == JA_CHANNEL_PAUSED) channels[i].state = JA_CHANNEL_PLAYING;
|
||||
@@ -225,7 +363,10 @@ void JA_ResumeChannel(const int channel) {
|
||||
}
|
||||
}
|
||||
|
||||
void JA_StopChannel(const int channel) {
|
||||
void JA_StopChannel(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return;
|
||||
|
||||
if (channel == -1) {
|
||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||
channels[i].state = JA_CHANNEL_FREE;
|
||||
@@ -239,13 +380,34 @@ void JA_StopChannel(const int channel) {
|
||||
}
|
||||
}
|
||||
|
||||
JA_Channel_state JA_GetChannelState(const int channel) {
|
||||
JA_Channel_state JA_GetChannelState(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return JA_SOUND_DISABLED;
|
||||
|
||||
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
|
||||
return channels[channel].state;
|
||||
}
|
||||
|
||||
int JA_SetVolume(int volume) {
|
||||
JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||
return JA_volume;
|
||||
int JA_SetSoundVolume(int volume)
|
||||
{
|
||||
JA_soundVolume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||
return JA_soundVolume;
|
||||
}
|
||||
|
||||
void JA_EnableSound(const bool value)
|
||||
{
|
||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
|
||||
{
|
||||
if (channels[i].state == JA_CHANNEL_PLAYING) JA_StopChannel(i);
|
||||
}
|
||||
JA_soundEnabled = value;
|
||||
}
|
||||
|
||||
int JA_SetVolume(int volume)
|
||||
{
|
||||
JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||
JA_soundVolume = JA_musicVolume/2;
|
||||
return JA_musicVolume;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,12 @@
|
||||
#pragma once
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
||||
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
|
||||
#include <SDL2/SDL_audio.h> // for SDL_AudioFormat
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||
struct JA_Music_t; // lines 8-8
|
||||
struct JA_Sound_t; // lines 7-7
|
||||
|
||||
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED, JA_SOUND_DISABLED };
|
||||
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED, JA_MUSIC_DISABLED };
|
||||
|
||||
struct JA_Sound_t;
|
||||
struct JA_Music_t;
|
||||
@@ -11,20 +15,30 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels);
|
||||
void JA_Quit();
|
||||
|
||||
JA_Music_t *JA_LoadMusic(const char* filename);
|
||||
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length);
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
|
||||
void JA_PauseMusic();
|
||||
void JA_ResumeMusic();
|
||||
void JA_StopMusic();
|
||||
void JA_FadeOutMusic(const int milliseconds);
|
||||
JA_Music_state JA_GetMusicState();
|
||||
void JA_DeleteMusic(JA_Music_t *music);
|
||||
int JA_SetMusicVolume(int volume);
|
||||
void JA_SetMusicPosition(float value);
|
||||
float JA_GetMusicPosition();
|
||||
void JA_EnableMusic(const bool value);
|
||||
|
||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length);
|
||||
JA_Sound_t *JA_LoadSound(Uint8* buffer, Uint32 length);
|
||||
JA_Sound_t *JA_LoadSound(const char* filename);
|
||||
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
|
||||
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop = 0);
|
||||
void JA_PauseChannel(const int channel);
|
||||
void JA_ResumeChannel(const int channel);
|
||||
void JA_StopChannel(const int channel);
|
||||
JA_Channel_state JA_GetChannelState(const int channel);
|
||||
void JA_DeleteSound(JA_Sound_t *sound);
|
||||
int JA_SetSoundVolume(int volume);
|
||||
void JA_EnableSound(const bool value);
|
||||
|
||||
int JA_SetVolume(int volume);
|
||||
int JA_SetVolume(int volume);
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "lang.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <fstream> // for basic_ifstream, basic_istream, ifstream
|
||||
#include "asset.h" // for Asset
|
||||
|
||||
// Constructor
|
||||
Lang::Lang(Asset *mAsset)
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/asset.h"
|
||||
#include <string>
|
||||
|
||||
#ifndef LANG_H
|
||||
#define LANG_H
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string, basic_string
|
||||
class Asset;
|
||||
|
||||
// Códigos de idioma
|
||||
#define es_ES 0
|
||||
#define ba_BA 1
|
||||
#define en_UK 2
|
||||
#define MAX_LANGUAGES 3
|
||||
constexpr int es_ES = 0;
|
||||
constexpr int ba_BA = 1;
|
||||
constexpr int en_UK = 2;
|
||||
constexpr int MAX_LANGUAGES = 3;
|
||||
|
||||
// Textos
|
||||
#define MAX_TEXT_STRINGS 100
|
||||
constexpr int MAX_TEXT_STRINGS = 100;
|
||||
|
||||
// Clase Lang
|
||||
class Lang
|
||||
@@ -35,5 +32,4 @@ public:
|
||||
|
||||
// Obtiene la cadena de texto del indice
|
||||
std::string getText(int index);
|
||||
};
|
||||
#endif
|
||||
};
|
||||
@@ -1,7 +1,19 @@
|
||||
#include "logo.h"
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // for min
|
||||
#include <string> // for basic_string
|
||||
#include "asset.h" // for Asset
|
||||
#include "const.h" // for bgColor, SECTION_PROG_LOGO, SECTION_PROG...
|
||||
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "jail_audio.h" // for JA_StopMusic
|
||||
#include "screen.h" // for Screen
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for section_t, color_t
|
||||
|
||||
#define INIT_FADE 100
|
||||
#define END_LOGO 200
|
||||
// Valores de inicialización y fin
|
||||
constexpr int INIT_FADE = 100;
|
||||
constexpr int END_LOGO = 200;
|
||||
|
||||
// Constructor
|
||||
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section)
|
||||
@@ -119,9 +131,6 @@ void Logo::update()
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
checkLogoEnd();
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/asset.h"
|
||||
#include "common/input.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/utils.h"
|
||||
#include "const.h"
|
||||
|
||||
#ifndef LOGO_H
|
||||
#define LOGO_H
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
class Asset;
|
||||
class Input;
|
||||
class Screen;
|
||||
class Sprite;
|
||||
class Texture;
|
||||
struct section_t;
|
||||
|
||||
// Clase Logo
|
||||
class Logo
|
||||
@@ -59,5 +57,3 @@ public:
|
||||
// Bucle principal
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,8 +39,8 @@ Reescribiendo el código el 27/09/2022
|
||||
|
||||
*/
|
||||
|
||||
#include "director.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream> // for char_traits, basic_ostream, operator<<, endl
|
||||
#include "director.h" // for Director
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#include "../const.h"
|
||||
#include "menu.h"
|
||||
#include <iostream>
|
||||
#include <algorithm> // for max, min
|
||||
#include <fstream> // for char_traits, basic_ifstream, basic_istream
|
||||
#include <sstream> // for basic_stringstream
|
||||
#include "asset.h" // for Asset
|
||||
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "jail_audio.h" // for JA_LoadSound, JA_PlaySound, JA_DeleteSound
|
||||
#include "text.h" // for Text
|
||||
|
||||
// Constructor
|
||||
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file)
|
||||
@@ -700,7 +705,7 @@ void Menu::render()
|
||||
else
|
||||
{ // Si no es seleccionable
|
||||
if ((item[i].linkedUp) && (i == selector.index + 1))
|
||||
{// Si el elemento está enlazado con el elemento superior se pinta del color del selector
|
||||
{ // Si el elemento está enlazado con el elemento superior se pinta del color del selector
|
||||
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
|
||||
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
|
||||
}
|
||||
@@ -1,30 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "input.h"
|
||||
#include "jail_audio.h"
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "utils.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for color_t
|
||||
class Asset;
|
||||
class Input;
|
||||
class Text;
|
||||
struct JA_Sound_t;
|
||||
|
||||
#ifndef MENU_H
|
||||
#define MENU_H
|
||||
|
||||
// Tipos de fondos para el menu
|
||||
#define MENU_BACKGROUND_TRANSPARENT 0
|
||||
#define MENU_BACKGROUND_SOLID 1
|
||||
// Tipos de fondos para el menú
|
||||
constexpr int MENU_BACKGROUND_TRANSPARENT = 0;
|
||||
constexpr int MENU_BACKGROUND_SOLID = 1;
|
||||
|
||||
// Tipos de archivos de audio
|
||||
#define SOUND_ACCEPT 0
|
||||
#define SOUND_MOVE 1
|
||||
#define SOUND_CANCEL 2
|
||||
constexpr int SOUND_ACCEPT = 0;
|
||||
constexpr int SOUND_MOVE = 1;
|
||||
constexpr int SOUND_CANCEL = 2;
|
||||
|
||||
// Opciones de menu
|
||||
#define MENU_NO_OPTION -1
|
||||
// Opciones de menú
|
||||
constexpr int MENU_NO_OPTION = -1;
|
||||
|
||||
// Clase Menu
|
||||
class Menu
|
||||
@@ -232,5 +228,3 @@ public:
|
||||
// Establece el rectangulo de fondo del menu
|
||||
void setRectSize(int w = 0, int h = 0);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "movingsprite.h"
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "sprite.h"
|
||||
|
||||
#ifndef MOVINGSPRITE_H
|
||||
#define MOVINGSPRITE_H
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16
|
||||
#include "sprite.h" // for Sprite
|
||||
class Texture;
|
||||
|
||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||
class MovingSprite : public Sprite
|
||||
@@ -163,5 +163,3 @@ public:
|
||||
// Devuelve el incremento en el eje X en pixels
|
||||
int getIncX();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,9 @@
|
||||
#include "const.h"
|
||||
#include "player.h"
|
||||
#include <stdlib.h> // for rand
|
||||
#include "animatedsprite.h" // for AnimatedSprite
|
||||
#include "const.h" // for PLAY_AREA_LEFT, PLAY_AREA_RIGHT
|
||||
#include "input.h" // for inputs_e
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Player::Player(float x, int y, SDL_Renderer *renderer, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/input.h"
|
||||
#include "common/texture.h"
|
||||
#include "common/utils.h"
|
||||
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for circle_t
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
// Contadores
|
||||
#define DEATH_COUNTER 350
|
||||
constexpr int DEATH_COUNTER = 350;
|
||||
|
||||
// Estados del jugador
|
||||
#define PLAYER_STATUS_WALKING_LEFT 0
|
||||
#define PLAYER_STATUS_WALKING_RIGHT 1
|
||||
#define PLAYER_STATUS_WALKING_STOP 2
|
||||
constexpr int PLAYER_STATUS_WALKING_LEFT = 0;
|
||||
constexpr int PLAYER_STATUS_WALKING_RIGHT = 1;
|
||||
constexpr int PLAYER_STATUS_WALKING_STOP = 2;
|
||||
|
||||
#define PLAYER_STATUS_FIRING_UP 0
|
||||
#define PLAYER_STATUS_FIRING_LEFT 1
|
||||
#define PLAYER_STATUS_FIRING_RIGHT 2
|
||||
#define PLAYER_STATUS_FIRING_NO 3
|
||||
constexpr int PLAYER_STATUS_FIRING_UP = 0;
|
||||
constexpr int PLAYER_STATUS_FIRING_LEFT = 1;
|
||||
constexpr int PLAYER_STATUS_FIRING_RIGHT = 2;
|
||||
constexpr int PLAYER_STATUS_FIRING_NO = 3;
|
||||
|
||||
// Variables del jugador
|
||||
#define PLAYER_INVULNERABLE_COUNTER 200
|
||||
#define PLAYER_POWERUP_COUNTER 1500
|
||||
constexpr int PLAYER_INVULNERABLE_COUNTER = 200;
|
||||
constexpr int PLAYER_POWERUP_COUNTER = 1500;
|
||||
|
||||
// Clase Player
|
||||
class Player
|
||||
@@ -37,7 +35,7 @@ private:
|
||||
AnimatedSprite *bodySprite; // Sprite para dibujar el cuerpo
|
||||
AnimatedSprite *legsSprite; // Sprite para dibujar las piernas
|
||||
AnimatedSprite *deathSprite; // Sprite para dibujar el jugador derrotado
|
||||
AnimatedSprite *fireSprite; // Sprite para dibujar el aura del jugador con el poder a tope
|
||||
AnimatedSprite *fireSprite; // Sprite para dibujar el aura del jugador con el poder a tope
|
||||
|
||||
// Variables
|
||||
float posX; // Posicion en el eje X
|
||||
@@ -217,5 +215,3 @@ public:
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 getDeathCounter();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
#include "screen.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // for SDL_DISABLE, SDL_ENABLE
|
||||
#include <SDL2/SDL_mouse.h> // for SDL_ShowCursor
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <algorithm> // for max, min
|
||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||
#include <string> // for basic_string, char_traits, string
|
||||
class Asset;
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
||||
@@ -11,9 +17,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
||||
this->options = options;
|
||||
this->asset = asset;
|
||||
|
||||
// Crea los objetos
|
||||
notify = new Notify(renderer, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
|
||||
|
||||
gameCanvasWidth = options->gameWidth;
|
||||
gameCanvasHeight = options->gameHeight;
|
||||
borderWidth = options->borderWidth * 2;
|
||||
@@ -47,7 +50,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
delete notify;
|
||||
SDL_DestroyTexture(gameCanvas);
|
||||
}
|
||||
|
||||
@@ -77,9 +79,6 @@ void Screen::blit()
|
||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||
|
||||
// Dibuja las notificaciones
|
||||
renderNotifications();
|
||||
|
||||
// Muestra por pantalla el renderizador
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
@@ -178,9 +177,6 @@ void Screen::setVideoMode(int videoMode)
|
||||
options->videoMode = videoMode;
|
||||
options->screen.windowWidth = windowWidth;
|
||||
options->screen.windowHeight = windowHeight;
|
||||
|
||||
// Establece el tamaño de las notificaciones
|
||||
setNotificationSize();
|
||||
}
|
||||
|
||||
// Camibia entre pantalla completa y ventana
|
||||
@@ -383,54 +379,4 @@ void Screen::renderFX()
|
||||
{
|
||||
renderFade();
|
||||
renderSpectrumFade();
|
||||
}
|
||||
|
||||
// Actualiza el notificador
|
||||
void Screen::updateNotifier()
|
||||
{
|
||||
notify->update();
|
||||
notifyActive = notify->active();
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
||||
{
|
||||
notify->showText(text1, text2, icon);
|
||||
}
|
||||
|
||||
// Dibuja las notificaciones
|
||||
void Screen::renderNotifications()
|
||||
{
|
||||
if (!notifyActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
|
||||
notify->render();
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
}
|
||||
|
||||
// Establece el tamaño de las notificaciones
|
||||
void Screen::setNotificationSize()
|
||||
{
|
||||
if (options->videoMode == 0)
|
||||
{
|
||||
if (options->windowSize == 3)
|
||||
{
|
||||
notificationLogicalWidth = (windowWidth * 3) / 2;
|
||||
notificationLogicalHeight = (windowHeight * 3) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
notificationLogicalWidth = windowWidth * 2;
|
||||
notificationLogicalHeight = windowHeight * 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||
{
|
||||
notificationLogicalWidth = windowWidth / 3;
|
||||
notificationLogicalHeight = windowHeight / 3;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "notify.h"
|
||||
#include "utils.h"
|
||||
#include "../const.h"
|
||||
#include <vector>
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for color_t
|
||||
class Asset;
|
||||
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
#define FILTER_NEAREST 0
|
||||
#define FILTER_LINEAL 1
|
||||
// Tipos de filtro
|
||||
constexpr int FILTER_NEAREST = 0;
|
||||
constexpr int FILTER_LINEAL = 1;
|
||||
|
||||
class Screen
|
||||
{
|
||||
@@ -22,7 +21,6 @@ private:
|
||||
Asset *asset; // Objeto con el listado de recursos
|
||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||
options_t *options; // Variable con todas las opciones del programa
|
||||
Notify *notify; // Dibuja notificaciones por pantalla
|
||||
|
||||
// Variables
|
||||
int windowWidth; // Ancho de la pantalla o ventana
|
||||
@@ -64,12 +62,6 @@ private:
|
||||
// Dibuja el spectrum fade
|
||||
void renderSpectrumFade();
|
||||
|
||||
// Dibuja las notificaciones
|
||||
void renderNotifications();
|
||||
|
||||
// Establece el tamaño de las notificaciones
|
||||
void setNotificationSize();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
||||
@@ -134,12 +126,4 @@ public:
|
||||
|
||||
// Dibuja los efectos
|
||||
void renderFX();
|
||||
|
||||
// Actualiza el notificador
|
||||
void updateNotifier();
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "smartsprite.h"
|
||||
#include "movingsprite.h" // for MovingSprite
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
SmartSprite::SmartSprite(Texture *texture, SDL_Renderer *renderer)
|
||||
@@ -1,12 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "animatedsprite.h"
|
||||
#include "utils.h"
|
||||
#include <vector>
|
||||
|
||||
#ifndef SMARTSPRITE_H
|
||||
#define SMARTSPRITE_H
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include "animatedsprite.h" // for AnimatedSprite
|
||||
class Texture;
|
||||
|
||||
// Clase SmartSprite
|
||||
class SmartSprite : public AnimatedSprite
|
||||
@@ -69,5 +65,3 @@ public:
|
||||
// Obtiene el valor de la variable
|
||||
bool hasFinished();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "sprite.h"
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
|
||||
@@ -1,10 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "texture.h"
|
||||
|
||||
#ifndef SPRITE_H
|
||||
#define SPRITE_H
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
class Texture;
|
||||
|
||||
// Clase sprite
|
||||
class Sprite
|
||||
@@ -91,6 +89,4 @@ public:
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
};
|
||||
|
||||
#endif
|
||||
};
|
||||
@@ -1,7 +1,10 @@
|
||||
|
||||
#include "text.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <fstream> // for char_traits, basic_ostream, basic_ifstream, ope...
|
||||
#include <iostream> // for cout
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for color_t
|
||||
|
||||
// Llena una estructuta textFile_t desde un fichero
|
||||
textFile_t LoadTextFile(std::string file, bool verbose)
|
||||
@@ -1,15 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "sprite.h"
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string
|
||||
class Sprite;
|
||||
class Texture;
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef TEXT_H
|
||||
#define TEXT_H
|
||||
|
||||
#define TXT_COLOR 1
|
||||
#define TXT_SHADOW 2
|
||||
#define TXT_CENTER 4
|
||||
#define TXT_STROKE 8
|
||||
// Opciones de texto
|
||||
constexpr int TXT_COLOR = 1;
|
||||
constexpr int TXT_SHADOW = 2;
|
||||
constexpr int TXT_CENTER = 4;
|
||||
constexpr int TXT_STROKE = 8;
|
||||
|
||||
struct offset_t
|
||||
{
|
||||
@@ -64,7 +66,7 @@ public:
|
||||
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe texto con extras
|
||||
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1);
|
||||
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = color_t(255, 255, 255), Uint8 shadowDistance = 1, color_t shadowColor = color_t(0, 0, 0), int lenght = -1);
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
int lenght(std::string text, int kerning = 1);
|
||||
@@ -78,5 +80,3 @@ public:
|
||||
// Establece si se usa un tamaño fijo de letra
|
||||
void setFixedWidth(bool value);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,13 @@
|
||||
|
||||
#include "texture.h"
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_log.h> // for SDL_Log
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGB24, SDL_PIXELFORMAT...
|
||||
#include <SDL2/SDL_surface.h> // for SDL_CreateRGBSurfaceWithFormatFrom
|
||||
#include <stdlib.h> // for exit
|
||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
#include <iostream>
|
||||
#include "stb_image.h" // for stbi_failure_reason, stbi_image_free
|
||||
|
||||
// Constructor
|
||||
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for basic_string, string
|
||||
|
||||
class Texture
|
||||
{
|
||||
@@ -62,5 +61,3 @@ public:
|
||||
// Obtiene la textura
|
||||
SDL_Texture *getSDLTexture();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,25 @@
|
||||
#include "title.h"
|
||||
#include "common/jscore.h"
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLS...
|
||||
#include <stdlib.h> // for rand
|
||||
#include <iostream> // for basic_ostream, operator<<, basic_ostrea...
|
||||
#include <string> // for basic_string, operator+, char_traits
|
||||
#include "animatedsprite.h" // for AnimatedSprite
|
||||
#include "asset.h" // for Asset
|
||||
#include "const.h" // for GAMECANVAS_CENTER_X, SECTION_PROG_QUIT
|
||||
#include "fade.h" // for Fade
|
||||
#include "game.h" // for Game
|
||||
#include "input.h" // for Input, INPUT_USE_GAMECONTROLLER, INPUT_...
|
||||
#include "jail_audio.h" // for JA_StopMusic, JA_GetMusicState, JA_Play...
|
||||
#include "lang.h" // for Lang, ba_BA, en_UK, es_ES
|
||||
#include "menu.h" // for Menu
|
||||
#include "screen.h" // for Screen, FILTER_LINEAL, FILTER_NEAREST
|
||||
#include "smartsprite.h" // for SmartSprite
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section)
|
||||
@@ -206,9 +226,6 @@ void Title::init()
|
||||
|
||||
// Actualiza los textos de los menus
|
||||
updateMenuLabels();
|
||||
|
||||
// Comprueba si se puede acceder a la tabla de puntuaciones y habilita la opción de menu
|
||||
setHiScoreTableOptionMenu();
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
@@ -223,9 +240,6 @@ void Title::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
|
||||
switch (section->subsection)
|
||||
{
|
||||
// Sección 1 - Titulo desplazandose
|
||||
@@ -321,10 +335,6 @@ void Title::update()
|
||||
{
|
||||
runInstructions(m_auto);
|
||||
}
|
||||
if (section->name != SECTION_PROG_QUIT)
|
||||
{
|
||||
runHiScoreTable(mhst_auto);
|
||||
}
|
||||
}
|
||||
else
|
||||
section->name = SECTION_PROG_LOGO;
|
||||
@@ -478,23 +488,13 @@ void Title::update()
|
||||
runInstructions(m_manual);
|
||||
break;
|
||||
|
||||
case 12: // HISCORE TABLE
|
||||
runHiScoreTable(mhst_manual);
|
||||
break;
|
||||
|
||||
case 13: // JAILERID:
|
||||
runEnterID();
|
||||
setHiScoreTableOptionMenu();
|
||||
updateMenuLabels();
|
||||
break;
|
||||
|
||||
case 14: // ACCEPT
|
||||
case 12: // ACCEPT
|
||||
applyOptions();
|
||||
menu.active->reset();
|
||||
menu.active = menu.title;
|
||||
break;
|
||||
|
||||
case 15: // CANCEL
|
||||
case 13: // CANCEL
|
||||
options = &optionsPrevious;
|
||||
updateMenuLabels();
|
||||
menu.active->reset();
|
||||
@@ -515,10 +515,6 @@ void Title::update()
|
||||
{
|
||||
if (demo)
|
||||
{
|
||||
if (section->name != SECTION_PROG_QUIT)
|
||||
{
|
||||
runHiScoreTable(mhst_auto);
|
||||
}
|
||||
runDemoGame();
|
||||
if (section->name != SECTION_PROG_QUIT)
|
||||
{
|
||||
@@ -918,15 +914,6 @@ void Title::updateMenuLabels()
|
||||
// HOW TO PLAY
|
||||
menu.options->setItemCaption(i, lang->getText(2));
|
||||
|
||||
i++;
|
||||
// HISCORE TABLE
|
||||
menu.options->setItemCaption(i, lang->getText(93));
|
||||
|
||||
i++;
|
||||
// JAILERID;
|
||||
const std::string jailerID = options->online.jailerID == "" ? lang->getText(64) : options->online.jailerID;
|
||||
menu.options->setItemCaption(i, "JAILERID: " + jailerID);
|
||||
|
||||
i++;
|
||||
// ACCEPT
|
||||
menu.options->setItemCaption(i, lang->getText(9)); // ACCEPT
|
||||
@@ -1004,22 +991,6 @@ void Title::runInstructions(mode_e mode)
|
||||
delete instructions;
|
||||
}
|
||||
|
||||
// Ejecuta la parte donde se muestra la tabla de puntuaciones
|
||||
void Title::runHiScoreTable(mode_hiScoreTable_e mode)
|
||||
{
|
||||
if (!options->online.enabled)
|
||||
{
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
section->subsection = SUBSECTION_TITLE_1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, options, section);
|
||||
hiScoreTable->run(mode);
|
||||
delete hiScoreTable;
|
||||
}
|
||||
|
||||
// Ejecuta el juego en modo demo
|
||||
void Title::runDemoGame()
|
||||
{
|
||||
@@ -1028,14 +999,6 @@ void Title::runDemoGame()
|
||||
delete demoGame;
|
||||
}
|
||||
|
||||
// Introduce el JailerID
|
||||
void Title::runEnterID()
|
||||
{
|
||||
enterID = new EnterID(renderer, screen, asset, lang, options, section);
|
||||
enterID->run();
|
||||
delete enterID;
|
||||
}
|
||||
|
||||
// Modifica las opciones para los controles de los jugadores
|
||||
bool Title::updatePlayerInputs(int numPlayer)
|
||||
{
|
||||
@@ -1186,19 +1149,4 @@ void Title::reLoadTextures()
|
||||
crisisTexture->reLoad();
|
||||
gradientTexture->reLoad();
|
||||
createTiledBackground();
|
||||
}
|
||||
|
||||
// Comprueba si se puede acceder a la tabla de puntuaciones y habilita la opción de menu
|
||||
void Title::setHiScoreTableOptionMenu()
|
||||
{
|
||||
if (options->online.sessionEnabled)
|
||||
{
|
||||
menu.options->setSelectable(12, true);
|
||||
menu.options->setGreyed(12, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu.options->setSelectable(12, false);
|
||||
menu.options->setGreyed(12, true);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/asset.h"
|
||||
#include "common/input.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/menu.h"
|
||||
#include "common/movingsprite.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/smartsprite.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/text.h"
|
||||
#include "common/utils.h"
|
||||
#include "const.h"
|
||||
#include "fade.h"
|
||||
#include "game.h"
|
||||
#include "enter_id.h"
|
||||
#include "hiscore_table.h"
|
||||
#include "instructions.h"
|
||||
#include "item.h"
|
||||
|
||||
#ifndef TITLE_H
|
||||
#define TITLE_H
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||
#include <vector> // for vector
|
||||
#include "instructions.h" // for mode_e
|
||||
#include "utils.h" // for input_t, options_t, section_t
|
||||
class AnimatedSprite;
|
||||
class Asset;
|
||||
class Fade;
|
||||
class Game;
|
||||
class Input;
|
||||
class Lang;
|
||||
class Menu;
|
||||
class Screen;
|
||||
class SmartSprite;
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
|
||||
// Textos
|
||||
#define TEXT_COPYRIGHT "@2020,2023 JailDesigner (v2.3.1)"
|
||||
constexpr const char *TEXT_COPYRIGHT = "@2020,2023 JailDesigner (v2.3.2)";
|
||||
|
||||
// Contadores
|
||||
#define TITLE_COUNTER 800
|
||||
constexpr int TITLE_COUNTER = 800;
|
||||
|
||||
// Cantidad de eventos de la pantalla de titulo
|
||||
#define TITLE_TOTAL_EVENTS 2
|
||||
// Cantidad de eventos de la pantalla de título
|
||||
constexpr int TITLE_TOTAL_EVENTS = 2;
|
||||
|
||||
class Title
|
||||
{
|
||||
@@ -50,9 +50,7 @@ private:
|
||||
Input *input; // Objeto para leer las entradas de teclado o mando
|
||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
Instructions *instructions; // Objeto para la sección de las instrucciones
|
||||
HiScoreTable *hiScoreTable; // Objeto para mostrar las mejores puntuaciones online
|
||||
Game *demoGame; // Objeto para lanzar la demo del juego
|
||||
EnterID *enterID; // Objeto para introducir o modificar el JailerID
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
section_t *section; // Indicador para el bucle del titulo
|
||||
|
||||
@@ -125,15 +123,9 @@ private:
|
||||
// Ejecuta la parte donde se muestran las instrucciones
|
||||
void runInstructions(mode_e mode);
|
||||
|
||||
// Ejecuta la parte donde se muestra la tabla de puntuaciones
|
||||
void runHiScoreTable(mode_hiScoreTable_e mode);
|
||||
|
||||
// Ejecuta el juego en modo demo
|
||||
void runDemoGame();
|
||||
|
||||
// Introduce el JailerID
|
||||
void runEnterID();
|
||||
|
||||
// Modifica las opciones para los controles de los jugadores
|
||||
bool updatePlayerInputs(int numPlayer);
|
||||
|
||||
@@ -146,9 +138,6 @@ private:
|
||||
// Recarga las texturas
|
||||
void reLoadTextures();
|
||||
|
||||
// Comprueba si se puede acceder a la tabla de puntuaciones y habilita la opción de menu
|
||||
void setHiScoreTableOptionMenu();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section);
|
||||
@@ -159,5 +148,3 @@ public:
|
||||
// Bucle para el titulo del juego
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "utils.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h> // for abs, free, malloc
|
||||
#include <cmath> // for round, abs
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
double distanceSquared(int x1, int y1, int x2, int y2)
|
||||
@@ -1,21 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "texture.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint32
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
// Dificultad del juego
|
||||
#define DIFFICULTY_EASY 0
|
||||
#define DIFFICULTY_NORMAL 1
|
||||
#define DIFFICULTY_HARD 2
|
||||
|
||||
// Tipo de filtro
|
||||
#define FILTER_NEAREST 0
|
||||
#define FILTER_LINEAL 1
|
||||
constexpr int DIFFICULTY_EASY = 0;
|
||||
constexpr int DIFFICULTY_NORMAL = 1;
|
||||
constexpr int DIFFICULTY_HARD = 2;
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct circle_t
|
||||
@@ -52,9 +45,12 @@ struct line_t
|
||||
// Estructura para definir un color
|
||||
struct color_t
|
||||
{
|
||||
Uint8 r;
|
||||
Uint8 g;
|
||||
Uint8 b;
|
||||
Uint8 r;
|
||||
Uint8 g;
|
||||
Uint8 b;
|
||||
|
||||
color_t() : r(0), g(0), b(0) {} // Constructor por defecto
|
||||
color_t(Uint8 red, Uint8 green, Uint8 blue) : r(red), g(green), b(blue) {}
|
||||
};
|
||||
|
||||
// Tipos de paleta
|
||||
@@ -64,16 +60,6 @@ enum palette_e
|
||||
p_zxarne
|
||||
};
|
||||
|
||||
// Posiciones de las notificaciones
|
||||
enum not_pos_e
|
||||
{
|
||||
pos_top,
|
||||
pos_bottom,
|
||||
pos_left,
|
||||
pos_middle,
|
||||
pos_right
|
||||
};
|
||||
|
||||
// Estructura para saber la seccion y subseccion del programa
|
||||
struct section_t
|
||||
{
|
||||
@@ -100,18 +86,6 @@ struct input_t
|
||||
Uint8 deviceType; // Tipo de dispositivo (teclado o mando)
|
||||
};
|
||||
|
||||
// Estructura para el servicio online
|
||||
struct online_t
|
||||
{
|
||||
bool enabled; // Indica si se quiere usar el modo online o no
|
||||
bool sessionEnabled; // Indica ya se ha hecho login
|
||||
std::string server; // Servidor para los servicios online
|
||||
int port; // Puerto del servidor
|
||||
std::string gameID; // Identificador del juego para los servicios online
|
||||
std::string jailerID; // Identificador del jugador para los servicios online
|
||||
int score; // Puntuación almacenada online
|
||||
};
|
||||
|
||||
// Estructura con opciones de la pantalla
|
||||
struct op_screen_t
|
||||
{
|
||||
@@ -119,15 +93,6 @@ struct op_screen_t
|
||||
int windowHeight; // Alto de la ventana
|
||||
};
|
||||
|
||||
// Estructura para las opciones de las notificaciones
|
||||
struct op_notification_t
|
||||
{
|
||||
not_pos_e posH; // Ubicación de las notificaciones en pantalla
|
||||
not_pos_e posV; // Ubicación de las notificaciones en pantalla
|
||||
bool sound; // Indica si las notificaciones suenan
|
||||
color_t color; // Color de las notificaciones
|
||||
};
|
||||
|
||||
// Estructura con todas las opciones de configuración del programa
|
||||
struct options_t
|
||||
{
|
||||
@@ -150,9 +115,7 @@ struct options_t
|
||||
palette_e palette; // Paleta de colores a usar en el juego
|
||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||
|
||||
online_t online; // Datos del servicio online
|
||||
op_screen_t screen; // Opciones relativas a la clase screen
|
||||
op_notification_t notifications; // Opciones relativas a las notificaciones;
|
||||
};
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
@@ -202,5 +165,3 @@ std::string boolToString(bool value);
|
||||
|
||||
// Convierte una cadena a minusculas
|
||||
std::string toLower(std::string str);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "writer.h"
|
||||
#include "text.h" // for Text
|
||||
|
||||
// Constructor
|
||||
Writer::Writer(Text *text)
|
||||
@@ -1,11 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
|
||||
#ifndef WRITER_H
|
||||
#define WRITER_H
|
||||
#include <string> // for string, basic_string
|
||||
class Text;
|
||||
|
||||
// Clase Writer. Pinta texto en pantalla letra a letra a partir de una cadena y un bitmap
|
||||
class Writer
|
||||
@@ -71,5 +67,3 @@ public:
|
||||
// Obtiene el valor de la variable
|
||||
bool hasFinished();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user