Compare commits
14 Commits
afe835914e
...
2024-10-20
| Author | SHA1 | Date | |
|---|---|---|---|
| 2cb22ed013 | |||
| a3a583deb7 | |||
| b263e0c4be | |||
| 3bf61fc758 | |||
| 2377815c02 | |||
| 7434869894 | |||
| 848d61b5c0 | |||
| cbc9b3f071 | |||
| 8bca5095da | |||
| a4b4e188cd | |||
| f23dcae5b6 | |||
| b879673bc2 | |||
| a8701dbebc | |||
| 808f1595e9 |
|
Before Width: | Height: | Size: 84 B After Width: | Height: | Size: 84 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 772 B |
BIN
data/gfx/player/player1_power.png
Normal file
|
After Width: | Height: | Size: 929 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
|
Before Width: | Height: | Size: 772 B |
BIN
data/gfx/player/player2_power.png
Normal file
|
After Width: | Height: | Size: 941 B |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
|
Before Width: | Height: | Size: 944 B |
|
Before Width: | Height: | Size: 84 B |
@@ -5,6 +5,29 @@
|
|||||||
#include <iterator> // for back_insert_iterator, back_inserter
|
#include <iterator> // for back_insert_iterator, back_inserter
|
||||||
#include <sstream> // for basic_stringstream
|
#include <sstream> // for basic_stringstream
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||||
|
Animations loadAnimationsFromFile(const std::string &file_path)
|
||||||
|
{
|
||||||
|
std::vector<std::string> buffer;
|
||||||
|
std::ifstream file(file_path);
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||||
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||||
|
|
||||||
|
while (std::getline(file, line))
|
||||||
|
{
|
||||||
|
buffer.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path)
|
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path)
|
||||||
@@ -18,7 +41,7 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::vector<std::string> &animations)
|
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const Animations &animations)
|
||||||
: MovingSprite(texture),
|
: MovingSprite(texture),
|
||||||
current_animation_(0)
|
current_animation_(0)
|
||||||
{
|
{
|
||||||
@@ -176,149 +199,6 @@ SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
|||||||
return animations_[indexA].frames[indexF];
|
return animations_[indexA].frames[indexF];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga la animación desde un vector
|
|
||||||
bool AnimatedSprite::loadFromVector(const std::vector<std::string> &source)
|
|
||||||
{
|
|
||||||
// Inicializa variables
|
|
||||||
auto frames_per_row = 0;
|
|
||||||
auto frame_width = 0;
|
|
||||||
auto frame_height = 0;
|
|
||||||
auto max_tiles = 0;
|
|
||||||
|
|
||||||
// Indicador de éxito en el proceso
|
|
||||||
auto success = true;
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
// Recorre todo el vector
|
|
||||||
auto index = 0;
|
|
||||||
while (index < (int)source.size())
|
|
||||||
{
|
|
||||||
// Lee desde el vector
|
|
||||||
line = source.at(index);
|
|
||||||
|
|
||||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
|
||||||
if (line == "[animation]")
|
|
||||||
{
|
|
||||||
Animation animation;
|
|
||||||
animation.counter = 0;
|
|
||||||
animation.current_frame = 0;
|
|
||||||
animation.completed = false;
|
|
||||||
animation.name.clear();
|
|
||||||
animation.speed = 5;
|
|
||||||
animation.loop = 0;
|
|
||||||
animation.frames.clear();
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
// Aumenta el indice para leer la siguiente linea
|
|
||||||
index++;
|
|
||||||
line = source.at(index);
|
|
||||||
|
|
||||||
// Encuentra la posición del caracter '='
|
|
||||||
int pos = line.find("=");
|
|
||||||
|
|
||||||
// Procesa las dos subcadenas
|
|
||||||
if (pos != static_cast<int>(line.npos))
|
|
||||||
{
|
|
||||||
if (line.substr(0, pos) == "name")
|
|
||||||
{
|
|
||||||
animation.name = line.substr(pos + 1, line.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "speed")
|
|
||||||
{
|
|
||||||
animation.speed = std::stoi(line.substr(pos + 1, line.length()));
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "loop")
|
|
||||||
{
|
|
||||||
animation.loop = std::stoi(line.substr(pos + 1, line.length()));
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frames")
|
|
||||||
{
|
|
||||||
// Se introducen los valores separados por comas en un vector
|
|
||||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
|
||||||
std::string tmp;
|
|
||||||
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
|
||||||
while (getline(ss, tmp, ','))
|
|
||||||
{
|
|
||||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
|
||||||
const int num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
|
|
||||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
|
||||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
|
||||||
animation.frames.push_back(rect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (line != "[/animation]");
|
|
||||||
|
|
||||||
// Añade la animación al vector de animaciones
|
|
||||||
animations_.push_back(animation);
|
|
||||||
}
|
|
||||||
|
|
||||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Encuentra la posición del caracter '='
|
|
||||||
int pos = line.find("=");
|
|
||||||
|
|
||||||
// Procesa las dos subcadenas
|
|
||||||
if (pos != (int)line.npos)
|
|
||||||
{
|
|
||||||
if (line.substr(0, pos) == "frames_per_row")
|
|
||||||
{
|
|
||||||
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frame_width")
|
|
||||||
{
|
|
||||||
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frame_height")
|
|
||||||
{
|
|
||||||
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normaliza valores
|
|
||||||
if (frames_per_row == 0 && frame_width > 0)
|
|
||||||
{
|
|
||||||
frames_per_row = texture_->getWidth() / frame_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
|
|
||||||
{
|
|
||||||
const int w = texture_->getWidth() / frame_width;
|
|
||||||
const int h = texture_->getHeight() / frame_height;
|
|
||||||
max_tiles = w * h;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pone un valor por defecto
|
|
||||||
setWidth(frame_width);
|
|
||||||
setHeight(frame_height);
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece la animacion actual
|
// Establece la animacion actual
|
||||||
void AnimatedSprite::setCurrentAnimation(const std::string &name)
|
void AnimatedSprite::setCurrentAnimation(const std::string &name)
|
||||||
{
|
{
|
||||||
@@ -399,14 +279,7 @@ std::vector<Animation> AnimatedSprite::loadFromFile(const std::string &file_path
|
|||||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||||
if (line == "[animation]")
|
if (line == "[animation]")
|
||||||
{
|
{
|
||||||
Animation animation;
|
Animation animation = Animation();
|
||||||
animation.counter = 0;
|
|
||||||
animation.current_frame = 0;
|
|
||||||
animation.completed = false;
|
|
||||||
animation.name.clear();
|
|
||||||
animation.speed = 5;
|
|
||||||
animation.loop = 0;
|
|
||||||
animation.frames.clear();
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -520,3 +393,139 @@ std::vector<Animation> AnimatedSprite::loadFromFile(const std::string &file_path
|
|||||||
|
|
||||||
return animations;
|
return animations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Carga la animación desde un vector
|
||||||
|
bool AnimatedSprite::loadFromVector(const Animations &source)
|
||||||
|
{
|
||||||
|
// Inicializa variables
|
||||||
|
auto frames_per_row = 0;
|
||||||
|
auto frame_width = 0;
|
||||||
|
auto frame_height = 0;
|
||||||
|
auto max_tiles = 0;
|
||||||
|
|
||||||
|
// Indicador de éxito en el proceso
|
||||||
|
auto success = true;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
// Recorre todo el vector
|
||||||
|
auto index = 0;
|
||||||
|
while (index < (int)source.size())
|
||||||
|
{
|
||||||
|
// Lee desde el vector
|
||||||
|
line = source.at(index);
|
||||||
|
|
||||||
|
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||||
|
if (line == "[animation]")
|
||||||
|
{
|
||||||
|
Animation animation = Animation();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
// Aumenta el indice para leer la siguiente linea
|
||||||
|
index++;
|
||||||
|
line = source.at(index);
|
||||||
|
|
||||||
|
// Encuentra la posición del caracter '='
|
||||||
|
int pos = line.find("=");
|
||||||
|
|
||||||
|
// Procesa las dos subcadenas
|
||||||
|
if (pos != static_cast<int>(line.npos))
|
||||||
|
{
|
||||||
|
if (line.substr(0, pos) == "name")
|
||||||
|
{
|
||||||
|
animation.name = line.substr(pos + 1, line.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "speed")
|
||||||
|
{
|
||||||
|
animation.speed = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "loop")
|
||||||
|
{
|
||||||
|
animation.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "frames")
|
||||||
|
{
|
||||||
|
// Se introducen los valores separados por comas en un vector
|
||||||
|
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||||
|
std::string tmp;
|
||||||
|
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||||
|
while (getline(ss, tmp, ','))
|
||||||
|
{
|
||||||
|
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||||
|
const int num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
|
||||||
|
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||||
|
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||||
|
animation.frames.push_back(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (line != "[/animation]");
|
||||||
|
|
||||||
|
// Añade la animación al vector de animaciones
|
||||||
|
animations_.push_back(animation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Encuentra la posición del caracter '='
|
||||||
|
int pos = line.find("=");
|
||||||
|
|
||||||
|
// Procesa las dos subcadenas
|
||||||
|
if (pos != (int)line.npos)
|
||||||
|
{
|
||||||
|
if (line.substr(0, pos) == "frames_per_row")
|
||||||
|
{
|
||||||
|
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "frame_width")
|
||||||
|
{
|
||||||
|
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "frame_height")
|
||||||
|
{
|
||||||
|
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normaliza valores
|
||||||
|
if (frames_per_row == 0 && frame_width > 0)
|
||||||
|
{
|
||||||
|
frames_per_row = texture_->getWidth() / frame_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
|
||||||
|
{
|
||||||
|
const int w = texture_->getWidth() / frame_width;
|
||||||
|
const int h = texture_->getHeight() / frame_height;
|
||||||
|
max_tiles = w * h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pone un valor por defecto
|
||||||
|
setWidth(frame_width);
|
||||||
|
setHeight(frame_height);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
@@ -17,8 +17,15 @@ struct Animation
|
|||||||
bool completed; // Indica si ha finalizado la animación
|
bool completed; // Indica si ha finalizado la animación
|
||||||
int current_frame; // Frame actual
|
int current_frame; // Frame actual
|
||||||
int counter; // Contador para las animaciones
|
int counter; // Contador para las animaciones
|
||||||
|
|
||||||
|
Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using Animations = std::vector<std::string>;
|
||||||
|
|
||||||
|
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||||
|
Animations loadAnimationsFromFile(const std::string &file_path);
|
||||||
|
|
||||||
class AnimatedSprite : public MovingSprite
|
class AnimatedSprite : public MovingSprite
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@@ -33,12 +40,12 @@ protected:
|
|||||||
std::vector<Animation> loadFromFile(const std::string &file_path);
|
std::vector<Animation> loadFromFile(const std::string &file_path);
|
||||||
|
|
||||||
// Carga la animación desde un vector
|
// Carga la animación desde un vector
|
||||||
bool loadFromVector(const std::vector<std::string> &source);
|
bool loadFromVector(const Animations &source);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
|
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
|
||||||
AnimatedSprite(std::shared_ptr<Texture> texture, const std::vector<std::string> &animations);
|
AnimatedSprite(std::shared_ptr<Texture> texture, const Animations &animations);
|
||||||
explicit AnimatedSprite(std::shared_ptr<Texture> texture);
|
explicit AnimatedSprite(std::shared_ptr<Texture> texture);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWops
|
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWops
|
||||||
#include <SDL2/SDL_stdinc.h> // for SDL_max
|
#include <SDL2/SDL_stdinc.h> // for SDL_max
|
||||||
#include <stddef.h> // for size_t
|
#include <stddef.h> // for size_t
|
||||||
@@ -68,10 +69,10 @@ bool Asset::check() const
|
|||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
std::cout << "\n** Checking files" << std::endl;
|
std::cout << "\n** CHECKING FILES" << std::endl;
|
||||||
|
|
||||||
std::cout << "Executable path is: " << executable_path_ << std::endl;
|
// std::cout << "Executable path is: " << executable_path_ << std::endl;
|
||||||
std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
|
// std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
|
||||||
|
|
||||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||||
for (int type = 0; type < static_cast<int>(AssetType::MAX_ASSET_TYPE); ++type)
|
for (int type = 0; type < static_cast<int>(AssetType::MAX_ASSET_TYPE); ++type)
|
||||||
@@ -99,11 +100,13 @@ bool Asset::check() const
|
|||||||
success &= checkFile(f.file);
|
success &= checkFile(f.file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (success)
|
||||||
|
std::cout << " All files are OK." << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resultado
|
// Resultado
|
||||||
std::cout << (success ? "\n** All files OK.\n" : "\n** A file is missing. Exiting.\n") << std::endl;
|
std::cout << (success ? "\n** CHECKING FILES COMPLETED.\n" : "\n** CHECKING FILES FAILED.\n") << std::endl;
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -123,12 +126,8 @@ bool Asset::checkFile(const std::string &path) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
||||||
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
if (!success)
|
||||||
std::cout << "Checking file: ";
|
printWithDots("Checking file : ", file_name, (success ? " [ OK ]" : " [ ERROR ]"));
|
||||||
std::cout.width(longest_name_ + 2);
|
|
||||||
std::cout.fill('.');
|
|
||||||
std::cout << file_name;
|
|
||||||
std::cout << (success ? " [OK]" : " [ERROR]") << std::endl;
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,35 +5,37 @@
|
|||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "moving_sprite.h" // for MovingSprite
|
#include "moving_sprite.h" // for MovingSprite
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
|
#include "screen.h"
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Background::Background(SDL_Renderer *renderer)
|
Background::Background()
|
||||||
: renderer_(renderer),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
buildings_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_buildings.png"))),
|
|
||||||
top_clouds_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds1.png"))),
|
buildings_texture_(Resource::get()->getTexture("game_buildings.png")),
|
||||||
bottom_clouds_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds2.png"))),
|
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")),
|
||||||
grass_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_grass.png"))),
|
bottom_clouds_texture_(Resource::get()->getTexture("game_clouds2.png")),
|
||||||
gradients_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_sky_colors.png")))
|
grass_texture_(Resource::get()->getTexture("game_grass.png")),
|
||||||
|
gradients_texture_(Resource::get()->getTexture("game_sky_colors.png")),
|
||||||
|
|
||||||
|
gradient_number_(0),
|
||||||
|
alpha_(0),
|
||||||
|
clouds_speed_(0),
|
||||||
|
transition_(0),
|
||||||
|
counter_(0),
|
||||||
|
rect_({0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2}),
|
||||||
|
src_rect_({0, 0, 320, 240}),
|
||||||
|
dst_rect_({0, 0, 320, 240}),
|
||||||
|
base_(rect_.h),
|
||||||
|
color_({param.background.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b}),
|
||||||
|
alpha_color_text_(param.background.attenuate_alpha),
|
||||||
|
alpha_color_text_temp_(param.background.attenuate_alpha)
|
||||||
|
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
{
|
{
|
||||||
gradient_number_ = 0;
|
|
||||||
alpha_ = 0;
|
|
||||||
clouds_speed_ = 0;
|
|
||||||
transition_ = 0;
|
|
||||||
counter_ = 0;
|
|
||||||
|
|
||||||
rect_ = {0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2};
|
|
||||||
src_rect_ = {0, 0, 320, 240};
|
|
||||||
dst_rect_ = {0, 0, 320, 240};
|
|
||||||
|
|
||||||
base_ = rect_.h;
|
|
||||||
color_ = {param.background.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b};
|
|
||||||
alpha_color_text_ = alpha_color_text_temp_ = param.background.attenuate_alpha;
|
|
||||||
|
|
||||||
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
|
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
|
||||||
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
|
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
|
||||||
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
|
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
|
||||||
@@ -86,11 +88,11 @@ Background::Background(SDL_Renderer *renderer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea la textura para componer el fondo
|
// Crea la textura para componer el fondo
|
||||||
canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||||
SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Crea la textura para atenuar el fondo
|
// Crea la textura para atenuar el fondo
|
||||||
color_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
color_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||||
SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND);
|
||||||
setColor(color_);
|
setColor(color_);
|
||||||
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_);
|
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_);
|
||||||
@@ -119,7 +121,7 @@ void Background::update()
|
|||||||
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
|
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
|
||||||
|
|
||||||
// Incrementa el contador
|
// Incrementa el contador
|
||||||
counter_++;
|
++counter_;
|
||||||
|
|
||||||
// Compone todos los elementos del fondo en la textura
|
// Compone todos los elementos del fondo en la textura
|
||||||
fillCanvas();
|
fillCanvas();
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Background(SDL_Renderer *renderer);
|
Background();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Background();
|
~Background();
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
|||||||
power_ = 1;
|
power_ = 1;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
vel_y_ = abs(vel_x) * 2;
|
vel_y_ = fabs(vel_x_ * 2.0f);
|
||||||
max_vel_y_ = abs(vel_x) * 2;
|
max_vel_y_ = vel_y_;
|
||||||
gravity_ = 0.00f;
|
gravity_ = 0.00f;
|
||||||
default_vel_y_ = abs(vel_x) * 2;
|
default_vel_y_ = vel_y_;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
score_ = BALLOON_SCORE_1;
|
score_ = BALLOON_SCORE_1;
|
||||||
@@ -142,10 +142,10 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
|||||||
power_ = 3;
|
power_ = 3;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
vel_y_ = abs(vel_x) * 2;
|
vel_y_ = fabs(vel_x_ * 2.0f);
|
||||||
max_vel_y_ = abs(vel_x) * 2;
|
max_vel_y_ = vel_y_;
|
||||||
gravity_ = 0.00f;
|
gravity_ = 0.00f;
|
||||||
default_vel_y_ = abs(vel_x) * 2;
|
default_vel_y_ = vel_y_;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
score_ = BALLOON_SCORE_2;
|
score_ = BALLOON_SCORE_2;
|
||||||
@@ -163,10 +163,10 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
|||||||
power_ = 7;
|
power_ = 7;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
vel_y_ = abs(vel_x) * 2;
|
vel_y_ = fabs(vel_x_ * 2.0f);
|
||||||
max_vel_y_ = abs(vel_x) * 2;
|
max_vel_y_ = vel_y_;
|
||||||
gravity_ = 0.00f;
|
gravity_ = 0.00f;
|
||||||
default_vel_y_ = abs(vel_x) * 2;
|
default_vel_y_ = vel_y_;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
score_ = BALLOON_SCORE_3;
|
score_ = BALLOON_SCORE_3;
|
||||||
@@ -184,10 +184,10 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
|||||||
power_ = 15;
|
power_ = 15;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
vel_y_ = abs(vel_x) * 2;
|
vel_y_ = fabs(vel_x_ * 2.0f);
|
||||||
max_vel_y_ = abs(vel_x) * 2;
|
max_vel_y_ = vel_y_;
|
||||||
gravity_ = 0.00f;
|
gravity_ = 0.00f;
|
||||||
default_vel_y_ = abs(vel_x) * 2;
|
default_vel_y_ = vel_y_;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
score_ = BALLOON_SCORE_4;
|
score_ = BALLOON_SCORE_4;
|
||||||
@@ -238,13 +238,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
|||||||
bouncing_.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
|
bouncing_.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
|
||||||
bouncing_.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
|
bouncing_.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
|
||||||
|
|
||||||
// Alto y ancho del sprite_
|
// Configura el sprite
|
||||||
sprite_->setWidth(width_);
|
sprite_->setPos({static_cast<int>(pos_x_), static_cast<int>(pos_y_), width_, height_});
|
||||||
sprite_->setHeight(height_);
|
|
||||||
|
|
||||||
// Posición X,Y del sprite_
|
|
||||||
sprite_->setPosX((int)pos_x_);
|
|
||||||
sprite_->setPosY((int)pos_y_);
|
|
||||||
|
|
||||||
// Tamaño del circulo de colisión
|
// Tamaño del circulo de colisión
|
||||||
collider_.r = width_ / 2;
|
collider_.r = width_ / 2;
|
||||||
@@ -396,10 +391,6 @@ void Balloon::move()
|
|||||||
|
|
||||||
// Aplica la gravedad al objeto sin pasarse de una velocidad máxima
|
// Aplica la gravedad al objeto sin pasarse de una velocidad máxima
|
||||||
vel_y_ += gravity_;
|
vel_y_ += gravity_;
|
||||||
|
|
||||||
// Al parecer esta asignación se quedó sin hacer y ahora el juego no funciona
|
|
||||||
// correctamente si se aplica, así que se deja sin efecto
|
|
||||||
// vel_y_ = std::min(vel_y_, max_vel_y_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición del sprite_
|
// Actualiza la posición del sprite_
|
||||||
@@ -460,7 +451,7 @@ void Balloon::update()
|
|||||||
updateColliders();
|
updateColliders();
|
||||||
updateState();
|
updateState();
|
||||||
updateBounce();
|
updateBounce();
|
||||||
counter_++;
|
++counter_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,15 +600,15 @@ int Balloon::getHeight() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Balloon::setVelY(float vel_y_)
|
void Balloon::setVelY(float vel_y)
|
||||||
{
|
{
|
||||||
this->vel_y_ = vel_y_;
|
vel_y_ = vel_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Balloon::setSpeed(float speed_)
|
void Balloon::setSpeed(float speed)
|
||||||
{
|
{
|
||||||
this->speed_ = speed_;
|
speed_ = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
|
|||||||
@@ -37,15 +37,11 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[i].number_of_balloons = 0;
|
balloon_formation_[i].number_of_balloons = 0;
|
||||||
for (int j = 0; j < MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION; j++)
|
for (int j = 0; j < MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION; j++)
|
||||||
{
|
{
|
||||||
balloon_formation_[i].init[j].x = 0;
|
balloon_formation_[i].init[j] = BalloonFormationParams();
|
||||||
balloon_formation_[i].init[j].y = 0;
|
|
||||||
balloon_formation_[i].init[j].vel_x = 0;
|
|
||||||
balloon_formation_[i].init[j].kind = 0;
|
|
||||||
balloon_formation_[i].init[j].creation_counter = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int creation_time = 300;
|
constexpr int CREATION_TIME = 300;
|
||||||
int inc_x = 0;
|
int inc_x = 0;
|
||||||
int inc_time = 0;
|
int inc_time = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@@ -61,7 +57,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y4;
|
balloon_formation_[j].init[i].y = y4;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME + (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro
|
// #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro
|
||||||
@@ -75,7 +71,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y4;
|
balloon_formation_[j].init[i].y = y4;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME + (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #02 - Cuatro enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
// #02 - Cuatro enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
||||||
@@ -89,7 +85,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y2;
|
balloon_formation_[j].init[i].y = y2;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #03 - Cuatro enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
// #03 - Cuatro enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
||||||
@@ -103,7 +99,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y2;
|
balloon_formation_[j].init[i].y = y2;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha
|
// #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha
|
||||||
@@ -117,7 +113,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda
|
// #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda
|
||||||
@@ -131,7 +127,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha
|
// #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha
|
||||||
@@ -145,7 +141,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda
|
// #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda
|
||||||
@@ -159,7 +155,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha
|
// #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha
|
||||||
@@ -173,7 +169,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y1;
|
balloon_formation_[j].init[i].y = y1;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda
|
// #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda
|
||||||
@@ -187,7 +183,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y1;
|
balloon_formation_[j].init[i].y = y1;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #10 - Tres enemigos BALLOON4 seguidos desde la izquierda
|
// #10 - Tres enemigos BALLOON4 seguidos desde la izquierda
|
||||||
@@ -201,7 +197,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y4;
|
balloon_formation_[j].init[i].y = y4;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #11 - Tres enemigos BALLOON4 seguidos desde la derecha
|
// #11 - Tres enemigos BALLOON4 seguidos desde la derecha
|
||||||
@@ -215,7 +211,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y4;
|
balloon_formation_[j].init[i].y = y4;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #12 - Seis enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
// #12 - Seis enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
||||||
@@ -229,7 +225,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y2;
|
balloon_formation_[j].init[i].y = y2;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #13 - Seis enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
// #13 - Seis enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
||||||
@@ -243,7 +239,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y2;
|
balloon_formation_[j].init[i].y = y2;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados
|
// #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados
|
||||||
@@ -257,7 +253,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados
|
// #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados
|
||||||
@@ -271,7 +267,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos
|
// #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos
|
||||||
@@ -285,7 +281,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos
|
// #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos
|
||||||
@@ -299,7 +295,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos
|
// #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos
|
||||||
@@ -313,7 +309,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y1;
|
balloon_formation_[j].init[i].y = y1;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos
|
// #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos
|
||||||
@@ -327,7 +323,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_[j].init[i].y = y1;
|
balloon_formation_[j].init[i].y = y1;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME - (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos
|
// #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos
|
||||||
@@ -350,7 +346,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
}
|
}
|
||||||
balloon_formation_[j].init[i].y = y4;
|
balloon_formation_[j].init[i].y = y4;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = CREATION_TIME + (inc_time * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos
|
// #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos
|
||||||
@@ -365,13 +361,13 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
balloon_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) - (inc_time * i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x2_100 - ((i - half) * inc_x);
|
balloon_formation_[j].init[i].x = x2_100 - ((i - half) * inc_x);
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) - (inc_time * (i - half));
|
||||||
}
|
}
|
||||||
balloon_formation_[j].init[i].y = y2;
|
balloon_formation_[j].init[i].y = y2;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
@@ -389,13 +385,13 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) - (inc_time * i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) - (inc_time * (i - half));
|
||||||
}
|
}
|
||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
@@ -413,13 +409,13 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) - (inc_time * i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) - (inc_time * (i - half));
|
||||||
}
|
}
|
||||||
balloon_formation_[j].init[i].y = y3;
|
balloon_formation_[j].init[i].y = y3;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
@@ -436,13 +432,13 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x1_50;
|
balloon_formation_[j].init[i].x = x1_50;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) + (inc_time * i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x1_50;
|
balloon_formation_[j].init[i].x = x1_50;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * (i - half));
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) + (inc_time * (i - half));
|
||||||
}
|
}
|
||||||
balloon_formation_[j].init[i].y = y1;
|
balloon_formation_[j].init[i].y = y1;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
@@ -459,13 +455,13 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x1_50 + 20;
|
balloon_formation_[j].init[i].x = x1_50 + 20;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) - (inc_time * i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
balloon_formation_[j].init[i].x = x1_50 - 20;
|
balloon_formation_[j].init[i].x = x1_50 - 20;
|
||||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
balloon_formation_[j].init[i].creation_counter = (CREATION_TIME) - (inc_time * (i - half));
|
||||||
}
|
}
|
||||||
balloon_formation_[j].init[i].y = y1;
|
balloon_formation_[j].init[i].y = y1;
|
||||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
|
|||||||
@@ -6,11 +6,15 @@ constexpr int MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION = 50;
|
|||||||
// Estructuras
|
// Estructuras
|
||||||
struct BalloonFormationParams
|
struct BalloonFormationParams
|
||||||
{
|
{
|
||||||
int x; // Posición en el eje X donde crear al enemigo
|
int x = 0; // Posición en el eje X donde crear al enemigo
|
||||||
int y; // Posición en el eje Y donde crear al enemigo
|
int y = 0; // Posición en el eje Y donde crear al enemigo
|
||||||
float vel_x; // Velocidad inicial en el eje X
|
float vel_x = 0.0f; // Velocidad inicial en el eje X
|
||||||
int kind; // Tipo de enemigo
|
int kind = 0; // Tipo de enemigo
|
||||||
int creation_counter; // Temporizador para la creación del enemigo
|
int creation_counter = 0; // Temporizador para la creación del enemigo
|
||||||
|
|
||||||
|
// Constructor que inicializa todos los campos con valores proporcionados o predeterminados
|
||||||
|
BalloonFormationParams(int x_val = 0, int y_val = 0, float vel_x_val = 0.0f, int kind_val = 0, int creation_counter_val = 0)
|
||||||
|
: x(x_val), y(y_val), vel_x(vel_x_val), kind(kind_val), creation_counter(creation_counter_val) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BalloonFormationUnit // Contiene la información de una formación enemiga
|
struct BalloonFormationUnit // Contiene la información de una formación enemiga
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ void DefineButtons::checkInput()
|
|||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
{
|
{
|
||||||
section::name = section::Name::QUIT;
|
section::name = section::Name::QUIT;
|
||||||
section::options = section::Options::QUIT_NORMAL;
|
section::options = section::Options::QUIT_WITH_KEYBOARD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ void DefineButtons::incIndexButton()
|
|||||||
// Guarda los cambios en las opciones
|
// Guarda los cambios en las opciones
|
||||||
saveBindingsToOptions();
|
saveBindingsToOptions();
|
||||||
|
|
||||||
//input_->allActive(index_controller_);
|
// input_->allActive(index_controller_);
|
||||||
|
|
||||||
// Reinicia variables
|
// Reinicia variables
|
||||||
index_button_ = 0;
|
index_button_ = 0;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include "on_screen_help.h" // for OnScreenHelp
|
#include "on_screen_help.h" // for OnScreenHelp
|
||||||
#include "options.h" // for options, loadOptionsFile, saveO...
|
#include "options.h" // for options, loadOptionsFile, saveO...
|
||||||
#include "param.h" // for param, loadParamsFromFile
|
#include "param.h" // for param, loadParamsFromFile
|
||||||
|
#include "resource.h" //for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
#include "title.h" // for Title
|
#include "title.h" // for Title
|
||||||
@@ -73,11 +74,8 @@ Director::Director(int argc, const char *argv[])
|
|||||||
// Crea el objeto que controla los ficheros de recursos
|
// Crea el objeto que controla los ficheros de recursos
|
||||||
Asset::init(executable_path_);
|
Asset::init(executable_path_);
|
||||||
|
|
||||||
// Si falta algún fichero no inicia el programa
|
// Crea el indice de ficheros
|
||||||
if (!setFileList())
|
setFileList();
|
||||||
{
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
// Carga el fichero de configuración
|
||||||
loadOptionsFile(Asset::get()->get("config.txt"));
|
loadOptionsFile(Asset::get()->get("config.txt"));
|
||||||
@@ -106,21 +104,18 @@ Director::Director(int argc, const char *argv[])
|
|||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
lang::loadFromFile(getLangFile((lang::Code)options.game.language));
|
lang::loadFromFile(getLangFile((lang::Code)options.game.language));
|
||||||
|
|
||||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
|
||||||
initInput();
|
|
||||||
|
|
||||||
Screen::init(window_, renderer_);
|
Screen::init(window_, renderer_);
|
||||||
|
|
||||||
Notifier::init(renderer_, std::string(), Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Asset::get()->get("notify.wav"));
|
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"));
|
||||||
|
|
||||||
OnScreenHelp::init();
|
OnScreenHelp::init();
|
||||||
|
|
||||||
// Carga los sonidos del juego
|
|
||||||
loadSounds();
|
|
||||||
|
|
||||||
// Carga las musicas del juego
|
|
||||||
loadMusics();
|
|
||||||
|
|
||||||
globalInputs::init();
|
globalInputs::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,26 +124,23 @@ Director::~Director()
|
|||||||
saveOptionsFile(Asset::get()->get("config.txt"));
|
saveOptionsFile(Asset::get()->get("config.txt"));
|
||||||
|
|
||||||
Asset::destroy();
|
Asset::destroy();
|
||||||
|
Resource::destroy();
|
||||||
Input::destroy();
|
Input::destroy();
|
||||||
Screen::destroy();
|
Screen::destroy();
|
||||||
Notifier::destroy();
|
Notifier::destroy();
|
||||||
OnScreenHelp::destroy();
|
OnScreenHelp::destroy();
|
||||||
|
|
||||||
sounds_.clear();
|
|
||||||
musics_.clear();
|
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer_);
|
SDL_DestroyRenderer(renderer_);
|
||||||
SDL_DestroyWindow(window_);
|
SDL_DestroyWindow(window_);
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
|
std::cout << "\nBye!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inicializa el objeto input
|
// Asigna los botones y teclas al objeto Input
|
||||||
void Director::initInput()
|
void Director::bindInputs()
|
||||||
{
|
{
|
||||||
// Busca si hay mandos conectados
|
|
||||||
Input::get()->discoverGameControllers();
|
|
||||||
|
|
||||||
// Teclado - Movimiento del jugador
|
// Teclado - Movimiento del jugador
|
||||||
Input::get()->bindKey(InputType::UP, SDL_SCANCODE_UP);
|
Input::get()->bindKey(InputType::UP, SDL_SCANCODE_UP);
|
||||||
Input::get()->bindKey(InputType::DOWN, SDL_SCANCODE_DOWN);
|
Input::get()->bindKey(InputType::DOWN, SDL_SCANCODE_DOWN);
|
||||||
@@ -335,7 +327,7 @@ bool Director::initSDL()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea el indice de ficheros
|
// Crea el indice de ficheros
|
||||||
bool Director::setFileList()
|
void Director::setFileList()
|
||||||
{
|
{
|
||||||
#ifdef MACOS_BUNDLE
|
#ifdef MACOS_BUNDLE
|
||||||
const std::string prefix = "/../Resources";
|
const std::string prefix = "/../Resources";
|
||||||
@@ -379,8 +371,12 @@ bool Director::setFileList()
|
|||||||
Asset::get()->add(prefix + "/data/shaders/crtpi.glsl", AssetType::DATA);
|
Asset::get()->add(prefix + "/data/shaders/crtpi.glsl", AssetType::DATA);
|
||||||
|
|
||||||
// Texturas
|
// Texturas
|
||||||
Asset::get()->add(prefix + "/data/gfx/controllers/controllers.png", AssetType::BITMAP);
|
|
||||||
|
|
||||||
|
{ // Controllers
|
||||||
|
Asset::get()->add(prefix + "/data/gfx/controllers/controllers.png", AssetType::BITMAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Balloons
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.ani", AssetType::ANIMATION);
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.png", AssetType::BITMAP);
|
||||||
@@ -389,7 +385,9 @@ bool Director::setFileList()
|
|||||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.ani", AssetType::ANIMATION);
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.ani", AssetType::ANIMATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Explosions
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.ani", AssetType::ANIMATION);
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.png", AssetType::BITMAP);
|
||||||
@@ -398,31 +396,45 @@ bool Director::setFileList()
|
|||||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.ani", AssetType::ANIMATION);
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.ani", AssetType::ANIMATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Power Ball
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/powerball.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/balloon/powerball.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/balloon/powerball.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/balloon/powerball.ani", AssetType::ANIMATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Bala
|
||||||
Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Juego
|
||||||
Asset::get()->add(prefix + "/data/gfx/game/game_buildings.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game/game_buildings.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game/game_clouds1.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game/game_clouds1.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game/game_clouds2.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game/game_clouds2.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game/game_grass.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game/game_grass.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game/game_power_meter.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game/game_power_meter.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Game Text
|
||||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_1000_points.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_1000_points.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_2500_points.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_2500_points.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_5000_points.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_5000_points.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_powerup.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_powerup.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_one_hit.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_one_hit.png", AssetType::BITMAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Intro
|
||||||
Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Logo
|
||||||
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/logo/logo_since_1998.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/logo/logo_since_1998.png", AssetType::BITMAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Items
|
||||||
Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.ani", AssetType::ANIMATION);
|
||||||
Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.png", AssetType::BITMAP);
|
||||||
@@ -435,43 +447,51 @@ bool Director::setFileList()
|
|||||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/item/item_coffee.ani", AssetType::ANIMATION);
|
||||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.ani", AssetType::ANIMATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Titulo
|
||||||
Asset::get()->add(prefix + "/data/gfx/title/title_bg_tile.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/title/title_bg_tile.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/title/title_coffee.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/title/title_coffee.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/title/title_crisis.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/title/title_crisis.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/title/title_arcade_edition.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/title/title_arcade_edition.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/title/title_dust.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/title/title_dust.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/title/title_dust.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/title/title_dust.ani", AssetType::ANIMATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Jugador 1
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player1.gif", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/player/player1.gif", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player1_pal1.gif", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player1_one_coffee_palette.pal", AssetType::PALETTE);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player1_pal2.gif", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player1_two_coffee_palette.pal", AssetType::PALETTE);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player1_pal3.gif", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player1_all_white_palette.pal", AssetType::PALETTE);
|
||||||
|
Asset::get()->add(prefix + "/data/gfx/player/player1_power.png", AssetType::BITMAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Jugador 2
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player2.gif", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/player/player2.gif", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player2_pal1.gif", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player2_one_coffee_palette.pal", AssetType::PALETTE);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player2_pal2.gif", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player2_two_coffee_palette.pal", AssetType::PALETTE);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player2_pal3.gif", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player2_all_white_palette.pal", AssetType::PALETTE);
|
||||||
|
Asset::get()->add(prefix + "/data/gfx/player/player2_power.png", AssetType::BITMAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // Animaciones del jugador
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/player/player.ani", AssetType::ANIMATION);
|
||||||
|
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player_power.gif", AssetType::BITMAP);
|
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player_power_pal.gif", AssetType::PALETTE);
|
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player_power.ani", AssetType::ANIMATION);
|
Asset::get()->add(prefix + "/data/gfx/player/player_power.ani", AssetType::ANIMATION);
|
||||||
|
}
|
||||||
|
|
||||||
// Fuentes de texto
|
// Fuentes de texto
|
||||||
Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::FONT);
|
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::FONT);
|
Asset::get()->add(prefix + "/data/font/nokia.png", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/font/nokia_big2.png", AssetType::FONT);
|
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::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/nokia2.txt", AssetType::FONT);
|
||||||
Asset::get()->add(prefix + "/data/font/nokia_big2.txt", AssetType::FONT);
|
Asset::get()->add(prefix + "/data/font/nokia_big2.txt", AssetType::FONT);
|
||||||
Asset::get()->add(prefix + "/data/font/smb2_big.png", 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_big.txt", AssetType::FONT);
|
||||||
Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::FONT);
|
Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::BITMAP);
|
||||||
Asset::get()->add(prefix + "/data/font/smb2_pal1.gif", 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);
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
@@ -479,7 +499,9 @@ bool Director::setFileList()
|
|||||||
Asset::get()->add(prefix + "/data/lang/en_UK.txt", AssetType::LANG);
|
Asset::get()->add(prefix + "/data/lang/en_UK.txt", AssetType::LANG);
|
||||||
Asset::get()->add(prefix + "/data/lang/ba_BA.txt", AssetType::LANG);
|
Asset::get()->add(prefix + "/data/lang/ba_BA.txt", AssetType::LANG);
|
||||||
|
|
||||||
return Asset::get()->check();
|
// Si falta algun fichero, sale del programa
|
||||||
|
if (!Asset::get()->check())
|
||||||
|
throw std::runtime_error("Falta algun fichero");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los parametros para configurar el juego
|
// Carga los parametros para configurar el juego
|
||||||
@@ -567,38 +589,6 @@ void Director::createSystemFolder(const std::string &folder)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los sonidos del juego
|
|
||||||
void Director::loadSounds()
|
|
||||||
{
|
|
||||||
// Obtiene la lista con las rutas a los ficheros de sonidos
|
|
||||||
auto list = Asset::get()->getListByType(AssetType::SOUND);
|
|
||||||
sounds_.clear();
|
|
||||||
|
|
||||||
for (const auto &l : list)
|
|
||||||
{
|
|
||||||
auto last_index = l.find_last_of('/') + 1;
|
|
||||||
auto name = l.substr(last_index);
|
|
||||||
|
|
||||||
sounds_.emplace_back(SoundFile{name, JA_LoadSound(l.c_str())});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carga las musicas del juego
|
|
||||||
void Director::loadMusics()
|
|
||||||
{
|
|
||||||
// Obtiene la lista con las rutas a los ficheros musicales
|
|
||||||
auto list = Asset::get()->getListByType(AssetType::MUSIC);
|
|
||||||
musics_.clear();
|
|
||||||
|
|
||||||
for (const auto &l : list)
|
|
||||||
{
|
|
||||||
auto last_index = l.find_last_of('/') + 1;
|
|
||||||
auto name = l.substr(last_index);
|
|
||||||
|
|
||||||
musics_.emplace_back(MusicFile{name, JA_LoadMusic(l.c_str())});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ejecuta la sección con el logo
|
// Ejecuta la sección con el logo
|
||||||
void Director::runLogo()
|
void Director::runLogo()
|
||||||
{
|
{
|
||||||
@@ -609,14 +599,14 @@ void Director::runLogo()
|
|||||||
// Ejecuta la sección con la secuencia de introducción
|
// Ejecuta la sección con la secuencia de introducción
|
||||||
void Director::runIntro()
|
void Director::runIntro()
|
||||||
{
|
{
|
||||||
auto intro = std::make_unique<Intro>(getMusic(musics_, "intro.ogg"));
|
auto intro = std::make_unique<Intro>();
|
||||||
intro->run();
|
intro->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta la sección con el título del juego
|
// Ejecuta la sección con el título del juego
|
||||||
void Director::runTitle()
|
void Director::runTitle()
|
||||||
{
|
{
|
||||||
auto title = std::make_unique<Title>(getMusic(musics_, "title.ogg"));
|
auto title = std::make_unique<Title>();
|
||||||
title->run();
|
title->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,21 +615,21 @@ void Director::runGame()
|
|||||||
{
|
{
|
||||||
const auto player_id = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
|
const auto player_id = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
|
||||||
constexpr auto current_stage = 0;
|
constexpr auto current_stage = 0;
|
||||||
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg"));
|
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_OFF);
|
||||||
game->run();
|
game->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta la sección donde se muestran las instrucciones
|
// Ejecuta la sección donde se muestran las instrucciones
|
||||||
void Director::runInstructions()
|
void Director::runInstructions()
|
||||||
{
|
{
|
||||||
auto instructions = std::make_unique<Instructions>(getMusic(musics_, "title.ogg"));
|
auto instructions = std::make_unique<Instructions>();
|
||||||
instructions->run();
|
instructions->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||||
void Director::runHiScoreTable()
|
void Director::runHiScoreTable()
|
||||||
{
|
{
|
||||||
auto hi_score_table = std::make_unique<HiScoreTable>(getMusic(musics_, "title.ogg"));
|
auto hi_score_table = std::make_unique<HiScoreTable>();
|
||||||
hi_score_table->run();
|
hi_score_table->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,7 +638,7 @@ void Director::runDemoGame()
|
|||||||
{
|
{
|
||||||
const auto player_id = (rand() % 2) + 1;
|
const auto player_id = (rand() % 2) + 1;
|
||||||
constexpr auto current_stage = 0;
|
constexpr auto current_stage = 0;
|
||||||
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_ON, nullptr);
|
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_ON);
|
||||||
game->run();
|
game->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,20 +688,20 @@ int Director::run()
|
|||||||
|
|
||||||
#ifdef ARCADE
|
#ifdef ARCADE
|
||||||
// Comprueba si ha de apagar el sistema
|
// Comprueba si ha de apagar el sistema
|
||||||
if (section::options == section::Options::QUIT_SHUTDOWN)
|
if (section::options == section::Options::QUIT_WITH_CONTROLLER)
|
||||||
shutdownSystem();
|
shutdownSystem();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const auto return_code = (section::options == section::Options::QUIT_NORMAL) ? "keyboard" : "controller";
|
const auto return_code = (section::options == section::Options::QUIT_WITH_KEYBOARD) ? "with keyboard" : (section::options == section::Options::QUIT_WITH_CONTROLLER) ? "with controller"
|
||||||
std::cout << "\nGame end with " << return_code << std::endl;
|
: "from event";
|
||||||
|
std::cout << "\nGame end " << return_code << std::endl;
|
||||||
|
|
||||||
#ifndef VERBOSE
|
#ifndef VERBOSE
|
||||||
// Habilita de nuevo los std::cout
|
// Habilita de nuevo los std::cout
|
||||||
std::cout.rdbuf(orig_buf);
|
std::cout.rdbuf(orig_buf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (return_code == std::string("keyboard")) ? 0 : 1;
|
return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene una fichero a partir de un lang::Code
|
// Obtiene una fichero a partir de un lang::Code
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ namespace lang
|
|||||||
{
|
{
|
||||||
enum class Code : int;
|
enum class Code : int;
|
||||||
}
|
}
|
||||||
struct MusicFile;
|
struct ResourceMusic;
|
||||||
struct SoundFile;
|
struct ResourceSound;
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
constexpr char WINDOW_CAPTION[] = "Coffee Crisis Arcade Edition";
|
constexpr char WINDOW_CAPTION[] = "Coffee Crisis Arcade Edition";
|
||||||
@@ -20,14 +20,12 @@ private:
|
|||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Window *window_; // La ventana donde dibujamos
|
SDL_Window *window_; // La ventana donde dibujamos
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
std::streambuf *orig_buf; ///< Puntero al buffer de flujo original para restaurar std::cout
|
std::streambuf *orig_buf; // Puntero al buffer de flujo original para restaurar std::cout
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::string executable_path_; // Path del ejecutable
|
std::string executable_path_; // Path del ejecutable
|
||||||
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
||||||
std::string param_file_argument_; // Argumento para gestionar el fichero con los parametros del programa
|
std::string param_file_argument_; // Argumento para gestionar el fichero con los parametros del programa
|
||||||
std::vector<SoundFile> sounds_; // Vector con los sonidos
|
|
||||||
std::vector<MusicFile> musics_; // Vector con las musicas
|
|
||||||
|
|
||||||
// Inicializa jail_audio
|
// Inicializa jail_audio
|
||||||
void initJailAudio();
|
void initJailAudio();
|
||||||
@@ -35,20 +33,14 @@ private:
|
|||||||
// Arranca SDL y crea la ventana
|
// Arranca SDL y crea la ventana
|
||||||
bool initSDL();
|
bool initSDL();
|
||||||
|
|
||||||
// Inicializa el objeto input
|
// Asigna los botones y teclas al objeto Input
|
||||||
void initInput();
|
void bindInputs();
|
||||||
|
|
||||||
// Carga los parametros para configurar el juego
|
// Carga los parametros para configurar el juego
|
||||||
void loadParams(const std::string &file_path);
|
void loadParams(const std::string &file_path);
|
||||||
|
|
||||||
// Crea el indice de ficheros
|
// Crea el indice de ficheros
|
||||||
bool setFileList();
|
void setFileList();
|
||||||
|
|
||||||
// Carga los sonidos del juego
|
|
||||||
void loadSounds();
|
|
||||||
|
|
||||||
// Carga las musicas del juego
|
|
||||||
void loadMusics();
|
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void checkProgramArguments(int argc, const char *argv[]);
|
void checkProgramArguments(int argc, const char *argv[]);
|
||||||
|
|||||||
@@ -4,11 +4,12 @@
|
|||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // for rand
|
||||||
#include <algorithm> // for min, max
|
#include <algorithm> // for min, max
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "screen.h"
|
||||||
#include "utils.h" // for Param, ParamGame, ParamFade
|
#include "utils.h" // for Param, ParamGame, ParamFade
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Fade::Fade(SDL_Renderer *renderer)
|
Fade::Fade()
|
||||||
: renderer_(renderer)
|
: renderer_(Screen::get()->getRenderer())
|
||||||
{
|
{
|
||||||
// Crea la textura donde dibujar el fade
|
// Crea la textura donde dibujar el fade
|
||||||
backbuffer_ = 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);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Fade(SDL_Renderer *renderer);
|
Fade();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Fade();
|
~Fade();
|
||||||
|
|||||||
434
source/game.cpp
@@ -22,13 +22,14 @@
|
|||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
#include "input.h" // for InputType, Input, INPUT_DO_NOT_ALL...
|
#include "input.h" // for InputType, Input, INPUT_DO_NOT_ALL...
|
||||||
#include "item.h" // for Item, ItemType::COFFEE_MACHINE, ItemType::CLOCK
|
#include "item.h" // for Item, ItemType::COFFEE_MACHINE, ItemType::CLOCK
|
||||||
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
|
#include "jail_audio.h" // for JA_PlaySound
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
||||||
#include "notifier.h" // for Notifier
|
#include "notifier.h" // for Notifier
|
||||||
#include "options.h" // for options
|
#include "options.h" // for options
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
#include "player.h" // for Player, PlayerStatus
|
#include "player.h" // for Player, PlayerStatus
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "scoreboard.h" // for Scoreboard, ScoreboardMode, SCOREB...
|
#include "scoreboard.h" // for Scoreboard, ScoreboardMode, SCOREB...
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
@@ -37,11 +38,11 @@
|
|||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
struct JA_Music_t; // lines 35-35
|
struct JA_Music_t; // lines 35-35
|
||||||
struct JA_Sound_t; // lines 36-36
|
struct JA_Sound_t; // lines 36-36
|
||||||
|
#include "dbgtxt.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music)
|
Game::Game(int player_id, int current_stage, bool demo)
|
||||||
: music_(music),
|
: current_stage_(current_stage)
|
||||||
current_stage_(current_stage)
|
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
asset_ = Asset::get();
|
asset_ = Asset::get();
|
||||||
@@ -55,11 +56,11 @@ Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music)
|
|||||||
difficulty_ = options.game.difficulty;
|
difficulty_ = options.game.difficulty;
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
Scoreboard::init(renderer_);
|
Scoreboard::init();
|
||||||
scoreboard_ = Scoreboard::get();
|
scoreboard_ = Scoreboard::get();
|
||||||
fade_ = std::make_unique<Fade>(renderer_);
|
fade_ = std::make_unique<Fade>();
|
||||||
|
|
||||||
background_ = std::make_unique<Background>(renderer_);
|
background_ = std::make_unique<Background>();
|
||||||
explosions_ = std::make_unique<Explosions>();
|
explosions_ = std::make_unique<Explosions>();
|
||||||
balloon_formations_ = std::make_unique<BalloonFormations>();
|
balloon_formations_ = std::make_unique<BalloonFormations>();
|
||||||
|
|
||||||
@@ -69,10 +70,10 @@ Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music)
|
|||||||
// Inicializa los vectores con los datos para la demo
|
// Inicializa los vectores con los datos para la demo
|
||||||
if (demo_.enabled)
|
if (demo_.enabled)
|
||||||
{ // Aleatoriza la asignación del fichero
|
{ // Aleatoriza la asignación del fichero
|
||||||
const auto index1 = rand() % 2;
|
const auto demo1 = rand() % 2;
|
||||||
const auto index2 = (index1 + 1) % 2;
|
const auto demo2 = (demo1 == 0) ? 1 : 0;
|
||||||
loadDemoFile(asset_->get("demo1.bin"), &this->demo_.data_file[index1]);
|
demo_.data.emplace_back(Resource::get()->getDemoData(demo1));
|
||||||
loadDemoFile(asset_->get("demo2.bin"), &this->demo_.data_file[index2]);
|
demo_.data.emplace_back(Resource::get()->getDemoData(demo2));
|
||||||
}
|
}
|
||||||
|
|
||||||
background_->setPos(param.game.play_area.rect);
|
background_->setPos(param.game.play_area.rect);
|
||||||
@@ -92,10 +93,13 @@ Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music)
|
|||||||
Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
// Guarda las puntuaciones en un fichero
|
// Guarda las puntuaciones en un fichero
|
||||||
|
if (!demo_.enabled)
|
||||||
|
{
|
||||||
auto manager = std::make_unique<ManageHiScoreTable>(&options.game.hi_score_table);
|
auto manager = std::make_unique<ManageHiScoreTable>(&options.game.hi_score_table);
|
||||||
manager->saveToFile(asset_->get("score.bin"));
|
manager->saveToFile(asset_->get("score.bin"));
|
||||||
|
}
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
saveDemoFile(asset->get("demo1.bin"));
|
saveDemoFile(Asset::get()->get("demo1.bin"), demo_.data.at(0));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Elimina todos los objetos contenidos en vectores
|
// Elimina todos los objetos contenidos en vectores
|
||||||
@@ -112,9 +116,6 @@ Game::~Game()
|
|||||||
// Inicializa las variables necesarias para la sección 'Game'
|
// Inicializa las variables necesarias para la sección 'Game'
|
||||||
void Game::init(int player_id)
|
void Game::init(int player_id)
|
||||||
{
|
{
|
||||||
ticks_ = 0;
|
|
||||||
ticks_speed_ = 15;
|
|
||||||
|
|
||||||
// Elimina qualquier jugador que hubiese antes de crear los nuevos
|
// Elimina qualquier jugador que hubiese antes de crear los nuevos
|
||||||
players_.clear();
|
players_.clear();
|
||||||
|
|
||||||
@@ -189,6 +190,7 @@ void Game::init(int player_id)
|
|||||||
scoreboard_->setMode(SCOREBOARD_CENTER_PANEL, ScoreboardMode::STAGE_INFO);
|
scoreboard_->setMode(SCOREBOARD_CENTER_PANEL, ScoreboardMode::STAGE_INFO);
|
||||||
|
|
||||||
// Resto de variables
|
// Resto de variables
|
||||||
|
ticks_ = 0;
|
||||||
hi_score_.score = options.game.hi_score_table[0].score;
|
hi_score_.score = options.game.hi_score_table[0].score;
|
||||||
hi_score_.name = options.game.hi_score_table[0].name;
|
hi_score_.name = options.game.hi_score_table[0].name;
|
||||||
paused_ = false;
|
paused_ = false;
|
||||||
@@ -200,8 +202,8 @@ void Game::init(int player_id)
|
|||||||
menace_current_ = 0;
|
menace_current_ = 0;
|
||||||
menace_threshold_ = 0;
|
menace_threshold_ = 0;
|
||||||
hi_score_achieved_ = false;
|
hi_score_achieved_ = false;
|
||||||
stage_bitmap_counter_ = STAGE_COUNTER;
|
stage_bitmap_counter_ = STAGE_COUNTER_;
|
||||||
game_over_counter_ = GAME_OVER_COUNTER;
|
game_over_counter_ = GAME_OVER_COUNTER_;
|
||||||
time_stopped_ = false;
|
time_stopped_ = false;
|
||||||
time_stopped_counter_ = 0;
|
time_stopped_counter_ = 0;
|
||||||
counter_ = 0;
|
counter_ = 0;
|
||||||
@@ -211,13 +213,13 @@ void Game::init(int player_id)
|
|||||||
helper_.need_coffee = false;
|
helper_.need_coffee = false;
|
||||||
helper_.need_coffee_machine = false;
|
helper_.need_coffee_machine = false;
|
||||||
helper_.need_power_ball = false;
|
helper_.need_power_ball = false;
|
||||||
helper_.counter = HELP_COUNTER;
|
helper_.counter = HELP_COUNTER_;
|
||||||
helper_.item_disk_odds = ITEM_POINTS_1_DISK_ODDS;
|
helper_.item_disk_odds = ITEM_POINTS_1_DISK_ODDS_;
|
||||||
helper_.item_gavina_odds = ITEM_POINTS_2_GAVINA_ODDS;
|
helper_.item_gavina_odds = ITEM_POINTS_2_GAVINA_ODDS_;
|
||||||
helper_.item_pacmar_odds = ITEM_POINTS_3_PACMAR_ODDS;
|
helper_.item_pacmar_odds = ITEM_POINTS_3_PACMAR_ODDS_;
|
||||||
helper_.item_clock_odds = ITEM_CLOCK_ODDS;
|
helper_.item_clock_odds = ITEM_CLOCK_ODDS_;
|
||||||
helper_.item_coffee_odds = ITEM_COFFEE_ODDS;
|
helper_.item_coffee_odds = ITEM_COFFEE_ODDS_;
|
||||||
helper_.item_coffee_machine_odds = ITEM_COFFEE_MACHINE_ODDS;
|
helper_.item_coffee_machine_odds = ITEM_COFFEE_MACHINE_ODDS_;
|
||||||
power_ball_enabled_ = false;
|
power_ball_enabled_ = false;
|
||||||
power_ball_counter_ = 0;
|
power_ball_counter_ = 0;
|
||||||
coffee_machine_enabled_ = false;
|
coffee_machine_enabled_ = false;
|
||||||
@@ -279,7 +281,7 @@ void Game::init(int player_id)
|
|||||||
|
|
||||||
// Modo grabar demo
|
// Modo grabar demo
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo.recording = true;
|
demo_.recording = true;
|
||||||
#else
|
#else
|
||||||
demo_.recording = false;
|
demo_.recording = false;
|
||||||
#endif
|
#endif
|
||||||
@@ -300,156 +302,105 @@ void Game::init(int player_id)
|
|||||||
// Carga los recursos necesarios para la sección 'Game'
|
// Carga los recursos necesarios para la sección 'Game'
|
||||||
void Game::loadMedia()
|
void Game::loadMedia()
|
||||||
{
|
{
|
||||||
std::cout << "\n** LOADING RESOURCES FOR GAME SECTION" << std::endl;
|
unloadMedia();
|
||||||
|
|
||||||
// Limpia
|
|
||||||
{
|
|
||||||
// Texturas
|
|
||||||
game_text_textures_.clear();
|
|
||||||
balloon_textures_.clear();
|
|
||||||
explosions_textures_.clear();
|
|
||||||
item_textures_.clear();
|
|
||||||
player_textures_.clear();
|
|
||||||
|
|
||||||
// Animaciones
|
|
||||||
player_animations_.clear();
|
|
||||||
balloon_animations_.clear();
|
|
||||||
explosions_animations_.clear();
|
|
||||||
item_animations_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Texturas
|
// Texturas
|
||||||
{
|
{
|
||||||
bullet_texture_ = std::make_shared<Texture>(renderer_, asset_->get("bullet.png"));
|
bullet_texture_ = Resource::get()->getTexture("bullet.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Game_text
|
// Texturas - Game_text
|
||||||
{
|
{
|
||||||
game_text_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("game_text_1000_points.png")));
|
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_1000_points.png"));
|
||||||
game_text_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("game_text_2500_points.png")));
|
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_2500_points.png"));
|
||||||
game_text_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("game_text_5000_points.png")));
|
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_5000_points.png"));
|
||||||
game_text_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("game_text_powerup.png")));
|
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_powerup.png"));
|
||||||
game_text_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("game_text_one_hit.png")));
|
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_one_hit.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Globos
|
// Texturas - Globos
|
||||||
{
|
{
|
||||||
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("balloon1.png")));
|
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon1.png"));
|
||||||
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("balloon2.png")));
|
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon2.png"));
|
||||||
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("balloon3.png")));
|
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon3.png"));
|
||||||
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("balloon4.png")));
|
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon4.png"));
|
||||||
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("powerball.png")));
|
balloon_textures_.emplace_back(Resource::get()->getTexture("powerball.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Explosiones
|
// Texturas - Explosiones
|
||||||
{
|
{
|
||||||
explosions_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("explosion1.png")));
|
explosions_textures_.emplace_back(Resource::get()->getTexture("explosion1.png"));
|
||||||
explosions_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("explosion2.png")));
|
explosions_textures_.emplace_back(Resource::get()->getTexture("explosion2.png"));
|
||||||
explosions_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("explosion3.png")));
|
explosions_textures_.emplace_back(Resource::get()->getTexture("explosion3.png"));
|
||||||
explosions_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("explosion4.png")));
|
explosions_textures_.emplace_back(Resource::get()->getTexture("explosion4.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Items
|
// Texturas - Items
|
||||||
{
|
{
|
||||||
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_points1_disk.png")));
|
item_textures_.emplace_back(Resource::get()->getTexture("item_points1_disk.png"));
|
||||||
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_points2_gavina.png")));
|
item_textures_.emplace_back(Resource::get()->getTexture("item_points2_gavina.png"));
|
||||||
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_points3_pacmar.png")));
|
item_textures_.emplace_back(Resource::get()->getTexture("item_points3_pacmar.png"));
|
||||||
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_clock.png")));
|
item_textures_.emplace_back(Resource::get()->getTexture("item_clock.png"));
|
||||||
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_coffee.png")));
|
item_textures_.emplace_back(Resource::get()->getTexture("item_coffee.png"));
|
||||||
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_coffee_machine.png")));
|
item_textures_.emplace_back(Resource::get()->getTexture("item_coffee_machine.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Player1
|
// Texturas - Player1
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||||
player_texture.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player1.gif")));
|
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
|
||||||
player_texture.back()->addPalette(asset_->get("player1_pal1.gif"));
|
player_texture.emplace_back(Resource::get()->getTexture("player1_power.png"));
|
||||||
player_texture.back()->addPalette(asset_->get("player1_pal2.gif"));
|
|
||||||
player_texture.back()->addPalette(asset_->get("player1_pal3.gif"));
|
|
||||||
|
|
||||||
player_texture.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player_power.gif")));
|
|
||||||
player_texture.back()->addPalette(asset_->get("player_power_pal.gif"));
|
|
||||||
|
|
||||||
player_textures_.push_back(player_texture);
|
player_textures_.push_back(player_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Player2
|
// Texturas - Player2
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||||
player_texture.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player2.gif")));
|
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
|
||||||
player_texture.back()->addPalette(asset_->get("player2_pal1.gif"));
|
player_texture.emplace_back(Resource::get()->getTexture("player2_power.png"));
|
||||||
player_texture.back()->addPalette(asset_->get("player2_pal2.gif"));
|
|
||||||
player_texture.back()->addPalette(asset_->get("player2_pal3.gif"));
|
|
||||||
|
|
||||||
player_texture.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player_power.gif")));
|
|
||||||
player_texture.back()->addPalette(asset_->get("player_power_pal.gif"));
|
|
||||||
player_texture.back()->setPalette(1);
|
|
||||||
|
|
||||||
player_textures_.push_back(player_texture);
|
player_textures_.push_back(player_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animaciones -- Jugador
|
// Animaciones -- Jugador
|
||||||
{
|
{
|
||||||
player_animations_.emplace_back(loadAnimations(asset_->get("player.ani")));
|
player_animations_.emplace_back(Resource::get()->getAnimation("player.ani"));
|
||||||
player_animations_.emplace_back(loadAnimations(asset_->get("player_power.ani")));
|
player_animations_.emplace_back(Resource::get()->getAnimation("player_power.ani"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animaciones -- Globos
|
// Animaciones -- Globos
|
||||||
{
|
{
|
||||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("balloon1.ani")));
|
balloon_animations_.emplace_back(Resource::get()->getAnimation("balloon1.ani"));
|
||||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("balloon2.ani")));
|
balloon_animations_.emplace_back(Resource::get()->getAnimation("balloon2.ani"));
|
||||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("balloon3.ani")));
|
balloon_animations_.emplace_back(Resource::get()->getAnimation("balloon3.ani"));
|
||||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("balloon4.ani")));
|
balloon_animations_.emplace_back(Resource::get()->getAnimation("balloon4.ani"));
|
||||||
balloon_animations_.emplace_back(loadAnimations(asset_->get("powerball.ani")));
|
balloon_animations_.emplace_back(Resource::get()->getAnimation("powerball.ani"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animaciones -- Explosiones
|
// Animaciones -- Explosiones
|
||||||
{
|
{
|
||||||
explosions_animations_.emplace_back(loadAnimations(asset_->get("explosion1.ani")));
|
explosions_animations_.emplace_back(Resource::get()->getAnimation("explosion1.ani"));
|
||||||
explosions_animations_.emplace_back(loadAnimations(asset_->get("explosion2.ani")));
|
explosions_animations_.emplace_back(Resource::get()->getAnimation("explosion2.ani"));
|
||||||
explosions_animations_.emplace_back(loadAnimations(asset_->get("explosion3.ani")));
|
explosions_animations_.emplace_back(Resource::get()->getAnimation("explosion3.ani"));
|
||||||
explosions_animations_.emplace_back(loadAnimations(asset_->get("explosion4.ani")));
|
explosions_animations_.emplace_back(Resource::get()->getAnimation("explosion4.ani"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animaciones -- Items
|
// Animaciones -- Items
|
||||||
{
|
{
|
||||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_points1_disk.ani")));
|
item_animations_.emplace_back(Resource::get()->getAnimation("item_points1_disk.ani"));
|
||||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_points2_gavina.ani")));
|
item_animations_.emplace_back(Resource::get()->getAnimation("item_points2_gavina.ani"));
|
||||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_points3_pacmar.ani")));
|
item_animations_.emplace_back(Resource::get()->getAnimation("item_points3_pacmar.ani"));
|
||||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_clock.ani")));
|
item_animations_.emplace_back(Resource::get()->getAnimation("item_clock.ani"));
|
||||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_coffee.ani")));
|
item_animations_.emplace_back(Resource::get()->getAnimation("item_coffee.ani"));
|
||||||
item_animations_.emplace_back(loadAnimations(asset_->get("item_coffee_machine.ani")));
|
item_animations_.emplace_back(Resource::get()->getAnimation("item_coffee_machine.ani"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texto
|
// Texto
|
||||||
{
|
{
|
||||||
text_ = std::make_unique<Text>(asset_->get("smb2.gif"), asset_->get("smb2.txt"), renderer_);
|
text_ = std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"));
|
||||||
text_big_ = std::make_unique<Text>(asset_->get("smb2_big.png"), asset_->get("smb2_big.txt"), renderer_);
|
text_big_ = std::make_unique<Text>(Resource::get()->getTexture("smb2_big.png"), Resource::get()->getTextFile("smb2_big.txt"));
|
||||||
text_nokia2_ = std::make_unique<Text>(asset_->get("nokia2.png"), asset_->get("nokia2.txt"), renderer_);
|
text_nokia2_ = std::make_unique<Text>(Resource::get()->getTexture("nokia2.png"), Resource::get()->getTextFile("nokia2.txt"));
|
||||||
text_nokia2_big_ = std::make_unique<Text>(asset_->get("nokia_big2.png"), asset_->get("nokia_big2.txt"), renderer_);
|
text_nokia2_big_ = std::make_unique<Text>(Resource::get()->getTexture("nokia_big2.png"), Resource::get()->getTextFile("nokia_big2.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sonidos
|
|
||||||
{
|
|
||||||
balloon_sound_ = JA_LoadSound(asset_->get("balloon.wav").c_str());
|
|
||||||
bubble1_sound_ = JA_LoadSound(asset_->get("bubble1.wav").c_str());
|
|
||||||
bubble2_sound_ = JA_LoadSound(asset_->get("bubble2.wav").c_str());
|
|
||||||
bubble3_sound_ = JA_LoadSound(asset_->get("bubble3.wav").c_str());
|
|
||||||
bubble4_sound_ = JA_LoadSound(asset_->get("bubble4.wav").c_str());
|
|
||||||
bullet_sound_ = JA_LoadSound(asset_->get("bullet.wav").c_str());
|
|
||||||
clock_sound_ = JA_LoadSound(asset_->get("clock.wav").c_str());
|
|
||||||
coffee_out_sound_ = JA_LoadSound(asset_->get("coffeeout.wav").c_str());
|
|
||||||
hi_score_sound_ = JA_LoadSound(asset_->get("hiscore.wav").c_str());
|
|
||||||
item_drop_sound_ = JA_LoadSound(asset_->get("itemdrop.wav").c_str());
|
|
||||||
item_pick_up_sound_ = JA_LoadSound(asset_->get("itempickup.wav").c_str());
|
|
||||||
player_collision_sound_ = JA_LoadSound(asset_->get("player_collision.wav").c_str());
|
|
||||||
power_ball_sound_ = JA_LoadSound(asset_->get("powerball.wav").c_str());
|
|
||||||
stage_change_sound_ = JA_LoadSound(asset_->get("stage_change.wav").c_str());
|
|
||||||
coffee_machine_sound_ = JA_LoadSound(asset_->get("title.wav").c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "** RESOURCES FOR GAME SECTION LOADED\n"
|
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera los recursos previamente cargados
|
// Libera los recursos previamente cargados
|
||||||
@@ -467,118 +418,8 @@ void Game::unloadMedia()
|
|||||||
balloon_animations_.clear();
|
balloon_animations_.clear();
|
||||||
explosions_animations_.clear();
|
explosions_animations_.clear();
|
||||||
item_animations_.clear();
|
item_animations_.clear();
|
||||||
|
|
||||||
// Sonidos
|
|
||||||
JA_DeleteSound(balloon_sound_);
|
|
||||||
JA_DeleteSound(bullet_sound_);
|
|
||||||
JA_DeleteSound(player_collision_sound_);
|
|
||||||
JA_DeleteSound(hi_score_sound_);
|
|
||||||
JA_DeleteSound(item_drop_sound_);
|
|
||||||
JA_DeleteSound(item_pick_up_sound_);
|
|
||||||
JA_DeleteSound(coffee_out_sound_);
|
|
||||||
JA_DeleteSound(stage_change_sound_);
|
|
||||||
JA_DeleteSound(bubble1_sound_);
|
|
||||||
JA_DeleteSound(bubble2_sound_);
|
|
||||||
JA_DeleteSound(bubble3_sound_);
|
|
||||||
JA_DeleteSound(bubble4_sound_);
|
|
||||||
JA_DeleteSound(clock_sound_);
|
|
||||||
JA_DeleteSound(power_ball_sound_);
|
|
||||||
JA_DeleteSound(coffee_machine_sound_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga el fichero de datos para la demo
|
|
||||||
bool Game::loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA])
|
|
||||||
{
|
|
||||||
// Indicador de éxito en la carga
|
|
||||||
auto success = true;
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
|
||||||
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
|
|
||||||
if (!file)
|
|
||||||
{ // El fichero no existe
|
|
||||||
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
|
||||||
|
|
||||||
// Creamos el fichero para escritura
|
|
||||||
file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
|
||||||
|
|
||||||
// Si ha creado el fichero
|
|
||||||
if (file)
|
|
||||||
{
|
|
||||||
std::cout << "New file (" << file_name.c_str() << ") created!" << std::endl;
|
|
||||||
|
|
||||||
// Inicializas los datos y los guarda en el fichero
|
|
||||||
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
|
||||||
{
|
|
||||||
DemoKeys dk;
|
|
||||||
dk.left = 0;
|
|
||||||
dk.right = 0;
|
|
||||||
dk.no_input = 0;
|
|
||||||
dk.fire = 0;
|
|
||||||
dk.fire_left = 0;
|
|
||||||
dk.fire_right = 0;
|
|
||||||
(*data_file)[i] = dk;
|
|
||||||
SDL_RWwrite(file, &dk, sizeof(DemoKeys), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cerramos el fichero
|
|
||||||
SDL_RWclose(file);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Si no puede crear el fichero
|
|
||||||
std::cout << "Error: Unable to create file " << file_name.c_str() << std::endl;
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// El fichero existe
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Mensaje de proceder a la carga de los datos
|
|
||||||
std::cout << "Reading file: " << file_name.c_str() << std::endl;
|
|
||||||
|
|
||||||
// Lee todos los datos del fichero y los deja en el destino
|
|
||||||
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
|
||||||
{
|
|
||||||
DemoKeys tmp;
|
|
||||||
SDL_RWread(file, &tmp, sizeof(DemoKeys), 1);
|
|
||||||
(*data_file)[i] = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cierra el fichero
|
|
||||||
SDL_RWclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef RECORDING
|
|
||||||
// Guarda el fichero de datos para la demo
|
|
||||||
bool Game::saveDemoFile(const std::string &file_path)
|
|
||||||
{
|
|
||||||
auto success = true;
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
|
||||||
|
|
||||||
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
|
||||||
if (file)
|
|
||||||
{
|
|
||||||
// Guarda los datos
|
|
||||||
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
|
||||||
{
|
|
||||||
SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(DemoKeys), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "Writing file " << file_name.c_str() << std::endl;
|
|
||||||
|
|
||||||
// Cierra el fichero
|
|
||||||
SDL_RWclose(file);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
#endif // RECORDING
|
|
||||||
|
|
||||||
// Crea una formación de enemigos
|
// Crea una formación de enemigos
|
||||||
void Game::deployBalloonFormation()
|
void Game::deployBalloonFormation()
|
||||||
{
|
{
|
||||||
@@ -598,7 +439,7 @@ void Game::deployBalloonFormation()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Decrementa el contador de despliegues enemigos de la PowerBall
|
// Decrementa el contador de despliegues enemigos de la PowerBall
|
||||||
power_ball_counter_ > 0 ? power_ball_counter_-- : power_ball_counter_ = 0;
|
power_ball_counter_ = (power_ball_counter_ > 0) ? (power_ball_counter_ - 1) : 0;
|
||||||
|
|
||||||
// Elige una formación enemiga la azar
|
// Elige una formación enemiga la azar
|
||||||
auto set = rand() % 10;
|
auto set = rand() % 10;
|
||||||
@@ -649,7 +490,7 @@ void Game::updateHiScore()
|
|||||||
if (hi_score_achieved_ == false)
|
if (hi_score_achieved_ == false)
|
||||||
{
|
{
|
||||||
hi_score_achieved_ = true;
|
hi_score_achieved_ = true;
|
||||||
JA_PlaySound(hi_score_sound_);
|
JA_PlaySound(Resource::get()->getSound("hiscore.wav"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -725,7 +566,7 @@ void Game::updateStage()
|
|||||||
updateHiScore();
|
updateHiScore();
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
}
|
}
|
||||||
JA_PlaySound(stage_change_sound_);
|
JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
|
||||||
stage_bitmap_counter_ = 0;
|
stage_bitmap_counter_ = 0;
|
||||||
balloon_speed_ = default_balloon_speed_;
|
balloon_speed_ = default_balloon_speed_;
|
||||||
setBalloonSpeed(balloon_speed_);
|
setBalloonSpeed(balloon_speed_);
|
||||||
@@ -734,7 +575,7 @@ void Game::updateStage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Incrementa el contador del bitmap que aparece mostrando el cambio de fase
|
// Incrementa el contador del bitmap que aparece mostrando el cambio de fase
|
||||||
if (stage_bitmap_counter_ < STAGE_COUNTER)
|
if (stage_bitmap_counter_ < STAGE_COUNTER_)
|
||||||
{
|
{
|
||||||
stage_bitmap_counter_++;
|
stage_bitmap_counter_++;
|
||||||
}
|
}
|
||||||
@@ -763,7 +604,11 @@ void Game::updateGameOver()
|
|||||||
{
|
{
|
||||||
// Hace sonar aleatoriamente uno de los 4 sonidos de burbujas
|
// Hace sonar aleatoriamente uno de los 4 sonidos de burbujas
|
||||||
const auto index = rand() % 4;
|
const auto index = rand() % 4;
|
||||||
JA_Sound_t *sound[4] = {bubble1_sound_, bubble2_sound_, bubble3_sound_, bubble4_sound_};
|
JA_Sound_t *sound[4] = {
|
||||||
|
Resource::get()->getSound("bubble1.wav"),
|
||||||
|
Resource::get()->getSound("bubble2.wav"),
|
||||||
|
Resource::get()->getSound("bubble3.wav"),
|
||||||
|
Resource::get()->getSound("bubble4.wav")};
|
||||||
JA_PlaySound(sound[index], 0);
|
JA_PlaySound(sound[index], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -802,9 +647,8 @@ void Game::renderBalloons()
|
|||||||
std::shared_ptr<Balloon> Game::createBalloon(float x, int y, int kind, float velx, float speed, int creation_timer)
|
std::shared_ptr<Balloon> Game::createBalloon(float x, int y, int kind, float velx, float speed, int creation_timer)
|
||||||
{
|
{
|
||||||
const auto index = (kind - 1) % 4;
|
const auto index = (kind - 1) % 4;
|
||||||
auto b = std::make_shared<Balloon>(x, y, kind, velx, speed, creation_timer, balloon_textures_[index], balloon_animations_[index]);
|
balloons_.emplace_back(std::make_shared<Balloon>(x, y, kind, velx, speed, creation_timer, balloon_textures_[index], balloon_animations_[index]));
|
||||||
balloons_.push_back(b);
|
return balloons_.back();
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea una PowerBall
|
// Crea una PowerBall
|
||||||
@@ -903,11 +747,11 @@ void Game::popBalloon(std::shared_ptr<Balloon> balloon)
|
|||||||
{ // En cualquier otro caso, crea dos globos de un tipo inferior
|
{ // En cualquier otro caso, crea dos globos de un tipo inferior
|
||||||
auto balloon_left = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, balloon_speed_, 0);
|
auto balloon_left = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, balloon_speed_, 0);
|
||||||
balloon_left->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
balloon_left->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||||
balloon_left->setVelY(balloon_left->getClass() == BALLOON_CLASS ? -2.50f : BALLOON_VELX_NEGATIVE);
|
balloon_left->setVelY(balloon_left->getClass() == BALLOON_CLASS ? -2.50f : BALLOON_VELX_NEGATIVE * 2.0f);
|
||||||
|
|
||||||
auto balloon_right = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, balloon_speed_, 0);
|
auto balloon_right = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, balloon_speed_, 0);
|
||||||
balloon_right->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
balloon_right->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||||
balloon_right->setVelY(balloon_right->getClass() == BALLOON_CLASS ? -2.50f : BALLOON_VELX_NEGATIVE);
|
balloon_right->setVelY(balloon_right->getClass() == BALLOON_CLASS ? -2.50f : BALLOON_VELX_NEGATIVE * 2.0f);
|
||||||
|
|
||||||
// Elimina el globo
|
// Elimina el globo
|
||||||
explosions_->add(balloon->getPosX(), balloon->getPosY(), size);
|
explosions_->add(balloon->getPosX(), balloon->getPosY(), size);
|
||||||
@@ -991,7 +835,7 @@ void Game::destroyAllBalloons()
|
|||||||
}
|
}
|
||||||
|
|
||||||
balloon_deploy_counter_ = 300;
|
balloon_deploy_counter_ = 300;
|
||||||
JA_PlaySound(power_ball_sound_);
|
JA_PlaySound(Resource::get()->getSound("powerball.wav"));
|
||||||
screen_->flash(flash_color, 5);
|
screen_->flash(flash_color, 5);
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
}
|
}
|
||||||
@@ -1119,7 +963,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
JA_PlaySound(item_pick_up_sound_);
|
JA_PlaySound(Resource::get()->getSound("itempickup.wav"));
|
||||||
item->disable();
|
item->disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1154,7 +998,7 @@ void Game::checkBulletBalloonCollision()
|
|||||||
if (droppeditem != ItemType::COFFEE_MACHINE)
|
if (droppeditem != ItemType::COFFEE_MACHINE)
|
||||||
{
|
{
|
||||||
createItem(droppeditem, balloon->getPosX(), balloon->getPosY());
|
createItem(droppeditem, balloon->getPosX(), balloon->getPosY());
|
||||||
JA_PlaySound(item_drop_sound_);
|
JA_PlaySound(Resource::get()->getSound("itemdrop.wav"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1167,7 +1011,7 @@ void Game::checkBulletBalloonCollision()
|
|||||||
popBalloon(balloon);
|
popBalloon(balloon);
|
||||||
|
|
||||||
// Sonido de explosión
|
// Sonido de explosión
|
||||||
JA_PlaySound(balloon_sound_);
|
JA_PlaySound(Resource::get()->getSound("balloon.wav"));
|
||||||
|
|
||||||
// Deshabilita la bala
|
// Deshabilita la bala
|
||||||
bullet->disable();
|
bullet->disable();
|
||||||
@@ -1209,8 +1053,7 @@ void Game::renderBullets()
|
|||||||
// Crea un objeto bala
|
// Crea un objeto bala
|
||||||
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner)
|
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner)
|
||||||
{
|
{
|
||||||
auto b = std::make_unique<Bullet>(x, y, kind, powered_up, owner, &(param.game.play_area.rect), bullet_texture_);
|
bullets_.emplace_back(std::make_unique<Bullet>(x, y, kind, powered_up, owner, &(param.game.play_area.rect), bullet_texture_));
|
||||||
bullets_.push_back(std::move(b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vacia el vector de balas
|
// Vacia el vector de balas
|
||||||
@@ -1238,7 +1081,7 @@ void Game::updateItems()
|
|||||||
item->update();
|
item->update();
|
||||||
if (item->isOnFloor())
|
if (item->isOnFloor())
|
||||||
{
|
{
|
||||||
JA_PlaySound(coffee_machine_sound_);
|
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1293,7 +1136,7 @@ ItemType Game::dropItem()
|
|||||||
case 4:
|
case 4:
|
||||||
if (lucky_number < helper_.item_coffee_odds)
|
if (lucky_number < helper_.item_coffee_odds)
|
||||||
{
|
{
|
||||||
helper_.item_coffee_odds = ITEM_COFFEE_ODDS;
|
helper_.item_coffee_odds = ITEM_COFFEE_ODDS_;
|
||||||
return ItemType::COFFEE;
|
return ItemType::COFFEE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1308,7 +1151,7 @@ ItemType Game::dropItem()
|
|||||||
case 5:
|
case 5:
|
||||||
if (lucky_number < helper_.item_coffee_machine_odds)
|
if (lucky_number < helper_.item_coffee_machine_odds)
|
||||||
{
|
{
|
||||||
helper_.item_coffee_machine_odds = ITEM_COFFEE_MACHINE_ODDS;
|
helper_.item_coffee_machine_odds = ITEM_COFFEE_MACHINE_ODDS_;
|
||||||
if (!coffee_machine_enabled_ && helper_.need_coffee_machine)
|
if (!coffee_machine_enabled_ && helper_.need_coffee_machine)
|
||||||
{
|
{
|
||||||
return ItemType::COFFEE_MACHINE;
|
return ItemType::COFFEE_MACHINE;
|
||||||
@@ -1439,7 +1282,7 @@ void Game::killPlayer(std::shared_ptr<Player> &player)
|
|||||||
// Lo pierde
|
// Lo pierde
|
||||||
player->removeExtraHit();
|
player->removeExtraHit();
|
||||||
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
||||||
JA_PlaySound(coffee_out_sound_);
|
JA_PlaySound(Resource::get()->getSound("coffeeout.wav"));
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1450,9 +1293,9 @@ void Game::killPlayer(std::shared_ptr<Player> &player)
|
|||||||
JA_PauseMusic();
|
JA_PauseMusic();
|
||||||
}
|
}
|
||||||
stopAllBalloons(10);
|
stopAllBalloons(10);
|
||||||
JA_PlaySound(player_collision_sound_);
|
JA_PlaySound(Resource::get()->getSound("player_collision.wav"));
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
JA_PlaySound(coffee_out_sound_);
|
JA_PlaySound(Resource::get()->getSound("coffeeout.wav"));
|
||||||
player->setStatusPlaying(PlayerStatus::DYING);
|
player->setStatusPlaying(PlayerStatus::DYING);
|
||||||
if (!demo_.enabled)
|
if (!demo_.enabled)
|
||||||
{
|
{
|
||||||
@@ -1507,7 +1350,7 @@ void Game::updateTimeStoppedCounter()
|
|||||||
if (time_stopped_counter_ > 0)
|
if (time_stopped_counter_ > 0)
|
||||||
{
|
{
|
||||||
time_stopped_counter_--;
|
time_stopped_counter_--;
|
||||||
stopAllBalloons(TIME_STOPPED_COUNTER);
|
stopAllBalloons(TIME_STOPPED_COUNTER_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1529,7 +1372,7 @@ void Game::updateBalloonDeployCounter()
|
|||||||
void Game::update()
|
void Game::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
if (SDL_GetTicks() - ticks_ > TICKS_SPEED_)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
@@ -1565,9 +1408,9 @@ void Game::update()
|
|||||||
checkInput();
|
checkInput();
|
||||||
|
|
||||||
// Incrementa el contador de la demo
|
// Incrementa el contador de la demo
|
||||||
if (demo.counter < TOTAL_DEMO_DATA)
|
if (demo_.counter < TOTAL_DEMO_DATA)
|
||||||
{
|
{
|
||||||
demo.counter++;
|
demo_.counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si se ha llenado el vector con datos, sale del programa
|
// Si se ha llenado el vector con datos, sale del programa
|
||||||
@@ -1755,7 +1598,7 @@ void Game::updateMenace()
|
|||||||
void Game::renderMessages()
|
void Game::renderMessages()
|
||||||
{
|
{
|
||||||
// GetReady
|
// GetReady
|
||||||
if (counter_ < STAGE_COUNTER && !demo_.enabled)
|
if (counter_ < STAGE_COUNTER_ && !demo_.enabled)
|
||||||
{
|
{
|
||||||
text_nokia2_big_->write((int)get_ready_bitmap_path_[counter_], param.game.play_area.center_y - 8, lang::getText(75), -2);
|
text_nokia2_big_->write((int)get_ready_bitmap_path_[counter_], param.game.play_area.center_y - 8, lang::getText(75), -2);
|
||||||
}
|
}
|
||||||
@@ -1772,20 +1615,20 @@ void Game::renderMessages()
|
|||||||
{
|
{
|
||||||
if (time_stopped_counter_ % 30 == 0)
|
if (time_stopped_counter_ % 30 == 0)
|
||||||
{
|
{
|
||||||
JA_PlaySound(clock_sound_);
|
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (time_stopped_counter_ % 15 == 0)
|
if (time_stopped_counter_ % 15 == 0)
|
||||||
{
|
{
|
||||||
JA_PlaySound(clock_sound_);
|
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// STAGE NUMBER
|
// STAGE NUMBER
|
||||||
if (stage_bitmap_counter_ < STAGE_COUNTER)
|
if (stage_bitmap_counter_ < STAGE_COUNTER_)
|
||||||
{
|
{
|
||||||
const auto stage_number = balloon_formations_->getStage(current_stage_).number;
|
const auto stage_number = balloon_formations_->getStage(current_stage_).number;
|
||||||
std::string text;
|
std::string text;
|
||||||
@@ -1815,9 +1658,9 @@ void Game::renderMessages()
|
|||||||
// Habilita el efecto del item de detener el tiempo
|
// Habilita el efecto del item de detener el tiempo
|
||||||
void Game::enableTimeStopItem()
|
void Game::enableTimeStopItem()
|
||||||
{
|
{
|
||||||
stopAllBalloons(TIME_STOPPED_COUNTER);
|
stopAllBalloons(TIME_STOPPED_COUNTER_);
|
||||||
setTimeStopped(true);
|
setTimeStopped(true);
|
||||||
incTimeStoppedCounter(TIME_STOPPED_COUNTER);
|
incTimeStoppedCounter(TIME_STOPPED_COUNTER_);
|
||||||
if (JA_GetMusicState() == JA_MUSIC_PLAYING && !demo_.enabled)
|
if (JA_GetMusicState() == JA_MUSIC_PLAYING && !demo_.enabled)
|
||||||
{
|
{
|
||||||
JA_PauseMusic();
|
JA_PauseMusic();
|
||||||
@@ -1843,7 +1686,7 @@ void Game::checkMusicStatus()
|
|||||||
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
|
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
|
||||||
{
|
{
|
||||||
// Si se ha completado el juego o los jugadores han terminado, detiene la música
|
// Si se ha completado el juego o los jugadores han terminado, detiene la música
|
||||||
game_completed_ || allPlayersAreGameOver() ? JA_StopMusic() : JA_PlayMusic(music_);
|
game_completed_ || allPlayersAreGameOver() ? JA_StopMusic() : JA_PlayMusic(Resource::get()->getMusic("playing.ogg"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1888,7 +1731,7 @@ void Game::initPaths()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Letrero de STAGE #
|
// Letrero de STAGE #
|
||||||
constexpr auto first_part = STAGE_COUNTER / 4; // 50
|
constexpr auto first_part = STAGE_COUNTER_ / 4; // 50
|
||||||
constexpr auto second_part = first_part * 3; // 150
|
constexpr auto second_part = first_part * 3; // 150
|
||||||
const auto center_point = param.game.play_area.center_y - (BLOCK * 2);
|
const auto center_point = param.game.play_area.center_y - (BLOCK * 2);
|
||||||
const auto distance = (param.game.play_area.rect.h) - (param.game.play_area.center_y - 16);
|
const auto distance = (param.game.play_area.rect.h) - (param.game.play_area.center_y - 16);
|
||||||
@@ -1903,7 +1746,7 @@ void Game::initPaths()
|
|||||||
stage_bitmap_path_[i] = (int)center_point;
|
stage_bitmap_path_[i] = (int)center_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = second_part; i < STAGE_COUNTER; ++i)
|
for (int i = second_part; i < STAGE_COUNTER_; ++i)
|
||||||
{
|
{
|
||||||
stage_bitmap_path_[i] = (sin[(int)(((i - 149) * 1.8f) + 90)] * (center_point + 17) - 17);
|
stage_bitmap_path_[i] = (sin[(int)(((i - 149) * 1.8f) + 90)] * (center_point + 17) - 17);
|
||||||
}
|
}
|
||||||
@@ -1930,7 +1773,7 @@ void Game::initPaths()
|
|||||||
get_ready_bitmap_path_[i] = (int)finish1;
|
get_ready_bitmap_path_[i] = (int)finish1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = second_part; i < STAGE_COUNTER; ++i)
|
for (int i = second_part; i < STAGE_COUNTER_; ++i)
|
||||||
{
|
{
|
||||||
get_ready_bitmap_path_[i] = sin[(int)((i - second_part) * 1.8f)];
|
get_ready_bitmap_path_[i] = sin[(int)((i - second_part) * 1.8f)];
|
||||||
get_ready_bitmap_path_[i] *= distance2;
|
get_ready_bitmap_path_[i] *= distance2;
|
||||||
@@ -1946,7 +1789,7 @@ void Game::updateGameCompleted()
|
|||||||
game_completed_counter_++;
|
game_completed_counter_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game_completed_counter_ == GAME_COMPLETED_END)
|
if (game_completed_counter_ == GAME_COMPLETED_END_)
|
||||||
{
|
{
|
||||||
section::name = section::Name::TITLE;
|
section::name = section::Name::TITLE;
|
||||||
section::options = section::Options::TITLE_1;
|
section::options = section::Options::TITLE_1;
|
||||||
@@ -2022,6 +1865,7 @@ void Game::checkEvents()
|
|||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section::name = section::Name::QUIT;
|
section::name = section::Name::QUIT;
|
||||||
|
section::options = section::Options::QUIT_FROM_EVENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2093,20 +1937,6 @@ void Game::checkEvents()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ralentiza mucho la lógica
|
|
||||||
case SDLK_4:
|
|
||||||
{
|
|
||||||
ticks_speed_ *= 10;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Acelera mucho la lógica
|
|
||||||
case SDLK_5:
|
|
||||||
{
|
|
||||||
ticks_speed_ /= 10;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2115,27 +1945,6 @@ void Game::checkEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga las animaciones
|
|
||||||
std::vector<std::string> Game::loadAnimations(const std::string &file_path)
|
|
||||||
{
|
|
||||||
std::vector<std::string> buffer;
|
|
||||||
std::ifstream file(file_path);
|
|
||||||
if (!file)
|
|
||||||
{
|
|
||||||
std::cerr << "Error: no se pudo abrir el archivo " << file_path << std::endl;
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string line;
|
|
||||||
std::cout << "Animation loaded: " << file_path.substr(file_path.find_last_of("\\/") + 1) << std::endl;
|
|
||||||
while (std::getline(file, line))
|
|
||||||
{
|
|
||||||
buffer.push_back(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Elimina todos los objetos contenidos en vectores
|
// Elimina todos los objetos contenidos en vectores
|
||||||
void Game::deleteAllVectorObjects()
|
void Game::deleteAllVectorObjects()
|
||||||
{
|
{
|
||||||
@@ -2327,7 +2136,7 @@ void Game::handleDemoMode()
|
|||||||
// Incluye movimientos (izquierda, derecha, sin movimiento) y disparos automáticos.
|
// Incluye movimientos (izquierda, derecha, sin movimiento) y disparos automáticos.
|
||||||
void Game::handleDemoPlayerInput(const std::shared_ptr<Player> &player, int index)
|
void Game::handleDemoPlayerInput(const std::shared_ptr<Player> &player, int index)
|
||||||
{
|
{
|
||||||
const auto &demoData = demo_.data_file[index][demo_.counter];
|
const auto &demoData = demo_.data[index][demo_.counter];
|
||||||
|
|
||||||
if (demoData.left == 1)
|
if (demoData.left == 1)
|
||||||
player->setInput(InputType::LEFT);
|
player->setInput(InputType::LEFT);
|
||||||
@@ -2352,6 +2161,7 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
|
|||||||
player->setInput(bulletType == BulletType::UP ? InputType::FIRE_CENTER : bulletType == BulletType::LEFT ? InputType::FIRE_LEFT
|
player->setInput(bulletType == BulletType::UP ? InputType::FIRE_CENTER : bulletType == BulletType::LEFT ? InputType::FIRE_LEFT
|
||||||
: InputType::FIRE_RIGHT);
|
: InputType::FIRE_RIGHT);
|
||||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
|
||||||
|
JA_PlaySound(Resource::get()->getSound("bullet.wav"));
|
||||||
player->setFireCooldown(10); // Establece un tiempo de espera para el próximo disparo.
|
player->setFireCooldown(10); // Establece un tiempo de espera para el próximo disparo.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2386,21 +2196,21 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
|
|||||||
{
|
{
|
||||||
player->setInput(InputType::LEFT);
|
player->setInput(InputType::LEFT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo.keys.left = 1;
|
demo_.keys.left = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (input_->checkInput(InputType::RIGHT, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::RIGHT, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||||
{
|
{
|
||||||
player->setInput(InputType::RIGHT);
|
player->setInput(InputType::RIGHT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo.keys.right = 1;
|
demo_.keys.right = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player->setInput(InputType::NONE);
|
player->setInput(InputType::NONE);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo.keys.no_input = 1;
|
demo_.keys.no_input = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2414,21 +2224,21 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
|
|||||||
{
|
{
|
||||||
handleFireInput(player, BulletType::UP);
|
handleFireInput(player, BulletType::UP);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo.keys.fire = 1;
|
demo_.keys.fire = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (input_->checkInput(InputType::FIRE_LEFT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::FIRE_LEFT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||||
{
|
{
|
||||||
handleFireInput(player, BulletType::LEFT);
|
handleFireInput(player, BulletType::LEFT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo.keys.fire_left = 1;
|
demo_.keys.fire_left = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
||||||
{
|
{
|
||||||
handleFireInput(player, BulletType::RIGHT);
|
handleFireInput(player, BulletType::RIGHT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo.keys.fire_right = 1;
|
demo_.keys.fire_right = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,26 +32,6 @@ constexpr bool GAME_MODE_DEMO_ON = true;
|
|||||||
|
|
||||||
// Cantidad de elementos a escribir en los ficheros de datos
|
// Cantidad de elementos a escribir en los ficheros de datos
|
||||||
constexpr int TOTAL_SCORE_DATA = 3;
|
constexpr int TOTAL_SCORE_DATA = 3;
|
||||||
constexpr int TOTAL_DEMO_DATA = 2000;
|
|
||||||
|
|
||||||
// Contadores
|
|
||||||
constexpr int STAGE_COUNTER = 200;
|
|
||||||
constexpr int HELP_COUNTER = 1000;
|
|
||||||
constexpr int GAME_COMPLETED_START_FADE = 500;
|
|
||||||
constexpr int GAME_COMPLETED_END = 700;
|
|
||||||
constexpr int GAME_OVER_COUNTER = 350;
|
|
||||||
|
|
||||||
// Porcentaje de aparición de los objetos
|
|
||||||
constexpr int ITEM_POINTS_1_DISK_ODDS = 10;
|
|
||||||
constexpr int ITEM_POINTS_2_GAVINA_ODDS = 6;
|
|
||||||
constexpr int ITEM_POINTS_3_PACMAR_ODDS = 3;
|
|
||||||
constexpr int ITEM_CLOCK_ODDS = 5;
|
|
||||||
constexpr int ITEM_COFFEE_ODDS = 5;
|
|
||||||
constexpr int ITEM_POWER_BALL_ODDS = 0;
|
|
||||||
constexpr int ITEM_COFFEE_MACHINE_ODDS = 4;
|
|
||||||
|
|
||||||
// Valores para las variables asociadas a los objetos
|
|
||||||
constexpr int TIME_STOPPED_COUNTER = 300;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Esta clase gestiona un estado del programa. Se encarga de toda la parte en la
|
Esta clase gestiona un estado del programa. Se encarga de toda la parte en la
|
||||||
@@ -83,6 +63,7 @@ constexpr int TIME_STOPPED_COUNTER = 300;
|
|||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
// Estructuras
|
||||||
struct Helper
|
struct Helper
|
||||||
{
|
{
|
||||||
bool need_coffee; // Indica si se necesitan cafes
|
bool need_coffee; // Indica si se necesitan cafes
|
||||||
@@ -97,14 +78,25 @@ private:
|
|||||||
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
|
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Demo
|
// Constantes
|
||||||
{
|
|
||||||
bool enabled; // Indica si está activo el modo demo
|
// Contadores
|
||||||
bool recording; // Indica si está activado el modo para grabar la demo
|
static constexpr int STAGE_COUNTER_ = 200;
|
||||||
int counter; // Contador para el modo demo
|
static constexpr int HELP_COUNTER_ = 1000;
|
||||||
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
|
static constexpr int GAME_COMPLETED_START_FADE_ = 500;
|
||||||
DemoKeys data_file[2][TOTAL_DEMO_DATA]; // Vector con diferentes sets de datos con los movimientos para la demo
|
static constexpr int GAME_COMPLETED_END_ = 700;
|
||||||
};
|
static constexpr int GAME_OVER_COUNTER_ = 350;
|
||||||
|
static constexpr int TIME_STOPPED_COUNTER_ = 300;
|
||||||
|
static constexpr int TICKS_SPEED_ = 15;
|
||||||
|
|
||||||
|
// Porcentaje de aparición de los objetos
|
||||||
|
static constexpr int ITEM_POINTS_1_DISK_ODDS_ = 10;
|
||||||
|
static constexpr int ITEM_POINTS_2_GAVINA_ODDS_ = 6;
|
||||||
|
static constexpr int ITEM_POINTS_3_PACMAR_ODDS_ = 3;
|
||||||
|
static constexpr int ITEM_CLOCK_ODDS_ = 5;
|
||||||
|
static constexpr int ITEM_COFFEE_ODDS_ = 5;
|
||||||
|
static constexpr int ITEM_POWER_BALL_ODDS_ = 0;
|
||||||
|
static constexpr int ITEM_COFFEE_MACHINE_ODDS_ = 4;
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
@@ -145,33 +137,14 @@ private:
|
|||||||
|
|
||||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||||
|
|
||||||
JA_Sound_t *balloon_sound_; // Sonido para la explosión del globo
|
|
||||||
JA_Sound_t *bullet_sound_; // Sonido para los disparos
|
|
||||||
JA_Sound_t *player_collision_sound_; // Sonido para la colisión del jugador con un enemigo
|
|
||||||
JA_Sound_t *hi_score_sound_; // Sonido para cuando se alcanza la máxima puntuación
|
|
||||||
JA_Sound_t *item_drop_sound_; // Sonido para cuando se genera un item
|
|
||||||
JA_Sound_t *item_pick_up_sound_; // Sonido para cuando se recoge un item
|
|
||||||
JA_Sound_t *coffee_out_sound_; // Sonido para cuando el jugador pierde el café al recibir un impacto
|
|
||||||
JA_Sound_t *stage_change_sound_; // Sonido para cuando se cambia de fase
|
|
||||||
JA_Sound_t *bubble1_sound_; // Sonido para cuando el jugador muere
|
|
||||||
JA_Sound_t *bubble2_sound_; // Sonido para cuando el jugador muere
|
|
||||||
JA_Sound_t *bubble3_sound_; // Sonido para cuando el jugador muere
|
|
||||||
JA_Sound_t *bubble4_sound_; // Sonido para cuando el jugador muere
|
|
||||||
JA_Sound_t *clock_sound_; // Sonido para cuando se detiene el tiempo con el item reloj
|
|
||||||
JA_Sound_t *power_ball_sound_; // Sonido para cuando se explota una Power Ball
|
|
||||||
JA_Sound_t *coffee_machine_sound_; // Sonido para cuando la máquina de café toca el suelo
|
|
||||||
|
|
||||||
JA_Music_t *music_; // Musica de fondo
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
bool hi_score_achieved_; // Indica si se ha superado la puntuación máxima
|
bool hi_score_achieved_; // Indica si se ha superado la puntuación máxima
|
||||||
HiScoreEntry hi_score_; // Máxima puntuación y nombre de quien la ostenta
|
HiScoreEntry hi_score_; // Máxima puntuación y nombre de quien la ostenta
|
||||||
int current_stage_; // Indica la fase actual
|
int current_stage_; // Indica la fase actual
|
||||||
int stage_bitmap_counter_; // Contador para el tiempo visible del texto de Stage
|
int stage_bitmap_counter_; // Contador para el tiempo visible del texto de Stage
|
||||||
float stage_bitmap_path_[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
|
float stage_bitmap_path_[STAGE_COUNTER_]; // Vector con los puntos Y por donde se desplaza el texto
|
||||||
float get_ready_bitmap_path_[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
|
float get_ready_bitmap_path_[STAGE_COUNTER_]; // Vector con los puntos X por donde se desplaza el texto
|
||||||
int game_over_counter_; // Contador para el estado de fin de partida
|
int game_over_counter_; // Contador para el estado de fin de partida
|
||||||
int menace_current_; // Nivel de amenaza actual
|
int menace_current_; // Nivel de amenaza actual
|
||||||
int menace_threshold_; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
int menace_threshold_; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
||||||
@@ -219,12 +192,6 @@ private:
|
|||||||
// Libera los recursos previamente cargados
|
// Libera los recursos previamente cargados
|
||||||
void unloadMedia();
|
void unloadMedia();
|
||||||
|
|
||||||
// Carga el fichero de datos para la demo
|
|
||||||
bool loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA]);
|
|
||||||
#ifdef RECORDING
|
|
||||||
// Guarda el fichero de datos para la demo
|
|
||||||
bool saveDemoFile(const std::string &file_path);
|
|
||||||
#endif
|
|
||||||
// Crea una formación de enemigos
|
// Crea una formación de enemigos
|
||||||
void deployBalloonFormation();
|
void deployBalloonFormation();
|
||||||
|
|
||||||
@@ -399,9 +366,6 @@ private:
|
|||||||
// Comprueba si todos los jugadores han terminado de jugar
|
// Comprueba si todos los jugadores han terminado de jugar
|
||||||
bool allPlayersAreNotPlaying();
|
bool allPlayersAreNotPlaying();
|
||||||
|
|
||||||
// Carga las animaciones
|
|
||||||
std::vector<std::string> loadAnimations(const std::string &file_path);
|
|
||||||
|
|
||||||
// Elimina todos los objetos contenidos en vectores
|
// Elimina todos los objetos contenidos en vectores
|
||||||
void deleteAllVectorObjects();
|
void deleteAllVectorObjects();
|
||||||
|
|
||||||
@@ -468,7 +432,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(int playerID, int current_stage, bool demo, JA_Music_t *music);
|
Game(int playerID, int current_stage, bool demo);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Game();
|
~Game();
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
#include <algorithm> // for max
|
#include <algorithm> // for max
|
||||||
#include "animated_sprite.h" // for SpriteAnimated
|
#include "animated_sprite.h" // for SpriteAnimated
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound
|
#include "jail_audio.h" // JA_PlaySound
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "smart_sprite.h" // for SpriteSmart
|
#include "smart_sprite.h" // for SpriteSmart
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
@@ -13,20 +14,19 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameLogo::GameLogo(int x, int y)
|
GameLogo::GameLogo(int x, int y)
|
||||||
: dust_texture_(std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"))),
|
: dust_texture_(Resource::get()->getTexture("title_dust.png")),
|
||||||
coffee_texture_(std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"))),
|
coffee_texture_(Resource::get()->getTexture("title_coffee.png")),
|
||||||
crisis_texture_(std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png"))),
|
crisis_texture_(Resource::get()->getTexture("title_crisis.png")),
|
||||||
arcade_edition_texture_(std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"))),
|
arcade_edition_texture_(Resource::get()->getTexture("title_arcade_edition.png")),
|
||||||
|
|
||||||
dust_left_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Asset::get()->get("title_dust.ani"))),
|
dust_left_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Resource::get()->getAnimation("title_dust.ani"))),
|
||||||
dust_right_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Asset::get()->get("title_dust.ani"))),
|
dust_right_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Resource::get()->getAnimation("title_dust.ani"))),
|
||||||
|
|
||||||
coffee_sprite_(std::make_unique<SmartSprite>(coffee_texture_)),
|
coffee_sprite_(std::make_unique<SmartSprite>(coffee_texture_)),
|
||||||
crisis_sprite_(std::make_unique<SmartSprite>(crisis_texture_)),
|
crisis_sprite_(std::make_unique<SmartSprite>(crisis_texture_)),
|
||||||
|
|
||||||
arcade_edition_sprite_(std::make_unique<Sprite>(arcade_edition_texture_, (param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight())),
|
arcade_edition_sprite_(std::make_unique<Sprite>(arcade_edition_texture_, (param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight())),
|
||||||
|
|
||||||
crash_sound_(JA_LoadSound(Asset::get()->get("title.wav").c_str())),
|
|
||||||
|
|
||||||
x_(x),
|
x_(x),
|
||||||
y_(y)
|
y_(y)
|
||||||
@@ -35,12 +35,6 @@ GameLogo::GameLogo(int x, int y)
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
GameLogo::~GameLogo()
|
|
||||||
{
|
|
||||||
JA_DeleteSound(crash_sound_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
void GameLogo::init()
|
void GameLogo::init()
|
||||||
{
|
{
|
||||||
@@ -137,7 +131,7 @@ void GameLogo::update()
|
|||||||
status_ = Status::SHAKING;
|
status_ = Status::SHAKING;
|
||||||
|
|
||||||
// Reproduce el efecto sonoro
|
// Reproduce el efecto sonoro
|
||||||
JA_PlaySound(crash_sound_);
|
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory> // for unique_ptr, shared_ptr
|
#include <memory> // for unique_ptr, shared_ptr
|
||||||
class AnimatedSprite;
|
#include "animated_sprite.h"
|
||||||
class SmartSprite;
|
#include "smart_sprite.h"
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Texture;
|
class Texture;
|
||||||
struct JA_Sound_t; // lines 10-10
|
struct JA_Sound_t; // lines 10-10
|
||||||
@@ -43,8 +43,6 @@ private:
|
|||||||
|
|
||||||
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition"
|
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition"
|
||||||
|
|
||||||
JA_Sound_t *crash_sound_; // Sonido con el impacto del título
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int x_; // Posición donde dibujar el logo
|
int x_; // Posición donde dibujar el logo
|
||||||
int y_; // Posición donde dibujar el logo
|
int y_; // Posición donde dibujar el logo
|
||||||
@@ -63,7 +61,7 @@ public:
|
|||||||
GameLogo(int x, int y);
|
GameLogo(int x, int y);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~GameLogo();
|
~GameLogo() = default;
|
||||||
|
|
||||||
// Pinta la clase en pantalla
|
// Pinta la clase en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace globalInputs
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef ARCADE
|
#ifdef ARCADE
|
||||||
const int index = code == section::Options::QUIT_NORMAL ? 94 : 116;
|
const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
||||||
Notifier::get()->showText(lang::getText(index), std::string(), -1, exit_code);
|
Notifier::get()->showText(lang::getText(index), std::string(), -1, exit_code);
|
||||||
#else
|
#else
|
||||||
Notifier::get()->showText(lang::getText(94), std::string(), -1, exit_code);
|
Notifier::get()->showText(lang::getText(94), std::string(), -1, exit_code);
|
||||||
@@ -69,7 +69,7 @@ namespace globalInputs
|
|||||||
// Comprueba si se sale con el teclado
|
// Comprueba si se sale con el teclado
|
||||||
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
quit(section::Options::QUIT_NORMAL);
|
quit(section::Options::QUIT_WITH_KEYBOARD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ namespace globalInputs
|
|||||||
// Comprueba si se sale con el mando
|
// Comprueba si se sale con el mando
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
quit(section::Options::QUIT_SHUTDOWN);
|
quit(section::Options::QUIT_WITH_CONTROLLER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,37 +15,29 @@
|
|||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "options.h" // for options
|
#include "options.h" // for options
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_SHADOW, TEXT...
|
#include "text.h" // for Text, TEXT_CENTER, TEXT_SHADOW, TEXT...
|
||||||
#include "utils.h" // for Param, ParamGame, Color, HiScoreEntry
|
#include "utils.h" // for Param, ParamGame, Color, HiScoreEntry
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable::HiScoreTable(JA_Music_t *music)
|
HiScoreTable::HiScoreTable()
|
||||||
: music_(music)
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
|
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"))),
|
||||||
|
counter_(0),
|
||||||
|
ticks_(0),
|
||||||
|
view_area_({0, 0, param.game.width, param.game.height}),
|
||||||
|
fade_mode_(FadeMode::IN)
|
||||||
{
|
{
|
||||||
// Copia punteros
|
// Inicializa el resto de variables
|
||||||
renderer_ = Screen::get()->getRenderer();
|
|
||||||
|
|
||||||
// Objetos
|
|
||||||
fade_ = std::make_unique<Fade>(renderer_);
|
|
||||||
background_ = std::make_unique<Background>(renderer_);
|
|
||||||
text_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer_);
|
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
|
||||||
backbuffer_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
|
||||||
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
section::name = section::Name::HI_SCORE_TABLE;
|
section::name = section::Name::HI_SCORE_TABLE;
|
||||||
ticks_ = 0;
|
|
||||||
ticks_speed_ = 15;
|
|
||||||
counter_ = 0;
|
|
||||||
counter_end_ = 800;
|
|
||||||
view_area_ = {0, 0, param.game.width, param.game.height};
|
|
||||||
fade_mode_ = FadeMode::IN;
|
|
||||||
|
|
||||||
// Inicializa objetos
|
// Inicializa objetos
|
||||||
|
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
||||||
background_->setPos(param.game.game_area.rect);
|
background_->setPos(param.game.game_area.rect);
|
||||||
background_->setCloudsSpeed(-0.1f);
|
background_->setCloudsSpeed(-0.1f);
|
||||||
background_->setGradientNumber(1);
|
background_->setGradientNumber(1);
|
||||||
@@ -70,7 +62,7 @@ HiScoreTable::~HiScoreTable()
|
|||||||
void HiScoreTable::update()
|
void HiScoreTable::update()
|
||||||
{
|
{
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
if (SDL_GetTicks() - ticks_ > TICKS_SPEED_)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
@@ -78,7 +70,7 @@ void HiScoreTable::update()
|
|||||||
// Mantiene la música sonando
|
// Mantiene la música sonando
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music_);
|
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
@@ -99,7 +91,7 @@ void HiScoreTable::update()
|
|||||||
background_->setAlpha(96);
|
background_->setAlpha(96);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter_ == counter_end_)
|
if (counter_ == COUNTER_END_)
|
||||||
{
|
{
|
||||||
fade_->activate();
|
fade_->activate();
|
||||||
}
|
}
|
||||||
@@ -188,6 +180,7 @@ void HiScoreTable::checkEvents()
|
|||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section::name = section::Name::QUIT;
|
section::name = section::Name::QUIT;
|
||||||
|
section::options = section::Options::QUIT_FROM_EVENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ class Background; // lines 8-8
|
|||||||
class Fade; // lines 9-9
|
class Fade; // lines 9-9
|
||||||
class Text; // lines 10-10
|
class Text; // lines 10-10
|
||||||
enum class FadeMode : Uint8; // lines 11-11
|
enum class FadeMode : Uint8; // lines 11-11
|
||||||
struct JA_Music_t; // lines 12-12
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
|
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
|
||||||
@@ -25,10 +24,13 @@ struct JA_Music_t; // lines 12-12
|
|||||||
class HiScoreTable
|
class HiScoreTable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
// Constantes
|
||||||
|
static constexpr Uint16 COUNTER_END_ = 800; // Valor final para el contador
|
||||||
|
static constexpr Uint32 TICKS_SPEED_ = 15; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
||||||
JA_Music_t *music_; // Musica de fondo
|
|
||||||
|
|
||||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||||
@@ -36,9 +38,7 @@ private:
|
|||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Uint16 counter_; // Contador
|
Uint16 counter_; // Contador
|
||||||
Uint16 counter_end_; // Valor final para el contador
|
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
SDL_Rect view_area_; // Parte de la textura que se muestra en pantalla
|
SDL_Rect view_area_; // Parte de la textura que se muestra en pantalla
|
||||||
FadeMode fade_mode_; // Modo de fade a utilizar
|
FadeMode fade_mode_; // Modo de fade a utilizar
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit HiScoreTable(JA_Music_t *music);
|
HiScoreTable();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~HiScoreTable();
|
~HiScoreTable();
|
||||||
|
|||||||
@@ -416,10 +416,9 @@ bool Input::discoverGameControllers()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||||
std::cout << "\nChecking for game controllers...\n";
|
// std::cout << " " << num_joysticks_ << " joysticks found" << std::endl;
|
||||||
std::cout << num_joysticks_ << " joysticks found, " << num_gamepads_ << " are gamepads\n";
|
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
if (num_gamepads_ > 0)
|
if (num_gamepads_ > 0)
|
||||||
{
|
{
|
||||||
@@ -434,7 +433,7 @@ bool Input::discoverGameControllers()
|
|||||||
connected_controllers_.push_back(pad);
|
connected_controllers_.push_back(pad);
|
||||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||||
{
|
{
|
||||||
std::cout << name << std::endl;
|
std::cout << "#" << i << ": " << name << std::endl;
|
||||||
}
|
}
|
||||||
controller_names_.push_back(name);
|
controller_names_.push_back(name);
|
||||||
}
|
}
|
||||||
@@ -449,6 +448,8 @@ bool Input::discoverGameControllers()
|
|||||||
SDL_GameControllerEventState(SDL_ENABLE);
|
SDL_GameControllerEventState(SDL_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,26 +13,26 @@
|
|||||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
|
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR, TEXT_...
|
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR, TEXT_...
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
#include "tiled_bg.h" // for Tiledbg, TILED_MODE_STATIC
|
#include "tiled_bg.h" // for TiledBG, TILED_MODE_STATIC
|
||||||
#include "utils.h" // for Param, ParamGame, Color, shdw_txt_color
|
#include "utils.h" // for Param, ParamGame, Color, shdw_txt_color
|
||||||
struct JA_Music_t; // lines 22-22
|
struct JA_Music_t; // lines 22-22
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Instructions::Instructions(JA_Music_t *music)
|
Instructions::Instructions()
|
||||||
: music_(music)
|
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
renderer_ = Screen::get()->getRenderer();
|
renderer_ = Screen::get()->getRenderer();
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
text_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer_);
|
text_ = std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"));
|
||||||
tiled_bg_ = std::make_unique<Tiledbg>(Asset::get()->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_STATIC);
|
tiled_bg_ = std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC);
|
||||||
fade_ = std::make_unique<Fade>(renderer_);
|
fade_ = std::make_unique<Fade>();
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
// Crea un backbuffer para el renderizador
|
||||||
backbuffer_ = 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);
|
||||||
@@ -80,20 +80,11 @@ Instructions::~Instructions()
|
|||||||
void Instructions::iniSprites()
|
void Instructions::iniSprites()
|
||||||
{
|
{
|
||||||
// Inicializa las texturas
|
// Inicializa las texturas
|
||||||
auto item1 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_points1_disk.png"));
|
item_textures_.emplace_back(Resource::get()->getTexture("item_points1_disk.png"));
|
||||||
item_textures_.push_back(item1);
|
item_textures_.emplace_back(Resource::get()->getTexture("item_points2_gavina.png"));
|
||||||
|
item_textures_.emplace_back(Resource::get()->getTexture("item_points3_pacmar.png"));
|
||||||
auto item2 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_points2_gavina.png"));
|
item_textures_.emplace_back(Resource::get()->getTexture("item_clock.png"));
|
||||||
item_textures_.push_back(item2);
|
item_textures_.emplace_back(Resource::get()->getTexture("item_coffee.png"));
|
||||||
|
|
||||||
auto item3 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_points3_pacmar.png"));
|
|
||||||
item_textures_.push_back(item3);
|
|
||||||
|
|
||||||
auto item4 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_clock.png"));
|
|
||||||
item_textures_.push_back(item4);
|
|
||||||
|
|
||||||
auto item5 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_coffee.png"));
|
|
||||||
item_textures_.push_back(item5);
|
|
||||||
|
|
||||||
// Inicializa los sprites
|
// Inicializa los sprites
|
||||||
for (int i = 0; i < (int)item_textures_.size(); ++i)
|
for (int i = 0; i < (int)item_textures_.size(); ++i)
|
||||||
@@ -231,7 +222,7 @@ void Instructions::update()
|
|||||||
|
|
||||||
// Mantiene la música sonando
|
// Mantiene la música sonando
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
JA_PlayMusic(music_);
|
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
Screen::get()->update();
|
Screen::get()->update();
|
||||||
@@ -306,6 +297,7 @@ void Instructions::checkEvents()
|
|||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section::name = section::Name::QUIT;
|
section::name = section::Name::QUIT;
|
||||||
|
section::options = section::Options::QUIT_FROM_EVENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class Fade;
|
|||||||
class Sprite;
|
class Sprite;
|
||||||
class Text;
|
class Text;
|
||||||
class Texture;
|
class Texture;
|
||||||
class Tiledbg;
|
class TiledBG;
|
||||||
struct JA_Music_t; // lines 14-14
|
struct JA_Music_t; // lines 14-14
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -33,11 +33,10 @@ private:
|
|||||||
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
|
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::vector<std::unique_ptr<Sprite>> sprites_; // Vector con los sprites de los items
|
||||||
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
||||||
std::unique_ptr<Tiledbg> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||||
|
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
JA_Music_t *music_; // Musica de fondo
|
|
||||||
SDL_Texture *texture_; // Textura fija con el texto
|
SDL_Texture *texture_; // Textura fija con el texto
|
||||||
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
||||||
|
|
||||||
@@ -79,7 +78,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Instructions(JA_Music_t *music);
|
Instructions();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Instructions();
|
~Instructions();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic
|
#include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
#include "smart_sprite.h" // for SpriteSmart
|
#include "smart_sprite.h" // for SpriteSmart
|
||||||
@@ -19,15 +20,11 @@
|
|||||||
struct JA_Music_t; // lines 19-19
|
struct JA_Music_t; // lines 19-19
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro::Intro(JA_Music_t *music)
|
Intro::Intro()
|
||||||
: music_(music)
|
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
auto renderer = Screen::get()->getRenderer();
|
|
||||||
|
|
||||||
// Reserva memoria para los objetos
|
// Reserva memoria para los objetos
|
||||||
texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("intro.png"));
|
texture_ = Resource::get()->getTexture("intro.png");
|
||||||
text_ = std::make_shared<Text>(Asset::get()->get("nokia.png"), Asset::get()->get("nokia.txt"), renderer);
|
text_ = std::make_shared<Text>(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt"));
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section::name = section::Name::INTRO;
|
section::name = section::Name::INTRO;
|
||||||
@@ -173,6 +170,7 @@ void Intro::checkEvents()
|
|||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
{
|
{
|
||||||
section::name = section::Name::QUIT;
|
section::name = section::Name::QUIT;
|
||||||
|
section::options = section::Options::QUIT_FROM_EVENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,7 +423,7 @@ void Intro::render()
|
|||||||
// Bucle principal
|
// Bucle principal
|
||||||
void Intro::run()
|
void Intro::run()
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music_, 0);
|
JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0);
|
||||||
|
|
||||||
while (section::name == section::Name::INTRO)
|
while (section::name == section::Name::INTRO)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ private:
|
|||||||
// Variables
|
// Variables
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint8 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
Uint8 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||||
JA_Music_t *music_; // Musica para la intro
|
|
||||||
int scene_; // Indica que escena está activa
|
int scene_; // Indica que escena está activa
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -51,7 +50,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Intro(JA_Music_t *music);
|
Intro();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Intro() = default;
|
~Intro() = default;
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ JA_Music_t *JA_LoadMusic(const char* filename) {
|
|||||||
|
|
||||||
void JA_PlayMusic(JA_Music_t *music, const int loop)
|
void JA_PlayMusic(JA_Music_t *music, const int loop)
|
||||||
{
|
{
|
||||||
if (!JA_musicEnabled) return;
|
if (!JA_musicEnabled || !music) return;
|
||||||
|
|
||||||
if (current_music != NULL) {
|
if (current_music != NULL) {
|
||||||
current_music->pos = 0;
|
current_music->pos = 0;
|
||||||
@@ -223,7 +223,7 @@ JA_Sound_t *JA_LoadSound(const char* filename) {
|
|||||||
|
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop)
|
int JA_PlaySound(JA_Sound_t *sound, const int loop)
|
||||||
{
|
{
|
||||||
if (!JA_soundEnabled) return 0;
|
if (!JA_soundEnabled || !sound) return 0;
|
||||||
|
|
||||||
int channel = 0;
|
int channel = 0;
|
||||||
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "input.h" // for Input
|
#include "input.h" // for Input
|
||||||
#include "jail_audio.h" // for JA_StopMusic
|
#include "jail_audio.h" // for JA_StopMusic
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
@@ -16,14 +17,10 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
|
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
|
||||||
|
since_sprite_(std::make_unique<Sprite>(since_texture_)),
|
||||||
|
jail_texture_(Resource::get()->getTexture("logo_jailgames.png"))
|
||||||
{
|
{
|
||||||
// Copia la dirección de los objetos
|
|
||||||
SDL_Renderer *renderer = Screen::get()->getRenderer();
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
|
||||||
jail_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames.png"));
|
|
||||||
since_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_since_1998.png"));
|
|
||||||
since_sprite_ = std::make_unique<Sprite>(since_texture_, (param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight());
|
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
counter_ = 0;
|
counter_ = 0;
|
||||||
@@ -31,6 +28,7 @@ Logo::Logo()
|
|||||||
ticks_ = 0;
|
ticks_ = 0;
|
||||||
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
|
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
|
||||||
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
||||||
|
since_sprite_->setPosition({(param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight()});
|
||||||
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
|
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
|
||||||
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
||||||
since_texture_->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ??
|
since_texture_->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ??
|
||||||
@@ -75,6 +73,7 @@ void Logo::checkEvents()
|
|||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section::name = section::Name::QUIT;
|
section::name = section::Name::QUIT;
|
||||||
|
section::options = section::Options::QUIT_FROM_EVENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_Pla...
|
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
@@ -12,9 +14,9 @@
|
|||||||
Notifier *Notifier::notifier_ = nullptr;
|
Notifier *Notifier::notifier_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||||
void Notifier::init(SDL_Renderer *renderer, std::string icon_file, std::string bitmap_file, std::string text_file, const std::string &sound_file)
|
void Notifier::init(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file)
|
||||||
{
|
{
|
||||||
Notifier::notifier_ = new Notifier(renderer, icon_file, bitmap_file, text_file, sound_file);
|
Notifier::notifier_ = new Notifier(icon_file, text, sound_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||||
@@ -30,9 +32,9 @@ Notifier *Notifier::get()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Notifier::Notifier(SDL_Renderer *renderer, std::string icon_file, std::string bitmap_file, std::string text_file, const std::string &sound_file)
|
Notifier::Notifier(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file)
|
||||||
: renderer_(renderer),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
text_(std::make_unique<Text>(bitmap_file, text_file, renderer)),
|
text_(text),
|
||||||
bg_color_(param.notification.color),
|
bg_color_(param.notification.color),
|
||||||
wait_time_(150),
|
wait_time_(150),
|
||||||
stack_(false),
|
stack_(false),
|
||||||
@@ -42,7 +44,7 @@ Notifier::Notifier(SDL_Renderer *renderer, std::string icon_file, std::string bi
|
|||||||
has_icons_ = !icon_file.empty();
|
has_icons_ = !icon_file.empty();
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
icon_texture_ = has_icons_ ? std::make_unique<Texture>(renderer, icon_file) : nullptr;
|
icon_texture_ = has_icons_ ? std::make_unique<Texture>(renderer_, icon_file) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ private:
|
|||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
|
|
||||||
std::shared_ptr<Texture> icon_texture_; // Textura para los iconos de las notificaciones
|
std::shared_ptr<Texture> icon_texture_; // Textura para los iconos de las notificaciones
|
||||||
std::unique_ptr<Text> text_; // Objeto para dibujar texto
|
std::shared_ptr<Text> text_; // Objeto para dibujar texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Color bg_color_; // Color de fondo de las notificaciones
|
Color bg_color_; // Color de fondo de las notificaciones
|
||||||
@@ -82,14 +82,14 @@ private:
|
|||||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera
|
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Notifier(SDL_Renderer *renderer, std::string icon_file, std::string bitmap_file, std::string text_file, const std::string &sound_file);
|
Notifier(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Notifier();
|
~Notifier();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto notifier con esta función estática
|
// [SINGLETON] Crearemos el objeto notifier con esta función estática
|
||||||
static void init(SDL_Renderer *renderer, std::string icon_file, std::string bitmap_file, std::string text_file, const std::string &sound_file);
|
static void init(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file);
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto notifier con esta función estática
|
// [SINGLETON] Destruiremos el objeto notifier con esta función estática
|
||||||
static void destroy();
|
static void destroy();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
@@ -95,10 +96,10 @@ void OnScreenHelp::fillTexture()
|
|||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
|
||||||
|
|
||||||
// Crea el objeto para el texto
|
// Crea el objeto para el texto
|
||||||
auto text = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer());
|
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||||
|
|
||||||
// Crea la textura con los gráficos
|
// Crea la textura con los gráficos
|
||||||
auto controllersTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("controllers.png"));
|
auto controllersTexture = Resource::get()->getTexture("controllers.png");
|
||||||
|
|
||||||
// Crea el sprite para dibujar los gráficos
|
// Crea el sprite para dibujar los gráficos
|
||||||
auto sprite = std::make_unique<Sprite>(controllersTexture, (SDL_Rect){0, 0, 16, 16});
|
auto sprite = std::make_unique<Sprite>(controllersTexture, (SDL_Rect){0, 0, 16, 16});
|
||||||
@@ -170,7 +171,7 @@ void OnScreenHelp::toggleState()
|
|||||||
// Calcula la longitud en pixels del texto más largo
|
// Calcula la longitud en pixels del texto más largo
|
||||||
auto OnScreenHelp::getLargestStringSize() -> int const
|
auto OnScreenHelp::getLargestStringSize() -> int const
|
||||||
{
|
{
|
||||||
auto text = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer());
|
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||||
auto size = 0;
|
auto size = 0;
|
||||||
|
|
||||||
for (int i = 107; i <= 113; ++i)
|
for (int i = 107; i <= 113; ++i)
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ void Player::update()
|
|||||||
setAnimation();
|
setAnimation();
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
updateCooldown();
|
updateCooldown();
|
||||||
updatePowerUpCounter();
|
updatePowerUp();
|
||||||
updateInvulnerable();
|
updateInvulnerable();
|
||||||
updateContinueCounter();
|
updateContinueCounter();
|
||||||
updateEnterNameCounter();
|
updateEnterNameCounter();
|
||||||
@@ -578,7 +578,7 @@ void Player::updateInvulnerable()
|
|||||||
{
|
{
|
||||||
if (invulnerable_counter_ > 0)
|
if (invulnerable_counter_ > 0)
|
||||||
{
|
{
|
||||||
invulnerable_counter_--;
|
--invulnerable_counter_;
|
||||||
invulnerable_counter_ % 8 > 3 ? player_sprite_->getTexture()->setPalette(coffees_) : player_sprite_->getTexture()->setPalette(3);
|
invulnerable_counter_ % 8 > 3 ? player_sprite_->getTexture()->setPalette(coffees_) : player_sprite_->getTexture()->setPalette(3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -615,15 +615,12 @@ void Player::setPowerUpCounter(int value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el valor de la variable
|
// Actualiza el valor de la variable
|
||||||
void Player::updatePowerUpCounter()
|
void Player::updatePowerUp()
|
||||||
{
|
{
|
||||||
if ((power_up_counter_ > 0) && (power_up_))
|
if (power_up_)
|
||||||
{
|
{
|
||||||
power_up_counter_--;
|
--power_up_counter_;
|
||||||
}
|
power_up_ = power_up_counter_ > 0;
|
||||||
else
|
|
||||||
{
|
|
||||||
power_up_ = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ private:
|
|||||||
SDL_Rect *play_area_; // Rectangulo con la zona de juego
|
SDL_Rect *play_area_; // Rectangulo con la zona de juego
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int id_; // Numero de identificación para el jugador
|
int id_; // Numero de identificación para el jugador. Player1 = 1, Player2 = 2
|
||||||
float pos_x_; // Posicion en el eje X
|
float pos_x_; // Posicion en el eje X
|
||||||
int pos_y_; // Posicion en el eje Y
|
int pos_y_; // Posicion en el eje Y
|
||||||
float default_pos_x_; // Posición inicial para el jugador
|
float default_pos_x_; // Posición inicial para el jugador
|
||||||
@@ -245,7 +245,7 @@ public:
|
|||||||
void setPowerUpCounter(int value);
|
void setPowerUpCounter(int value);
|
||||||
|
|
||||||
// Actualiza el valor de la variable
|
// Actualiza el valor de la variable
|
||||||
void updatePowerUpCounter();
|
void updatePowerUp();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool hasExtraHit() const;
|
bool hasExtraHit() const;
|
||||||
|
|||||||
256
source/resource.cpp
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include "resource.h"
|
||||||
|
#include "asset.h"
|
||||||
|
#include "screen.h"
|
||||||
|
|
||||||
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
|
Resource *Resource::resource_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||||
|
void Resource::init()
|
||||||
|
{
|
||||||
|
Resource::resource_ = new Resource();
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||||
|
void Resource::destroy()
|
||||||
|
{
|
||||||
|
delete Resource::resource_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||||
|
Resource *Resource::get()
|
||||||
|
{
|
||||||
|
return Resource::resource_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Resource::Resource()
|
||||||
|
{
|
||||||
|
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||||
|
loadSounds();
|
||||||
|
loadMusics();
|
||||||
|
loadTextures();
|
||||||
|
loadTextFiles();
|
||||||
|
loadAnimations();
|
||||||
|
loadDemoData();
|
||||||
|
addPalettes();
|
||||||
|
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Resource::~Resource()
|
||||||
|
{
|
||||||
|
sounds_.clear();
|
||||||
|
musics_.clear();
|
||||||
|
textures_.clear();
|
||||||
|
text_files_.clear();
|
||||||
|
animations_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el sonido a partir de un nombre
|
||||||
|
JA_Sound_t *Resource::getSound(const std::string &name)
|
||||||
|
{
|
||||||
|
for (const auto &s : sounds_)
|
||||||
|
{
|
||||||
|
if (s.name == name)
|
||||||
|
{
|
||||||
|
return s.sound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cerr << "Error: Sonido no encontrado " << name << std::endl;
|
||||||
|
throw std::runtime_error("Sonido no encontrado: " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene la música a partir de un nombre
|
||||||
|
JA_Music_t *Resource::getMusic(const std::string &name)
|
||||||
|
{
|
||||||
|
for (const auto &m : musics_)
|
||||||
|
{
|
||||||
|
if (m.name == name)
|
||||||
|
{
|
||||||
|
return m.music;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cerr << "Error: Música no encontrada " << name << std::endl;
|
||||||
|
throw std::runtime_error("Música no encontrada: " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene la textura a partir de un nombre
|
||||||
|
std::shared_ptr<Texture> Resource::getTexture(const std::string &name)
|
||||||
|
{
|
||||||
|
for (const auto &t : textures_)
|
||||||
|
{
|
||||||
|
if (t.name == name)
|
||||||
|
{
|
||||||
|
return t.texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cerr << "Error: Imagen no encontrada " << name << std::endl;
|
||||||
|
throw std::runtime_error("Imagen no encontrada: " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el fichero de texto a partir de un nombre
|
||||||
|
std::shared_ptr<TextFile> Resource::getTextFile(const std::string &name)
|
||||||
|
{
|
||||||
|
for (const auto &t : text_files_)
|
||||||
|
{
|
||||||
|
if (t.name == name)
|
||||||
|
{
|
||||||
|
return t.text_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cerr << "Error: TextFile no encontrado " << name << std::endl;
|
||||||
|
throw std::runtime_error("TextFile no encontrado: " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene la animación a partir de un nombre
|
||||||
|
Animations &Resource::getAnimation(const std::string &name)
|
||||||
|
{
|
||||||
|
for (auto &a : animations_)
|
||||||
|
{
|
||||||
|
if (a.name == name)
|
||||||
|
{
|
||||||
|
return a.animation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cerr << "Error: Animación no encontrada " << name << std::endl;
|
||||||
|
throw std::runtime_error("Animación no encontrada: " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
|
||||||
|
DemoData &Resource::getDemoData(int index)
|
||||||
|
{
|
||||||
|
return demos_.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga los sonidos
|
||||||
|
void Resource::loadSounds()
|
||||||
|
{
|
||||||
|
std::cout << "\n>> SOUND FILES" << std::endl;
|
||||||
|
|
||||||
|
// Obtiene la lista con las rutas a los ficheros de sonidos
|
||||||
|
auto list = Asset::get()->getListByType(AssetType::SOUND);
|
||||||
|
sounds_.clear();
|
||||||
|
|
||||||
|
for (const auto &l : list)
|
||||||
|
{
|
||||||
|
// Encuentra el último índice de '/'
|
||||||
|
auto last_index = l.find_last_of('/') + 1;
|
||||||
|
|
||||||
|
// Obtiene la subcadena desde el último '/'
|
||||||
|
auto name = l.substr(last_index);
|
||||||
|
|
||||||
|
sounds_.emplace_back(ResourceSound(name, JA_LoadSound(l.c_str())));
|
||||||
|
printWithDots("Sound : ", name, "[ LOADED ]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga las musicas
|
||||||
|
void Resource::loadMusics()
|
||||||
|
{
|
||||||
|
std::cout << "\n>> MUSIC FILES" << std::endl;
|
||||||
|
|
||||||
|
// Obtiene la lista con las rutas a los ficheros musicales
|
||||||
|
auto list = Asset::get()->getListByType(AssetType::MUSIC);
|
||||||
|
musics_.clear();
|
||||||
|
|
||||||
|
for (const auto &l : list)
|
||||||
|
{
|
||||||
|
// Encuentra el último índice de '/'
|
||||||
|
auto last_index = l.find_last_of('/') + 1;
|
||||||
|
|
||||||
|
// Obtiene la subcadena desde el último '/'
|
||||||
|
auto name = l.substr(last_index);
|
||||||
|
|
||||||
|
musics_.emplace_back(ResourceMusic(name, JA_LoadMusic(l.c_str())));
|
||||||
|
printWithDots("Music : ", name, "[ LOADED ]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga las texturas
|
||||||
|
void Resource::loadTextures()
|
||||||
|
{
|
||||||
|
std::cout << "\n>> TEXTURES" << std::endl;
|
||||||
|
|
||||||
|
// Obtiene la lista con las rutas a los ficheros png
|
||||||
|
auto list = Asset::get()->getListByType(AssetType::BITMAP);
|
||||||
|
textures_.clear();
|
||||||
|
|
||||||
|
for (const auto &l : list)
|
||||||
|
{
|
||||||
|
// Encuentra el último índice de '/'
|
||||||
|
auto last_index = l.find_last_of('/') + 1;
|
||||||
|
|
||||||
|
// Obtiene la subcadena desde el último '/'
|
||||||
|
auto name = l.substr(last_index);
|
||||||
|
|
||||||
|
textures_.emplace_back(ResourceTexture(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga los ficheros de texto
|
||||||
|
void Resource::loadTextFiles()
|
||||||
|
{
|
||||||
|
std::cout << "\n>> TEXT FILES" << std::endl;
|
||||||
|
// Obtiene la lista con las rutas a los ficheros png
|
||||||
|
auto list = Asset::get()->getListByType(AssetType::FONT);
|
||||||
|
text_files_.clear();
|
||||||
|
|
||||||
|
for (const auto &l : list)
|
||||||
|
{
|
||||||
|
// Encuentra el último índice de '/'
|
||||||
|
auto last_index = l.find_last_of('/') + 1;
|
||||||
|
|
||||||
|
// Obtiene la subcadena desde el último '/'
|
||||||
|
auto name = l.substr(last_index);
|
||||||
|
|
||||||
|
text_files_.emplace_back(ResourceTextFile(name, loadTextFile(l)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga las animaciones
|
||||||
|
void Resource::loadAnimations()
|
||||||
|
{
|
||||||
|
std::cout << "\n>> ANIMATIONS" << std::endl;
|
||||||
|
// Obtiene la lista con las rutas a los ficheros ani
|
||||||
|
auto list = Asset::get()->getListByType(AssetType::ANIMATION);
|
||||||
|
animations_.clear();
|
||||||
|
|
||||||
|
for (const auto &l : list)
|
||||||
|
{
|
||||||
|
// Encuentra el último índice de '/'
|
||||||
|
auto last_index = l.find_last_of('/') + 1;
|
||||||
|
|
||||||
|
// Obtiene la subcadena desde el último '/'
|
||||||
|
auto name = l.substr(last_index);
|
||||||
|
|
||||||
|
animations_.emplace_back(ResourceAnimation(name, loadAnimationsFromFile(l)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga los datos para el modo demostración
|
||||||
|
void Resource::loadDemoData()
|
||||||
|
{
|
||||||
|
std::cout << "\n>> DEMO_FILES" << std::endl;
|
||||||
|
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get("demo1.bin")));
|
||||||
|
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get("demo2.bin")));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Añade paletas a las texturas
|
||||||
|
void Resource::addPalettes()
|
||||||
|
{
|
||||||
|
// Jugador 1
|
||||||
|
std::cout << "\n>> PALETTES" << std::endl;
|
||||||
|
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_one_coffee_palette.pal"));
|
||||||
|
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_two_coffee_palette.pal"));
|
||||||
|
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_all_white_palette.pal"));
|
||||||
|
|
||||||
|
// Jugador 2
|
||||||
|
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_one_coffee_palette.pal"));
|
||||||
|
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_two_coffee_palette.pal"));
|
||||||
|
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_all_white_palette.pal"));
|
||||||
|
|
||||||
|
// Fuentes
|
||||||
|
getTexture("smb2.gif")->addPaletteFromFile(Asset::get()->get("smb2_palette1.pal"));
|
||||||
|
}
|
||||||
137
source/resource.h
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "texture.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "animated_sprite.h"
|
||||||
|
|
||||||
|
// Estructura para almacenar ficheros de sonido y su nombre
|
||||||
|
struct ResourceSound
|
||||||
|
{
|
||||||
|
std::string name; // Nombre del sonido
|
||||||
|
JA_Sound_t *sound; // Objeto con el sonido
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
ResourceSound(const std::string &name, JA_Sound_t *sound)
|
||||||
|
: name(name), sound(sound) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para almacenar ficheros musicales y su nombre
|
||||||
|
struct ResourceMusic
|
||||||
|
{
|
||||||
|
std::string name; // Nombre de la musica
|
||||||
|
JA_Music_t *music; // Objeto con la música
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
ResourceMusic(const std::string &name, JA_Music_t *music)
|
||||||
|
: name(name), music(music) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para almacenar objetos Texture y su nombre
|
||||||
|
struct ResourceTexture
|
||||||
|
{
|
||||||
|
std::string name; // Nombre de la textura
|
||||||
|
std::shared_ptr<Texture> texture; // Objeto con la textura
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
ResourceTexture(const std::string &name, std::shared_ptr<Texture> texture)
|
||||||
|
: name(name), texture(texture) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para almacenar ficheros TextFile y su nombre
|
||||||
|
struct ResourceTextFile
|
||||||
|
{
|
||||||
|
std::string name; // Nombre del fichero
|
||||||
|
std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
ResourceTextFile(const std::string &name, std::shared_ptr<TextFile> text_file)
|
||||||
|
: name(name), text_file(text_file) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para almacenar ficheros animaciones y su nombre
|
||||||
|
struct ResourceAnimation
|
||||||
|
{
|
||||||
|
std::string name; // Nombre del fichero
|
||||||
|
Animations animation; // Objeto con las animaciones
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
ResourceAnimation(const std::string &name, Animations animation)
|
||||||
|
: name(name), animation(animation) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Resource
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// [SINGLETON] Objeto resource privado para Don Melitón
|
||||||
|
static Resource *resource_;
|
||||||
|
|
||||||
|
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
||||||
|
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<ResourceAnimation> animations_; // Vector con las animaciones
|
||||||
|
std::vector<DemoData> demos_; // Vector con los ficheros de datos para el modo demostración
|
||||||
|
|
||||||
|
// Carga los sonidos
|
||||||
|
void loadSounds();
|
||||||
|
|
||||||
|
// Carga las musicas
|
||||||
|
void loadMusics();
|
||||||
|
|
||||||
|
// Carga las texturas
|
||||||
|
void loadTextures();
|
||||||
|
|
||||||
|
// Carga los ficheros de texto
|
||||||
|
void loadTextFiles();
|
||||||
|
|
||||||
|
// Carga las animaciones
|
||||||
|
void loadAnimations();
|
||||||
|
|
||||||
|
// Carga los datos para el modo demostración
|
||||||
|
void loadDemoData();
|
||||||
|
|
||||||
|
// Añade paletas a las texturas
|
||||||
|
void addPalettes();
|
||||||
|
|
||||||
|
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Resource();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Resource();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto resource con esta función estática
|
||||||
|
static void init();
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto resource con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él
|
||||||
|
static Resource *get();
|
||||||
|
|
||||||
|
// Obtiene el sonido a partir de un nombre
|
||||||
|
JA_Sound_t *getSound(const std::string &name);
|
||||||
|
|
||||||
|
// Obtiene la música a partir de un nombre
|
||||||
|
JA_Music_t *getMusic(const std::string &name);
|
||||||
|
|
||||||
|
// Obtiene la textura a partir de un nombre
|
||||||
|
std::shared_ptr<Texture> getTexture(const std::string &name);
|
||||||
|
|
||||||
|
// Obtiene el fichero de texto a partir de un nombre
|
||||||
|
std::shared_ptr<TextFile> getTextFile(const std::string &name);
|
||||||
|
|
||||||
|
// Obtiene la animación a partir de un nombre
|
||||||
|
Animations &getAnimation(const std::string &name);
|
||||||
|
|
||||||
|
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
|
||||||
|
DemoData &getDemoData(int index);
|
||||||
|
};
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
|
#include "resource.h" // for Resource
|
||||||
|
#include "screen.h"
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
@@ -15,9 +17,9 @@
|
|||||||
Scoreboard *Scoreboard::scoreboard_ = nullptr;
|
Scoreboard *Scoreboard::scoreboard_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto score_board con esta función estática
|
// [SINGLETON] Crearemos el objeto score_board con esta función estática
|
||||||
void Scoreboard::init(SDL_Renderer *renderer)
|
void Scoreboard::init()
|
||||||
{
|
{
|
||||||
Scoreboard::scoreboard_ = new Scoreboard(renderer);
|
Scoreboard::scoreboard_ = new Scoreboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto score_board con esta función estática
|
// [SINGLETON] Destruiremos el objeto score_board con esta función estática
|
||||||
@@ -33,12 +35,12 @@ Scoreboard *Scoreboard::get()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
Scoreboard::Scoreboard()
|
||||||
: renderer_(renderer),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
|
|
||||||
game_power_meter_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_power_meter.png"))),
|
game_power_meter_texture_(Resource::get()->getTexture("game_power_meter.png")),
|
||||||
power_meter_sprite_(std::make_unique<Sprite>(game_power_meter_texture_)),
|
power_meter_sprite_(std::make_unique<Sprite>(game_power_meter_texture_)),
|
||||||
text_scoreboard_(std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer)),
|
text_scoreboard_(std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"))),
|
||||||
|
|
||||||
stage_(1),
|
stage_(1),
|
||||||
hi_score_(0),
|
hi_score_(0),
|
||||||
@@ -106,7 +108,7 @@ std::string Scoreboard::updateScoreText(int num)
|
|||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
void Scoreboard::updateCounter()
|
void Scoreboard::updateCounter()
|
||||||
{
|
{
|
||||||
if (SDL_GetTicks() - ticks_ > SCOREBOARD_TICK_SPEED)
|
if (SDL_GetTicks() - ticks_ > SCOREBOARD_TICK_SPEED_)
|
||||||
{
|
{
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
counter_++;
|
counter_++;
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ constexpr int SCOREBOARD_LEFT_PANEL = 0;
|
|||||||
constexpr int SCOREBOARD_CENTER_PANEL = 1;
|
constexpr int SCOREBOARD_CENTER_PANEL = 1;
|
||||||
constexpr int SCOREBOARD_RIGHT_PANEL = 2;
|
constexpr int SCOREBOARD_RIGHT_PANEL = 2;
|
||||||
constexpr int SCOREBOARD_MAX_PANELS = 3;
|
constexpr int SCOREBOARD_MAX_PANELS = 3;
|
||||||
constexpr int SCOREBOARD_TICK_SPEED = 100;
|
|
||||||
|
|
||||||
// Enums
|
// Enums
|
||||||
enum class ScoreboardMode : int
|
enum class ScoreboardMode : int
|
||||||
@@ -42,6 +41,9 @@ struct Panel
|
|||||||
class Scoreboard
|
class Scoreboard
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
// Constantes
|
||||||
|
static constexpr int SCOREBOARD_TICK_SPEED_ = 100;
|
||||||
|
|
||||||
// [SINGLETON] Objeto scoreboard privado para Don Melitón
|
// [SINGLETON] Objeto scoreboard privado para Don Melitón
|
||||||
static Scoreboard *scoreboard_;
|
static Scoreboard *scoreboard_;
|
||||||
|
|
||||||
@@ -103,14 +105,14 @@ private:
|
|||||||
// [SINGLETON] Ahora el constructor y el destructor son privados
|
// [SINGLETON] Ahora el constructor y el destructor son privados
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Scoreboard(SDL_Renderer *renderer);
|
Scoreboard();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Scoreboard();
|
~Scoreboard();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto scoreboard con esta función estática
|
// [SINGLETON] Crearemos el objeto scoreboard con esta función estática
|
||||||
static void init(SDL_Renderer *renderer);
|
static void init();
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto scoreboard con esta función estática
|
// [SINGLETON] Destruiremos el objeto scoreboard con esta función estática
|
||||||
static void destroy();
|
static void destroy();
|
||||||
|
|||||||
@@ -23,9 +23,10 @@ namespace section
|
|||||||
GAME_PLAY_2P = 1,
|
GAME_PLAY_2P = 1,
|
||||||
TITLE_1 = 2,
|
TITLE_1 = 2,
|
||||||
TITLE_2 = 3,
|
TITLE_2 = 3,
|
||||||
QUIT_NORMAL = 4,
|
QUIT_WITH_KEYBOARD = 4,
|
||||||
QUIT_SHUTDOWN = 5,
|
QUIT_WITH_CONTROLLER = 5,
|
||||||
NONE = 6,
|
QUIT_FROM_EVENT = 6,
|
||||||
|
NONE = 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Name name;
|
extern Name name;
|
||||||
|
|||||||
@@ -2,23 +2,24 @@
|
|||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
|
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
|
||||||
#include <iostream> // for cout
|
#include <iostream> // for cout
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
|
|
||||||
// Llena una estructuta TextFile desde un fichero
|
// Llena una estructuta TextFile desde un fichero
|
||||||
TextFile LoadTextFile(std::string file_path)
|
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
||||||
{
|
{
|
||||||
TextFile tf;
|
auto tf = std::make_shared<TextFile>();
|
||||||
|
|
||||||
// Inicializa a cero el vector con las coordenadas
|
// Inicializa a cero el vector con las coordenadas
|
||||||
for (int i = 0; i < 128; ++i)
|
for (int i = 0; i < 128; ++i)
|
||||||
{
|
{
|
||||||
tf.offset[i].x = 0;
|
tf->offset[i].x = 0;
|
||||||
tf.offset[i].y = 0;
|
tf->offset[i].y = 0;
|
||||||
tf.offset[i].w = 0;
|
tf->offset[i].w = 0;
|
||||||
tf.box_width = 0;
|
tf->box_width = 0;
|
||||||
tf.box_height = 0;
|
tf->box_height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abre el fichero para leer los valores
|
// Abre el fichero para leer los valores
|
||||||
@@ -32,11 +33,11 @@ TextFile LoadTextFile(std::string file_path)
|
|||||||
// Lee los dos primeros valores del fichero
|
// Lee los dos primeros valores del fichero
|
||||||
std::getline(file, buffer);
|
std::getline(file, buffer);
|
||||||
std::getline(file, buffer);
|
std::getline(file, buffer);
|
||||||
tf.box_width = std::stoi(buffer);
|
tf->box_width = std::stoi(buffer);
|
||||||
|
|
||||||
std::getline(file, buffer);
|
std::getline(file, buffer);
|
||||||
std::getline(file, buffer);
|
std::getline(file, buffer);
|
||||||
tf.box_height = std::stoi(buffer);
|
tf->box_height = std::stoi(buffer);
|
||||||
|
|
||||||
// lee el resto de datos del fichero
|
// lee el resto de datos del fichero
|
||||||
auto index = 32;
|
auto index = 32;
|
||||||
@@ -46,7 +47,7 @@ TextFile LoadTextFile(std::string file_path)
|
|||||||
// Almacena solo las lineas impares
|
// Almacena solo las lineas impares
|
||||||
if (line_read % 2 == 1)
|
if (line_read % 2 == 1)
|
||||||
{
|
{
|
||||||
tf.offset[index++].w = std::stoi(buffer);
|
tf->offset[index++].w = std::stoi(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limpia el buffer
|
// Limpia el buffer
|
||||||
@@ -55,64 +56,41 @@ TextFile LoadTextFile(std::string file_path)
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
std::cout << "Text loaded: " << file_name << std::endl;
|
printWithDots("Text File : ", file_name, "[ LOADED ]");
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// El fichero no se puede abrir
|
// El fichero no se puede abrir
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Warning: Unable to open " << file_name << " file" << std::endl;
|
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||||
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||||
for (int i = 32; i < 128; ++i)
|
for (int i = 32; i < 128; ++i)
|
||||||
{
|
{
|
||||||
tf.offset[i].x = ((i - 32) % 15) * tf.box_width;
|
tf->offset[i].x = ((i - 32) % 15) * tf->box_width;
|
||||||
tf.offset[i].y = ((i - 32) / 15) * tf.box_height;
|
tf->offset[i].y = ((i - 32) / 15) * tf->box_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Text::Text(const std::string &bitmap_file, const std::string &text_file, SDL_Renderer *renderer)
|
Text::Text(std::shared_ptr<Texture> texture, const std::string &text_file)
|
||||||
{
|
{
|
||||||
// Carga los offsets desde el fichero
|
// Carga los offsets desde el fichero
|
||||||
auto tf = LoadTextFile(text_file);
|
auto tf = loadTextFile(text_file);
|
||||||
|
|
||||||
// Inicializa variables desde la estructura
|
// Inicializa variables desde la estructura
|
||||||
box_height_ = tf.box_height;
|
box_height_ = tf->box_height;
|
||||||
box_width_ = tf.box_width;
|
box_width_ = tf->box_width;
|
||||||
for (int i = 0; i < 128; ++i)
|
for (int i = 0; i < 128; ++i)
|
||||||
{
|
{
|
||||||
offset_[i].x = tf.offset[i].x;
|
offset_[i].x = tf->offset[i].x;
|
||||||
offset_[i].y = tf.offset[i].y;
|
offset_[i].y = tf->offset[i].y;
|
||||||
offset_[i].w = tf.offset[i].w;
|
offset_[i].w = tf->offset[i].w;
|
||||||
}
|
|
||||||
|
|
||||||
// Crea los objetos
|
|
||||||
texture_ = std::make_shared<Texture>(renderer, bitmap_file);
|
|
||||||
sprite_ = std::make_unique<Sprite>(texture_, (SDL_Rect){0, 0, box_width_, box_height_});
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
fixed_width_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Text::Text(const std::string &text_file, std::shared_ptr<Texture> texture)
|
|
||||||
{
|
|
||||||
// Carga los offsets desde el fichero
|
|
||||||
auto tf = LoadTextFile(text_file);
|
|
||||||
|
|
||||||
// Inicializa variables desde la estructura
|
|
||||||
box_height_ = tf.box_height;
|
|
||||||
box_width_ = tf.box_width;
|
|
||||||
for (int i = 0; i < 128; ++i)
|
|
||||||
{
|
|
||||||
offset_[i].x = tf.offset[i].x;
|
|
||||||
offset_[i].y = tf.offset[i].y;
|
|
||||||
offset_[i].w = tf.offset[i].w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
@@ -123,7 +101,7 @@ Text::Text(const std::string &text_file, std::shared_ptr<Texture> texture)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Text::Text(TextFile *text_file, std::shared_ptr<Texture> texture)
|
Text::Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file)
|
||||||
{
|
{
|
||||||
// Inicializa variables desde la estructura
|
// Inicializa variables desde la estructura
|
||||||
box_height_ = text_file->box_height;
|
box_height_ = text_file->box_height;
|
||||||
@@ -262,15 +240,3 @@ void Text::setFixedWidth(bool value)
|
|||||||
{
|
{
|
||||||
fixed_width_ = value;
|
fixed_width_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga una paleta de colores para el texto
|
|
||||||
void Text::addPalette(const std::string &path)
|
|
||||||
{
|
|
||||||
texture_->addPalette(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece una paleta de colores para el texto
|
|
||||||
void Text::setPalette(int index)
|
|
||||||
{
|
|
||||||
texture_->setPalette(index);
|
|
||||||
}
|
|
||||||
@@ -26,7 +26,7 @@ struct TextFile
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Llena una estructuta TextFile desde un fichero
|
// Llena una estructuta TextFile desde un fichero
|
||||||
TextFile LoadTextFile(std::string file);
|
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path);
|
||||||
|
|
||||||
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
||||||
class Text
|
class Text
|
||||||
@@ -34,7 +34,6 @@ class Text
|
|||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::unique_ptr<Sprite> sprite_; // Objeto con los graficos para el texto
|
std::unique_ptr<Sprite> sprite_; // Objeto con los graficos para el texto
|
||||||
std::shared_ptr<Texture> texture_; // Textura con los bitmaps del texto
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int box_width_; // Anchura de la caja de cada caracter en el png
|
int box_width_; // Anchura de la caja de cada caracter en el png
|
||||||
@@ -44,9 +43,8 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Text(const std::string &bitmap_file, const std::string &text_file, SDL_Renderer *renderer);
|
Text(std::shared_ptr<Texture> texture, const std::string &text_file);
|
||||||
Text(const std::string &text_file, std::shared_ptr<Texture> texture);
|
Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file);
|
||||||
Text(TextFile *text_file, std::shared_ptr<Texture> texture);
|
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Text() = default;
|
~Text() = default;
|
||||||
@@ -77,10 +75,4 @@ public:
|
|||||||
|
|
||||||
// Establece si se usa un tamaño fijo de letra
|
// Establece si se usa un tamaño fijo de letra
|
||||||
void setFixedWidth(bool value);
|
void setFixedWidth(bool value);
|
||||||
|
|
||||||
// Carga una paleta de colores para el texto
|
|
||||||
void addPalette(const std::string &path);
|
|
||||||
|
|
||||||
// Establece una paleta de colores para el texto
|
|
||||||
void setPalette(int index);
|
|
||||||
};
|
};
|
||||||
@@ -1,27 +1,28 @@
|
|||||||
|
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
#include <SDL2/SDL_surface.h> // for SDL_CreateRGBSurfaceWithFormatFrom
|
#include <SDL2/SDL_surface.h> // for SDL_CreateRGBSurfaceWithFormatFrom
|
||||||
#include <fcntl.h> // for SEEK_END, SEEK_SET
|
#include <fcntl.h> // for SEEK_END, SEEK_SET
|
||||||
#include <stdio.h> // for fseek, fclose, fopen, fread, ftell, NULL
|
#include <stdio.h> // for fseek, fclose, fopen, fread, ftell, NULL
|
||||||
#include <stdlib.h> // for malloc, free, exit
|
#include <stdlib.h> // for malloc, free, exit
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include "gif.c" // for LoadGif, LoadPalette
|
#include "gif.c" // for LoadGif, LoadPalette
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h" // for stbi_failure_reason, stbi_image_free
|
#include "stb_image.h" // for stbi_failure_reason, stbi_image_free
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Texture::Texture(SDL_Renderer *renderer, const std::string &path)
|
Texture::Texture(SDL_Renderer *renderer, const std::string &path)
|
||||||
: renderer_(renderer), path_(path)
|
: texture_(nullptr),
|
||||||
|
renderer_(renderer),
|
||||||
|
surface_(nullptr),
|
||||||
|
width_(0),
|
||||||
|
height_(0),
|
||||||
|
path_(path),
|
||||||
|
current_palette_(0)
|
||||||
{
|
{
|
||||||
// Inicializa
|
|
||||||
surface_ = nullptr;
|
|
||||||
texture_ = nullptr;
|
|
||||||
width_ = 0;
|
|
||||||
height_ = 0;
|
|
||||||
paletteIndex_ = 0;
|
|
||||||
palettes_.clear();
|
|
||||||
|
|
||||||
// Carga el fichero en la textura
|
// Carga el fichero en la textura
|
||||||
if (!path_.empty())
|
if (!path_.empty())
|
||||||
{
|
{
|
||||||
@@ -37,9 +38,14 @@ Texture::Texture(SDL_Renderer *renderer, const std::string &path)
|
|||||||
// .gif
|
// .gif
|
||||||
else if (extension == "gif")
|
else if (extension == "gif")
|
||||||
{
|
{
|
||||||
|
// Crea la surface desde un fichero
|
||||||
surface_ = loadSurface(path_);
|
surface_ = loadSurface(path_);
|
||||||
addPalette(path_);
|
|
||||||
setPaletteColor(0, 0, 0x00000000);
|
// Añade la propia paleta del fichero a la lista
|
||||||
|
addPaletteFromFile(path_);
|
||||||
|
//setPaletteColor(0, 0, 0x00000000);
|
||||||
|
|
||||||
|
// Crea la textura, establece el BlendMode y copia la surface a la textura
|
||||||
createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
|
createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
|
||||||
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
|
||||||
flipSurface();
|
flipSurface();
|
||||||
@@ -50,24 +56,26 @@ Texture::Texture(SDL_Renderer *renderer, const std::string &path)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Texture::~Texture()
|
Texture::~Texture()
|
||||||
{
|
{
|
||||||
unload();
|
unloadTexture();
|
||||||
|
unloadSurface();
|
||||||
|
palettes_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga una imagen desde un fichero
|
// Carga una imagen desde un fichero
|
||||||
bool Texture::loadFromFile(const std::string &path)
|
bool Texture::loadFromFile(const std::string &file_path)
|
||||||
{
|
{
|
||||||
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(path.c_str(), &width, &height, &orig_format, req_format);
|
unsigned char *data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format);
|
||||||
if (!data)
|
if (!data)
|
||||||
{
|
{
|
||||||
std::cout << "Loading image failed: " << stbi_failure_reason() << std::endl;
|
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||||
exit(1);
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
std::cout << "Image loaded: " << file_name << std::endl;
|
printWithDots("Image : ", file_name, "[ LOADED ]");
|
||||||
}
|
}
|
||||||
|
|
||||||
int depth, pitch;
|
int depth, pitch;
|
||||||
@@ -86,7 +94,7 @@ bool Texture::loadFromFile(const std::string &path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Limpia
|
// Limpia
|
||||||
unload();
|
unloadTexture();
|
||||||
|
|
||||||
// La textura final
|
// La textura final
|
||||||
SDL_Texture *newTexture = nullptr;
|
SDL_Texture *newTexture = nullptr;
|
||||||
@@ -95,7 +103,7 @@ bool Texture::loadFromFile(const std::string &path)
|
|||||||
auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void *>(data), width, height, depth, pitch, pixel_format);
|
auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void *>(data), width, height, depth, pitch, pixel_format);
|
||||||
if (loadedSurface == nullptr)
|
if (loadedSurface == nullptr)
|
||||||
{
|
{
|
||||||
std::cout << "Unable to load image " << path << std::endl;
|
std::cout << "Unable to load image " << file_path << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -103,7 +111,7 @@ bool Texture::loadFromFile(const std::string &path)
|
|||||||
newTexture = SDL_CreateTextureFromSurface(renderer_, loadedSurface);
|
newTexture = SDL_CreateTextureFromSurface(renderer_, loadedSurface);
|
||||||
if (newTexture == nullptr)
|
if (newTexture == nullptr)
|
||||||
{
|
{
|
||||||
std::cout << "Unable to create texture from " << path << "! SDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Unable to create texture from " << file_path << "! SDL Error: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -141,7 +149,7 @@ bool Texture::createBlank(int width, int height, SDL_PixelFormatEnum format, SDL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Libera la memoria de la textura
|
// Libera la memoria de la textura
|
||||||
void Texture::unload()
|
void Texture::unloadTexture()
|
||||||
{
|
{
|
||||||
// Libera la textura
|
// Libera la textura
|
||||||
if (texture_)
|
if (texture_)
|
||||||
@@ -151,13 +159,6 @@ void Texture::unload()
|
|||||||
width_ = 0;
|
width_ = 0;
|
||||||
height_ = 0;
|
height_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera la surface
|
|
||||||
if (surface_)
|
|
||||||
{
|
|
||||||
deleteSurface(surface_);
|
|
||||||
surface_ = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el color para la modulacion
|
// Establece el color para la modulacion
|
||||||
@@ -228,61 +229,56 @@ SDL_Texture *Texture::getSDLTexture()
|
|||||||
return texture_;
|
return texture_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea una nueva surface
|
// Desencadenar la superficie actual
|
||||||
/*Surface Texture::newSurface(int w, int h)
|
void Texture::unloadSurface()
|
||||||
{
|
{
|
||||||
Surface surf = static_cast<Surface>(malloc(sizeof(surface_s)));
|
surface_.reset(); // Resetea el shared_ptr
|
||||||
surf->w = w;
|
width_ = 0;
|
||||||
surf->h = h;
|
height_ = 0;
|
||||||
surf->data = static_cast<Uint8 *>(malloc(w * h));
|
|
||||||
return surf;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Elimina una surface
|
|
||||||
void Texture::deleteSurface(Surface surface)
|
|
||||||
{
|
|
||||||
if (surface == nullptr)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (surface->data != nullptr)
|
|
||||||
{
|
|
||||||
free(surface->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(surface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea una surface desde un fichero .gif
|
// Crea una surface desde un fichero .gif
|
||||||
Surface Texture::loadSurface(const std::string &file_name)
|
std::shared_ptr<Surface> Texture::loadSurface(const std::string &file_path)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(file_name.c_str(), "rb");
|
// Desencadenar la superficie actual
|
||||||
if (!f)
|
unloadSurface();
|
||||||
|
|
||||||
|
// Abrir el archivo usando std::ifstream para manejo automático del recurso
|
||||||
|
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
||||||
|
if (!file)
|
||||||
{
|
{
|
||||||
return nullptr;
|
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||||
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
// Obtener el tamaño del archivo
|
||||||
long size = ftell(f);
|
std::streamsize size = file.tellg();
|
||||||
fseek(f, 0, SEEK_SET);
|
file.seekg(0, std::ios::beg);
|
||||||
Uint8 *buffer = static_cast<Uint8 *>(malloc(size));
|
|
||||||
fread(buffer, size, 1, f);
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
|
// Leer el contenido del archivo en un buffer
|
||||||
|
std::vector<Uint8> buffer(size);
|
||||||
|
if (!file.read(reinterpret_cast<char *>(buffer.data()), size))
|
||||||
|
{
|
||||||
|
std::cerr << "Error al leer el fichero " << file_path << std::endl;
|
||||||
|
throw std::runtime_error("Error al leer el fichero: " + file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cerrar el archivo (automáticamente manejado por std::ifstream)
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
// Llamar a la función LoadGif
|
||||||
Uint16 w, h;
|
Uint16 w, h;
|
||||||
Uint8 *pixels = LoadGif(buffer, &w, &h);
|
Uint8 *rawPixels = LoadGif(buffer.data(), &w, &h);
|
||||||
if (pixels == nullptr)
|
if (!rawPixels)
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface surface = static_cast<Surface>(malloc(sizeof(surface_s)));
|
// Crear un std::shared_ptr con std::make_shared para pixels
|
||||||
surface->w = w;
|
auto pixels = std::shared_ptr<Uint8[]>(rawPixels, std::default_delete<Uint8[]>());
|
||||||
surface->h = h;
|
auto surface = std::make_shared<Surface>(w, h, pixels);
|
||||||
surface->data = pixels;
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
|
// Actualizar la anchura y altura
|
||||||
width_ = w;
|
width_ = w;
|
||||||
height_ = h;
|
height_ = h;
|
||||||
|
|
||||||
@@ -305,7 +301,7 @@ void Texture::flipSurface()
|
|||||||
SDL_LockTexture(texture_, nullptr, reinterpret_cast<void **>(&pixels), &pitch);
|
SDL_LockTexture(texture_, nullptr, reinterpret_cast<void **>(&pixels), &pitch);
|
||||||
for (int i = 0; i < width_ * height_; ++i)
|
for (int i = 0; i < width_ * height_; ++i)
|
||||||
{
|
{
|
||||||
pixels[i] = palettes_[paletteIndex_][surface_->data[i]];
|
pixels[i] = palettes_[current_palette_][surface_->data[i]];
|
||||||
}
|
}
|
||||||
SDL_UnlockTexture(texture_);
|
SDL_UnlockTexture(texture_);
|
||||||
}
|
}
|
||||||
@@ -317,14 +313,20 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga una paleta desde un fichero
|
// Carga una paleta desde un fichero
|
||||||
std::vector<Uint32> Texture::loadPal(const std::string &file_name)
|
std::vector<Uint32> Texture::loadPaletteFromFile(const std::string &file_path)
|
||||||
{
|
{
|
||||||
std::vector<Uint32> palette;
|
std::vector<Uint32> palette;
|
||||||
|
|
||||||
FILE *f = fopen(file_name.c_str(), "rb");
|
FILE *f = fopen(file_path.c_str(), "rb");
|
||||||
if (!f)
|
if (!f)
|
||||||
{
|
{
|
||||||
return palette;
|
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||||
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
|
printWithDots("Image : ", file_name, "[ LOADED ]");
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
@@ -351,9 +353,9 @@ std::vector<Uint32> Texture::loadPal(const std::string &file_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Añade una paleta a la lista
|
// Añade una paleta a la lista
|
||||||
void Texture::addPalette(const std::string &path)
|
void Texture::addPaletteFromFile(const std::string &path)
|
||||||
{
|
{
|
||||||
palettes_.push_back(loadPal(path));
|
palettes_.emplace_back(loadPaletteFromFile(path));
|
||||||
setPaletteColor((int)palettes_.size() - 1, 0, 0x00000000);
|
setPaletteColor((int)palettes_.size() - 1, 0, 0x00000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +364,7 @@ void Texture::setPalette(int palette)
|
|||||||
{
|
{
|
||||||
if (palette < (int)palettes_.size())
|
if (palette < (int)palettes_.size())
|
||||||
{
|
{
|
||||||
paletteIndex_ = palette;
|
current_palette_ = palette;
|
||||||
flipSurface();
|
flipSurface();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,18 @@
|
|||||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint32, Uint16
|
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint32, Uint16
|
||||||
#include <string> // for string, basic_string
|
#include <string> // for string, basic_string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
// Definiciones de tipos
|
// Definiciones de tipos
|
||||||
struct surface_s
|
struct Surface
|
||||||
{
|
{
|
||||||
Uint8 *data;
|
std::shared_ptr<Uint8[]> data;
|
||||||
Uint16 w, h;
|
Uint16 w, h;
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct surface_s *Surface;
|
// Constructor
|
||||||
|
Surface(Uint16 width, Uint16 height, std::shared_ptr<Uint8[]> pixels)
|
||||||
|
: data(pixels), w(width), h(height) {}
|
||||||
|
};
|
||||||
|
|
||||||
class Texture
|
class Texture
|
||||||
{
|
{
|
||||||
@@ -23,29 +26,29 @@ private:
|
|||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Texture *texture_; // La textura
|
SDL_Texture *texture_; // La textura
|
||||||
SDL_Renderer *renderer_; // Renderizador donde dibujar la textura
|
SDL_Renderer *renderer_; // Renderizador donde dibujar la textura
|
||||||
Surface surface_; // Surface para usar imagenes en formato gif con paleta
|
std::shared_ptr<Surface> surface_; // Surface para usar imagenes en formato gif con paleta
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int width_; // Ancho de la imagen
|
int width_; // Ancho de la imagen
|
||||||
int height_; // Alto de la imagen
|
int height_; // Alto de la imagen
|
||||||
std::string path_; // Ruta de la imagen de la textura
|
std::string path_; // Ruta de la imagen de la textura
|
||||||
std::vector<std::vector<Uint32>> palettes_; // Vector con las diferentes paletas
|
std::vector<std::vector<Uint32>> palettes_; // Vector con las diferentes paletas
|
||||||
int paletteIndex_; // Indice de la paleta en uso
|
int current_palette_; // Indice de la paleta en uso
|
||||||
|
|
||||||
// Crea una nueva surface
|
|
||||||
//Surface newSurface(int w, int h);
|
|
||||||
|
|
||||||
// Elimina una surface
|
|
||||||
void deleteSurface(Surface surface);
|
|
||||||
|
|
||||||
// Crea una surface desde un fichero .gif
|
// Crea una surface desde un fichero .gif
|
||||||
Surface loadSurface(const std::string &file_name);
|
std::shared_ptr<Surface> loadSurface(const std::string &file_name);
|
||||||
|
|
||||||
// Vuelca la surface en la textura
|
// Vuelca la surface en la textura
|
||||||
void flipSurface();
|
void flipSurface();
|
||||||
|
|
||||||
// Carga una paleta desde un fichero
|
// Carga una paleta desde un fichero
|
||||||
std::vector<Uint32> loadPal(const std::string &file_name);
|
std::vector<Uint32> loadPaletteFromFile(const std::string &file_name);
|
||||||
|
|
||||||
|
// Libera la memoria de la textura
|
||||||
|
void unloadTexture();
|
||||||
|
|
||||||
|
// Desencadenar la superficie actual
|
||||||
|
void unloadSurface();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -60,9 +63,6 @@ public:
|
|||||||
// Crea una textura en blanco
|
// Crea una textura en blanco
|
||||||
bool createBlank(int width, int height, SDL_PixelFormatEnum format = SDL_PIXELFORMAT_RGBA8888, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
bool createBlank(int width, int height, SDL_PixelFormatEnum format = SDL_PIXELFORMAT_RGBA8888, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||||
|
|
||||||
// Libera la memoria de la textura
|
|
||||||
void unload();
|
|
||||||
|
|
||||||
// Establece el color para la modulacion
|
// Establece el color para la modulacion
|
||||||
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ public:
|
|||||||
SDL_Texture *getSDLTexture();
|
SDL_Texture *getSDLTexture();
|
||||||
|
|
||||||
// Añade una paleta a la lista
|
// Añade una paleta a la lista
|
||||||
void addPalette(const std::string &path);
|
void addPaletteFromFile(const std::string &path);
|
||||||
|
|
||||||
// Establece un color de la paleta
|
// Establece un color de la paleta
|
||||||
void setPaletteColor(int palette, int index, Uint32 color);
|
void setPaletteColor(int palette, int index, Uint32 color);
|
||||||
|
|||||||
@@ -1,116 +1,102 @@
|
|||||||
#include "tiled_bg.h"
|
#include "tiled_bg.h"
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
#include <SDL2/SDL_stdinc.h> // for SDL_sinf
|
|
||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // for rand
|
||||||
#include <memory> // for unique_ptr, make_shared, make_unique
|
#include <memory> // for unique_ptr, make_shared, make_unique
|
||||||
|
#include <cmath> // for sinf
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Tiledbg::Tiledbg(std::string texture_path, SDL_Rect pos, int mode)
|
TiledBG::TiledBG(SDL_Rect pos, TiledBGMode mode)
|
||||||
: texture_path_(texture_path), pos_(pos), mode_(mode)
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
|
pos_(pos),
|
||||||
|
counter_(0),
|
||||||
|
mode_(mode == TiledBGMode::RANDOM ? static_cast<TiledBGMode>(rand() % 2) : mode)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
renderer_ = Screen::get()->getRenderer();
|
|
||||||
|
|
||||||
// Crea la textura para el mosaico de fondo
|
// Crea la textura para el mosaico de fondo
|
||||||
canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos_.w * 2, pos_.h * 2);
|
canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos_.w * 2, pos_.h * 2);
|
||||||
|
|
||||||
// Inicializa las variables
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Tiledbg::~Tiledbg()
|
|
||||||
{
|
|
||||||
SDL_DestroyTexture(canvas_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las variables
|
|
||||||
void Tiledbg::init()
|
|
||||||
{
|
|
||||||
counter_ = 0;
|
|
||||||
if (mode_ == TILED_MODE_RANDOM)
|
|
||||||
{
|
|
||||||
mode_ = rand() % 2;
|
|
||||||
}
|
|
||||||
tile_width_ = 64;
|
|
||||||
tile_height_ = 64;
|
|
||||||
|
|
||||||
// Rellena la textura con el contenido
|
// Rellena la textura con el contenido
|
||||||
fillTexture();
|
fillTexture();
|
||||||
|
|
||||||
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida
|
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida
|
||||||
// con el mosaico que hay pintado en el titulo al iniciar
|
// con el mosaico que hay pintado en el titulo al iniciar
|
||||||
window_.x = 128;
|
window_ = {128, 96, pos_.w, pos_.h};
|
||||||
window_.y = 96;
|
|
||||||
window_.w = pos_.w;
|
|
||||||
window_.h = pos_.h;
|
|
||||||
|
|
||||||
// Inicializa los valores del vector con los valores del seno
|
// Inicializa los valores del vector con los valores del seno
|
||||||
for (int i = 0; i < 360; ++i)
|
for (int i = 0; i < 360; ++i)
|
||||||
{
|
{
|
||||||
sin_[i] = SDL_sinf((float)i * 3.14f / 180.0f);
|
sin_[i] = std::sin(i * 3.14159 / 180.0); // Convierte grados a radianes y calcula el seno
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
TiledBG::~TiledBG()
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(canvas_);
|
||||||
|
}
|
||||||
|
|
||||||
// Rellena la textura con el contenido
|
// Rellena la textura con el contenido
|
||||||
void Tiledbg::fillTexture()
|
void TiledBG::fillTexture()
|
||||||
{
|
{
|
||||||
// Crea los objetos para pintar en la textura de fondo
|
// Crea los objetos para pintar en la textura de fondo
|
||||||
auto bg_tile_texture = std::make_shared<Texture>(renderer_, texture_path_);
|
auto tile = std::make_unique<Sprite>(Resource::get()->getTexture("title_bg_tile.png"), (SDL_Rect){0, 0, TILE_WIDTH_, TILE_HEIGHT_});
|
||||||
auto tile = std::make_unique<Sprite>(bg_tile_texture, (SDL_Rect){0, 0, tile_width_, tile_height_});
|
|
||||||
|
|
||||||
// Prepara para dibujar sobre la textura
|
// Prepara para dibujar sobre la textura
|
||||||
auto temp = SDL_GetRenderTarget(renderer_);
|
auto temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer_, canvas_);
|
SDL_SetRenderTarget(renderer_, canvas_);
|
||||||
|
|
||||||
// Rellena la textura con el tile
|
// Rellena la textura con el tile
|
||||||
const auto i_max = pos_.w * 2 / tile_width_;
|
const auto i_max = pos_.w * 2 / TILE_WIDTH_;
|
||||||
const auto j_max = pos_.h * 2 / tile_height_;
|
const auto j_max = pos_.h * 2 / TILE_HEIGHT_;
|
||||||
tile->setSpriteClip(0, 0, tile_width_, tile_height_);
|
tile->setSpriteClip(0, 0, TILE_WIDTH_, TILE_HEIGHT_);
|
||||||
for (int i = 0; i < i_max; ++i)
|
for (int i = 0; i < i_max; ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < j_max; ++j)
|
for (int j = 0; j < j_max; ++j)
|
||||||
{
|
{
|
||||||
tile->setX(i * tile_width_);
|
tile->setX(i * TILE_WIDTH_);
|
||||||
tile->setY(j * tile_height_);
|
tile->setY(j * TILE_HEIGHT_);
|
||||||
tile->render();
|
tile->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelve a colocar el renderizador como estaba
|
// Vuelve a colocar el renderizador como estaba
|
||||||
SDL_SetRenderTarget(renderer_, temp);
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
|
|
||||||
// Libera la memoria utilizada por los objetos
|
|
||||||
bg_tile_texture->unload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta la clase en pantalla
|
// Pinta la clase en pantalla
|
||||||
void Tiledbg::render()
|
void TiledBG::render()
|
||||||
{
|
{
|
||||||
SDL_RenderCopy(renderer_, canvas_, &window_, &pos_);
|
SDL_RenderCopy(renderer_, canvas_, &window_, &pos_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
void Tiledbg::update()
|
void TiledBG::update()
|
||||||
{
|
{
|
||||||
if (mode_ == TILED_MODE_DIAGONAL)
|
switch (mode_)
|
||||||
|
{
|
||||||
|
case TiledBGMode::DIAGONAL:
|
||||||
{ // El tileado de fondo se desplaza en diagonal
|
{ // El tileado de fondo se desplaza en diagonal
|
||||||
++window_.x %= tile_width_;
|
++window_.x %= TILE_WIDTH_;
|
||||||
++window_.y %= tile_height_;
|
++window_.y %= TILE_HEIGHT_;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (mode_ == TILED_MODE_CIRCLE)
|
case TiledBGMode::CIRCLE:
|
||||||
{ // El tileado de fondo se desplaza en circulo
|
{ // El tileado de fondo se desplaza en circulo
|
||||||
++counter_ %= 360;
|
++counter_ %= 360;
|
||||||
window_.x = 128 + (int(sin_[(counter_ + 270) % 360] * 128));
|
window_.x = 128 + (int(sin_[(counter_ + 270) % 360] * 128));
|
||||||
window_.y = 96 + (int(sin_[(360 - counter_) % 360] * 96));
|
window_.y = 96 + (int(sin_[(360 - counter_) % 360] * 96));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga las texturas
|
// Recarga las texturas
|
||||||
void Tiledbg::reLoad()
|
void TiledBG::reLoad()
|
||||||
{
|
{
|
||||||
fillTexture();
|
fillTexture();
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,13 @@
|
|||||||
#include <string> // for string, basic_string
|
#include <string> // for string, basic_string
|
||||||
|
|
||||||
// Modos de funcionamiento para el tileado de fondo
|
// Modos de funcionamiento para el tileado de fondo
|
||||||
#define TILED_MODE_CIRCLE 0
|
enum class TiledBGMode : int
|
||||||
#define TILED_MODE_DIAGONAL 1
|
{
|
||||||
#define TILED_MODE_RANDOM 2
|
CIRCLE = 0,
|
||||||
#define TILED_MODE_STATIC 3
|
DIAGONAL = 1,
|
||||||
|
RANDOM = 2,
|
||||||
|
STATIC = 3,
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Esta clase dibuja un tileado de fondo. Para ello se sirve de una textura "canvas", que rellena con los tiles.
|
Esta clase dibuja un tileado de fondo. Para ello se sirve de una textura "canvas", que rellena con los tiles.
|
||||||
@@ -16,36 +19,34 @@
|
|||||||
textura en pantalla
|
textura en pantalla
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Clase Tiledbg
|
// Clase TiledBG
|
||||||
class Tiledbg
|
class TiledBG
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
// Constantes
|
||||||
|
static constexpr int TILE_WIDTH_ = 64; // Ancho del tile
|
||||||
|
static constexpr int TILE_HEIGHT_ = 64; // Alto del tile
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
SDL_Rect window_; // Ventana visible para la textura de fondo del titulo
|
SDL_Rect window_; // Ventana visible para la textura de fondo del titulo
|
||||||
SDL_Texture *canvas_; // Textura donde dibujar el fondo formado por tiles
|
SDL_Texture *canvas_; // Textura donde dibujar el fondo formado por tiles
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::string texture_path_; // Fichero para usar en la textura
|
SDL_Rect pos_; // Posición y tamaño del mosaico
|
||||||
SDL_Rect pos_; // Posición y tamaña del mosaico
|
|
||||||
int counter_; // Contador
|
int counter_; // Contador
|
||||||
int mode_; // Tipo de movimiento del mosaico
|
TiledBGMode mode_; // Tipo de movimiento del mosaico
|
||||||
float sin_[360]; // Vector con los valores del seno precalculados
|
double sin_[360]; // Vector con los valores del seno precalculados
|
||||||
int tile_width_; // Ancho del tile
|
|
||||||
int tile_height_; // Alto del tile
|
|
||||||
|
|
||||||
// Inicializa las variables
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Rellena la textura con el contenido
|
// Rellena la textura con el contenido
|
||||||
void fillTexture();
|
void fillTexture();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Tiledbg(std::string texture_path, SDL_Rect pos, int mode);
|
TiledBG(SDL_Rect pos, TiledBGMode mode);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Tiledbg();
|
~TiledBG();
|
||||||
|
|
||||||
// Pinta la clase en pantalla
|
// Pinta la clase en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "notifier.h" // for Notifier
|
#include "notifier.h" // for Notifier
|
||||||
#include "options.h" // for options
|
#include "options.h" // for options
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Options, options, Name, name
|
#include "section.h" // for Options, options, Name, name
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
@@ -22,64 +23,50 @@
|
|||||||
struct JA_Music_t; // lines 17-17
|
struct JA_Music_t; // lines 17-17
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title(JA_Music_t *music)
|
Title::Title()
|
||||||
: music_(music)
|
: 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"))),
|
||||||
|
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_))),
|
||||||
|
counter_(0),
|
||||||
|
ticks_(0),
|
||||||
|
demo_(true),
|
||||||
|
next_section_(section::Name::GAME),
|
||||||
|
post_fade_(0),
|
||||||
|
num_controllers_(Input::get()->getNumControllers())
|
||||||
{
|
{
|
||||||
// Copia las direcciones de los punteros y objetos
|
// Configura objetos
|
||||||
input_ = Input::get();
|
|
||||||
screen_ = Screen::get();
|
|
||||||
SDL_Renderer *renderer = screen_->getRenderer();
|
|
||||||
|
|
||||||
// Reserva memoria y crea los objetos
|
|
||||||
fade_ = std::make_unique<Fade>(renderer);
|
|
||||||
|
|
||||||
text1_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer);
|
|
||||||
text1_->addPalette(Asset::get()->get("smb2_pal1.gif"));
|
|
||||||
text1_->setPalette(1);
|
|
||||||
text2_ = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer);
|
|
||||||
|
|
||||||
mini_logo_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("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());
|
|
||||||
|
|
||||||
tiled_bg_ = std::make_unique<Tiledbg>(Asset::get()->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM);
|
|
||||||
|
|
||||||
game_logo_ = std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position);
|
|
||||||
game_logo_->enable();
|
game_logo_->enable();
|
||||||
|
|
||||||
define_buttons_ = std::make_unique<DefineButtons>(std::move(text2_));
|
|
||||||
|
|
||||||
// Inicializa los valores
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa los valores de las variables
|
|
||||||
void Title::init()
|
|
||||||
{
|
|
||||||
// Inicializa variables
|
|
||||||
section::options = section::Options::TITLE_1;
|
|
||||||
counter_ = 0;
|
|
||||||
next_section_ = section::Name::GAME;
|
|
||||||
post_fade_ = 0;
|
|
||||||
ticks_ = 0;
|
|
||||||
ticks_speed_ = 15;
|
|
||||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||||
fade_->setPost(param.fade.post_duration);
|
fade_->setPost(param.fade.post_duration);
|
||||||
demo_ = true;
|
Resource::get()->getTexture("smb2.gif")->setPalette(1);
|
||||||
num_controllers_ = input_->getNumControllers();
|
|
||||||
|
// Asigna valores a otras variables
|
||||||
|
section::options = section::Options::TITLE_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Title::~Title()
|
||||||
|
{
|
||||||
|
Resource::get()->getTexture("smb2.gif")->setPalette(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void Title::update()
|
void Title::update()
|
||||||
{
|
{
|
||||||
// Calcula la lógica de los objetos
|
// Calcula la lógica de los objetos
|
||||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
if (SDL_GetTicks() - ticks_ > TICKS_SPEED_)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks_
|
// Actualiza el contador de ticks_
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
screen_->update();
|
Screen::get()->update();
|
||||||
|
|
||||||
// Comprueba el fade_ y si se ha acabado
|
// Comprueba el fade_ y si se ha acabado
|
||||||
fade_->update();
|
fade_->update();
|
||||||
@@ -116,7 +103,7 @@ void Title::update()
|
|||||||
// Reproduce la música
|
// Reproduce la música
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music_);
|
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el logo con el título del juego
|
// Actualiza el logo con el título del juego
|
||||||
@@ -138,10 +125,10 @@ void Title::update()
|
|||||||
void Title::render()
|
void Title::render()
|
||||||
{
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen_->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen_->clean(bg_color);
|
Screen::get()->clean(bg_color);
|
||||||
|
|
||||||
// Dibuja el mosacico de fondo
|
// Dibuja el mosacico de fondo
|
||||||
tiled_bg_->render();
|
tiled_bg_->render();
|
||||||
@@ -176,7 +163,7 @@ void Title::render()
|
|||||||
fade_->render();
|
fade_->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen_->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
@@ -193,6 +180,7 @@ void Title::checkEvents()
|
|||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section::name = section::Name::QUIT;
|
section::name = section::Name::QUIT;
|
||||||
|
section::options = section::Options::QUIT_FROM_EVENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +229,7 @@ void Title::checkInput()
|
|||||||
if (!define_buttons_->isEnabled())
|
if (!define_buttons_->isEnabled())
|
||||||
{
|
{
|
||||||
// Comprueba el teclado para empezar a jugar
|
// Comprueba el teclado para empezar a jugar
|
||||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||||
{
|
{
|
||||||
@@ -251,27 +239,27 @@ void Title::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los mandos
|
// Comprueba los mandos
|
||||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
||||||
if (input_->checkModInput(InputType::SERVICE, InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkModInput(InputType::SERVICE, InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
swapControllers();
|
swapControllers();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si algun mando quiere ser configurado
|
// Comprueba si algun mando quiere ser configurado
|
||||||
if (input_->checkModInput(InputType::SERVICE, InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkModInput(InputType::SERVICE, InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
define_buttons_->enable(i);
|
define_buttons_->enable(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el botón de START de los mandos
|
// Comprueba el botón de START de los mandos
|
||||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
// Si no está el botón de servicio activo
|
// Si no está el botón de servicio activo
|
||||||
if (!input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (!Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||||
{
|
{
|
||||||
@@ -285,7 +273,7 @@ void Title::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
// Comprueba el input para el resto de objetos
|
||||||
screen_->checkInput();
|
Screen::get()->checkInput();
|
||||||
define_buttons_->checkInput();
|
define_buttons_->checkInput();
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||||
@@ -320,7 +308,7 @@ void Title::resetCounter()
|
|||||||
// Intercambia la asignación de mandos a los jugadores
|
// Intercambia la asignación de mandos a los jugadores
|
||||||
void Title::swapControllers()
|
void Title::swapControllers()
|
||||||
{
|
{
|
||||||
const auto num_controllers = input_->getNumControllers();
|
const auto num_controllers = Input::get()->getNumControllers();
|
||||||
|
|
||||||
if (num_controllers == 0)
|
if (num_controllers == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,11 +7,14 @@
|
|||||||
#include "game_logo.h" // for GameLogo
|
#include "game_logo.h" // for GameLogo
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "tiled_bg.h" // for Tiledbg
|
#include "tiled_bg.h" // for TiledBG
|
||||||
class Input; // lines 17-17
|
class Input; // lines 17-17
|
||||||
class Screen; // lines 18-18
|
class Screen; // lines 18-18
|
||||||
class Texture; // lines 20-20
|
class Texture; // lines 20-20
|
||||||
namespace section { enum class Name; }
|
namespace section
|
||||||
|
{
|
||||||
|
enum class Name;
|
||||||
|
}
|
||||||
struct JA_Music_t; // lines 21-21
|
struct JA_Music_t; // lines 21-21
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
@@ -39,33 +42,28 @@ constexpr bool ALLOW_TITLE_ANIMATION_SKIP = true;
|
|||||||
class Title
|
class Title
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Constantes
|
||||||
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
static constexpr Uint32 TICKS_SPEED_ = 15; // Velocidad a la que se repiten los bucles del programa
|
||||||
Input *input_; // Objeto para leer las entradas de teclado o mando
|
|
||||||
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
|
|
||||||
std::unique_ptr<DefineButtons> define_buttons_; // Objeto para definir los botones del joystic
|
|
||||||
std::shared_ptr<Texture> mini_logo_texture_; // Textura con el logo de JailGames mini
|
|
||||||
std::unique_ptr<Sprite> mini_logo_sprite_; // Sprite con el logo de JailGames mini
|
|
||||||
|
|
||||||
|
// Objetos y punteros
|
||||||
std::unique_ptr<Text> text1_; // Objeto de texto para poder escribir textos en pantalla
|
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::unique_ptr<Text> text2_; // Objeto de texto para poder escribir textos en pantalla
|
||||||
std::unique_ptr<Fade> fade_; // Objeto para realizar fundidos 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
|
||||||
|
std::shared_ptr<Texture> mini_logo_texture_; // Textura con el logo de JailGames mini
|
||||||
|
std::unique_ptr<Sprite> mini_logo_sprite_; // Sprite con el logo de JailGames mini
|
||||||
|
std::unique_ptr<DefineButtons> define_buttons_; // Objeto para definir los botones del joystic
|
||||||
|
|
||||||
JA_Music_t *music_; // Musica para el titulo
|
|
||||||
|
|
||||||
// Variable
|
// Variable
|
||||||
int counter_; // Temporizador para la pantalla de titulo
|
int counter_; // Temporizador para la pantalla de titulo
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
bool demo_; // Indica si el modo demo estará activo
|
bool demo_; // Indica si el modo demo estará activo
|
||||||
section::Name next_section_; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
section::Name next_section_; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
||||||
int post_fade_; // Opción a realizar cuando termina el fundido
|
int post_fade_; // Opción a realizar cuando termina el fundido
|
||||||
int num_controllers_; // Número de mandos conectados
|
int num_controllers_; // Número de mandos conectados
|
||||||
|
|
||||||
// Inicializa los valores de las variables
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
@@ -89,10 +87,10 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Title(JA_Music_t *music);
|
Title();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Title() = default;
|
~Title();
|
||||||
|
|
||||||
// Bucle para el titulo del juego
|
// Bucle para el titulo del juego
|
||||||
void run();
|
void run();
|
||||||
|
|||||||
116
source/utils.cpp
@@ -1,4 +1,6 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
#include <algorithm> // for min, clamp, find_if_not, transform
|
#include <algorithm> // for min, clamp, find_if_not, transform
|
||||||
#include <cctype> // for tolower, isspace
|
#include <cctype> // for tolower, isspace
|
||||||
#include <cmath> // for cos, pow, M_PI
|
#include <cmath> // for cos, pow, M_PI
|
||||||
@@ -104,38 +106,6 @@ std::string toLower(const std::string &str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el fichero de sonido a partir de un nombre
|
|
||||||
JA_Sound_t *getSound(const std::vector<SoundFile> &sounds, const std::string &name)
|
|
||||||
{
|
|
||||||
for (const auto &s : sounds)
|
|
||||||
{
|
|
||||||
if (s.name == name)
|
|
||||||
{
|
|
||||||
return s.file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el fichero de música a partir de un nombre
|
|
||||||
JA_Music_t *getMusic(const std::vector<MusicFile> &music, const std::string &name)
|
|
||||||
{
|
|
||||||
for (const auto &m : music)
|
|
||||||
{
|
|
||||||
if (m.name == name)
|
|
||||||
{
|
|
||||||
return m.file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ordena las entradas de la tabla de records
|
|
||||||
HiScoreEntry sortHiScoreTable(const HiScoreEntry &entry1, const HiScoreEntry &entry2)
|
|
||||||
{
|
|
||||||
return (entry1.score > entry2.score) ? entry1 : entry2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja un circulo
|
// Dibuja un circulo
|
||||||
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius)
|
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius)
|
||||||
{
|
{
|
||||||
@@ -220,3 +190,85 @@ bool stringInVector(const std::vector<std::string> &vec, const std::string &str)
|
|||||||
{
|
{
|
||||||
return std::find(vec.begin(), vec.end(), str) != vec.end();
|
return std::find(vec.begin(), vec.end(), str) != vec.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Imprime por pantalla una linea de texto de tamaño fijo rellena con puntos
|
||||||
|
void printWithDots(const std::string &text1, const std::string &text2, const std::string &text3)
|
||||||
|
{
|
||||||
|
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
||||||
|
std::cout << text1;
|
||||||
|
|
||||||
|
std::cout.width(50 - text1.length() - text3.length());
|
||||||
|
std::cout.fill('.');
|
||||||
|
std::cout << text2;
|
||||||
|
|
||||||
|
std::cout << text3 << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga el fichero de datos para la demo
|
||||||
|
DemoData loadDemoDataFromFile(const std::string &file_path)
|
||||||
|
{
|
||||||
|
DemoData dd;
|
||||||
|
|
||||||
|
// Indicador de éxito en la carga
|
||||||
|
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||||
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
|
printWithDots("DemoData : ", file_name, "[ LOADED ]");
|
||||||
|
|
||||||
|
// Lee todos los datos del fichero y los deja en el destino
|
||||||
|
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
||||||
|
{
|
||||||
|
DemoKeys dk = DemoKeys();
|
||||||
|
SDL_RWread(file, &dk, sizeof(DemoKeys), 1);
|
||||||
|
dd.push_back(dk);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
SDL_RWclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dd;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef RECORDING
|
||||||
|
// Guarda el fichero de datos para la demo
|
||||||
|
bool saveDemoFile(const std::string &file_path, const DemoData &dd)
|
||||||
|
{
|
||||||
|
auto success = true;
|
||||||
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
|
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
||||||
|
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
// Guarda los datos
|
||||||
|
for (const auto &data : dd)
|
||||||
|
{
|
||||||
|
if (SDL_RWwrite(file, &data, sizeof(DemoKeys), 1) != 1)
|
||||||
|
{
|
||||||
|
std::cerr << "Error al escribir el fichero " << file_name << std::endl;
|
||||||
|
success = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
std::cout << "Writing file " << file_name.c_str() << std::endl;
|
||||||
|
}
|
||||||
|
// Cierra el fichero
|
||||||
|
SDL_RWclose(file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
#endif // RECORDING
|
||||||
@@ -17,6 +17,10 @@ namespace lang
|
|||||||
struct JA_Music_t; // lines 12-12
|
struct JA_Music_t; // lines 12-12
|
||||||
struct JA_Sound_t; // lines 13-13
|
struct JA_Sound_t; // lines 13-13
|
||||||
|
|
||||||
|
// Constantes
|
||||||
|
constexpr int BLOCK = 8;
|
||||||
|
constexpr int TOTAL_DEMO_DATA = 2000;
|
||||||
|
|
||||||
// Dificultad del juego
|
// Dificultad del juego
|
||||||
enum class GameDifficulty
|
enum class GameDifficulty
|
||||||
{
|
{
|
||||||
@@ -25,9 +29,6 @@ enum class GameDifficulty
|
|||||||
HARD = 2,
|
HARD = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tamaño de bloque
|
|
||||||
constexpr int BLOCK = 8;
|
|
||||||
|
|
||||||
// Estructura para definir un circulo
|
// Estructura para definir un circulo
|
||||||
struct Circle
|
struct Circle
|
||||||
{
|
{
|
||||||
@@ -58,7 +59,6 @@ struct HiScoreEntry
|
|||||||
int score; // Puntuación
|
int score; // Puntuación
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para mapear el teclado usado en la demo
|
|
||||||
struct DemoKeys
|
struct DemoKeys
|
||||||
{
|
{
|
||||||
Uint8 left;
|
Uint8 left;
|
||||||
@@ -67,6 +67,21 @@ struct DemoKeys
|
|||||||
Uint8 fire;
|
Uint8 fire;
|
||||||
Uint8 fire_left;
|
Uint8 fire_left;
|
||||||
Uint8 fire_right;
|
Uint8 fire_right;
|
||||||
|
|
||||||
|
// Constructor que inicializa todos los campos
|
||||||
|
DemoKeys(Uint8 l = 0, Uint8 r = 0, Uint8 ni = 0, Uint8 f = 0, Uint8 fl = 0, Uint8 fr = 0)
|
||||||
|
: left(l), right(r), no_input(ni), fire(f), fire_left(fl), fire_right(fr) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
using DemoData = std::vector<DemoKeys>;
|
||||||
|
|
||||||
|
struct Demo
|
||||||
|
{
|
||||||
|
bool enabled; // Indica si está activo el modo demo
|
||||||
|
bool recording; // Indica si está activado el modo para grabar la demo
|
||||||
|
int counter; // Contador para el modo demo
|
||||||
|
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
|
||||||
|
std::vector<DemoData> data; // Vector con diferentes sets de datos con los movimientos para la demo
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para las opciones de la ventana
|
// Estructura para las opciones de la ventana
|
||||||
@@ -215,20 +230,6 @@ struct Param
|
|||||||
ParamNotification notification; // Opciones para las notificaciones
|
ParamNotification notification; // Opciones para las notificaciones
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para almacenar ficheros de sonido y su nombre
|
|
||||||
struct SoundFile
|
|
||||||
{
|
|
||||||
std::string name; // Nombre del sonido
|
|
||||||
JA_Sound_t *file; // Fichero con el sonido
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para almacenar ficheros musicales y su nombre
|
|
||||||
struct MusicFile
|
|
||||||
{
|
|
||||||
std::string name; // Nombre de la musica
|
|
||||||
JA_Music_t *file; // Fichero con la música
|
|
||||||
};
|
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
double distanceSquared(int x1, int y1, int x2, int y2);
|
double distanceSquared(int x1, int y1, int x2, int y2);
|
||||||
|
|
||||||
@@ -256,15 +257,6 @@ std::string boolToOnOff(bool value);
|
|||||||
// Convierte una cadena a minusculas
|
// Convierte una cadena a minusculas
|
||||||
std::string toLower(const std::string &str);
|
std::string toLower(const std::string &str);
|
||||||
|
|
||||||
// Obtiene el fichero de sonido a partir de un nombre
|
|
||||||
JA_Sound_t *getSound(const std::vector<SoundFile> &sounds, const std::string &name);
|
|
||||||
|
|
||||||
// Obtiene el fichero de música a partir de un nombre
|
|
||||||
JA_Music_t *getMusic(const std::vector<MusicFile> &music, const std::string &name);
|
|
||||||
|
|
||||||
// Ordena las entradas de la tabla de records
|
|
||||||
HiScoreEntry sortHiScoreTable(const HiScoreEntry &entry1, const HiScoreEntry &entry2);
|
|
||||||
|
|
||||||
// Dibuja un circulo
|
// Dibuja un circulo
|
||||||
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius);
|
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius);
|
||||||
|
|
||||||
@@ -286,6 +278,17 @@ double easeInOutSine(double t);
|
|||||||
// Comprueba si una vector contiene una cadena
|
// Comprueba si una vector contiene una cadena
|
||||||
bool stringInVector(const std::vector<std::string> &vec, const std::string &str);
|
bool stringInVector(const std::vector<std::string> &vec, const std::string &str);
|
||||||
|
|
||||||
|
// Imprime por pantalla una linea de texto de tamaño fijo rellena con puntos
|
||||||
|
void printWithDots(const std::string &text1, const std::string &text2, const std::string &text3);
|
||||||
|
|
||||||
|
// Carga el fichero de datos para la demo
|
||||||
|
DemoData loadDemoDataFromFile(const std::string &file_path);
|
||||||
|
|
||||||
|
#ifdef RECORDING
|
||||||
|
// Guarda el fichero de datos para la demo
|
||||||
|
bool saveDemoFile(const std::string &file_path, const DemoData &dd);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Colores
|
// Colores
|
||||||
extern const Color bg_color;
|
extern const Color bg_color;
|
||||||
extern const Color no_color;
|
extern const Color no_color;
|
||||||
|
|||||||