Compare commits
8 Commits
2024-11-03
...
3f9c4b887f
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f9c4b887f | |||
| 27ccae6132 | |||
| 443f0f3254 | |||
| 2e62214a4b | |||
| 7b1c2a6005 | |||
| 2256ee46eb | |||
| 087fd3377c | |||
| 30735f00e8 |
104
CMakeLists.txt
Normal file
104
CMakeLists.txt
Normal file
@@ -0,0 +1,104 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(coffee_crisis_arcade_edition VERSION 0.01)
|
||||
|
||||
# Configuración de compilador para MinGW en Windows, si es necesario
|
||||
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
set(CMAKE_CXX_COMPILER "g++")
|
||||
set(CMAKE_C_COMPILER "gcc")
|
||||
endif()
|
||||
|
||||
# Establecer estándar de C++
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
# Define el directorio de los archivos fuente
|
||||
set(DIR_SOURCES "${CMAKE_SOURCE_DIR}/source")
|
||||
|
||||
# Cargar todos los archivos fuente en DIR_SOURCES
|
||||
file(GLOB SOURCES "${DIR_SOURCES}/*.cpp")
|
||||
|
||||
# Verificar si se encontraron archivos fuente
|
||||
if(NOT SOURCES)
|
||||
message(FATAL_ERROR "No se encontraron archivos fuente en ${DIR_SOURCES}. Verifica que el directorio existe y contiene archivos .cpp.")
|
||||
endif()
|
||||
|
||||
# Configuración de SDL2
|
||||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
link_directories(${SDL2_LIBDIR})
|
||||
|
||||
# Definir las bibliotecas comunes
|
||||
set(LIBS SDL2main SDL2)
|
||||
|
||||
# Objetivos específicos por plataforma
|
||||
if(WIN32)
|
||||
set(LIBS ${LIBS} mingw32 opengl32 gdi32 winmm imm32 ole32 version)
|
||||
|
||||
# Windows estándar
|
||||
add_executable(${PROJECT_NAME}_windows ${SOURCES})
|
||||
target_compile_definitions(${PROJECT_NAME}_windows PRIVATE WINDOWS_BUILD)
|
||||
set_target_properties(${PROJECT_NAME}_windows PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
|
||||
target_link_libraries(${PROJECT_NAME}_windows ${LIBS})
|
||||
|
||||
# Windows Debug
|
||||
add_executable(${PROJECT_NAME}_windows_debug ${SOURCES})
|
||||
target_compile_definitions(${PROJECT_NAME}_windows_debug PRIVATE WINDOWS_BUILD DEBUG VERBOSE)
|
||||
set_target_properties(${PROJECT_NAME}_windows_debug PROPERTIES OUTPUT_NAME "${PROJECT_NAME}_debug")
|
||||
target_link_libraries(${PROJECT_NAME}_windows_debug ${LIBS})
|
||||
|
||||
# Windows Release
|
||||
add_executable(${PROJECT_NAME}_windows_release ${SOURCES})
|
||||
target_compile_definitions(${PROJECT_NAME}_windows_release PRIVATE WINDOWS_BUILD)
|
||||
set_target_properties(${PROJECT_NAME}_windows_release PROPERTIES OUTPUT_NAME "${PROJECT_NAME}_release")
|
||||
target_link_libraries(${PROJECT_NAME}_windows_release ${LIBS})
|
||||
|
||||
elseif(APPLE)
|
||||
set(LIBS ${LIBS} "-framework OpenGL")
|
||||
|
||||
# macOS estándar
|
||||
add_executable(${PROJECT_NAME}_macos ${SOURCES})
|
||||
target_compile_definitions(${PROJECT_NAME}_macos PRIVATE MACOS_BUILD)
|
||||
set_target_properties(${PROJECT_NAME}_macos PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
|
||||
target_link_libraries(${PROJECT_NAME}_macos ${LIBS})
|
||||
|
||||
# macOS Debug
|
||||
add_executable(${PROJECT_NAME}_macos_debug ${SOURCES})
|
||||
target_compile_definitions(${PROJECT_NAME}_macos_debug PRIVATE MACOS_BUILD DEBUG VERBOSE)
|
||||
set_target_properties(${PROJECT_NAME}_macos_debug PROPERTIES OUTPUT_NAME "${PROJECT_NAME}_debug")
|
||||
target_link_libraries(${PROJECT_NAME}_macos_debug ${LIBS})
|
||||
|
||||
# macOS Release
|
||||
add_executable(${PROJECT_NAME}_macos_release ${SOURCES})
|
||||
target_compile_definitions(${PROJECT_NAME}_macos_release PRIVATE MACOS_BUILD)
|
||||
set_target_properties(${PROJECT_NAME}_macos_release PROPERTIES OUTPUT_NAME "${PROJECT_NAME}_release")
|
||||
target_link_libraries(${PROJECT_NAME}_macos_release ${LIBS})
|
||||
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
set(LIBS ${LIBS} GL)
|
||||
|
||||
# Linux estándar
|
||||
add_executable(${PROJECT_NAME}_linux ${SOURCES})
|
||||
target_compile_definitions(${PROJECT_NAME}_linux PRIVATE LINUX_BUILD)
|
||||
set_target_properties(${PROJECT_NAME}_linux PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
|
||||
target_link_libraries(${PROJECT_NAME}_linux ${LIBS})
|
||||
|
||||
# Linux Debug
|
||||
add_executable(${PROJECT_NAME}_linux_debug ${SOURCES})
|
||||
target_compile_definitions(${PROJECT_NAME}_linux_debug PRIVATE LINUX_BUILD DEBUG VERBOSE)
|
||||
set_target_properties(${PROJECT_NAME}_linux_debug PROPERTIES OUTPUT_NAME "${PROJECT_NAME}_debug")
|
||||
target_link_libraries(${PROJECT_NAME}_linux_debug ${LIBS})
|
||||
|
||||
# Linux Release
|
||||
add_executable(${PROJECT_NAME}_linux_release ${SOURCES})
|
||||
target_compile_definitions(${PROJECT_NAME}_linux_release PRIVATE LINUX_BUILD)
|
||||
set_target_properties(${PROJECT_NAME}_linux_release PROPERTIES OUTPUT_NAME "${PROJECT_NAME}_release")
|
||||
target_link_libraries(${PROJECT_NAME}_linux_release ${LIBS})
|
||||
endif()
|
||||
|
||||
# Agregar un custom target para cada tipo de build
|
||||
add_custom_target(build_windows_debug DEPENDS ${PROJECT_NAME}_windows_debug)
|
||||
add_custom_target(build_windows_release DEPENDS ${PROJECT_NAME}_windows_release)
|
||||
add_custom_target(build_macos_debug DEPENDS ${PROJECT_NAME}_macos_debug)
|
||||
add_custom_target(build_macos_release DEPENDS ${PROJECT_NAME}_macos_release)
|
||||
add_custom_target(build_linux_debug DEPENDS ${PROJECT_NAME}_linux_debug)
|
||||
add_custom_target(build_linux_release DEPENDS ${PROJECT_NAME}_linux_release)
|
||||
BIN
data/font/04b_25_2x.png
Normal file
BIN
data/font/04b_25_2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.9 KiB |
194
data/font/04b_25_2x.txt
Normal file
194
data/font/04b_25_2x.txt
Normal file
@@ -0,0 +1,194 @@
|
||||
# box width
|
||||
28
|
||||
# box height
|
||||
28
|
||||
# 32 espacio ( )
|
||||
16
|
||||
# 33 !
|
||||
10
|
||||
# 34 "
|
||||
16
|
||||
# 35
|
||||
20
|
||||
# 36 $
|
||||
20
|
||||
# 37 %
|
||||
18
|
||||
# 38 &
|
||||
22
|
||||
# 39 '
|
||||
10
|
||||
# 40 (
|
||||
14
|
||||
# 41 )
|
||||
14
|
||||
# 42 *
|
||||
14
|
||||
# 43 +
|
||||
18
|
||||
# 44 ,
|
||||
10
|
||||
# 45 -
|
||||
18
|
||||
# 46 .
|
||||
10
|
||||
# 47 /
|
||||
24
|
||||
# 48 0
|
||||
16
|
||||
# 49 1
|
||||
12
|
||||
# 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 :
|
||||
10
|
||||
# 59 ;
|
||||
10
|
||||
# 60 <
|
||||
16
|
||||
# 61 =
|
||||
16
|
||||
# 62 >
|
||||
16
|
||||
# 63 ?
|
||||
16
|
||||
# 64 @
|
||||
22
|
||||
# 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
|
||||
10
|
||||
# 74 J
|
||||
16
|
||||
# 75 K
|
||||
16
|
||||
# 76 L
|
||||
16
|
||||
# 77 M
|
||||
22
|
||||
# 78 N
|
||||
16
|
||||
# 79 O
|
||||
16
|
||||
# 80 P
|
||||
16
|
||||
# 81 Q
|
||||
16
|
||||
# 82 R
|
||||
16
|
||||
# 83 S
|
||||
16
|
||||
# 84 T
|
||||
18
|
||||
# 85 U
|
||||
16
|
||||
# 86 V
|
||||
16
|
||||
# 87 W
|
||||
22
|
||||
# 88 X
|
||||
16
|
||||
# 89 Y
|
||||
16
|
||||
# 90 Z
|
||||
16
|
||||
# 91 [
|
||||
14
|
||||
# 92 \
|
||||
22
|
||||
# 93 ]
|
||||
14
|
||||
# 94 ^
|
||||
12
|
||||
# 95 _
|
||||
14
|
||||
# 96 `
|
||||
12
|
||||
# 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
|
||||
10
|
||||
# 106 j
|
||||
16
|
||||
# 107 k
|
||||
16
|
||||
# 108 l
|
||||
16
|
||||
# 109 m
|
||||
22
|
||||
# 110 n
|
||||
16
|
||||
# 111 o
|
||||
16
|
||||
# 112 p
|
||||
16
|
||||
# 113 q
|
||||
16
|
||||
# 114 r
|
||||
16
|
||||
# 115 s
|
||||
16
|
||||
# 116 t
|
||||
18
|
||||
# 117 u
|
||||
16
|
||||
# 118 v
|
||||
16
|
||||
# 119 w
|
||||
22
|
||||
# 120 x
|
||||
16
|
||||
# 121 y
|
||||
16
|
||||
# 122 z
|
||||
16
|
||||
# 123 {
|
||||
2
|
||||
# 124 |
|
||||
2
|
||||
# 125 }
|
||||
2
|
||||
# 126 ~
|
||||
2
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 176 B After Width: | Height: | Size: 173 B |
@@ -1,16 +1,17 @@
|
||||
#include "define_buttons.h"
|
||||
#include <utility> // Para move
|
||||
#include "input.h" // Para Input, InputType
|
||||
#include "lang.h" // Para getText
|
||||
#include "options.h" // Para OptionsController, Options, options
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||
#include "section.h" // Para Name, Options, name, options
|
||||
#include "text.h" // Para Text
|
||||
#include <utility> // Para move
|
||||
#include "input.h" // Para Input, InputType
|
||||
#include "lang.h" // Para getText
|
||||
#include "options.h" // Para OptionsController, Options, options
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||
#include "resource.h" // Para Resource
|
||||
#include "section.h" // Para Name, Options, name, options
|
||||
#include "text.h" // Para Text
|
||||
|
||||
// Constructor
|
||||
DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
||||
DefineButtons::DefineButtons()
|
||||
: input_(Input::get()),
|
||||
text_(std::move(text_))
|
||||
text_(Resource::get()->getText("8bithud"))
|
||||
{
|
||||
// Inicializa variables
|
||||
x_ = param.game.width / 2;
|
||||
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit DefineButtons(std::unique_ptr<Text> text);
|
||||
DefineButtons();
|
||||
|
||||
// Destructor
|
||||
~DefineButtons() = default;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
|
||||
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
||||
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
|
||||
#include <bits/chrono.h> // Para duration, system_clock
|
||||
#include <chrono> // Para duration, system_clock
|
||||
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||
#include <stdio.h> // Para printf, perror
|
||||
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||
@@ -118,8 +118,7 @@ Director::Director(int argc, const char *argv[])
|
||||
Resource::init();
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
bindInputs();
|
||||
auto notifier_text = std::make_shared<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
Notifier::init(std::string(), notifier_text, Asset::get()->get("notify.wav"));
|
||||
Notifier::init(std::string(), Resource::get()->getText("8bithud"), Asset::get()->get("notify.wav"));
|
||||
OnScreenHelp::init();
|
||||
globalInputs::init();
|
||||
}
|
||||
@@ -496,6 +495,8 @@ void Director::setFileList()
|
||||
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);
|
||||
Asset::get()->add(prefix + "/data/font/04b_25_2x.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/04b_25_2x.txt", AssetType::FONT);
|
||||
|
||||
// Textos
|
||||
Asset::get()->add(prefix + "/data/lang/es_ES.txt", AssetType::LANG);
|
||||
@@ -615,7 +616,7 @@ void Director::runGame()
|
||||
{
|
||||
const auto player_id = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
|
||||
#ifdef DEBUG
|
||||
constexpr auto current_stage = 9;
|
||||
constexpr auto current_stage = 0;
|
||||
#else
|
||||
constexpr auto current_stage = 0;
|
||||
#endif
|
||||
|
||||
@@ -351,9 +351,9 @@ void Game::updateStage()
|
||||
createMessage(paths, Resource::get()->getTexture("last_stage"));
|
||||
else
|
||||
{
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("04b_25.png"), Resource::get()->getTextFile("04b_25.txt"));
|
||||
auto text = Resource::get()->getText("04b_25_2x");
|
||||
const std::string caption = std::to_string(10 - current_stage_) + lang::getText(38);
|
||||
createMessage(paths, text->writeToTexture(caption, 2, -2));
|
||||
createMessage(paths, text->writeToTexture(caption, 1, -4));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -487,7 +487,7 @@ void Game::createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std
|
||||
const auto lower_size = static_cast<BalloonSize>(static_cast<int>(balloon->getSize()) - 1);
|
||||
auto b = createBalloon(0, balloon->getPosY(), balloon->getType(), lower_size, vx, balloon_speed_, 0);
|
||||
b->alignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
b->setVelY(b->getType() == BalloonType::BALLOON ? -2.50f : vx * 2.0f);
|
||||
b->setVelY(b->getType() == BalloonType::BALLOON ? -2.50f : BALLOON_VELX_NEGATIVE * 2.0f);
|
||||
if (balloon->isStopped())
|
||||
b->stop();
|
||||
if (balloon->isUsingReversedColor())
|
||||
|
||||
@@ -27,7 +27,7 @@ HiScoreTable::HiScoreTable()
|
||||
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
fade_(std::make_unique<Fade>()),
|
||||
background_(std::make_unique<Background>()),
|
||||
text_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
text_(Resource::get()->getText("smb2")),
|
||||
counter_(0),
|
||||
ticks_(0),
|
||||
view_area_({0, 0, param.game.width, param.game.height}),
|
||||
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
||||
|
||||
// Variables
|
||||
Uint16 counter_; // Contador
|
||||
|
||||
@@ -26,7 +26,7 @@ Instructions::Instructions()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
texture_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
text_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
text_(Resource::get()->getText("smb2")),
|
||||
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC)),
|
||||
fade_(std::make_unique<Fade>())
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ private:
|
||||
|
||||
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
|
||||
std::vector<std::unique_ptr<Sprite>> sprites_; // Vector con los sprites de los items
|
||||
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// Constructor
|
||||
Intro::Intro()
|
||||
: texture_(Resource::get()->getTexture("intro.png")),
|
||||
text_(std::make_shared<Text>(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt")))
|
||||
text_(Resource::get()->getText("nokia"))
|
||||
{
|
||||
|
||||
// Inicializa variables
|
||||
|
||||
@@ -94,7 +94,7 @@ void OnScreenHelp::fillTexture()
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
|
||||
|
||||
// Crea el objeto para el texto
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
auto text = Resource::get()->getText("8bithud");
|
||||
|
||||
// Crea la textura con los gráficos
|
||||
auto controllersTexture = Resource::get()->getTexture("controllers.png");
|
||||
@@ -169,7 +169,7 @@ void OnScreenHelp::toggleState()
|
||||
// Calcula la longitud en pixels del texto más largo
|
||||
auto OnScreenHelp::getLargestStringSize() -> int const
|
||||
{
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
auto text = Resource::get()->getText("8bithud");
|
||||
auto size = 0;
|
||||
|
||||
for (int i = 107; i <= 113; ++i)
|
||||
|
||||
@@ -42,6 +42,7 @@ Resource::Resource()
|
||||
loadAnimations();
|
||||
loadDemoData();
|
||||
addPalettes();
|
||||
createText();
|
||||
createTextures();
|
||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||
}
|
||||
@@ -106,6 +107,21 @@ std::shared_ptr<TextFile> Resource::getTextFile(const std::string &name)
|
||||
throw std::runtime_error("TextFile no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
std::shared_ptr<Text> Resource::getText(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(texts_.begin(), texts_.end(), [&name](const auto &t)
|
||||
{ return t.name == name; });
|
||||
|
||||
if (it != texts_.end())
|
||||
{
|
||||
return it->text;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Text no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("Text no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
AnimationsFileBuffer &Resource::getAnimation(const std::string &name)
|
||||
{
|
||||
@@ -239,7 +255,6 @@ void Resource::createTextures()
|
||||
};
|
||||
|
||||
std::cout << "\n>> CREATING TEXTURES" << std::endl;
|
||||
auto text = std::make_unique<Text>(getTexture("04b_25.png"), getTextFile("04b_25.txt"));
|
||||
|
||||
// Tamaño normal
|
||||
std::vector<NameAndText> strings = {
|
||||
@@ -251,6 +266,7 @@ void Resource::createTextures()
|
||||
NameAndText("game_text_stop", lang::getText(119)),
|
||||
NameAndText("1000000_points", lang::getText(76))};
|
||||
|
||||
auto text = getText("04b_25");
|
||||
for (const auto &s : strings)
|
||||
{
|
||||
textures_.emplace_back(ResourceTexture(s.name, text->writeToTexture(s.text, 1, -2)));
|
||||
@@ -264,9 +280,29 @@ void Resource::createTextures()
|
||||
NameAndText("congratulations", lang::getText(50)),
|
||||
NameAndText("game_over", "Game Over")};
|
||||
|
||||
auto text2 = getText("04b_25_2x");
|
||||
for (const auto &s : strings2X)
|
||||
{
|
||||
textures_.emplace_back(ResourceTexture(s.name, text->writeToTexture(s.text, 2, -2)));
|
||||
textures_.emplace_back(ResourceTexture(s.name, text2->writeToTexture(s.text, 1, -4)));
|
||||
printWithDots("Texture : ", s.name, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Crea los objetos de texto
|
||||
void Resource::createText()
|
||||
{
|
||||
std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl;
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> resources = {
|
||||
{"04b_25", "04b_25.png"},
|
||||
{"04b_25_2x", "04b_25_2x.png"},
|
||||
{"8bithud", "8bithud.png"},
|
||||
{"nokia", "nokia.png"},
|
||||
{"smb2", "smb2.gif"}};
|
||||
|
||||
for (const auto &resource : resources)
|
||||
{
|
||||
texts_.emplace_back(ResourceText(resource.first, std::make_shared<Text>(getTexture(resource.second), getTextFile(resource.first + ".txt"))));
|
||||
printWithDots("Text : ", resource.first, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,17 @@ struct ResourceTextFile
|
||||
: name(name), text_file(text_file) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar objetos Text y su nombre
|
||||
struct ResourceText
|
||||
{
|
||||
std::string name; // Nombre del objeto
|
||||
std::shared_ptr<Text> text; // Objeto
|
||||
|
||||
// Constructor
|
||||
ResourceText(const std::string &name, std::shared_ptr<Text> text)
|
||||
: name(name), text(text) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros animaciones y su nombre
|
||||
struct ResourceAnimation
|
||||
{
|
||||
@@ -75,6 +86,7 @@ private:
|
||||
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||
std::vector<ResourceTexture> textures_; // Vector con las musicas
|
||||
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
||||
std::vector<ResourceText> texts_; // Vector con los objetos de texto
|
||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
||||
std::vector<DemoData> demos_; // Vector con los ficheros de datos para el modo demostración
|
||||
|
||||
@@ -102,6 +114,9 @@ private:
|
||||
// Crea texturas
|
||||
void createTextures();
|
||||
|
||||
// Crea los objetos de texto
|
||||
void createText();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||
|
||||
// Constructor
|
||||
@@ -132,6 +147,9 @@ public:
|
||||
// Obtiene el fichero de texto a partir de un nombre
|
||||
std::shared_ptr<TextFile> getTextFile(const std::string &name);
|
||||
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
std::shared_ptr<Text> getText(const std::string &name);
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
AnimationsFileBuffer &getAnimation(const std::string &name);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ Scoreboard::Scoreboard()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
game_power_meter_texture_(Resource::get()->getTexture("game_power_meter.png")),
|
||||
power_meter_sprite_(std::make_unique<Sprite>(game_power_meter_texture_)),
|
||||
text_scoreboard_(std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt")))
|
||||
text_scoreboard_(Resource::get()->getText("8bithud"))
|
||||
{
|
||||
// Inicializa variables
|
||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||
|
||||
@@ -52,7 +52,7 @@ private:
|
||||
|
||||
std::shared_ptr<Texture> game_power_meter_texture_; // Textura con el marcador de poder de la fase
|
||||
std::unique_ptr<Sprite> power_meter_sprite_; // Sprite para el medidor de poder de la fase
|
||||
std::unique_ptr<Text> text_scoreboard_; // Fuente para el marcador del juego
|
||||
std::shared_ptr<Text> text_scoreboard_; // Fuente para el marcador del juego
|
||||
|
||||
SDL_Texture *background_ = nullptr; // Textura para dibujar el marcador
|
||||
std::vector<SDL_Texture *> panel_texture_; // Texturas para dibujar cada panel
|
||||
|
||||
@@ -164,6 +164,8 @@ std::shared_ptr<Texture> Text::writeToTexture(const std::string &text, int zoom,
|
||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
texture->setAsRenderTarget(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning);
|
||||
|
||||
return texture;
|
||||
|
||||
@@ -28,14 +28,13 @@
|
||||
|
||||
// Constructor
|
||||
Title::Title()
|
||||
: text1_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
text2_(std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"))),
|
||||
: text_(Resource::get()->getText("smb2")),
|
||||
fade_(std::make_unique<Fade>()),
|
||||
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::RANDOM)),
|
||||
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
|
||||
mini_logo_texture_(Resource::get()->getTexture("logo_jailgames_mini.png")),
|
||||
mini_logo_sprite_(std::make_unique<Sprite>(mini_logo_texture_, param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight())),
|
||||
define_buttons_(std::make_unique<DefineButtons>(std::move(text2_))),
|
||||
define_buttons_(std::make_unique<DefineButtons>()),
|
||||
num_controllers_(Input::get()->getNumControllers())
|
||||
{
|
||||
// Configura objetos
|
||||
@@ -146,7 +145,7 @@ void Title::render()
|
||||
// 'PRESS TO PLAY'
|
||||
if (counter_ % 50 > 14 && !define_buttons_->isEnabled())
|
||||
{
|
||||
text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow);
|
||||
}
|
||||
|
||||
// Mini logo
|
||||
@@ -156,7 +155,7 @@ void Title::render()
|
||||
mini_logo_sprite_->render();
|
||||
|
||||
// Texto con el copyright
|
||||
text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow);
|
||||
}
|
||||
|
||||
// Define Buttons
|
||||
|
||||
@@ -40,8 +40,7 @@ class Title
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::unique_ptr<Text> text1_; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::unique_ptr<Text> text2_; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::shared_ptr<Text> text_; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::unique_ptr<Fade> fade_; // Objeto para realizar fundidos en pantalla
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<GameLogo> game_logo_; // Objeto para dibujar el logo con el título del juego
|
||||
|
||||
Reference in New Issue
Block a user