Trabajando en el menu del titulo
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -3,189 +3,189 @@
|
|||||||
# box height
|
# box height
|
||||||
8
|
8
|
||||||
# 32 espacio ( )
|
# 32 espacio ( )
|
||||||
8
|
7
|
||||||
# 33 !
|
# 33 !
|
||||||
8
|
1
|
||||||
# 34 "
|
# 34 "
|
||||||
8
|
4
|
||||||
# 35 #
|
# 35 #
|
||||||
8
|
6
|
||||||
# 36 $
|
# 36 $
|
||||||
8
|
5
|
||||||
# 37 %
|
# 37 %
|
||||||
8
|
7
|
||||||
# 38 &
|
# 38 &
|
||||||
8
|
6
|
||||||
# 39 '
|
# 39 '
|
||||||
8
|
2
|
||||||
# 40 (
|
# 40 (
|
||||||
8
|
2
|
||||||
# 41 )
|
# 41 )
|
||||||
8
|
2
|
||||||
# 42 *
|
# 42 *
|
||||||
8
|
5
|
||||||
# 43 +
|
# 43 +
|
||||||
8
|
5
|
||||||
# 44 ,
|
# 44 ,
|
||||||
8
|
2
|
||||||
# 45 -
|
# 45 -
|
||||||
8
|
4
|
||||||
# 46 .
|
# 46 .
|
||||||
8
|
1
|
||||||
# 47 /
|
# 47 /
|
||||||
8
|
4
|
||||||
# 48 0
|
# 48 0
|
||||||
8
|
5
|
||||||
# 49 1
|
# 49 1
|
||||||
8
|
5
|
||||||
# 50 2
|
# 50 2
|
||||||
8
|
5
|
||||||
# 51 3
|
# 51 3
|
||||||
8
|
5
|
||||||
# 52 4
|
# 52 4
|
||||||
8
|
5
|
||||||
# 53 5
|
# 53 5
|
||||||
8
|
5
|
||||||
# 54 6
|
# 54 6
|
||||||
8
|
5
|
||||||
# 55 7
|
# 55 7
|
||||||
8
|
5
|
||||||
# 56 8
|
# 56 8
|
||||||
8
|
5
|
||||||
# 57 9
|
# 57 9
|
||||||
8
|
5
|
||||||
# 58 :
|
# 58 :
|
||||||
8
|
1
|
||||||
# 59 ;
|
# 59 ;
|
||||||
8
|
2
|
||||||
# 60 <
|
# 60 <
|
||||||
8
|
3
|
||||||
# 61 =
|
# 61 =
|
||||||
8
|
6
|
||||||
# 62 >
|
# 62 >
|
||||||
8
|
3
|
||||||
# 63 ?
|
# 63 ?
|
||||||
8
|
5
|
||||||
# 64 @
|
# 64 @
|
||||||
8
|
7
|
||||||
# 65 A
|
# 65 A
|
||||||
8
|
5
|
||||||
# 66 B
|
# 66 B
|
||||||
8
|
5
|
||||||
# 67 C
|
# 67 C
|
||||||
8
|
5
|
||||||
# 68 D
|
# 68 D
|
||||||
8
|
6
|
||||||
# 69 E
|
# 69 E
|
||||||
8
|
5
|
||||||
# 70 F
|
# 70 F
|
||||||
8
|
5
|
||||||
# 71 G
|
# 71 G
|
||||||
8
|
5
|
||||||
# 72 H
|
# 72 H
|
||||||
8
|
5
|
||||||
# 73 I
|
# 73 I
|
||||||
8
|
3
|
||||||
# 74 J
|
# 74 J
|
||||||
8
|
4
|
||||||
# 75 K
|
# 75 K
|
||||||
8
|
5
|
||||||
# 76 L
|
# 76 L
|
||||||
8
|
4
|
||||||
# 77 M
|
# 77 M
|
||||||
8
|
6
|
||||||
# 78 N
|
# 78 N
|
||||||
8
|
5
|
||||||
# 79 O
|
# 79 O
|
||||||
8
|
5
|
||||||
# 80 P
|
# 80 P
|
||||||
8
|
5
|
||||||
# 81 Q
|
# 81 Q
|
||||||
8
|
5
|
||||||
# 82 R
|
# 82 R
|
||||||
8
|
5
|
||||||
# 83 S
|
# 83 S
|
||||||
8
|
5
|
||||||
# 84 T
|
# 84 T
|
||||||
8
|
5
|
||||||
# 85 U
|
# 85 U
|
||||||
8
|
5
|
||||||
# 86 V
|
# 86 V
|
||||||
8
|
5
|
||||||
# 87 W
|
# 87 W
|
||||||
8
|
7
|
||||||
# 88 X
|
# 88 X
|
||||||
8
|
5
|
||||||
# 89 Y
|
# 89 Y
|
||||||
8
|
5
|
||||||
# 90 Z
|
# 90 Z
|
||||||
8
|
5
|
||||||
# 91 [
|
# 91 [
|
||||||
8
|
2
|
||||||
# 92 \
|
# 92 \
|
||||||
8
|
4
|
||||||
# 93 ]
|
# 93 ]
|
||||||
8
|
2
|
||||||
# 94 ^
|
# 94 ^
|
||||||
8
|
4
|
||||||
# 95 _
|
# 95 _
|
||||||
8
|
6
|
||||||
# 96 `
|
# 96 `
|
||||||
8
|
2
|
||||||
# 97 a
|
# 97 a
|
||||||
8
|
5
|
||||||
# 98 b
|
# 98 b
|
||||||
8
|
5
|
||||||
# 99 c
|
# 99 c
|
||||||
8
|
5
|
||||||
# 100 d
|
# 100 d
|
||||||
8
|
5
|
||||||
# 101 e
|
# 101 e
|
||||||
8
|
5
|
||||||
# 102 f
|
# 102 f
|
||||||
8
|
5
|
||||||
# 103 g
|
# 103 g
|
||||||
8
|
5
|
||||||
# 104 h
|
# 104 h
|
||||||
8
|
5
|
||||||
# 105 i
|
# 105 i
|
||||||
8
|
3
|
||||||
# 106 j
|
# 106 j
|
||||||
8
|
3
|
||||||
# 107 k
|
# 107 k
|
||||||
8
|
5
|
||||||
# 108 l
|
# 108 l
|
||||||
8
|
3
|
||||||
# 109 m
|
# 109 m
|
||||||
8
|
7
|
||||||
# 110 n
|
# 110 n
|
||||||
8
|
5
|
||||||
# 111 o
|
# 111 o
|
||||||
8
|
5
|
||||||
# 112 p
|
# 112 p
|
||||||
8
|
5
|
||||||
# 113 q
|
# 113 q
|
||||||
8
|
5
|
||||||
# 114 r
|
# 114 r
|
||||||
8
|
4
|
||||||
# 115 s
|
# 115 s
|
||||||
8
|
5
|
||||||
# 116 t
|
# 116 t
|
||||||
8
|
4
|
||||||
# 117 u
|
# 117 u
|
||||||
8
|
5
|
||||||
# 118 v
|
# 118 v
|
||||||
8
|
5
|
||||||
# 119 w
|
# 119 w
|
||||||
8
|
6
|
||||||
# 120 x
|
# 120 x
|
||||||
8
|
5
|
||||||
# 121 y
|
# 121 y
|
||||||
8
|
4
|
||||||
# 122 z
|
# 122 z
|
||||||
8
|
4
|
||||||
# 123 {
|
# 123 {
|
||||||
8
|
5
|
||||||
# 124 |
|
# 124 |
|
||||||
8
|
8
|
||||||
# 125 }
|
# 125 }
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::s
|
|||||||
// Destructor
|
// Destructor
|
||||||
AnimatedSprite::~AnimatedSprite()
|
AnimatedSprite::~AnimatedSprite()
|
||||||
{
|
{
|
||||||
for (auto a : animation)
|
for (auto &a : animation)
|
||||||
{
|
{
|
||||||
a.frames.clear();
|
a.frames.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ int Menu::getWidestItem()
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
// Obtenemos la anchura del item mas ancho
|
// Obtenemos la anchura del item mas ancho
|
||||||
for (auto i : item)
|
for (auto &i : item)
|
||||||
{
|
{
|
||||||
result = std::max(result, i.rect.w);
|
result = std::max(result, i.rect.w);
|
||||||
}
|
}
|
||||||
@@ -416,7 +416,7 @@ void Menu::centerMenuOnX(int value)
|
|||||||
x = (value) - (findWidth() / 2);
|
x = (value) - (findWidth() / 2);
|
||||||
|
|
||||||
// Reposiciona los elementos del menu
|
// Reposiciona los elementos del menu
|
||||||
for (auto i : item)
|
for (auto &i : item)
|
||||||
{
|
{
|
||||||
i.rect.x = x;
|
i.rect.x = x;
|
||||||
}
|
}
|
||||||
@@ -446,7 +446,7 @@ void Menu::centerMenuElementsOnX()
|
|||||||
{
|
{
|
||||||
areElementsCenteredOnX = true;
|
areElementsCenteredOnX = true;
|
||||||
|
|
||||||
for (auto i : item)
|
for (auto &i : item)
|
||||||
{
|
{
|
||||||
i.rect.x = (centerX - (i.rect.w / 2));
|
i.rect.x = (centerX - (i.rect.w / 2));
|
||||||
}
|
}
|
||||||
@@ -495,6 +495,9 @@ void Menu::setItemCaption(int index, std::string text)
|
|||||||
item[index].rect.w = this->text->lenght(item[index].label);
|
item[index].rect.w = this->text->lenght(item[index].label);
|
||||||
item[index].rect.h = this->text->getCharacterWidth();
|
item[index].rect.h = this->text->getCharacterWidth();
|
||||||
reorganize();
|
reorganize();
|
||||||
|
|
||||||
|
const std::string texto = item[index].label + ":" + std::to_string(item[index].rect.w);
|
||||||
|
printf("Adding menu item -> %s\n", texto.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el indice del itemm que se usará por defecto al cancelar el menu
|
// Establece el indice del itemm que se usará por defecto al cancelar el menu
|
||||||
@@ -559,7 +562,7 @@ int Menu::findHeight()
|
|||||||
int height = 0;
|
int height = 0;
|
||||||
|
|
||||||
// Obtenemos la altura de la suma de alturas de los items
|
// Obtenemos la altura de la suma de alturas de los items
|
||||||
for (auto i : item)
|
for (auto &i : item)
|
||||||
{
|
{
|
||||||
height += i.rect.h + i.hPaddingDown;
|
height += i.rect.h + i.hPaddingDown;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Prog::Prog(std::string executablePath)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_LOGO;
|
section.name = SECTION_PROG_TITLE;
|
||||||
}
|
}
|
||||||
input = new Input(asset->get("gamecontrollerdb.txt"));
|
input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||||
screen = new Screen(window, renderer, options);
|
screen = new Screen(window, renderer, options);
|
||||||
|
|||||||
@@ -56,12 +56,16 @@ void Text::init()
|
|||||||
mOffset[i].x = ((i - 32) % 15) * mBoxWidth;
|
mOffset[i].x = ((i - 32) % 15) * mBoxWidth;
|
||||||
mOffset[i].y = ((i - 32) / 15) * mBoxHeight;
|
mOffset[i].y = ((i - 32) / 15) * mBoxHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("Cargando %s\n", mFile.c_str());
|
||||||
|
const std::string texto = "w = "+ std::to_string(mBoxWidth) + ", h = " + std::to_string(mBoxHeight);
|
||||||
|
printf("%s\n",texto.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe texto en pantalla
|
// Escribe texto en pantalla
|
||||||
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||||
{
|
{
|
||||||
Uint16 shift = 0;
|
int shift = 0;
|
||||||
|
|
||||||
if (lenght == -1)
|
if (lenght == -1)
|
||||||
lenght = text.length();
|
lenght = text.length();
|
||||||
@@ -134,14 +138,15 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la longitud en pixels de una cadena
|
// Obtiene la longitud en pixels de una cadena
|
||||||
Uint16 Text::lenght(std::string text, int kerning)
|
int Text::lenght(std::string text, int kerning)
|
||||||
{
|
{
|
||||||
Uint16 shift = 0;
|
int shift = 0;
|
||||||
|
|
||||||
for (int i = 0; i < (int)text.length(); ++i)
|
for (int i = 0; i < (int)text.length(); i++)
|
||||||
shift += (mOffset[int(text[i])].w + kerning);
|
shift += (mOffset[int(text[i])].w + kerning);
|
||||||
|
|
||||||
return shift;
|
// Descuenta el kerning del último caracter
|
||||||
|
return shift - kerning;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el vector de offsets desde un fichero
|
// Inicializa el vector de offsets desde un fichero
|
||||||
@@ -178,7 +183,7 @@ void Text::initOffsetFromFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
// Devuelve el valor de la variable
|
||||||
Uint8 Text::getCharacterWidth()
|
int Text::getCharacterWidth()
|
||||||
{
|
{
|
||||||
return mBoxWidth;
|
return mBoxWidth;
|
||||||
}
|
}
|
||||||
@@ -21,12 +21,12 @@ private:
|
|||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
Uint8 w;
|
int w;
|
||||||
};
|
};
|
||||||
Offset mOffset[128]; // Vector con las posiciones y ancho de cada letra
|
Offset mOffset[128]; // Vector con las posiciones y ancho de cada letra
|
||||||
|
|
||||||
Uint8 mBoxWidth; // Anchura de la caja de cada caracter en el png
|
int mBoxWidth; // Anchura de la caja de cada caracter en el png
|
||||||
Uint8 mBoxHeight; // Altura de la caja de cada caracter en el png
|
int mBoxHeight; // Altura de la caja de cada caracter en el png
|
||||||
std::string mFile; // Fichero con los descriptores de la fuente
|
std::string mFile; // Fichero con los descriptores de la fuente
|
||||||
LTexture *texture; // Textura con los bitmaps del texto
|
LTexture *texture; // Textura con los bitmaps del texto
|
||||||
|
|
||||||
@@ -59,10 +59,10 @@ public:
|
|||||||
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1);
|
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1);
|
||||||
|
|
||||||
// Obtiene la longitud en pixels de una cadena
|
// Obtiene la longitud en pixels de una cadena
|
||||||
Uint16 lenght(std::string text, int kerning = 1);
|
int lenght(std::string text, int kerning = 1);
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
// Devuelve el valor de la variable
|
||||||
Uint8 getCharacterWidth();
|
int getCharacterWidth();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
|||||||
sprite = new AnimatedSprite(texture, renderer, asset->get("intro.ani"));
|
sprite = new AnimatedSprite(texture, renderer, asset->get("intro.ani"));
|
||||||
sprite->setCurrentAnimation("menu");
|
sprite->setCurrentAnimation("menu");
|
||||||
text = new Text(asset->get("dogica.png"), asset->get("dogica.txt"), renderer);
|
text = new Text(asset->get("dogica.png"), asset->get("dogica.txt"), renderer);
|
||||||
|
text2 = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||||
music = JA_LoadMusic(asset->get("music_title.ogg").c_str());
|
music = JA_LoadMusic(asset->get("music_title.ogg").c_str());
|
||||||
menu = new Menu(renderer, text, input);
|
menu = new Menu(renderer, text, input);
|
||||||
initMenu();
|
initMenu();
|
||||||
@@ -46,6 +47,9 @@ Title::~Title()
|
|||||||
delete text;
|
delete text;
|
||||||
text = nullptr;
|
text = nullptr;
|
||||||
|
|
||||||
|
delete text2;
|
||||||
|
text2 = nullptr;
|
||||||
|
|
||||||
delete menu;
|
delete menu;
|
||||||
menu = nullptr;
|
menu = nullptr;
|
||||||
|
|
||||||
@@ -59,7 +63,7 @@ void Title::initMenu()
|
|||||||
menu->loadAudioFile(asset->get("sound_menu_select.wav"), SOUND_ACCEPT);
|
menu->loadAudioFile(asset->get("sound_menu_select.wav"), SOUND_ACCEPT);
|
||||||
menu->loadAudioFile(asset->get("sound_menu_move.wav"), SOUND_MOVE);
|
menu->loadAudioFile(asset->get("sound_menu_move.wav"), SOUND_MOVE);
|
||||||
|
|
||||||
menu->init("TITLE", 0, 0, MENU_BACKGROUND_SOLID);
|
menu->init("TITLE", 0, 150, MENU_BACKGROUND_TRANSPARENT);
|
||||||
menu->addItem("START",2);
|
menu->addItem("START",2);
|
||||||
menu->addItem("OPTIONS", 5);
|
menu->addItem("OPTIONS", 5);
|
||||||
menu->addItem("EXIT");
|
menu->addItem("EXIT");
|
||||||
@@ -91,11 +95,11 @@ void Title::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cualquier tecla pulsada
|
// Cualquier tecla pulsada
|
||||||
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
/*if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_GAME;
|
||||||
section.subsection = 0;
|
section.subsection = 0;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
sprite->animate();
|
sprite->animate();
|
||||||
menu->update();
|
menu->update();
|
||||||
@@ -113,7 +117,7 @@ void Title::render()
|
|||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
sprite->render();
|
sprite->render();
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, 160, 200, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", -1, {255, 93, 4});
|
text2->writeDX(TXT_CENTER | TXT_COLOR, 160, 205, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", 0, {255, 93, 4});
|
||||||
menu->render();
|
menu->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ private:
|
|||||||
Asset *asset; // Objeto con los ficheros de recurso
|
Asset *asset; // Objeto con los ficheros de recurso
|
||||||
Input *input; // Objeto para gestionar las entradas
|
Input *input; // Objeto para gestionar las entradas
|
||||||
Text *text; // Objeto para escribir texto en pantalla
|
Text *text; // Objeto para escribir texto en pantalla
|
||||||
|
Text *text2; // Objeto para escribir texto en pantalla
|
||||||
Menu *menu; // Objeto para gestionar el menu del titulo
|
Menu *menu; // Objeto para gestionar el menu del titulo
|
||||||
AnimatedSprite *sprite; // Sprite para dibujar los graficos de la intro
|
AnimatedSprite *sprite; // Sprite para dibujar los graficos de la intro
|
||||||
JA_Music music; // Musica del titulo del juego
|
JA_Music music; // Musica del titulo del juego
|
||||||
|
|||||||
Reference in New Issue
Block a user