19 Commits

Author SHA1 Message Date
d3f17bc93a Release 2.0 2021-09-03 19:21:26 +02:00
b7490ed1c1 Preparing release 2.0 2021-09-03 12:58:54 +02:00
836deb720d new logo.png 2021-09-03 12:47:16 +02:00
7e9a1cb049 bug fixes 2021-09-02 10:07:54 +02:00
f928195a05 bug fixes 2021-09-01 22:58:50 +02:00
84b09a4987 Bug fixes 2021-09-01 19:26:34 +02:00
f0b9a1d134 Fixed offset from render messages with nokia font 2021-09-01 19:10:00 +02:00
64369921ec bug fixes 2021-09-01 17:23:12 +02:00
70ae7f67a9 Merge branch 'master' of https://gitea.sustancia.synology.me/JailDesigner/coffee_crisis 2021-09-01 16:54:41 +02:00
2ea86ef39f added font nokia2 2021-09-01 16:54:19 +02:00
658bb71441 bug fixes 2021-09-01 14:04:34 +02:00
0b996ea321 Working on support for various controllers 2021-08-31 21:36:09 +02:00
cf072424c6 Working on support for various controllers 2021-08-31 21:30:55 +02:00
42c0f19c68 Working on support for various controllers 2021-08-31 21:05:04 +02:00
8d1cabb288 updated some pngs 2021-08-31 18:00:55 +02:00
87aeaab6b8 bug fixes 2021-08-31 17:09:30 +02:00
ad5fb0fc22 Working on support for various controllers 2021-08-31 13:56:03 +02:00
8e6d546b97 Start to work on support for various controllers 2021-08-31 10:18:13 +02:00
f916381a9b added gamecontrollersDB.txt 2021-08-31 07:23:27 +02:00
23 changed files with 487 additions and 120 deletions

View File

@@ -3,7 +3,7 @@
# box height # box height
10 10
# 32 espacio ( ) # 32 espacio ( )
7 5
# 33 ! # 33 !
4 4
# 34 " # 34 "

BIN
media/font/nokia2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

194
media/font/nokia2.txt Normal file
View File

@@ -0,0 +1,194 @@
# box width
10
# box height
10
# 32 espacio ( )
5
# 33 !
4
# 34 "
5
# 35 #
7
# 36 $
7
# 37 %
8
# 38 &
8
# 39 '
3
# 40 (
5
# 41 )
5
# 42 *
7
# 43 +
7
# 44 ,
4
# 45 -
6
# 46 .
4
# 47 /
5
# 48 0
7
# 49 1
5
# 50 2
7
# 51 3
7
# 52 4
7
# 53 5
7
# 54 6
7
# 55 7
7
# 56 8
7
# 57 9
7
# 58 :
4
# 59 ;
4
# 60 <
6
# 61 =
6
# 62 >
6
# 63 ?
7
# 64 @
8
# 65 A
7
# 66 B
7
# 67 C
7
# 68 D
7
# 69 E
7
# 70 F
7
# 71 G
7
# 72 H
7
# 73 I
4
# 74 J
6
# 75 K
8
# 76 L
6
# 77 M
9
# 78 N
8
# 79 O
8
# 80 P
7
# 81 Q
8
# 82 R
7
# 83 S
6
# 84 T
8
# 85 U
7
# 86 V
8
# 87 W
9
# 88 X
8
# 89 Y
8
# 90 Z
7
# 91 [
4
# 92 \
5
# 93 ]
4
# 94 ^
5
# 95 _
8
# 96 `
4
# 97 a
7
# 98 b
7
# 99 c
6
# 100 d
7
# 101 e
7
# 102 f
5
# 103 g
7
# 104 h
7
# 105 i
4
# 106 j
5
# 107 k
7
# 108 l
4
# 109 m
10
# 110 n
7
# 111 o
7
# 112 p
7
# 113 q
7
# 114 r
6
# 115 s
6
# 116 t
5
# 117 u
7
# 118 v
7
# 119 w
9
# 120 x
7
# 121 y
7
# 122 z
7
# 123 { -> ñ
7
# 124 | -> ç
7
# 125 }
0
# 126 ~
0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

BIN
media/font/nokia_big2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@@ -3,7 +3,7 @@
# box height # box height
20 20
# 32 espacio ( ) # 32 espacio ( )
14 8
# 33 ! # 33 !
8 8
# 34 " # 34 "

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 773 B

After

Width:  |  Height:  |  Size: 654 B

View File

@@ -75,7 +75,7 @@ Temps detes:
## 37 - TEXTOS DEL JUEGO ## 37 - TEXTOS DEL JUEGO
D E M O D E M O
## 38 - TEXTOS DEL JUEGO ## 38 - TEXTOS DEL JUEGO
PANTALLA Pantalla
## 39 - MARCADOR ## 39 - MARCADOR
PUNTS PUNTS
## 40 - MARCADOR ## 40 - MARCADOR
@@ -99,7 +99,7 @@ SI
## 49 - MENU GAME OVER ## 49 - MENU GAME OVER
NO NO
## 50 - TEXTO DE COMPLETAR EL JUEGO ## 50 - TEXTO DE COMPLETAR EL JUEGO
FELICITATS!! Felicitats!!
## 51 - MENU DEL TITULO ## 51 - MENU DEL TITULO
1 JUGADOR 1 JUGADOR
## 52 - MENU DEL TITULO ## 52 - MENU DEL TITULO
@@ -113,7 +113,7 @@ mult
## 56 MARCADOR ## 56 MARCADOR
max. puntuacio max. puntuacio
## 57 MARCADOR ## 57 MARCADOR
nivell pantalla
## 58 - MENU DE OPCIONES ## 58 - MENU DE OPCIONES
MODE DE VISUALITZACIO MODE DE VISUALITZACIO
## 59 - MENU DE OPCIONES ## 59 - MENU DE OPCIONES
@@ -148,7 +148,11 @@ NEAREST
ACTIVADA ACTIVADA
## 74 - MENU DE OPCIONES ## 74 - MENU DE OPCIONES
DESACTIVADA DESACTIVADA
## 75 - MENU DE OPCIONES ## 75 - JUEGO
ENDAVANT! Endavant!
## 76 - JUEGO ## 76 - JUEGO
1.000.000 DE PUNTS! 1.000.000 de punts!
## 77 - PANTALLA DE GAME OVER
PUNTS J1:
## 78 - PANTALLA DE GAME OVER
PUNTS J2:

View File

@@ -71,11 +71,11 @@ FUCKING MACHINE!
## 35 - INTRO ## 35 - INTRO
Blop... blop... blop... Blop... blop... blop...
## 36 - TEXTOS DEL JUEGO ## 36 - TEXTOS DEL JUEGO
Time Stopped: Time stopped:
## 37 - TEXTOS DEL JUEGO ## 37 - TEXTOS DEL JUEGO
D E M O D E M O
## 38 - TEXTOS DEL JUEGO ## 38 - TEXTOS DEL JUEGO
STAGE Stage
## 39 - MARCADOR ## 39 - MARCADOR
SCORE SCORE
## 40 - MARCADOR ## 40 - MARCADOR
@@ -99,7 +99,7 @@ YES
## 49 - MENU GAME OVER ## 49 - MENU GAME OVER
NO NO
## 50 - TEXTO DE COMPLETAR EL JUEGO ## 50 - TEXTO DE COMPLETAR EL JUEGO
NICE!! Congratulations!!
## 51 - MENU DEL TITULO ## 51 - MENU DEL TITULO
1 PLAYER 1 PLAYER
## 52 - MENU DEL TITULO ## 52 - MENU DEL TITULO
@@ -149,6 +149,10 @@ ON
## 74 - MENU DE OPCIONES ## 74 - MENU DE OPCIONES
OFF OFF
## 75 - JUEGO ## 75 - JUEGO
GET READY! Get Ready!
## 76 - JUEGO ## 76 - JUEGO
1.000.000 POINTS! 1.000.000 points!
## 77 - PANTALLA DE GAME OVER
PLAYER1 SCORE:
## 78 - PANTALLA DE GAME OVER
PLAYER2 SCORE:

View File

@@ -75,7 +75,7 @@ Tiempo:
## 37 - TEXTOS DEL JUEGO ## 37 - TEXTOS DEL JUEGO
D E M O D E M O
## 38 - TEXTOS DEL JUEGO ## 38 - TEXTOS DEL JUEGO
FASE Fase
## 39 - MARCADOR ## 39 - MARCADOR
PUNTOS PUNTOS
## 40 - MARCADOR ## 40 - MARCADOR
@@ -99,7 +99,7 @@ SI
## 49 - MENU GAME OVER ## 49 - MENU GAME OVER
NO NO
## 50 - TEXTO DE COMPLETAR EL JUEGO ## 50 - TEXTO DE COMPLETAR EL JUEGO
FELICIDADES!! Felicidades!!
## 51 - MENU DEL TITULO ## 51 - MENU DEL TITULO
1 JUGADOR 1 JUGADOR
## 52 - MENU DEL TITULO ## 52 - MENU DEL TITULO
@@ -148,7 +148,11 @@ NEAREST
ACTIVADA ACTIVADA
## 74 - MENU DE OPCIONES ## 74 - MENU DE OPCIONES
DESACTIVADA DESACTIVADA
## 75 - MENU DE OPCIONES ## 75 - JUEGO
ADELANTE! Adelante!
## 76 - JUEGO ## 76 - JUEGO
1.000.000 DE PUNTOS! 1.000.000 de puntos!
## 77 - PANTALLA DE GAME OVER
PUNTUACION J1:
## 78 - PANTALLA DE GAME OVER
PUNTUACION J2:

View File

@@ -33,17 +33,14 @@ Director::Director(std::string path)
mOptions->windowSize = 3; mOptions->windowSize = 3;
mOptions->language = en_UK; mOptions->language = en_UK;
mOptions->difficulty = DIFFICULTY_NORMAL; mOptions->difficulty = DIFFICULTY_NORMAL;
mOptions->input[0] = INPUT_USE_KEYBOARD; mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
mOptions->input[1] = INPUT_USE_GAMECONTROLLER; mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
mOptions->filter = FILTER_NEAREST; mOptions->filter = FILTER_NEAREST;
mOptions->vSync = true; mOptions->vSync = true;
} }
// Crea los objetos // Crea los objetos
mInput = new Input(mFileList[52]); mInput = new Input(mFileList[53]);
//mInput2 = new Input(mOptions->input[1]);
//mInput[0] = new Input(INPUT_USE_KEYBOARD);
//mInput[1] = new Input(INPUT_USE_GAMECONTROLLER);
// Inicializa SDL // Inicializa SDL
initSDL(); initSDL();
@@ -51,6 +48,11 @@ Director::Director(std::string path)
// Inicializa JailAudio // Inicializa JailAudio
initJailAudio(); initJailAudio();
// Aplica las opciones
SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
SDL_SetWindowSize(mWindow, SCREEN_WIDTH * mOptions->windowSize, SCREEN_HEIGHT * mOptions->windowSize);
mLang->setLang(mOptions->language);
#ifdef __MIPSEL__ #ifdef __MIPSEL__
DIR *dir = opendir("/media/data/local/home/.coffee_crisis"); DIR *dir = opendir("/media/data/local/home/.coffee_crisis");
if (dir) if (dir)
@@ -126,7 +128,7 @@ void Director::init(Uint8 name)
mInput->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X); mInput->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
mInput->bindGameControllerButton(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y); mInput->bindGameControllerButton(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
mInput->bindGameControllerButton(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B); mInput->bindGameControllerButton(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
mInput->bindGameControllerButton(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE mInput->bindGameControllerButton(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
mInput->bindGameControllerButton(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE mInput->bindGameControllerButton(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
} }
@@ -143,13 +145,17 @@ bool Director::initSDL()
bool success = true; bool success = true;
// Inicializa SDL // Inicializa SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0) //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0)
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{ {
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError()); printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
success = false; success = false;
} }
else else
{ {
// Inicia el generador de numeros aleatorios
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
// Establece el filtro de la textura a nearest // Establece el filtro de la textura a nearest
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(mOptions->filter).c_str())) if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(mOptions->filter).c_str()))
{ {
@@ -259,7 +265,11 @@ void Director::setFileList()
mFileList[27] = mExecutablePath + "/" + "../media/font/8bithud.png"; mFileList[27] = mExecutablePath + "/" + "../media/font/8bithud.png";
mFileList[46] = mExecutablePath + "/" + "../media/font/8bithud.txt"; mFileList[46] = mExecutablePath + "/" + "../media/font/8bithud.txt";
mFileList[28] = mExecutablePath + "/" + "../media/font/nokia.png"; mFileList[28] = mExecutablePath + "/" + "../media/font/nokia.png";
mFileList[54] = mExecutablePath + "/" + "../media/font/nokia_big2.png";
mFileList[52] = mExecutablePath + "/" + "../media/font/nokia.txt"; mFileList[52] = mExecutablePath + "/" + "../media/font/nokia.txt";
mFileList[56] = mExecutablePath + "/" + "../media/font/nokia2.png";
mFileList[57] = mExecutablePath + "/" + "../media/font/nokia2.txt";
mFileList[55] = mExecutablePath + "/" + "../media/font/nokia_big2.txt";
mFileList[29] = mExecutablePath + "/" + "../media/font/smb2_big.png"; mFileList[29] = mExecutablePath + "/" + "../media/font/smb2_big.png";
mFileList[47] = mExecutablePath + "/" + "../media/font/smb2_big.txt"; mFileList[47] = mExecutablePath + "/" + "../media/font/smb2_big.txt";
mFileList[30] = mExecutablePath + "/" + "../media/font/smb2.png"; mFileList[30] = mExecutablePath + "/" + "../media/font/smb2.png";
@@ -271,7 +281,7 @@ void Director::setFileList()
mFileList[51] = mExecutablePath + "/" + "../media/lang/ba_BA.txt"; mFileList[51] = mExecutablePath + "/" + "../media/lang/ba_BA.txt";
// DATA // DATA
mFileList[52] = mExecutablePath + "/" + "../media/data/gamecontrollerdb.txt"; mFileList[53] = mExecutablePath + "/" + "../data/gamecontrollerdb.txt";
} }
// Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada // Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada
@@ -345,8 +355,8 @@ bool Director::loadConfigFile()
mOptions->windowSize = 3; mOptions->windowSize = 3;
mOptions->language = en_UK; mOptions->language = en_UK;
mOptions->difficulty = DIFFICULTY_NORMAL; mOptions->difficulty = DIFFICULTY_NORMAL;
mOptions->input[0] = INPUT_USE_KEYBOARD; mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
mOptions->input[1] = INPUT_USE_GAMECONTROLLER; mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
mOptions->filter = FILTER_NEAREST; mOptions->filter = FILTER_NEAREST;
mOptions->vSync = true; mOptions->vSync = true;
@@ -373,8 +383,8 @@ bool Director::loadConfigFile()
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1); SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1); SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1); SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
SDL_RWwrite(file, &mOptions->input[0], sizeof(mOptions->input[0]), 1); SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
SDL_RWwrite(file, &mOptions->input[1], sizeof(mOptions->input[1]), 1); SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1); SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1); SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
@@ -396,8 +406,8 @@ bool Director::loadConfigFile()
SDL_RWread(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1); SDL_RWread(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
SDL_RWread(file, &mOptions->language, sizeof(mOptions->language), 1); SDL_RWread(file, &mOptions->language, sizeof(mOptions->language), 1);
SDL_RWread(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1); SDL_RWread(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
SDL_RWread(file, &mOptions->input[0], sizeof(mOptions->input[0]), 1); SDL_RWread(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
SDL_RWread(file, &mOptions->input[1], sizeof(mOptions->input[1]), 1); SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1); SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1); SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
@@ -411,11 +421,6 @@ bool Director::loadConfigFile()
if ((mOptions->language < 0) || (mOptions->language > MAX_LANGUAGES)) if ((mOptions->language < 0) || (mOptions->language > MAX_LANGUAGES))
mOptions->language = en_UK; mOptions->language = en_UK;
// Aplica las opciones
SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
SDL_SetWindowSize(mWindow, SCREEN_WIDTH * mOptions->windowSize, SCREEN_HEIGHT * mOptions->windowSize);
mLang->setLang(mOptions->language);
// Cierra el fichero // Cierra el fichero
SDL_RWclose(file); SDL_RWclose(file);
} }
@@ -437,8 +442,8 @@ bool Director::saveConfigFile()
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1); SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1); SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1); SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
SDL_RWwrite(file, &mOptions->input[0], sizeof(mOptions->input[0]), 1); SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
SDL_RWwrite(file, &mOptions->input[1], sizeof(mOptions->input[1]), 1); SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1); SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1); SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);

View File

@@ -20,7 +20,7 @@
#include "game.h" #include "game.h"
#include "input.h" #include "input.h"
#include "fade.h" #include "fade.h"
#include <math.h> //#include <math.h>
#ifndef DIRECTOR_H #ifndef DIRECTOR_H
#define DIRECTOR_H #define DIRECTOR_H

View File

@@ -13,13 +13,13 @@ Game::Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *
mLang = lang; mLang = lang;
mInput = input; mInput = input;
mOptions = options; mOptions = options;
mOnePlayerControl = mOptions->input[0]; mOnePlayerControl = mOptions->input[0].deviceType;
// Pasa variables // Pasa variables
mDemo.enabled = demo; mDemo.enabled = demo;
mNumPlayers = numPlayers; mNumPlayers = numPlayers;
if (mNumPlayers == 1) if (mNumPlayers == 1)
mOptions->input[0] = INPUT_USE_ANY; mOptions->input[0].deviceType = INPUT_USE_ANY;
mDifficulty = mOptions->difficulty; mDifficulty = mOptions->difficulty;
// Crea los objetos // Crea los objetos
@@ -50,10 +50,14 @@ Game::Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *
mTextureText = new LTexture(); mTextureText = new LTexture();
mTextureTextScoreBoard = new LTexture(); mTextureTextScoreBoard = new LTexture();
mTextureTextBig = new LTexture(); mTextureTextBig = new LTexture();
mTextureTextNokia2 = new LTexture();
mTextureTextNokiaBig2 = new LTexture();
mText = new Text(mFileList[48], mTextureText, mRenderer); mText = new Text(mFileList[48], mTextureText, mRenderer);
mTextScoreBoard = new Text(mFileList[46], mTextureTextScoreBoard, mRenderer); mTextScoreBoard = new Text(mFileList[46], mTextureTextScoreBoard, mRenderer);
mTextBig = new Text(mFileList[47], mTextureTextBig, mRenderer); mTextBig = new Text(mFileList[47], mTextureTextBig, mRenderer);
mTextNokia2 = new Text(mFileList[57], mTextureTextNokia2, mRenderer);
mTextNokiaBig2 = new Text(mFileList[55], mTextureTextNokiaBig2, mRenderer);
mMenuGameOver = new Menu(mRenderer, mText, mInput, mFileList); mMenuGameOver = new Menu(mRenderer, mText, mInput, mFileList);
mMenuPause = new Menu(mRenderer, mText, mInput, mFileList); mMenuPause = new Menu(mRenderer, mText, mInput, mFileList);
@@ -93,7 +97,7 @@ Game::~Game()
saveScoreFile(); saveScoreFile();
saveDemoFile(); saveDemoFile();
mOptions->input[0] = mOnePlayerControl; mOptions->input[0].deviceType = mOnePlayerControl;
mRenderer = nullptr; mRenderer = nullptr;
mFileList = nullptr; mFileList = nullptr;
@@ -190,14 +194,28 @@ Game::~Game()
delete mTextureTextBig; delete mTextureTextBig;
mTextureTextBig = nullptr; mTextureTextBig = nullptr;
mTextureTextNokia2->unload();
delete mTextureTextNokia2;
mTextureTextNokia2 = nullptr;
mTextureTextNokiaBig2->unload();
delete mTextureTextNokiaBig2;
mTextureTextNokiaBig2 = nullptr;
delete mText; delete mText;
mText = nullptr; mText = nullptr;
delete mTextBig;
mTextBig = nullptr;
delete mTextScoreBoard; delete mTextScoreBoard;
mTextScoreBoard = nullptr; mTextScoreBoard = nullptr;
delete mTextureTextBig; delete mTextNokia2;
mTextureTextBig = nullptr; mTextNokia2 = nullptr;
delete mTextNokiaBig2;
mTextNokiaBig2 = nullptr;
delete mMenuGameOver; delete mMenuGameOver;
mMenuGameOver = nullptr; mMenuGameOver = nullptr;
@@ -370,6 +388,9 @@ void Game::init()
initEnemyPools(); initEnemyPools();
initGameStages(); initGameStages();
// BORRAR
//mStage[mCurrentStage].currentPower = mStage[mCurrentStage].powerToComplete - 10;
// Modo debug // Modo debug
mDebug.enabled = false; mDebug.enabled = false;
mDebug.enemySet = 0; mDebug.enemySet = 0;
@@ -523,6 +544,8 @@ bool Game::loadMedia()
success &= loadTextureFromFile(mTextureText, mFileList[30], mRenderer); success &= loadTextureFromFile(mTextureText, mFileList[30], mRenderer);
success &= loadTextureFromFile(mTextureTextScoreBoard, mFileList[27], mRenderer); success &= loadTextureFromFile(mTextureTextScoreBoard, mFileList[27], mRenderer);
success &= loadTextureFromFile(mTextureTextBig, mFileList[29], mRenderer); success &= loadTextureFromFile(mTextureTextBig, mFileList[29], mRenderer);
success &= loadTextureFromFile(mTextureTextNokia2, mFileList[56], mRenderer);
success &= loadTextureFromFile(mTextureTextNokiaBig2, mFileList[54], mRenderer);
success &= loadTextureFromFile(mTexturePlayer1Legs, mFileList[39], mRenderer); success &= loadTextureFromFile(mTexturePlayer1Legs, mFileList[39], mRenderer);
success &= loadTextureFromFile(mTexturePlayer1Head, mFileList[41], mRenderer); success &= loadTextureFromFile(mTexturePlayer1Head, mFileList[41], mRenderer);
@@ -2065,8 +2088,8 @@ void Game::destroyBalloon(Uint8 index)
} }
// Otorga los puntos correspondientes al globo // Otorga los puntos correspondientes al globo
mPlayer[0]->addScore(Uint32(score * mPlayer[0]->getScoreMultiplier() * mDifficultyScoreMultiplier)); for (int i = 0; i < mNumPlayers; i++)
//setScore(mPlayer[0]->getScore()); mPlayer[i]->addScore(Uint32(score * mPlayer[i]->getScoreMultiplier() * mDifficultyScoreMultiplier));
updateHiScore(); updateHiScore();
// Aumenta el poder de la fase // Aumenta el poder de la fase
@@ -2259,7 +2282,7 @@ void Game::moveBullets()
for (int i = 0; i < MAX_BULLETS; i++) for (int i = 0; i < MAX_BULLETS; i++)
if (mBullet[i]->isActive()) if (mBullet[i]->isActive())
if (mBullet[i]->move() == MSG_BULLET_OUT) if (mBullet[i]->move() == MSG_BULLET_OUT)
mPlayer[0]->decScoreMultiplier(); mPlayer[mBullet[i]->getOwner()]->decScoreMultiplier();
} }
// Pinta las balas activas // Pinta las balas activas
@@ -2334,10 +2357,10 @@ void Game::resetItems()
// Devuelve un item en función del azar // Devuelve un item en función del azar
Uint8 Game::dropItem() Uint8 Game::dropItem()
{ {
if (mPlayer[0]->isPowerUp() || (mCoffeeMachineEnabled)) //if (mPlayer[0]->isPowerUp() || (mCoffeeMachineEnabled))
return NO_KIND; // return NO_KIND;
else //else
return ITEM_COFFEE_MACHINE; // return ITEM_COFFEE_MACHINE;
const Uint8 luckyNumber = rand() % 100; const Uint8 luckyNumber = rand() % 100;
const Uint8 item = rand() % 6; const Uint8 item = rand() % 6;
@@ -2861,7 +2884,7 @@ void Game::checkGameInput()
if (mPlayer[i]->isAlive()) if (mPlayer[i]->isAlive())
{ {
// Input a la izquierda // Input a la izquierda
if (mInput->checkInput(INPUT_LEFT, REPEAT_TRUE, mOptions->input[i])) if (mInput->checkInput(INPUT_LEFT, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id))
{ {
mPlayer[i]->setInput(INPUT_LEFT); mPlayer[i]->setInput(INPUT_LEFT);
mDemo.keys.left = 1; mDemo.keys.left = 1;
@@ -2869,7 +2892,7 @@ void Game::checkGameInput()
else else
{ {
// Input a la derecha // Input a la derecha
if (mInput->checkInput(INPUT_RIGHT, REPEAT_TRUE, mOptions->input[i])) if (mInput->checkInput(INPUT_RIGHT, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id))
{ {
mPlayer[i]->setInput(INPUT_RIGHT); mPlayer[i]->setInput(INPUT_RIGHT);
mDemo.keys.right = 1; mDemo.keys.right = 1;
@@ -2882,7 +2905,7 @@ void Game::checkGameInput()
} }
} }
// Comprueba el input de disparar al centro // Comprueba el input de disparar al centro
if (mInput->checkInput(INPUT_BUTTON_2, REPEAT_TRUE, mOptions->input[i])) if (mInput->checkInput(INPUT_BUTTON_2, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id))
{ {
if (mPlayer[i]->canFire()) if (mPlayer[i]->canFire())
{ {
@@ -2898,7 +2921,7 @@ void Game::checkGameInput()
} }
// Comprueba el input de disparar a la izquierda // Comprueba el input de disparar a la izquierda
if (mInput->checkInput(INPUT_BUTTON_1, REPEAT_TRUE, mOptions->input[i])) if (mInput->checkInput(INPUT_BUTTON_1, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id))
{ {
if (mPlayer[i]->canFire()) if (mPlayer[i]->canFire())
{ {
@@ -2914,7 +2937,7 @@ void Game::checkGameInput()
} }
// Comprueba el input de disparar a la derecha // Comprueba el input de disparar a la derecha
if (mInput->checkInput(INPUT_BUTTON_3, REPEAT_TRUE, mOptions->input[i])) if (mInput->checkInput(INPUT_BUTTON_3, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id))
{ {
if (mPlayer[i]->canFire()) if (mPlayer[i]->canFire())
{ {
@@ -2930,7 +2953,7 @@ void Game::checkGameInput()
} }
// Comprueba el input de pausa // Comprueba el input de pausa
if (mInput->checkInput(INPUT_CANCEL, REPEAT_FALSE, mOptions->input[i])) if (mInput->checkInput(INPUT_CANCEL, REPEAT_FALSE, mOptions->input[i].deviceType, mOptions->input[i].id))
{ {
mSection.subsection = GAME_SECTION_PAUSE; mSection.subsection = GAME_SECTION_PAUSE;
@@ -2959,16 +2982,21 @@ void Game::renderMessages()
{ {
mSpriteGetReady->setPosX((int)mGetReadyBitmapPath[mCounter]); mSpriteGetReady->setPosX((int)mGetReadyBitmapPath[mCounter]);
//mSpriteGetReady->render(); //mSpriteGetReady->render();
const color_t color = {0x17, 0x17, 0x26}; //const color_t color = {0x17, 0x17, 0x26};
//mTextBig->writeShadowed((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), color, 2); //mTextBig->writeShadowed((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), color, 2);
mTextBig->writeDX(TXT_STROKE, (int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), 1, noColor, 1, shdwTxtColor); //mTextBig->writeDX(TXT_STROKE, (int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), 1, noColor, 1, shdwTxtColor);
mTextNokiaBig2->write((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), -2);
} }
// Time Stopped // Time Stopped
if (mTimeStopped) if (mTimeStopped)
{ {
if ((mTimeStoppedCounter > 100) || (mTimeStoppedCounter % 10 > 4)) if ((mTimeStoppedCounter > 100) || (mTimeStoppedCounter % 10 > 4))
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); mTextNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(36) + std::to_string(mTimeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor);
//{
// mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(36), -2);
// mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y + mTextNokiaBig2->getCharacterWidth() + 2, std::to_string(mTimeStoppedCounter / 10), -2);
//}
if (mTimeStoppedCounter > 100) if (mTimeStoppedCounter > 100)
{ {
@@ -2985,7 +3013,7 @@ void Game::renderMessages()
// D E M O // D E M O
if (mDemo.enabled) if (mDemo.enabled)
if (mDemo.counter % 30 > 14) if (mDemo.counter % 30 > 14)
mTextBig->writeDX(TXT_CENTER | TXT_SHADOW, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(37), 0, noColor, 2, shdwTxtColor); mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(37), 0, noColor, 2, shdwTxtColor);
// STAGE NUMBER // STAGE NUMBER
if (mStageBitmapCounter < STAGE_COUNTER) if (mStageBitmapCounter < STAGE_COUNTER)
@@ -2993,13 +3021,13 @@ void Game::renderMessages()
std::string text = mLang->getText(38) + std::to_string(mStage[mCurrentStage].number); std::string text = mLang->getText(38) + std::to_string(mStage[mCurrentStage].number);
if (!mGameCompleted) if (!mGameCompleted)
{ {
mTextBig->writeDX(TXT_CENTER | TXT_SHADOW, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, 1, noColor, 2, shdwTxtColor); mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, -2, noColor, 2, shdwTxtColor);
} }
else else
{ // Texto de juego completado { // Texto de juego completado
text = mLang->getText(50); text = mLang->getText(50);
mTextBig->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, 1, noColor, 1, shdwTxtColor); mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, -2, noColor, 1, shdwTxtColor);
mText->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter] + 17, mLang->getText(76), 1, noColor, 1, shdwTxtColor); mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter] + mTextNokiaBig2->getCharacterWidth() + 2, mLang->getText(76), -1, noColor, 1, shdwTxtColor);
} }
} }
} }
@@ -3271,6 +3299,9 @@ void Game::runPausedGame()
// Bucle para la pantalla de game over // Bucle para la pantalla de game over
void Game::runGameOverScreen() void Game::runGameOverScreen()
{ {
// Guarda los puntos
saveScoreFile();
// Reinicia el menu // Reinicia el menu
mMenuGameOver->reset(); mMenuGameOver->reset();
@@ -3327,8 +3358,17 @@ void Game::runGameOverScreen()
SDL_RenderClear(mRenderer); SDL_RenderClear(mRenderer);
// Dibuja los objetos // Dibuja los objetos
mTextBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), mLang->getText(43)); if (mNumPlayers == 1)
mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 1), mLang->getText(44) + std::to_string(mPlayer[0]->getScore())); {
mTextBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), mLang->getText(43));
mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 1), mLang->getText(44) + std::to_string(mPlayer[0]->getScore()));
}
else
{
mTextBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - 36, mLang->getText(43));
mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - 12, mLang->getText(77) + std::to_string(mPlayer[0]->getScore()));
mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y, mLang->getText(78) + std::to_string(mPlayer[1]->getScore()));
}
mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y + BLOCK * 2, mLang->getText(45)); mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y + BLOCK * 2, mLang->getText(45));
mMenuGameOver->render(); mMenuGameOver->render();
mFade->render(); mFade->render();
@@ -3424,7 +3464,7 @@ void Game::initPaths()
} }
// Letrero de GetReady // Letrero de GetReady
const int size = mTextBig->lenght(mLang->getText(75)); const int size = mTextNokiaBig2->lenght(mLang->getText(75), -2);
const float start1 = PLAY_AREA_LEFT - size; const float start1 = PLAY_AREA_LEFT - size;
const float finish1 = PLAY_AREA_CENTER_X - (size / 2); const float finish1 = PLAY_AREA_CENTER_X - (size / 2);
@@ -3467,6 +3507,7 @@ void Game::updateGameCompleted()
// Actualiza las variables de ayuda // Actualiza las variables de ayuda
void Game::updateHelper() void Game::updateHelper()
{ {
// El ayudante solo funciona para un jugador
// Solo ofrece ayuda cuando la amenaza o la velocidad es elevada // Solo ofrece ayuda cuando la amenaza o la velocidad es elevada
if (mMenaceCurrent > 15) if (mMenaceCurrent > 15)
{ {

View File

@@ -108,10 +108,14 @@ private:
LTexture *mTextureText; // Textura para el texto del juego LTexture *mTextureText; // Textura para el texto del juego
LTexture *mTextureTextScoreBoard; // Textura para el texto del marcador LTexture *mTextureTextScoreBoard; // Textura para el texto del marcador
LTexture *mTextureTextBig; // Textura para el texto grande LTexture *mTextureTextBig; // Textura para el texto grande
LTexture *mTextureTextNokia2; // Textura para la fuente de texto Nokia
LTexture *mTextureTextNokiaBig2; // Textura para la fuente de texto Nokia grande
Text *mText; // Fuente para los textos del juego Text *mText; // Fuente para los textos del juego
Text *mTextScoreBoard; // Fuente para el marcador del juego
Text *mTextBig; // Fuente de texto grande Text *mTextBig; // Fuente de texto grande
Text *mTextScoreBoard; // Fuente para el marcador del juego
Text *mTextNokia2; // Otra fuente de texto para mesajes
Text *mTextNokiaBig2; // Y la versión en grande
Menu *mMenuGameOver; // Menú de la pantalla de game over Menu *mMenuGameOver; // Menú de la pantalla de game over
Menu *mMenuPause; // Menú de la pantalla de pausa Menu *mMenuPause; // Menú de la pantalla de pausa

View File

@@ -1,7 +1,9 @@
#include "input.h" #include "input.h"
//#include <stdio.h>
#include <iostream> #include <iostream>
// Contestar cuantos joystics ha detectado
// Preguntarlepor los joystics que ha encontrado para ir poniendolos en la variable de opciones
// Constructor // Constructor
Input::Input(std::string file) Input::Input(std::string file)
{ {
@@ -24,9 +26,8 @@ Input::Input(std::string file)
// Destructor // Destructor
Input::~Input() Input::~Input()
{ {
//SDL_GameControllerClose(mGameController); for (int i = 0; i < mNumGamepads; i++)
//if (mGameController) mConnectedControllers[i] = nullptr;
mGameController = nullptr;
} }
// Asigna uno de los posibles inputs a una tecla del teclado // Asigna uno de los posibles inputs a una tecla del teclado
@@ -42,11 +43,14 @@ void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton butto
} }
// Comprueba si un input esta activo // Comprueba si un input esta activo
bool Input::checkInput(Uint8 input, bool repeat, int device) bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
{ {
bool successKeyboard = false; bool successKeyboard = false;
bool successGameController = false; bool successGameController = false;
if (device == INPUT_USE_ANY)
index = 0;
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY)) if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
{ {
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL); const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
@@ -92,7 +96,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device)
{ {
if (repeat) if (repeat)
{ {
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0) if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
successGameController = true; successGameController = true;
else else
successGameController = false; successGameController = false;
@@ -101,7 +105,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device)
{ {
if (!mGameControllerBindings[input].active) if (!mGameControllerBindings[input].active)
{ {
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0) if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
{ {
mGameControllerBindings[input].active = true; mGameControllerBindings[input].active = true;
successGameController = true; successGameController = true;
@@ -113,7 +117,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device)
} }
else else
{ {
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) == 0) if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) == 0)
{ {
mGameControllerBindings[input].active = false; mGameControllerBindings[input].active = false;
successGameController = false; successGameController = false;
@@ -137,6 +141,9 @@ bool Input::discoverGameController()
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1) if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str()) < 0)
printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError());
int nJoysticks = SDL_NumJoysticks(); int nJoysticks = SDL_NumJoysticks();
mNumGamepads = 0; mNumGamepads = 0;
@@ -159,18 +166,19 @@ bool Input::discoverGameController()
if (SDL_GameControllerGetAttached(pad) == 1) if (SDL_GameControllerGetAttached(pad) == 1)
{ {
mConnectedControllers.push_back(pad); mConnectedControllers.push_back(pad);
std::string separator(" #");
std::string name = SDL_GameControllerNameForIndex(i); std::string name = SDL_GameControllerNameForIndex(i);
std::cout << SDL_GameControllerNameForIndex(i) << std::endl;
name.resize(25); name.resize(25);
name = name + separator + std::to_string(i);
std::cout << name << std::endl;
mControllerNames.push_back(name); mControllerNames.push_back(name);
} }
else else
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl; std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
} }
mGameController = mConnectedControllers[0]; //mGameController = mConnectedControllers[0];
SDL_GameControllerEventState(SDL_ENABLE); SDL_GameControllerEventState(SDL_ENABLE);
SDL_GameControllerAddMappingsFromFile(mDBpath.c_str());
} }
return found; return found;
@@ -191,5 +199,11 @@ std::string Input::getControllerName(int index)
if (mNumGamepads > 0) if (mNumGamepads > 0)
return mControllerNames[index]; return mControllerNames[index];
else else
return ""; return "";
}
// Obten el numero de mandos conectados
int Input::getNumControllers()
{
return mNumGamepads;
} }

View File

@@ -49,7 +49,7 @@ private:
}; };
GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
SDL_GameController *mGameController; // Manejador para el mando //SDL_GameController *mGameController; // Manejador para el mando
std::vector<SDL_GameController*> mConnectedControllers; std::vector<SDL_GameController*> mConnectedControllers;
std::vector<std::string> mControllerNames; std::vector<std::string> mControllerNames;
int mNumGamepads; int mNumGamepads;
@@ -72,11 +72,14 @@ public:
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button); void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
// Comprueba si un input esta activo // Comprueba si un input esta activo
bool checkInput(Uint8 input, bool repeat, int device=INPUT_USE_ANY); bool checkInput(Uint8 input, bool repeat, int device=INPUT_USE_ANY, int index=0);
// Comprueba si hay algun mando conectado // Comprueba si hay algun mando conectado
bool gameControllerFound(); bool gameControllerFound();
// Obten el numero de mandos conectados
int getNumControllers();
// Obten el nombre de un mando de juego // Obten el nombre de un mando de juego
std::string getControllerName(int index); std::string getControllerName(int index);
}; };

View File

@@ -4,6 +4,9 @@
#include <dirent.h> #include <dirent.h>
#endif #endif
# define INIT_FADE 100
# define END_LOGO 200
// Constructor // Constructor
Logo::Logo(SDL_Renderer *renderer, std::string *fileList) Logo::Logo(SDL_Renderer *renderer, std::string *fileList)
{ {
@@ -71,6 +74,7 @@ section_t Logo::run()
{ {
init(); init();
const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}; const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
const int fadeLenght = END_LOGO - INIT_FADE;
while (mSection.name == PROG_SECTION_LOGO) while (mSection.name == PROG_SECTION_LOGO)
{ {
@@ -92,9 +96,6 @@ section_t Logo::run()
} }
} }
// Cambia el destino donde se pinta todo
//SDL_SetRenderTarget(mRenderer, mBackbuffer);
// Limpia el destino // Limpia el destino
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255); SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
SDL_RenderClear(mRenderer); SDL_RenderClear(mRenderer);
@@ -103,22 +104,16 @@ section_t Logo::run()
mSprite->render(); mSprite->render();
// Dibuja el fade // Dibuja el fade
if (mCounter >= 200) if (mCounter >= INIT_FADE)
{ {
Uint16 alpha = mCounter - 200; Uint16 alpha = (255 * (mCounter - INIT_FADE)) / fadeLenght;
if (alpha < 256) if (alpha < 256)
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, alpha); SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, alpha);
else else
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255); // alpha - 0 trans, 255 opaco SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
SDL_RenderFillRect(mRenderer, &rect); SDL_RenderFillRect(mRenderer, &rect);
} }
// Vuelve a usar el renderizador como destino
//SDL_SetRenderTarget(mRenderer, NULL);
// Copia el backbufer al renderizador
//SDL_RenderCopy(mRenderer, mBackbuffer, NULL, NULL);
// Actualiza la pantalla // Actualiza la pantalla
SDL_RenderPresent(mRenderer); SDL_RenderPresent(mRenderer);
@@ -134,7 +129,7 @@ section_t Logo::run()
JA_StopMusic(); JA_StopMusic();
} }
if (mCounter == 500) // minimo 200 + 255 if (mCounter == END_LOGO + 20)
{ {
mCounter = 0; mCounter = 0;
mSection.name = PROG_SECTION_INTRO; mSection.name = PROG_SECTION_INTRO;

View File

@@ -36,13 +36,9 @@ un tipo asociado diferente a NO_KIND
#include "director.h" #include "director.h"
#include <stdio.h> #include <stdio.h>
#include <string>
int main(int argc, char *args[]) int main(int argc, char *args[])
{ {
// Inicia el generador de numeros aleatorios
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
printf("Starting the game...\n\n"); printf("Starting the game...\n\n");
// Crea el objeto Director // Crea el objeto Director
@@ -54,6 +50,7 @@ int main(int argc, char *args[])
// Destruye el objeto Director // Destruye el objeto Director
delete mDirector; delete mDirector;
mDirector = nullptr; mDirector = nullptr;
printf("\nShutting down the game...\n"); printf("\nShutting down the game...\n");
return 0; return 0;

View File

@@ -143,6 +143,7 @@ void Text::initOffsetFromFile()
if (rfile.is_open() && rfile.good()) if (rfile.is_open() && rfile.good())
{ {
std::string buffer; std::string buffer;
//printf("Reading %s file\n", mFile.c_str());
// Lee los dos primeros valores del fichero // Lee los dos primeros valores del fichero
std::getline(rfile, buffer); std::getline(rfile, buffer);

View File

@@ -136,10 +136,27 @@ void Title::init(bool demo, Uint8 subsection)
mFade->init(0x17, 0x17, 0x26); mFade->init(0x17, 0x17, 0x26);
mDemo = demo; mDemo = demo;
if (!mInput->gameControllerFound()) //if (!mInput->gameControllerFound())
{ {
mOptions->input[0] = INPUT_USE_KEYBOARD; mOptions->input[0].id = 0;
mOptions->input[1] = INPUT_USE_GAMECONTROLLER; mOptions->input[0].name = "KEYBOARD";
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
mOptions->input[1].id = 0;
mOptions->input[1].name = "GAME CONTROLLER";
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
}
checkInputDevices();
mDeviceIndex[0] = mAvailableInputDevices.size() - 1;
mDeviceIndex[1] = 0;
if (mInput->gameControllerFound())
{
mOptions->input[1].id = mAvailableInputDevices[mDeviceIndex[1]].id;
mOptions->input[1].name = mAvailableInputDevices[mDeviceIndex[1]].name;
mOptions->input[1].deviceType = mAvailableInputDevices[mDeviceIndex[1]].deviceType;
} }
// Inicializa el bitmap de Coffee // Inicializa el bitmap de Coffee
@@ -349,7 +366,7 @@ void Title::updateMenuLabels()
i++; i++;
// PLAYER 1 CONTROLS - OPTIONS // PLAYER 1 CONTROLS - OPTIONS
switch (mOptions->input[0]) switch (mOptions->input[0].deviceType)
{ {
case INPUT_USE_KEYBOARD: case INPUT_USE_KEYBOARD:
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
@@ -363,7 +380,8 @@ void Title::updateMenuLabels()
else else
{ {
mMenu.options->setGreyed(i, false); mMenu.options->setGreyed(i, false);
mMenu.options->setItemCaption(i, mInput->getControllerName(0)); //mMenu.options->setItemCaption(i, mInput->getControllerName(0));
mMenu.options->setItemCaption(i, mOptions->input[0].name);
} }
break; break;
@@ -378,7 +396,7 @@ void Title::updateMenuLabels()
i++; i++;
// PLAYER 2 CONTROLS - OPTIONS // PLAYER 2 CONTROLS - OPTIONS
switch (mOptions->input[1]) switch (mOptions->input[1].deviceType)
{ {
case INPUT_USE_KEYBOARD: case INPUT_USE_KEYBOARD:
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
@@ -392,7 +410,8 @@ void Title::updateMenuLabels()
else else
{ {
mMenu.options->setGreyed(i, false); mMenu.options->setGreyed(i, false);
mMenu.options->setItemCaption(i, mInput->getControllerName(0)); //mMenu.options->setItemCaption(i, mInput->getControllerName(0));
mMenu.options->setItemCaption(i, mOptions->input[1].name);
} }
break; break;
@@ -755,11 +774,11 @@ section_t Title::run(Uint8 subsection)
updateMenuLabels(); updateMenuLabels();
break; break;
case 1: // PLAYER 1 CONTROLS case 1: // PLAYER 1 CONTROLS
switchInputs(1); updatePlayerInputs(0);
updateMenuLabels(); updateMenuLabels();
break; break;
case 3: // PLAYER 2 CONTROLS case 3: // PLAYER 2 CONTROLS
switchInputs(2); updatePlayerInputs(1);
updateMenuLabels(); updateMenuLabels();
break; break;
case 5: // Language case 5: // Language
@@ -908,17 +927,58 @@ void Title::runDemoGame()
} }
// Modifica las opciones para los controles de los jugadores // Modifica las opciones para los controles de los jugadores
void Title::switchInputs(int value) bool Title::updatePlayerInputs(int numPlayer)
{ {
Uint8 temp; const int numDevices = mAvailableInputDevices.size();
temp = mOptions->input[0];
mOptions->input[0] = mOptions->input[1];
mOptions->input[1] = temp;
// Si no hay mandos se deja todo de manera prefijada
if (!mInput->gameControllerFound()) if (!mInput->gameControllerFound())
{ {
mOptions->input[0] = INPUT_USE_KEYBOARD; mDeviceIndex[0] = 0;
mOptions->input[1] = INPUT_USE_GAMECONTROLLER; mDeviceIndex[1] = 0;
mOptions->input[0].id = -1;
mOptions->input[0].name = "KEYBOARD";
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
mOptions->input[1].id = 0;
mOptions->input[1].name = "GAME CONTROLLER";
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
return true;
}
else // Si hay mas de un dispositivo, se recorre el vector
{
printf("numplayer:%i\n",numPlayer);
printf("deviceindex:%i\n",mDeviceIndex[numPlayer]);
// Incrementa el indice
if (mDeviceIndex[numPlayer] < numDevices - 1)
mDeviceIndex[numPlayer]++;
else
mDeviceIndex[numPlayer] = 0;
printf("deviceindex:%i\n",mDeviceIndex[numPlayer]);
// Si coincide con el del otro jugador, se lo intercambian
if (mDeviceIndex[0] == mDeviceIndex[1])
{
printf("%i:%i\n",mDeviceIndex[0],mDeviceIndex[1]);
//const int temp = mDeviceIndex[0];
//mDeviceIndex[0] = mDeviceIndex[1];
//mDeviceIndex[1] = temp;
const int theOtherPlayer = (numPlayer + 1) % 2;
mDeviceIndex[theOtherPlayer]--;
if (mDeviceIndex[theOtherPlayer] < 0)
mDeviceIndex[theOtherPlayer]=numDevices-1;
printf("%i:%i\n",mDeviceIndex[0],mDeviceIndex[1]);
}
// Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador
mOptions->input[0] = mAvailableInputDevices[mDeviceIndex[0]];
mOptions->input[1] = mAvailableInputDevices[mDeviceIndex[1]];
return true;
} }
} }
@@ -941,3 +1001,30 @@ void Title::createTiledBackground()
SDL_SetRenderTarget(mRenderer, nullptr); SDL_SetRenderTarget(mRenderer, nullptr);
} }
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones
void Title::checkInputDevices()
{
printf("Filling devices for options menu...\n");
int numControllers = mInput->getNumControllers();
mAvailableInputDevices.clear();
input_t temp;
// Añade todos los mandos
if (numControllers > 0)
for (int i = 0; i < numControllers; i++)
{
temp.id = i;
temp.name = mInput->getControllerName(i);
temp.deviceType = INPUT_USE_GAMECONTROLLER;
mAvailableInputDevices.push_back(temp);
printf("Device %i:\t%s\n", (int)mAvailableInputDevices.size(), temp.name.c_str());
}
// Añade el teclado al final
temp.id = -1;
temp.name = "KEYBOARD";
temp.deviceType = INPUT_USE_KEYBOARD;
mAvailableInputDevices.push_back(temp);
printf("Device %i:\t%s\n\n", (int)mAvailableInputDevices.size(), temp.name.c_str());
}

View File

@@ -72,6 +72,8 @@ private:
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
options_t mOptionsPrevious; // Variable de respaldo para las opciones options_t mOptionsPrevious; // Variable de respaldo para las opciones
std::vector<input_t> mAvailableInputDevices; // Vector con todos los metodos de control disponibles
int mDeviceIndex[2]; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
// Carga los recursos necesarios para la sección 'Title' // Carga los recursos necesarios para la sección 'Title'
bool loadMedia(); bool loadMedia();
@@ -92,11 +94,14 @@ private:
void runDemoGame(); void runDemoGame();
// Modifica las opciones para los controles de los jugadores // Modifica las opciones para los controles de los jugadores
void switchInputs(int value); bool updatePlayerInputs(int numPlayer);
// Crea el mosaico de fondo del titulo // Crea el mosaico de fondo del titulo
void createTiledBackground(); void createTiledBackground();
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones
void checkInputDevices();
public: public:
// Constructor // Constructor
Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::string *fileList, options_t *options, Lang *lang); Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::string *fileList, options_t *options, Lang *lang);

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "ifdefs.h" #include "ifdefs.h"
#include "ltexture.h" #include "ltexture.h"
#include <string>
#ifndef UTILS_H #ifndef UTILS_H
#define UTILS_H #define UTILS_H
@@ -39,11 +40,19 @@ struct demoKeys_t
Uint8 fireRight; Uint8 fireRight;
}; };
// Estructura para albergar métodos de control
struct input_t
{
int id; // Identificador en el vector de mandos
std::string name; // Nombre del dispositivo
Uint8 deviceType; // Tipo de dispositivo (teclado o mando)
};
// Estructura con todas las opciones de configuración del programa // Estructura con todas las opciones de configuración del programa
struct options_t struct options_t
{ {
Uint8 difficulty; // Dificultad del juego Uint8 difficulty; // Dificultad del juego
Uint8 input[2]; // Modo de control (teclado o mando) input_t input[2]; // Modo de control (teclado o mando)
Uint8 language; // Idioma usado en el juego Uint8 language; // Idioma usado en el juego
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
Uint8 windowSize; // Contiene el valor del tamaño de la ventana Uint8 windowSize; // Contiene el valor del tamaño de la ventana