Afegida nova tipografia 04b_25

Eliminades tipografies que no s'utilitzaven
La classe Text ara pot tornar una textura amb el text
This commit is contained in:
2024-10-29 15:22:19 +01:00
parent 59e2865a4a
commit e2abf835f9
15 changed files with 157 additions and 540 deletions

BIN
data/font/04b_25.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

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

View File

@@ -495,16 +495,12 @@ void Director::setFileList()
Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT);
Asset::get()->add(prefix + "/data/font/nokia.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/nokia.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/font/nokia_big2.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/font/nokia.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/nokia.txt", AssetType::FONT);
Asset::get()->add(prefix + "/data/font/nokia2.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/font/nokia2.txt", AssetType::FONT);
Asset::get()->add(prefix + "/data/font/nokia_big2.txt", AssetType::FONT);
Asset::get()->add(prefix + "/data/font/smb2_big.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/font/smb2_big.txt", AssetType::FONT);
Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/font/smb2_palette1.pal", AssetType::PALETTE); Asset::get()->add(prefix + "/data/font/smb2_palette1.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/font/smb2.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/smb2.txt", AssetType::FONT);
Asset::get()->add(prefix + "/data/font/04b_25.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/font/04b_25.txt", AssetType::FONT);
// Textos // Textos
Asset::get()->add(prefix + "/data/lang/es_ES.txt", AssetType::LANG); Asset::get()->add(prefix + "/data/lang/es_ES.txt", AssetType::LANG);

View File

@@ -205,9 +205,9 @@ void Game::setResources()
// Texto // Texto
{ {
text_ = std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt")); text_ = std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"));
text_big_ = std::make_unique<Text>(Resource::get()->getTexture("smb2_big.png"), Resource::get()->getTextFile("smb2_big.txt")); text_nokia2_ = std::make_unique<Text>(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt"));
text_nokia2_ = std::make_unique<Text>(Resource::get()->getTexture("nokia2.png"), Resource::get()->getTextFile("nokia2.txt")); text_nokia2_big_ = std::make_unique<Text>(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt"));
text_nokia2_big_ = std::make_unique<Text>(Resource::get()->getTexture("nokia_big2.png"), Resource::get()->getTextFile("nokia_big2.txt")); text_04b_25_ = std::make_unique<Text>(Resource::get()->getTexture("04b_25.png"), Resource::get()->getTextFile("04b_25.txt"));
} }
} }

View File

@@ -145,7 +145,7 @@ private:
std::vector<std::vector<std::string>> explosions_animations_; // Vector con las animaciones de las explosiones std::vector<std::vector<std::string>> explosions_animations_; // Vector con las animaciones de las explosiones
std::unique_ptr<Text> text_; // Fuente para los textos del juego std::unique_ptr<Text> text_; // Fuente para los textos del juego
std::unique_ptr<Text> text_big_; // Fuente de texto grande std::unique_ptr<Text> text_04b_25_; // Fuente de texto grande
std::unique_ptr<Text> text_nokia2_; // Otra fuente de texto para mensajes std::unique_ptr<Text> text_nokia2_; // Otra fuente de texto para mensajes
std::unique_ptr<Text> text_nokia2_big_; // Y la versión en grande std::unique_ptr<Text> text_nokia2_big_; // Y la versión en grande

View File

@@ -139,9 +139,7 @@ Intro::Intro()
texts_[8]->setSpeed(16); texts_[8]->setSpeed(16);
for (auto &text : texts_) for (auto &text : texts_)
{
text->center(param.game.game_area.center_x); text->center(param.game.game_area.center_x);
}
} }
// Recarga todas las texturas // Recarga todas las texturas
@@ -171,9 +169,7 @@ void Intro::checkEvents()
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
{ {
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
{
reloadTextures(); reloadTextures();
}
break; break;
} }

View File

@@ -4,6 +4,7 @@
#include <iostream> // Para cerr #include <iostream> // Para cerr
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include "sprite.h" // Para Sprite #include "sprite.h" // Para Sprite
#include "screen.h" // Para Screen
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "utils.h" // Para Color, getFileName, printWithDots #include "utils.h" // Para Color, getFileName, printWithDots
@@ -122,26 +123,35 @@ Text::Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file
// Escribe texto en pantalla // Escribe texto en pantalla
void Text::write(int x, int y, const std::string &text, int kerning, int lenght) void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
{ {
auto shift = 0; int shift = 0;
if (lenght == -1) if (lenght == -1)
{
lenght = text.length(); lenght = text.length();
}
sprite_->setY(y); sprite_->setY(y);
const auto width = sprite_->getWidth();
const auto height = sprite_->getHeight();
for (int i = 0; i < lenght; ++i) for (int i = 0; i < lenght; ++i)
{ {
const auto index = static_cast<int>(text[i]); auto index = static_cast<int>(text[i]);
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height); sprite_->setSpriteClip(offset_[index].x, offset_[index].y, box_width_, box_height_);
sprite_->setX(x + shift); sprite_->setX(x + shift);
sprite_->render(); sprite_->render();
shift += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning); shift += offset_[static_cast<int>(text[i])].w + kerning;
} }
} }
// Escribe el texto en una textura
std::shared_ptr<Texture> Text::writeToTexture(int x, int y, const std::string &text, int kerning)
{
auto renderer = Screen::get()->getRenderer();
auto texture = std::make_shared<Texture>(renderer);
auto width = lenght(text, kerning);
texture->createBlank(width, box_height_);
texture->setAsRenderTarget(renderer);
write(0, 0, text, kerning);
return texture;
}
// Escribe el texto con colores // Escribe el texto con colores
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght) void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght)
{ {
@@ -211,12 +221,9 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerni
// Obtiene la longitud en pixels de una cadena // Obtiene la longitud en pixels de una cadena
int Text::lenght(const std::string &text, int kerning) const int Text::lenght(const std::string &text, int kerning) const
{ {
auto shift = 0; int shift = 0;
for (size_t i = 0; i < text.length(); ++i)
for (int i = 0; i < (int)text.length(); ++i) shift += (offset_[static_cast<int>(text[i])].w + kerning);
{
shift += (offset_[int(text[i])].w + kerning);
}
// Descuenta el kerning del último caracter // Descuenta el kerning del último caracter
return shift - kerning; return shift - kerning;

View File

@@ -51,6 +51,9 @@ public:
// Escribe el texto en pantalla // Escribe el texto en pantalla
void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1); void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1);
// Escribe el texto en una textura
std::shared_ptr<Texture> writeToTexture(int x, int y, const std::string &text, int kerning = 1);
// Escribe el texto con colores // Escribe el texto con colores
void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1); void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1);

View File

@@ -60,6 +60,9 @@ Texture::~Texture()
// Carga una imagen desde un fichero // Carga una imagen desde un fichero
bool Texture::loadFromFile(const std::string &file_path) bool Texture::loadFromFile(const std::string &file_path)
{ {
if (file_path.empty())
return false;
int req_format = STBI_rgb_alpha; int req_format = STBI_rgb_alpha;
int width, height, orig_format; int width, height, orig_format;
unsigned char *data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format); unsigned char *data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format);