Limpieza de código. Añadida la última versión de jail_audio

This commit is contained in:
2022-09-25 18:44:58 +02:00
parent f6494e69c8
commit 2979a6752c
35 changed files with 200 additions and 328 deletions

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "movingsprite.h" #include "movingsprite.h"
#ifndef ANIMATEDSPRITE_H #ifndef ANIMATEDSPRITE_H

View File

@@ -1,4 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
#include "utils.h" #include "utils.h"
#include "animatedsprite.h" #include "animatedsprite.h"
#include <vector> #include <vector>
@@ -69,6 +71,20 @@
class Balloon class Balloon
{ {
private: private:
// Estructura para las variables para el efecto de los rebotes
struct bouncing
{
bool enabled; // Si el efecto está activo
Uint8 counter; // Countador para el efecto
Uint8 speed; // Velocidad a la que transcurre el efecto
float zoomW; // Zoom aplicado a la anchura
float zoomH; // Zoom aplicado a la altura
float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom
std::vector<float> w; // Vector con los valores de zoom para el ancho del globo
std::vector<float> h; // Vector con los valores de zoom para el alto del globo
};
float mPosX; // Posición en el eje X float mPosX; // Posición en el eje X
float mPosY; // Posición en el eje Y float mPosY; // Posición en el eje Y
Uint8 mWidth; // Ancho Uint8 mWidth; // Ancho
@@ -99,30 +115,34 @@ private:
float mSpeed; // Velocidad a la que se mueven los globos float mSpeed; // Velocidad a la que se mueven los globos
Uint8 mSize; // Tamaño del globo Uint8 mSize; // Tamaño del globo
Uint8 mPower; // Cantidad de poder que alberga el globo Uint8 mPower; // Cantidad de poder que alberga el globo
bouncing mBouncing; // Contiene las variables para el efecto de rebote
struct bouncing // Estructura para las variables para el efecto de los rebotes // Alinea el circulo de colisión con la posición del objeto globo
{ void updateColliders();
bool enabled; // Si el efecto está activo
Uint8 counter; // Countador para el efecto
Uint8 speed; // Velocidad a la que transcurre el efecto
float zoomW; // Zoom aplicado a la anchura
float zoomH; // Zoom aplicado a la altura
float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom
std::vector<float> w; // Vector con los valores de zoom para el ancho del globo
std::vector<float> h; // Vector con los valores de zoom para el alto del globo
};
bouncing mBouncing;
void updateColliders(); // Alinea el circulo de colisión con la posición del objeto globo // Activa el efecto
void bounceStart(); // Activa el efecto void bounceStart();
void bounceStop(); // Detiene el efecto
void updateBounce(); // Aplica el efecto // Detiene el efecto
void updateState(); // Actualiza los estados del globo void bounceStop();
void updateAnimation(); // Establece la animación correspondiente
void setBeingCreated(bool state); // Establece el valor de la variable // Aplica el efecto
void setTimeToLive(Uint16 time); // Establece el valor de la variable void updateBounce();
Uint16 getTimeToLive(); // Obtiene del valor de la variable
// Actualiza los estados del globo
void updateState();
// Establece la animación correspondiente
void updateAnimation();
// Establece el valor de la variable
void setBeingCreated(bool state);
// Establece el valor de la variable
void setTimeToLive(Uint16 time);
// Obtiene del valor de la variable
Uint16 getTimeToLive();
public: public:
// Constructor // Constructor

View File

@@ -1,4 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
#include "utils.h" #include "utils.h"
#include "sprite.h" #include "sprite.h"

View File

@@ -1,4 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
#include "sprite.h" #include "sprite.h"
#ifndef COFFEEDROP_H #ifndef COFFEEDROP_H

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "utils.h" #include "utils.h"
#include "lang.h" #include "lang.h"
@@ -10,18 +11,10 @@
#define BLOCK 8 #define BLOCK 8
#define HALF_BLOCK BLOCK / 2 #define HALF_BLOCK BLOCK / 2
// Tamaño de la pantalla que contendrá la pantalla de juego
//#define REAL_SCREEN_WIDTH 256
//#define REAL_SCREEN_HEIGHT 192
// Tamaño de la pantalla de juego // Tamaño de la pantalla de juego
#define SCREEN_WIDTH 256 #define SCREEN_WIDTH 256
#define SCREEN_HEIGHT 192 #define SCREEN_HEIGHT 192
// Tamaño de la pantalla que se muestra
//const int VIEW_WIDTH = REAL_SCREEN_WIDTH * 3;
//const int VIEW_HEIGHT = REAL_SCREEN_HEIGHT * 3;
// Zona de juego // Zona de juego
const int PLAY_AREA_TOP = (0 * BLOCK); const int PLAY_AREA_TOP = (0 * BLOCK);
const int PLAY_AREA_BOTTOM = SCREEN_HEIGHT - (4 * BLOCK); const int PLAY_AREA_BOTTOM = SCREEN_HEIGHT - (4 * BLOCK);

View File

@@ -3,10 +3,6 @@
#include "director.h" #include "director.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
#ifdef __MIPSEL__
#include <sys/stat.h>
#include <dirent.h>
#endif
// Constructor // Constructor
Director::Director(std::string path) Director::Director(std::string path)
@@ -28,20 +24,6 @@ Director::Director(std::string path)
// Crea el puntero a la estructura y carga el fichero de configuración // Crea el puntero a la estructura y carga el fichero de configuración
mOptions = new options_t; mOptions = new options_t;
loadConfigFile(); loadConfigFile();
//if (!loadConfigFile())
//{
// mOptions->fullScreenMode = 0;
// mOptions->windowSize = 3;
// mOptions->language = en_UK;
// mOptions->difficulty = DIFFICULTY_NORMAL;
// mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
// mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
// mOptions->filter = FILTER_NEAREST;
// mOptions->vSync = true;
// mOptions->screenHeight = SCREEN_HEIGHT;
// mOptions->screenWidth = SCREEN_WIDTH;
// mOptions->integerScale = true;
//}
// Crea los objetos // Crea los objetos
mInput = new Input(mFileList[53]); mInput = new Input(mFileList[53]);
@@ -56,23 +38,8 @@ Director::Director(std::string path)
initJailAudio(); initJailAudio();
// Aplica las opciones // Aplica las opciones
//SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
//SDL_SetWindowSize(mWindow, REAL_SCREEN_WIDTH * mOptions->windowSize, REAL_SCREEN_HEIGHT * mOptions->windowSize);
mLang->setLang(mOptions->language); mLang->setLang(mOptions->language);
#ifdef __MIPSEL__
DIR *dir = opendir("/media/data/local/home/.coffee_crisis");
if (dir)
{
closedir(dir);
}
else if (ENOENT == errno)
{
int status = mkdir("/media/data/local/home/.coffee_crisis", 755);
}
#endif
// Inicializa el resto de variables // Inicializa el resto de variables
init(section); init(section);
} }
@@ -118,15 +85,9 @@ void Director::init(Uint8 name)
mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT); mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN); mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE); mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
#ifdef __MIPSEL__
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_LSHIFT);
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_SPACE);
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_LCTRL);
#else
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q); mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W); mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E); mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
#endif
mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
@@ -217,16 +178,10 @@ void Director::setFileList()
for (int i = 0; i < MAX_FILE_LIST; i++) for (int i = 0; i < MAX_FILE_LIST; i++)
mFileList[i] = ""; mFileList[i] = "";
// Ficheros binarios // Ficheros binarios
#ifdef __MIPSEL__
mFileList[0] = "/media/data/local/home/.coffee_crisis/score.bin";
mFileList[1] = "/media/data/local/home/.coffee_crisis/demo.bin";
mFileList[2] = "/media/data/local/home/.coffee_crisis/config.bin";
#else
mFileList[0] = mExecutablePath + "/" + "../data/score.bin"; mFileList[0] = mExecutablePath + "/" + "../data/score.bin";
mFileList[1] = mExecutablePath + "/" + "../data/demo.bin"; mFileList[1] = mExecutablePath + "/" + "../data/demo.bin";
mFileList[2] = mExecutablePath + "/" + "../data/config.bin"; mFileList[2] = mExecutablePath + "/" + "../data/config.bin";
#endif
// Musicas // Musicas
mFileList[3] = mExecutablePath + "/" + "../media/music/intro.ogg"; mFileList[3] = mExecutablePath + "/" + "../media/music/intro.ogg";

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "sprite.h" #include "sprite.h"
#include "movingsprite.h" #include "movingsprite.h"
#include "smartsprite.h" #include "smartsprite.h"

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "ltexture.h" #include "ltexture.h"
#ifndef FADE_H #ifndef FADE_H

View File

@@ -1,8 +1,4 @@
#include "game.h" #include "game.h"
#ifdef __MIPSEL__
#include <sys/stat.h>
#include <dirent.h>
#endif
// Constructor // Constructor
Game::Game(int numPlayers, SDL_Renderer *renderer, Screen *screen, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options) Game::Game(int numPlayers, SDL_Renderer *renderer, Screen *screen, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options)
@@ -79,18 +75,6 @@ Game::Game(int numPlayers, SDL_Renderer *renderer, Screen *screen, std::string *
mSpriteGrass = new Sprite(); mSpriteGrass = new Sprite();
mSpritePowerMeter = new Sprite(); mSpritePowerMeter = new Sprite();
mSpriteScoreBoard = new Sprite(); mSpriteScoreBoard = new Sprite();
#ifdef __MIPSEL__
DIR *dir = opendir("/media/data/local/home/.coffee_crisis");
if (dir)
{
closedir(dir);
}
else if (ENOENT == errno)
{
int status = mkdir("/media/data/local/home/.coffee_crisis", 755);
}
#endif
} }
Game::~Game() Game::~Game()

View File

@@ -1,9 +1,10 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
#include "balloon.h" #include "balloon.h"
#include "bullet.h" #include "bullet.h"
#include "const.h" #include "const.h"
#include "fade.h" #include "fade.h"
#include "ifdefs.h"
#include "input.h" #include "input.h"
#include "item.h" #include "item.h"
#include "jail_audio.h" #include "jail_audio.h"
@@ -74,13 +75,11 @@ private:
Uint8 numberOfEnemies; // Cantidad de enemigos que forman la formación Uint8 numberOfEnemies; // Cantidad de enemigos que forman la formación
enemyInits_t init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación enemyInits_t init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación
}; };
enemyFormation_t mEnemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
struct enemyPool_t struct enemyPool_t
{ {
enemyFormation_t *set[10]; // Conjunto de formaciones enemigas enemyFormation_t *set[10]; // Conjunto de formaciones enemigas
}; };
enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
struct stage_t // Contiene todas las variables relacionadas con una fase struct stage_t // Contiene todas las variables relacionadas con una fase
{ {
@@ -113,6 +112,23 @@ private:
int itemCoffeeMachineOdds; // Probabilidad de aparición del objeto int itemCoffeeMachineOdds; // Probabilidad de aparición del objeto
}; };
struct demo_t
{
bool enabled; // Indica si está activo el modo demo
bool recording; // Indica si está activado el modo para grabar la demo
Uint16 counter; // Contador para el modo demo
demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo
demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
};
struct debug_t
{
bool enabled; // Indica si se va a mostrar la información de debug
Uint8 enemySet; // Escoge el set enemigo a generar
Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo
float hudW, hudH; // Multiplica el tamaño del hud de debug;
};
SDL_Renderer *mRenderer; // El renderizador de la ventana SDL_Renderer *mRenderer; // El renderizador de la ventana
Screen *mScreen; // Objeto encargado de dibujar en pantalla Screen *mScreen; // Objeto encargado de dibujar en pantalla
std::string *mFileList; // Lista de ficheros con los recursos std::string *mFileList; // Lista de ficheros con los recursos
@@ -193,63 +209,49 @@ private:
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 mHiScore; // Puntuación máxima Uint32 mHiScore; // Puntuación máxima
bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima
section_t mSection; // Seccion actual dentro del juego section_t mSection; // Seccion actual dentro del juego
stage_t mStage[10]; // Variable con los datos de cada pantalla stage_t mStage[10]; // Variable con los datos de cada pantalla
Uint8 mCurrentStage; // Indica la fase actual Uint8 mCurrentStage; // Indica la fase actual
Uint8 mStageBitmapCounter; // Contador para el tiempo visible del texto de Stage Uint8 mStageBitmapCounter; // Contador para el tiempo visible del texto de Stage
float mStageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto float mStageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
float mGetReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto float mGetReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
Uint16 mDeathCounter; // Contador para la animación de muerte del jugador Uint16 mDeathCounter; // Contador para la animación de muerte del jugador
Uint8 mDeathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador Uint8 mDeathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador
Uint8 mMenaceCurrent; // Nivel de amenaza actual Uint8 mMenaceCurrent; // Nivel de amenaza actual
Uint8 mMenaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos Uint8 mMenaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
bool mTimeStopped; // Indica si el tiempo está detenido bool mTimeStopped; // Indica si el tiempo está detenido
Uint16 mTimeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido Uint16 mTimeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido
Uint8 mRemainingExplosions; // Cantidad de explosiones restantes Uint8 mRemainingExplosions; // Cantidad de explosiones restantes
Uint16 mRemainingExplosionsCounter; // Temporizador para la cantidad de explosiones restantes Uint16 mRemainingExplosionsCounter; // Temporizador para la cantidad de explosiones restantes
bool mExplosionTime; // Indica si las explosiones estan en marcha bool mExplosionTime; // Indica si las explosiones estan en marcha
Uint32 mCounter; // Contador para el juego Uint32 mCounter; // Contador para el juego
Uint32 mScoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos Uint32 mScoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos
SDL_Rect mGradientRect[4]; // Vector con las coordenadas de los 4 gradientes SDL_Rect mGradientRect[4]; // Vector con las coordenadas de los 4 gradientes
Uint16 mBalloonsPopped; // Lleva la cuenta de los globos explotados Uint16 mBalloonsPopped; // Lleva la cuenta de los globos explotados
Uint8 mLastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir; Uint8 mLastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir;
int mEnemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero int mEnemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
float mEnemySpeed; // Velocidad a la que se mueven los enemigos float mEnemySpeed; // Velocidad a la que se mueven los enemigos
float mDefaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar float mDefaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar
effect_t mEffect; // Variable para gestionar los efectos visuales effect_t mEffect; // Variable para gestionar los efectos visuales
helper_t mHelper; // Variable para gestionar las ayudas helper_t mHelper; // Variable para gestionar las ayudas
bool mPowerBallEnabled; // Indica si hay una powerball ya activa bool mPowerBallEnabled; // Indica si hay una powerball ya activa
Uint8 mPowerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra Uint8 mPowerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
bool mCoffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego bool mCoffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego
Uint8 mPostFade; // Qué hacer al acabar el fade Uint8 mPostFade; // Qué hacer al acabar el fade
float mSin[360]; // Vector con los valores del seno para 360 grados float mSin[360]; // Vector con los valores del seno para 360 grados
bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
int mGameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos int mGameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
Uint8 mDifficulty; // Dificultad del juego Uint8 mDifficulty; // Dificultad del juego
float mDifficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad float mDifficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
struct options_t *mOptions; // Variable con todas las variables de las opciones del programa struct options_t *mOptions; // Variable con todas las variables de las opciones del programa
Uint8 mOnePlayerControl; // Variable para almacenar el valor de las opciones Uint8 mOnePlayerControl; // Variable para almacenar el valor de las opciones
enemyFormation_t mEnemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
struct demo_t demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo
{ debug_t mDebug; // Variable con las opciones de debug
bool enabled; // Indica si está activo el modo demo
bool recording; // Indica si está activado el modo para grabar la demo
Uint16 counter; // Contador para el modo demo
demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo
demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
};
demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo
struct debug_t
{
bool enabled; // Indica si se va a mostrar la información de debug
Uint8 enemySet; // Escoge el set enemigo a generar
Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo
float hudW, hudH; // Multiplica el tamaño del hud de debug;
};
debug_t mDebug;
// Inicializa el vector con los valores del seno // Inicializa el vector con los valores del seno
void initSin(); void initSin();

View File

@@ -1,11 +0,0 @@
#include <SDL2/SDL.h>
#ifdef __linux__
#ifdef __MIPSEL__
#include "SDL.h"
#else
#include <SDL2/SDL.h>
#endif
#endif
#define UNUSED

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include <string> #include <string>
#include <vector> #include <vector>

View File

@@ -1,8 +1,4 @@
#include "instructions.h" #include "instructions.h"
#ifdef __MIPSEL__
#include <sys/stat.h>
#include <dirent.h>
#endif
const Uint8 SELF = 0; const Uint8 SELF = 0;

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
#include "const.h" #include "const.h"
#include "ifdefs.h"
#include "jail_audio.h" #include "jail_audio.h"
#include "screen.h" #include "screen.h"
#include "sprite.h" #include "sprite.h"

View File

@@ -1,8 +1,4 @@
#include "intro.h" #include "intro.h"
#ifdef __MIPSEL__
#include <sys/stat.h>
#include <dirent.h>
#endif
// Constructor // Constructor
Intro::Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang) Intro::Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang)

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "const.h" #include "const.h"
#include "utils.h" #include "utils.h"
#include "screen.h" #include "screen.h"
@@ -52,6 +53,9 @@ private:
Uint8 mEvents[INTRO_TOTAL_EVENTS]; // Vector para coordinar los eventos de la intro Uint8 mEvents[INTRO_TOTAL_EVENTS]; // Vector para coordinar los eventos de la intro
JA_Music mMusic; // Musica para la intro JA_Music mMusic; // Musica para la intro
// Carga los recursos
bool loadMedia();
public: public:
// Constructor // Constructor
Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang); Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang);
@@ -62,9 +66,6 @@ public:
// Inicializa las variables // Inicializa las variables
void init(); void init();
// Carga los recursos
bool loadMedia();
// Bucle principal // Bucle principal
section_t run(); section_t run();
}; };

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "animatedsprite.h" #include "animatedsprite.h"
#include "utils.h" #include "utils.h"
@@ -19,15 +20,15 @@
class Item class Item
{ {
private: private:
float mPosX; // Posición X del objeto float mPosX; // Posición X del objeto
float mPosY; // Posición Y del objeto float mPosY; // Posición Y del objeto
Uint8 mWidth; // Ancho del objeto Uint8 mWidth; // Ancho del objeto
Uint8 mHeight; // Alto del objeto Uint8 mHeight; // Alto del objeto
float mVelX; // Velocidad en el eje X float mVelX; // Velocidad en el eje X
float mVelY; // Velocidad en el eje Y float mVelY; // Velocidad en el eje Y
float mAccelX; // Aceleración en el eje X float mAccelX; // Aceleración en el eje X
float mAccelY; // Aceleración en el eje Y float mAccelY; // Aceleración en el eje Y
bool mFloorCollision; // Indica si el objeto colisiona con el suelo bool mFloorCollision; // Indica si el objeto colisiona con el suelo
AnimatedSprite *mSprite; // Sprite con los graficos del objeto AnimatedSprite *mSprite; // Sprite con los graficos del objeto
@@ -39,6 +40,8 @@ private:
void shiftColliders(); void shiftColliders();
public: public:
Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente
// Constructor // Constructor
Item(); Item();
@@ -93,9 +96,6 @@ public:
// Obtiene el circulo de colisión // Obtiene el circulo de colisión
circle_t &getCollider(); circle_t &getCollider();
// Temporizador con el tiempo que el objeto está presente
Uint16 mTimeToLive;
// Informa si el objeto ha colisionado con el suelo // Informa si el objeto ha colisionado con el suelo
bool floorCollision(); bool floorCollision();
}; };

View File

@@ -1,6 +1,7 @@
#ifndef __MIPSEL__
#include "jail_audio.h" #include "jail_audio.h"
#include "stb_vorbis.c" #include "stb_vorbis.c"
#include <SDL2/SDL.h>
#include <stdio.h>
#define JA_MAX_SIMULTANEOUS_CHANNELS 5 #define JA_MAX_SIMULTANEOUS_CHANNELS 5
@@ -30,16 +31,17 @@ JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
int JA_freq {48000}; int JA_freq {48000};
SDL_AudioFormat JA_format {AUDIO_S16}; SDL_AudioFormat JA_format {AUDIO_S16};
Uint8 JA_channels {2}; Uint8 JA_channels {2};
int JA_volume = 128;
void audioCallback(void * userdata, uint8_t * stream, int len) { void audioCallback(void * userdata, uint8_t * stream, int len) {
SDL_memset(stream, 0, len); SDL_memset(stream, 0, len);
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) { if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
const int size = SDL_min(len, current_music->samples*2-current_music->pos); const int size = SDL_min(len, current_music->samples*2-current_music->pos);
SDL_memcpy(stream, current_music->output+current_music->pos, size); SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_volume);
current_music->pos += size/2; current_music->pos += size/2;
if (size < len) { if (size < len) {
if (current_music->times != 0) { if (current_music->times != 0) {
SDL_memcpy(stream+size, current_music->output, len-size); SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_volume);
current_music->pos = (len-size)/2; current_music->pos = (len-size)/2;
if (current_music->times > 0) current_music->times--; if (current_music->times > 0) current_music->times--;
} else { } else {
@@ -52,11 +54,11 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].state == JA_CHANNEL_PLAYING) { if (channels[i].state == JA_CHANNEL_PLAYING) {
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos); 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, 64); SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2);
channels[i].pos += size; channels[i].pos += size;
if (size < len) { if (size < len) {
if (channels[i].times != 0) { if (channels[i].times != 0) {
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, 64); SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2);
channels[i].pos = len-size; channels[i].pos = len-size;
if (channels[i].times > 0) channels[i].times--; if (channels[i].times > 0) channels[i].times--;
} else { } else {
@@ -79,7 +81,19 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
JA_Music JA_LoadMusic(const char* filename) { JA_Music JA_LoadMusic(const char* filename) {
int chan, samplerate; int chan, samplerate;
JA_Music music = new JA_Music_t(); JA_Music music = new JA_Music_t();
music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
// [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);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
Uint8 *buffer = (Uint8*)malloc(fsize + 1);
fread(buffer, fsize, 1, f);
fclose(f);
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_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq); SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
@@ -134,6 +148,13 @@ void JA_DeleteMusic(JA_Music music) {
delete music; delete music;
} }
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length) {
JA_Sound sound = new JA_Sound_t();
sound->buffer = buffer;
sound->length = length;
return sound;
}
JA_Sound JA_LoadSound(const char* filename) { JA_Sound JA_LoadSound(const char* filename) {
JA_Sound sound = new JA_Sound_t(); JA_Sound sound = new JA_Sound_t();
SDL_AudioSpec wavSpec; SDL_AudioSpec wavSpec;
@@ -210,4 +231,8 @@ JA_Channel_state JA_GetChannelState(const int channel) {
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID; if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
return channels[channel].state; return channels[channel].state;
} }
#endif
int JA_SetVolume(int volume) {
JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
return JA_volume;
}

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "ifdefs.h" #include <SDL2/SDL.h>
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED }; 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 }; enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
@@ -17,6 +17,7 @@ void JA_StopMusic();
JA_Music_state JA_GetMusicState(); JA_Music_state JA_GetMusicState();
void JA_DeleteMusic(JA_Music music); void JA_DeleteMusic(JA_Music music);
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length);
JA_Sound JA_LoadSound(const char* filename); JA_Sound JA_LoadSound(const char* filename);
int JA_PlaySound(JA_Sound sound, const int loop = 0); int JA_PlaySound(JA_Sound sound, const int loop = 0);
void JA_PauseChannel(const int channel); void JA_PauseChannel(const int channel);
@@ -24,3 +25,5 @@ void JA_ResumeChannel(const int channel);
void JA_StopChannel(const int channel); void JA_StopChannel(const int channel);
JA_Channel_state JA_GetChannelState(const int channel); JA_Channel_state JA_GetChannelState(const int channel);
void JA_DeleteSound(JA_Sound sound); void JA_DeleteSound(JA_Sound sound);
int JA_SetVolume(int volume);

View File

@@ -1,106 +0,0 @@
#ifdef __MIPSEL__
#include "jail_audio.h"
#include <SDL2/SDL_mixer.h>
struct JA_Sound_t {
Mix_Chunk *mix_chunk;
};
struct JA_Music_t {
Mix_Music* mix_music;
};
JA_Music current_music{NULL};
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
Mix_AllocateChannels(8);
}
JA_Music JA_LoadMusic(const char* filename) {
int chan, samplerate;
JA_Music music = new JA_Music_t();
music->mix_music = Mix_LoadMUS(filename);
return music;
}
void JA_PlayMusic(JA_Music music, const int loop) {
if (current_music == music) return;
if (current_music != NULL) {
Mix_HaltMusic();
}
current_music = music;
Mix_PlayMusic(music->mix_music, loop);
}
void JA_PauseMusic() {
Mix_PauseMusic();
}
void JA_ResumeMusic() {
Mix_ResumeMusic();
}
void JA_StopMusic() {
Mix_HaltMusic();
}
JA_Music_state JA_GetMusicState() {
if (current_music == NULL) return JA_MUSIC_INVALID;
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 music) {
if (current_music == music) {
Mix_HaltMusic();
current_music = NULL;
}
Mix_FreeMusic(music->mix_music);
delete music;
}
JA_Sound JA_LoadSound(const char* filename) {
JA_Sound sound = new JA_Sound_t();
sound->mix_chunk = Mix_LoadWAV(filename);
return sound;
}
int JA_PlaySound(JA_Sound sound, const int loop) {
int channel = Mix_PlayChannel(-1, sound->mix_chunk, loop);
return channel;
}
void JA_DeleteSound(JA_Sound sound) {
Mix_FreeChunk(sound->mix_chunk);
delete 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;
}
}
#endif

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include <string> #include <string>
#ifndef LANG_H #ifndef LANG_H

View File

@@ -1,8 +1,4 @@
#include "logo.h" #include "logo.h"
#ifdef __MIPSEL__
#include <sys/stat.h>
#include <dirent.h>
#endif
#define INIT_FADE 100 #define INIT_FADE 100
#define END_LOGO 200 #define END_LOGO 200

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "const.h" #include "const.h"
#include "utils.h" #include "utils.h"
#include "sprite.h" #include "sprite.h"

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "sprite.h" #include "sprite.h"
#include "text.h" #include "text.h"
#include "input.h" #include "input.h"

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "sprite.h" #include "sprite.h"
#ifndef MOVINGSPRITE_H #ifndef MOVINGSPRITE_H

View File

@@ -1,4 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
#include "utils.h" #include "utils.h"
#include "input.h" #include "input.h"
#include "animatedsprite.h" #include "animatedsprite.h"

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "utils.h" #include "utils.h"
#ifndef SCREEN_H #ifndef SCREEN_H

View File

@@ -1,4 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
#include "utils.h" #include "utils.h"
#include "animatedsprite.h" #include "animatedsprite.h"

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "ltexture.h" #include "ltexture.h"
#ifndef SPRITE_H #ifndef SPRITE_H

View File

@@ -1,4 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
#include "sprite.h" #include "sprite.h"
#include "utils.h" #include "utils.h"

View File

@@ -1,8 +1,4 @@
#include "title.h" #include "title.h"
#ifdef __MIPSEL__
#include <sys/stat.h>
#include <dirent.h>
#endif
// Constructor // Constructor
Title::Title(SDL_Window *window, SDL_Renderer *renderer, Screen *screen, Input *input, std::string *fileList, options_t *options, Lang *lang) Title::Title(SDL_Window *window, SDL_Renderer *renderer, Screen *screen, Input *input, std::string *fileList, options_t *options, Lang *lang)
@@ -516,10 +512,6 @@ void Title::updateMenuLabels()
// Aplica las opciones de menu seleccionadas // Aplica las opciones de menu seleccionadas
void Title::applyOptions() void Title::applyOptions()
{ {
//SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
//if (mOptions->fullScreenMode == 0)
// SDL_SetWindowSize(mWindow, mOptions->screenWidth * mOptions->windowSize, mOptions->screenHeight * mOptions->windowSize);
//SDL_RenderSetLogicalSize(mRenderer, mOptions->screenWidth, mOptions->screenHeight);
mScreen->setVideoMode(mOptions->fullScreenMode); mScreen->setVideoMode(mOptions->fullScreenMode);
mLang->setLang(mOptions->language); mLang->setLang(mOptions->language);

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "const.h" #include "const.h"
#include "utils.h" #include "utils.h"
#include "sprite.h" #include "sprite.h"

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include "ltexture.h" #include "ltexture.h"
#include <string> #include <string>

View File

@@ -1,4 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
#include "sprite.h" #include "sprite.h"
#include "text.h" #include "text.h"