Start to work on dual input for P1
This commit is contained in:
@@ -42,6 +42,8 @@ Director::Director(std::string path)
|
||||
// Crea los objetos
|
||||
mInput1 = new Input(mOptions->player1Input);
|
||||
mInput2 = new Input(mOptions->player2Input);
|
||||
//mInput[0] = new Input(INPUT_USE_KEYBOARD);
|
||||
//mInput[1] = new Input(INPUT_USE_GAMECONTROLLER);
|
||||
|
||||
// Inicializa SDL
|
||||
initSDL();
|
||||
@@ -140,12 +142,11 @@ void Director::initJailAudio()
|
||||
// Arranca SDL y crea la ventana
|
||||
bool Director::initSDL()
|
||||
{
|
||||
// Indicador de inicialización
|
||||
// Indicador de éxito
|
||||
bool success = true;
|
||||
|
||||
// Inicializa SDL
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO | SDL_INIT_HAPTIC) < 0)
|
||||
//if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
|
||||
@@ -34,13 +34,12 @@ private:
|
||||
SDL_Window *mWindow; // La ventana donde dibujamos
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
|
||||
Input *mInput1; // Objeto Input para gestionar las entradas
|
||||
Input *mInput2; // Objeto Input para gestionar las entradas
|
||||
|
||||
Logo *mLogo; // Objeto para la sección del logo
|
||||
Intro *mIntro; // Objeto para la sección de la intro
|
||||
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones
|
||||
Game *mGame; // Objeto para la sección del juego
|
||||
Input *mInput1; // Objeto Input para gestionar las entradas
|
||||
Input *mInput2; // Objeto Input para gestionar las entradas
|
||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
|
||||
std::string mFileList[MAX_FILE_LIST]; // Vector con las rutas a los ficheros de recursos
|
||||
|
||||
@@ -315,6 +315,10 @@ void Game::init()
|
||||
mMenaceThreshold = 0;
|
||||
mHiScoreAchieved = false;
|
||||
mCurrentStage = 0;
|
||||
|
||||
// BORRAR
|
||||
mCurrentStage = 9;
|
||||
|
||||
mStageBitmapCounter = STAGE_COUNTER;
|
||||
mDeathCounter = DEATH_COUNTER;
|
||||
mExplosionTime = false;
|
||||
@@ -366,6 +370,9 @@ void Game::init()
|
||||
initEnemyPools();
|
||||
initGameStages();
|
||||
|
||||
// BORRAR
|
||||
mStage[mCurrentStage].currentPower = mStage[mCurrentStage].powerToComplete - 10;
|
||||
|
||||
// Modo debug
|
||||
mDebug.enabled = false;
|
||||
mDebug.enemySet = 0;
|
||||
@@ -1704,7 +1711,10 @@ void Game::updateStage()
|
||||
mStage[mCurrentStage].currentPower = 0; // Deja el poder a cero para que no vuelva a entrar en esta condición
|
||||
destroyAllBalloons(); // Destruye a todos los enemigos
|
||||
mStage[mCurrentStage].currentPower = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos lo globos
|
||||
mMenaceCurrent = 255;
|
||||
mMenaceCurrent = 255; // Sube el nivel de amenaza para que no cree mas globos
|
||||
for (int i = 0; i < mNumPlayers; i++) // Añade un millon de puntos a los jugadores que queden vivos
|
||||
if (mPlayer[i]->isAlive())
|
||||
mPlayer[i]->addScore(1000000);
|
||||
JA_StopMusic();
|
||||
}
|
||||
JA_PlaySound(mSoundStageChange);
|
||||
@@ -1735,7 +1745,7 @@ void Game::updateDeath()
|
||||
allPlayersAreDead &= (!mPlayer[i]->isAlive());
|
||||
|
||||
if (!mPlayer[i]->isAlive())
|
||||
{
|
||||
{
|
||||
// Animación
|
||||
if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 0)
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 0, 24, 24, 24);
|
||||
@@ -2946,15 +2956,16 @@ void Game::renderMessages()
|
||||
if ((mCounter < STAGE_COUNTER) && (!mDemo.enabled))
|
||||
{
|
||||
mSpriteGetReady->setPosX((int)mGetReadyBitmapPath[mCounter]);
|
||||
mSpriteGetReady->render();
|
||||
//mSpriteGetReady->render();
|
||||
const color_t color = {0x17, 0x17, 0x26};
|
||||
mTextBig->writeShadowed((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), color, 2);
|
||||
}
|
||||
|
||||
// Time Stopped
|
||||
if (mTimeStopped)
|
||||
{
|
||||
if ((mTimeStoppedCounter > 100) || (mTimeStoppedCounter % 10 > 4))
|
||||
//mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, "Time Stopped: " + std::to_string(mTimeStoppedCounter / 10));
|
||||
mText->writeDX(TXT_CENTER | TXT_SHADOW, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(36) + std::to_string(mTimeStoppedCounter / 10), 1, noColor, 1, shdwTxtColor);
|
||||
mText->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(36) + std::to_string(mTimeStoppedCounter / 10), 1, noColor, 1, shdwTxtColor);
|
||||
|
||||
if (mTimeStoppedCounter > 100)
|
||||
{
|
||||
@@ -2975,11 +2986,19 @@ void Game::renderMessages()
|
||||
|
||||
// STAGE NUMBER
|
||||
std::string text = mLang->getText(38) + std::to_string(mStage[mCurrentStage].number);
|
||||
if (mGameCompleted) // Texto de juego completado
|
||||
text = mLang->getText(50);
|
||||
|
||||
if (mStageBitmapCounter < STAGE_COUNTER)
|
||||
mTextBig->writeDX(TXT_CENTER | TXT_SHADOW, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, 1, noColor, 2, shdwTxtColor);
|
||||
{
|
||||
if (!mGameCompleted)
|
||||
{
|
||||
mTextBig->writeDX(TXT_CENTER | TXT_SHADOW, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, 1, noColor, 2, shdwTxtColor);
|
||||
}
|
||||
else
|
||||
{ // Texto de juego completado
|
||||
text = mLang->getText(50);
|
||||
mTextBig->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, 1, noColor, 1, shdwTxtColor);
|
||||
mText->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter] + 17, mLang->getText(76), 1, noColor, 1, shdwTxtColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Habilita el efecto del item de detener el tiempo
|
||||
|
||||
@@ -141,7 +141,7 @@ bool Input::discoverGameController()
|
||||
int nJoysticks = SDL_NumJoysticks();
|
||||
mNumGamepads = 0;
|
||||
|
||||
// Count how many controllers there are
|
||||
// Cuenta el numero de mandos
|
||||
for (int i = 0; i < nJoysticks; i++)
|
||||
if (SDL_IsGameController(i))
|
||||
mNumGamepads++;
|
||||
@@ -154,7 +154,7 @@ bool Input::discoverGameController()
|
||||
|
||||
for (int i = 0; i < mNumGamepads; i++)
|
||||
{
|
||||
// Open the controller and add it to our list
|
||||
// Abre el mando y lo añade a la lista
|
||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
mConnectedControllers.push_back(pad);
|
||||
@@ -167,4 +167,10 @@ bool Input::discoverGameController()
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
// Establece el método de entrada
|
||||
void Input::setSource(Uint8 value)
|
||||
{
|
||||
mSource = value;
|
||||
}
|
||||
@@ -54,6 +54,9 @@ private:
|
||||
|
||||
int mSource; // Indica si el objeto usará un mando o un teclado
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
bool discoverGameController();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Input(int source);
|
||||
@@ -70,8 +73,8 @@ public:
|
||||
// Comprueba si un input esta activo
|
||||
bool checkInput(Uint8 input, bool repeat);
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
bool discoverGameController();
|
||||
// Establece el método de entrada
|
||||
void setSource(Uint8 value);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -98,6 +98,7 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col
|
||||
const bool centered = ((flags & TXT_CENTER) == TXT_CENTER);
|
||||
const bool shadowed = ((flags & TXT_SHADOW) == TXT_SHADOW);
|
||||
const bool colored = ((flags & TXT_COLOR) == TXT_COLOR);
|
||||
const bool stroked = ((flags & TXT_STROKE) == TXT_STROKE);
|
||||
|
||||
if (centered)
|
||||
x -= (Text::lenght(text, kerning) / 2);
|
||||
@@ -105,6 +106,19 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col
|
||||
if (shadowed)
|
||||
writeColored(x + shadowDistance, y + shadowDistance, text, shadowColor, kerning, lenght);
|
||||
|
||||
if (stroked)
|
||||
{
|
||||
writeColored(x + shadowDistance, y + shadowDistance, text, shadowColor, kerning, lenght);
|
||||
writeColored(x - shadowDistance, y + shadowDistance, text, shadowColor, kerning, lenght);
|
||||
writeColored(x + shadowDistance, y - shadowDistance, text, shadowColor, kerning, lenght);
|
||||
writeColored(x - shadowDistance, y - shadowDistance, text, shadowColor, kerning, lenght);
|
||||
|
||||
writeColored(x, y + shadowDistance, text, shadowColor, kerning, lenght);
|
||||
writeColored(x, y - shadowDistance, text, shadowColor, kerning, lenght);
|
||||
writeColored(x + shadowDistance, y, text, shadowColor, kerning, lenght);
|
||||
writeColored(x - shadowDistance, y, text, shadowColor, kerning, lenght);
|
||||
}
|
||||
|
||||
if (colored)
|
||||
writeColored(x, y, text, textColor, kerning, lenght);
|
||||
else
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define TXT_COLOR 1
|
||||
#define TXT_SHADOW 2
|
||||
#define TXT_CENTER 4
|
||||
#define TXT_STROKE 8
|
||||
|
||||
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
||||
class Text
|
||||
|
||||
@@ -219,21 +219,7 @@ void Title::init(bool demo, Uint8 subsection)
|
||||
mEvents[i] = EVENT_WAITING;
|
||||
|
||||
// Crea el mosaico de fondo del titulo
|
||||
SDL_SetRenderTarget(mRenderer, mBackground);
|
||||
SDL_SetRenderDrawColor(mRenderer, 0x43, 0x43, 0x4F, 0xFF);
|
||||
SDL_RenderClear(mRenderer);
|
||||
|
||||
mTile->init(0, 0, 64, 64, mTitleTexture, mRenderer);
|
||||
mTile->setSpriteClip(192, 0, 64, 64);
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int j = 0; j < 6; j++)
|
||||
{
|
||||
mTile->setPosX(i * 64);
|
||||
mTile->setPosY(j * 64);
|
||||
mTile->render();
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||
createTiledBackground();
|
||||
|
||||
mBackgroundWindow.x = 0;
|
||||
mBackgroundWindow.y = 0;
|
||||
@@ -251,13 +237,10 @@ void Title::init(bool demo, Uint8 subsection)
|
||||
mMenu.title->addItem(mLang->getText(51)); // 1 PLAYER
|
||||
mMenu.title->addItem(mLang->getText(52), 0, 5); // 2 PLAYERS
|
||||
mMenu.title->addItem(mLang->getText(1), 0, 5); // OPTIONS
|
||||
//mMenu.title->addItem(mLang->getText(2), 0, 5); // HOW TO PLAY
|
||||
mMenu.title->addItem(mLang->getText(3)); // QUIT
|
||||
mMenu.title->addItem(mLang->getText(3)); // QUIT
|
||||
mMenu.title->setDefaultActionWhenCancel(3);
|
||||
mMenu.title->setBackgroundColor(0x30, 0x30, 0x40, 192);
|
||||
//mMenu.title->setSelectorColor(0xe5, 0x1c, 0x23, 255);
|
||||
mMenu.title->setSelectorColor(0xe5, 0x1c, 0x23, 0);
|
||||
//mMenu.title->setSelectorTextColor(0xFF, 0xF1, 0x76);
|
||||
mMenu.title->setSelectorTextColor(0xFF, 0xB4, 0x00);
|
||||
mMenu.title->centerMenuOnX(SCREEN_CENTER_X);
|
||||
mMenu.title->centerMenuElementsOnX();
|
||||
@@ -493,6 +476,7 @@ void Title::applyOptions()
|
||||
mLang->setLang(mOptions->language);
|
||||
|
||||
updateMenuLabels();
|
||||
createTiledBackground();
|
||||
}
|
||||
|
||||
// Bucle para el titulo del juego
|
||||
@@ -838,14 +822,14 @@ section_t Title::run(Uint8 subsection)
|
||||
// Bitmaps con el logo/titulo del juego
|
||||
mCoffeeBitmap->render();
|
||||
mCrisisBitmap->render();
|
||||
|
||||
|
||||
// Texto con el copyright y versión
|
||||
mText2->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, SCREEN_HEIGHT - (BLOCK * 2), TEXT_COPYRIGHT, 1, noColor, 1, shdwTxtColor);
|
||||
}
|
||||
|
||||
|
||||
if (mMenuVisible == true)
|
||||
mMenu.active->render();
|
||||
|
||||
|
||||
mDustBitmapR->animate(0);
|
||||
mDustBitmapL->animate(0);
|
||||
mDustBitmapR->render();
|
||||
@@ -908,4 +892,24 @@ void Title::SwitchInputs(int value)
|
||||
temp = mOptions->player1Input;
|
||||
mOptions->player1Input = mOptions->player2Input;
|
||||
mOptions->player2Input = temp;
|
||||
}
|
||||
|
||||
// Crea el mosaico de fondo del titulo
|
||||
void Title::createTiledBackground()
|
||||
{
|
||||
SDL_SetRenderTarget(mRenderer, mBackground);
|
||||
SDL_SetRenderDrawColor(mRenderer, 0x43, 0x43, 0x4F, 0xFF);
|
||||
SDL_RenderClear(mRenderer);
|
||||
|
||||
mTile->init(0, 0, 64, 64, mTitleTexture, mRenderer);
|
||||
mTile->setSpriteClip(192, 0, 64, 64);
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int j = 0; j < 6; j++)
|
||||
{
|
||||
mTile->setPosX(i * 64);
|
||||
mTile->setPosY(j * 64);
|
||||
mTile->render();
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||
}
|
||||
@@ -94,6 +94,9 @@ private:
|
||||
// Modifica las opciones para los controles de los jugadores
|
||||
void SwitchInputs(int value);
|
||||
|
||||
// Crea el mosaico de fondo del titulo
|
||||
void createTiledBackground();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::string *fileList, options_t *options, Lang *lang);
|
||||
|
||||
Reference in New Issue
Block a user