Compare commits

6 Commits

20 changed files with 372 additions and 35 deletions

89
CMakeLists.txt Normal file
View File

@@ -0,0 +1,89 @@
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(coffee_crisis_arcade_edition VERSION 0.01)
# Establecer estándar de C++
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Directorios principales
set(DIR_ROOT ${CMAKE_SOURCE_DIR})
set(DIR_SOURCES "${DIR_ROOT}/source")
set(DIR_BUILD "${DIR_ROOT}/build")
set(DIR_BIN "${DIR_ROOT}")
# Nombre del ejecutable
set(TARGET_NAME "coffee_crisis_arcade_edition")
set(TARGET_FILE "${DIR_BIN}/${TARGET_NAME}")
# Archivos de fuente e inclusión
file(GLOB_RECURSE SOURCES "${DIR_SOURCES}/*.cpp")
include_directories(${DIR_SOURCES})
# Configuración de SDL2
# Incluye rutas de SDL2 obtenidas con pkg-config
include_directories(/usr/local/include /usr/local/include/SDL2)
link_directories(/usr/local/lib)
# Configuración de compilación por plataforma
if(WIN32)
# Configuración para Windows
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os -ffunction-sections -fdata-sections -static-libstdc++ -Wl,-subsystem,windows")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(LIBS mingw32 ws2_32 SDL2main SDL2 opengl32)
add_compile_definitions(WINDOWS_BUILD)
elseif(APPLE)
# Configuración para macOS
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-deprecated -D_THREAD_SAFE")
set(LIBS SDL2 "-framework OpenGL")
add_compile_definitions(MACOS_BUILD)
else() # Linux
# Configuración para Linux
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os -ffunction-sections -fdata-sections")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(LIBS SDL2 GL)
add_compile_definitions(LINUX_BUILD)
endif()
# Configuración de compilación y enlace
add_executable(${TARGET_NAME} ${SOURCES})
target_link_libraries(${TARGET_NAME} ${LIBS})
# Objetivo para compilar en modo Release en Windows
if(WIN32)
add_custom_target(windows_release ALL
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_SOURCE_DIR}/${TARGET_NAME}_release"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_SOURCE_DIR}/${TARGET_NAME}_release"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/data" "${CMAKE_SOURCE_DIR}/${TARGET_NAME}_release/data"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/LICENSE" "${CMAKE_SOURCE_DIR}/${TARGET_NAME}_release"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/README.md" "${CMAKE_SOURCE_DIR}/${TARGET_NAME}_release"
)
endif()
# Objetivo para empaquetado en macOS (Intel y Apple Silicon)
if(APPLE)
add_custom_target(macos_release ALL
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_SOURCE_DIR}/${APP_NAME}.app"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_SOURCE_DIR}/${APP_NAME}.app/Contents/MacOS"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/data" "${CMAKE_SOURCE_DIR}/${APP_NAME}.app/Contents/Resources/data"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/LICENSE" "${CMAKE_SOURCE_DIR}/${APP_NAME}.app/Contents"
)
endif()
# Objetivo para empaquetado en Linux
if(UNIX AND NOT APPLE)
add_custom_target(linux_release ALL
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_SOURCE_DIR}/${APP_NAME}_release"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_SOURCE_DIR}/${APP_NAME}_release"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/data" "${CMAKE_SOURCE_DIR}/${APP_NAME}_release/data"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/LICENSE" "${CMAKE_SOURCE_DIR}/${APP_NAME}_release"
)
endif()
# Objetivo de limpieza
add_custom_target(custom_clean
COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIR_BUILD}
)

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
View 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

View File

@@ -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;

View File

@@ -58,7 +58,7 @@ private:
public:
// Constructor
explicit DefineButtons(std::unique_ptr<Text> text);
DefineButtons();
// Destructor
~DefineButtons() = default;

View File

@@ -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

View File

@@ -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())

View File

@@ -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}),

View File

@@ -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

View File

@@ -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>())
{

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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 ]");
}
}

View File

@@ -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);

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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