Compare commits
6 Commits
2024-10-14
...
e99c2c5265
| Author | SHA1 | Date | |
|---|---|---|---|
| e99c2c5265 | |||
| 942924c65c | |||
| 089da99b5b | |||
| 3fdd60c9e2 | |||
| 3b9885ab03 | |||
| 39a8c992e1 |
Binary file not shown.
|
Before Width: | Height: | Size: 935 B |
BIN
data/gfx/game_text/game_text_1000_points.png
Normal file
BIN
data/gfx/game_text/game_text_1000_points.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 337 B |
BIN
data/gfx/game_text/game_text_2500_points.png
Normal file
BIN
data/gfx/game_text/game_text_2500_points.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 376 B |
BIN
data/gfx/game_text/game_text_5000_points.png
Normal file
BIN
data/gfx/game_text/game_text_5000_points.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 364 B |
BIN
data/gfx/game_text/game_text_one_hit.png
Normal file
BIN
data/gfx/game_text/game_text_one_hit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 487 B |
BIN
data/gfx/game_text/game_text_powerup.png
Normal file
BIN
data/gfx/game_text/game_text_powerup.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 580 B |
@@ -8,6 +8,7 @@
|
|||||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
||||||
#include <SDL2/SDL_stdinc.h> // for SDL_bool, Uint32
|
#include <SDL2/SDL_stdinc.h> // for SDL_bool, Uint32
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <cstdlib> // for system
|
||||||
#include <errno.h> // for errno, EEXIST, EACCES, ENAMETOO...
|
#include <errno.h> // for errno, EEXIST, EACCES, ENAMETOO...
|
||||||
#include <stdio.h> // for printf, perror
|
#include <stdio.h> // for printf, perror
|
||||||
#include <string.h> // for strcmp
|
#include <string.h> // for strcmp
|
||||||
@@ -411,7 +412,12 @@ bool Director::setFileList()
|
|||||||
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);
|
||||||
Asset::get()->add(prefix + "/data/gfx/game/game_text.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_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_one_hit.png", AssetType::BITMAP);
|
||||||
|
|
||||||
Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP);
|
||||||
|
|
||||||
@@ -692,6 +698,12 @@ int Director::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ARCADE
|
||||||
|
// Comprueba si ha de apagar el sistema
|
||||||
|
if (section::options == section::Options::QUIT_SHUTDOWN)
|
||||||
|
shutdownSystem();
|
||||||
|
#endif
|
||||||
|
|
||||||
const int return_code = section::options == section::Options::QUIT_NORMAL ? 0 : 1;
|
const int return_code = section::options == section::Options::QUIT_NORMAL ? 0 : 1;
|
||||||
return return_code;
|
return return_code;
|
||||||
}
|
}
|
||||||
@@ -719,3 +731,21 @@ std::string Director::getLangFile(lang::Code code)
|
|||||||
|
|
||||||
return Asset::get()->get("en_UK.txt");
|
return Asset::get()->get("en_UK.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apaga el sistema
|
||||||
|
void Director::shutdownSystem()
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Apaga el sistema en Windows
|
||||||
|
system("shutdown /s /t 0");
|
||||||
|
#elif __APPLE__
|
||||||
|
// Apaga el sistema en macOS
|
||||||
|
system("sudo shutdown -h now");
|
||||||
|
#elif __linux__
|
||||||
|
// Apaga el sistema en Linux
|
||||||
|
system("shutdown -h now");
|
||||||
|
#else
|
||||||
|
// Sistema operativo no compatible
|
||||||
|
#error "Sistema operativo no soportado"
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -76,6 +76,9 @@ private:
|
|||||||
// Obtiene una fichero a partir de un lang::Code
|
// Obtiene una fichero a partir de un lang::Code
|
||||||
std::string getLangFile(lang::Code code);
|
std::string getLangFile(lang::Code code);
|
||||||
|
|
||||||
|
// Apaga el sistema
|
||||||
|
void shutdownSystem();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Director(int argc, const char *argv[]);
|
Director(int argc, const char *argv[]);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ void EnterName::init()
|
|||||||
|
|
||||||
// Inicia la lista de caracteres permitidos
|
// Inicia la lista de caracteres permitidos
|
||||||
character_list_ = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
|
character_list_ = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
|
||||||
pos_ = 0;
|
position_ = 0;
|
||||||
num_characters_ = (int)character_list_.size();
|
num_characters_ = (int)character_list_.size();
|
||||||
|
|
||||||
// Pone la lista de indices para que refleje el nombre
|
// Pone la lista de indices para que refleje el nombre
|
||||||
@@ -26,26 +26,27 @@ void EnterName::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Incrementa la posición
|
// Incrementa la posición
|
||||||
void EnterName::incPos()
|
void EnterName::incPosition()
|
||||||
{
|
{
|
||||||
pos_++;
|
position_++;
|
||||||
pos_ = std::min(pos_, NAME_LENGHT - 1);
|
position_ = std::min(position_, NAME_LENGHT - 1);
|
||||||
|
checkIfPositionHasBeenUsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrementa la posición
|
// Decrementa la posición
|
||||||
void EnterName::decPos()
|
void EnterName::decPosition()
|
||||||
{
|
{
|
||||||
pos_--;
|
position_--;
|
||||||
pos_ = std::max(pos_, 0);
|
position_ = std::max(position_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incrementa el índice
|
// Incrementa el índice
|
||||||
void EnterName::incIndex()
|
void EnterName::incIndex()
|
||||||
{
|
{
|
||||||
++character_index_[pos_];
|
++character_index_[position_];
|
||||||
if (character_index_[pos_] >= num_characters_)
|
if (character_index_[position_] >= num_characters_)
|
||||||
{
|
{
|
||||||
character_index_[pos_] = 0;
|
character_index_[position_] = 0;
|
||||||
}
|
}
|
||||||
updateName();
|
updateName();
|
||||||
}
|
}
|
||||||
@@ -53,15 +54,15 @@ void EnterName::incIndex()
|
|||||||
// Decrementa el índice
|
// Decrementa el índice
|
||||||
void EnterName::decIndex()
|
void EnterName::decIndex()
|
||||||
{
|
{
|
||||||
--character_index_[pos_];
|
--character_index_[position_];
|
||||||
if (character_index_[pos_] < 0)
|
if (character_index_[position_] < 0)
|
||||||
{
|
{
|
||||||
character_index_[pos_] = num_characters_ - 1;
|
character_index_[position_] = num_characters_ - 1;
|
||||||
}
|
}
|
||||||
updateName();
|
updateName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la variable
|
// Actualiza el nombre a partir de la lista de índices
|
||||||
void EnterName::updateName()
|
void EnterName::updateName()
|
||||||
{
|
{
|
||||||
name_.clear();
|
name_.clear();
|
||||||
@@ -74,16 +75,18 @@ void EnterName::updateName()
|
|||||||
// Actualiza la variable
|
// Actualiza la variable
|
||||||
void EnterName::updateCharacterIndex()
|
void EnterName::updateCharacterIndex()
|
||||||
{
|
{
|
||||||
// Rellena de espacios
|
// Rellena de espacios y marca como no usados
|
||||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||||
{
|
{
|
||||||
character_index_[i] = 0;
|
character_index_[i] = 0;
|
||||||
|
position_has_been_used_[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coloca los índices en funcion de los caracteres que forman el nombre
|
// Coloca los índices en funcion de los caracteres que forman el nombre
|
||||||
for (int i = 0; i < (int)name_.size(); ++i)
|
for (int i = 0; i < (int)name_.size(); ++i)
|
||||||
{
|
{
|
||||||
character_index_[i] = findIndex(name_.at(i));
|
character_index_[i] = findIndex(name_.at(i));
|
||||||
|
position_has_been_used_[i] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +110,21 @@ std::string EnterName::getName() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la posición que se está editando
|
// Obtiene la posición que se está editando
|
||||||
int EnterName::getPos() const
|
int EnterName::getPosition() const
|
||||||
{
|
{
|
||||||
return pos_;
|
return position_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba la posición y copia el caracter si es necesario
|
||||||
|
void EnterName::checkIfPositionHasBeenUsed()
|
||||||
|
{
|
||||||
|
auto used = position_has_been_used_[position_];
|
||||||
|
|
||||||
|
if (!used && position_ > 0)
|
||||||
|
{
|
||||||
|
character_index_[position_] = character_index_[position_ - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
position_has_been_used_[position_] = true;
|
||||||
|
updateName();
|
||||||
}
|
}
|
||||||
@@ -18,11 +18,12 @@ class EnterName
|
|||||||
private:
|
private:
|
||||||
std::string character_list_; // Lista de todos los caracteres permitidos
|
std::string character_list_; // Lista de todos los caracteres permitidos
|
||||||
std::string name_; // Nombre introducido
|
std::string name_; // Nombre introducido
|
||||||
int pos_; // Posición a editar del nombre
|
int position_; // Posición a editar del nombre
|
||||||
int num_characters_; // Cantidad de caracteres de la lista de caracteres
|
int num_characters_; // Cantidad de caracteres de la lista de caracteres
|
||||||
int character_index_[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
int character_index_[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||||
|
bool position_has_been_used_[NAME_LENGHT]; // Indica si en esa posición se ha puesto ya alguna letra. Se utiliza para replicar la letra anterior la primera vez
|
||||||
|
|
||||||
// Actualiza la variable
|
// Actualiza el nombre a partir de la lista de índices
|
||||||
void updateName();
|
void updateName();
|
||||||
|
|
||||||
// Actualiza la variable
|
// Actualiza la variable
|
||||||
@@ -31,6 +32,9 @@ private:
|
|||||||
// Encuentra el indice de un caracter en "characterList"
|
// Encuentra el indice de un caracter en "characterList"
|
||||||
int findIndex(char character);
|
int findIndex(char character);
|
||||||
|
|
||||||
|
// Comprueba la posición y copia el caracter si es necesario
|
||||||
|
void checkIfPositionHasBeenUsed();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
EnterName();
|
EnterName();
|
||||||
@@ -42,10 +46,10 @@ public:
|
|||||||
void init();
|
void init();
|
||||||
|
|
||||||
// Incrementa la posición
|
// Incrementa la posición
|
||||||
void incPos();
|
void incPosition();
|
||||||
|
|
||||||
// Decrementa la posición
|
// Decrementa la posición
|
||||||
void decPos();
|
void decPosition();
|
||||||
|
|
||||||
// Incrementa el índice
|
// Incrementa el índice
|
||||||
void incIndex();
|
void incIndex();
|
||||||
@@ -57,5 +61,5 @@ public:
|
|||||||
std::string getName() const;
|
std::string getName() const;
|
||||||
|
|
||||||
// Obtiene la posición que se está editando
|
// Obtiene la posición que se está editando
|
||||||
int getPos() const;
|
int getPosition() const;
|
||||||
};
|
};
|
||||||
284
source/game.cpp
284
source/game.cpp
@@ -21,7 +21,7 @@
|
|||||||
#include "fade.h" // for Fade, FadeType
|
#include "fade.h" // for Fade, FadeType
|
||||||
#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, ITEM_COFFEE_MACHINE, ITEM_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, JA_DeleteSound, JA_L...
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
||||||
@@ -39,7 +39,8 @@ struct JA_Sound_t; // lines 36-36
|
|||||||
|
|
||||||
// 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, JA_Music_t *music)
|
||||||
: music_(music), current_stage_(current_stage)
|
: music_(music),
|
||||||
|
current_stage_(current_stage)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
asset_ = Asset::get();
|
asset_ = Asset::get();
|
||||||
@@ -75,9 +76,11 @@ Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music)
|
|||||||
|
|
||||||
background_->setPos(param.game.play_area.rect);
|
background_->setPos(param.game.play_area.rect);
|
||||||
|
|
||||||
p1000_sprite_ = std::make_shared<SmartSprite>(game_text_texture_);
|
// game_text_sprites_.emplace_back(std::make_shared<SmartSprite>(game_text_textures_.at(0)));
|
||||||
p2500_sprite_ = std::make_shared<SmartSprite>(game_text_texture_);
|
// game_text_sprites_.emplace_back(std::make_shared<SmartSprite>(game_text_textures_.at(1)));
|
||||||
p5000_sprite_ = std::make_shared<SmartSprite>(game_text_texture_);
|
// game_text_sprites_.emplace_back(std::make_shared<SmartSprite>(game_text_textures_.at(2)));
|
||||||
|
// game_text_sprites_.emplace_back(std::make_shared<SmartSprite>(game_text_textures_.at(3)));
|
||||||
|
// game_text_sprites_.emplace_back(std::make_shared<SmartSprite>(game_text_textures_.at(4)));
|
||||||
|
|
||||||
explosions_->addTexture(1, explosions_textures_[0], explosions_animations_[0]);
|
explosions_->addTexture(1, explosions_textures_[0], explosions_animations_[0]);
|
||||||
explosions_->addTexture(2, explosions_textures_[1], explosions_animations_[1]);
|
explosions_->addTexture(2, explosions_textures_[1], explosions_animations_[1]);
|
||||||
@@ -295,54 +298,8 @@ void Game::init(int player_id)
|
|||||||
// Con los globos creados, calcula el nivel de amenaza
|
// Con los globos creados, calcula el nivel de amenaza
|
||||||
evaluateAndSetMenace();
|
evaluateAndSetMenace();
|
||||||
|
|
||||||
// Inicializa el bitmap de 1000 puntos
|
// Inicializa los sprites con los textos que aparecen al coger items
|
||||||
constexpr auto height = 15;
|
smart_sprites_.clear();
|
||||||
constexpr auto sprite1_width = 35;
|
|
||||||
constexpr auto sprite2_width = 38;
|
|
||||||
constexpr auto sprite3_width = 39;
|
|
||||||
p1000_sprite_->setPosX(0);
|
|
||||||
p1000_sprite_->setPosY(0);
|
|
||||||
p1000_sprite_->setWidth(sprite1_width);
|
|
||||||
p1000_sprite_->setHeight(height);
|
|
||||||
p1000_sprite_->setVelX(0.0f);
|
|
||||||
p1000_sprite_->setVelY(-0.5f);
|
|
||||||
p1000_sprite_->setAccelX(0.0f);
|
|
||||||
p1000_sprite_->setAccelY(-0.1f);
|
|
||||||
p1000_sprite_->setSpriteClip(0, 0, sprite1_width, height);
|
|
||||||
p1000_sprite_->setEnabled(false);
|
|
||||||
p1000_sprite_->setFinishedCounter(0);
|
|
||||||
p1000_sprite_->setDestX(0);
|
|
||||||
p1000_sprite_->setDestY(0);
|
|
||||||
|
|
||||||
// Inicializa el bitmap de 2500 puntos
|
|
||||||
p2500_sprite_->setPosX(0);
|
|
||||||
p2500_sprite_->setPosY(0);
|
|
||||||
p2500_sprite_->setWidth(sprite2_width);
|
|
||||||
p2500_sprite_->setHeight(height);
|
|
||||||
p2500_sprite_->setVelX(0.0f);
|
|
||||||
p2500_sprite_->setVelY(-0.5f);
|
|
||||||
p2500_sprite_->setAccelX(0.0f);
|
|
||||||
p2500_sprite_->setAccelY(-0.1f);
|
|
||||||
p2500_sprite_->setSpriteClip(sprite1_width, 0, sprite2_width, height);
|
|
||||||
p2500_sprite_->setEnabled(false);
|
|
||||||
p2500_sprite_->setFinishedCounter(0);
|
|
||||||
p2500_sprite_->setDestX(0);
|
|
||||||
p2500_sprite_->setDestY(0);
|
|
||||||
|
|
||||||
// Inicializa el bitmap de 5000 puntos
|
|
||||||
p5000_sprite_->setPosX(0);
|
|
||||||
p5000_sprite_->setPosY(0);
|
|
||||||
p5000_sprite_->setWidth(sprite3_width);
|
|
||||||
p5000_sprite_->setHeight(height);
|
|
||||||
p5000_sprite_->setVelX(0.0f);
|
|
||||||
p5000_sprite_->setVelY(-0.5f);
|
|
||||||
p5000_sprite_->setAccelX(0.0f);
|
|
||||||
p5000_sprite_->setAccelY(-0.1f);
|
|
||||||
p5000_sprite_->setSpriteClip(sprite1_width + sprite2_width, 0, sprite3_width, height);
|
|
||||||
p5000_sprite_->setEnabled(false);
|
|
||||||
p5000_sprite_->setFinishedCounter(0);
|
|
||||||
p5000_sprite_->setDestX(0);
|
|
||||||
p5000_sprite_->setDestY(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los recursos necesarios para la sección 'Game'
|
// Carga los recursos necesarios para la sección 'Game'
|
||||||
@@ -362,93 +319,73 @@ void Game::loadMedia()
|
|||||||
item_textures_.clear();
|
item_textures_.clear();
|
||||||
balloon_textures_.clear();
|
balloon_textures_.clear();
|
||||||
explosions_textures_.clear();
|
explosions_textures_.clear();
|
||||||
|
game_text_textures_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas
|
// Texturas
|
||||||
{
|
{
|
||||||
bullet_texture_ = std::make_shared<Texture>(renderer_, asset_->get("bullet.png"));
|
bullet_texture_ = std::make_shared<Texture>(renderer_, asset_->get("bullet.png"));
|
||||||
game_text_texture_ = std::make_shared<Texture>(renderer_, asset_->get("game_text.png"));
|
}
|
||||||
|
|
||||||
|
// 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(std::make_shared<Texture>(renderer_, asset_->get("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(std::make_shared<Texture>(renderer_, asset_->get("game_text_powerup.png")));
|
||||||
|
game_text_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("game_text_one_hit.png")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Globos
|
// Texturas - Globos
|
||||||
{
|
{
|
||||||
auto balloon1_texture = std::make_shared<Texture>(renderer_, asset_->get("balloon1.png"));
|
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("balloon1.png")));
|
||||||
balloon_textures_.push_back(balloon1_texture);
|
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("balloon2.png")));
|
||||||
|
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("balloon3.png")));
|
||||||
auto balloon2_texture = std::make_shared<Texture>(renderer_, asset_->get("balloon2.png"));
|
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("balloon4.png")));
|
||||||
balloon_textures_.push_back(balloon2_texture);
|
balloon_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("powerball.png")));
|
||||||
|
}
|
||||||
auto balloon3_texture = std::make_shared<Texture>(renderer_, asset_->get("balloon3.png"));
|
|
||||||
balloon_textures_.push_back(balloon3_texture);
|
|
||||||
|
|
||||||
auto balloon4_texture = std::make_shared<Texture>(renderer_, asset_->get("balloon4.png"));
|
|
||||||
balloon_textures_.push_back(balloon4_texture);
|
|
||||||
|
|
||||||
auto balloon5_texture = std::make_shared<Texture>(renderer_, asset_->get("powerball.png"));
|
|
||||||
balloon_textures_.push_back(balloon5_texture);
|
|
||||||
|
|
||||||
// Texturas - Explosiones
|
// Texturas - Explosiones
|
||||||
auto explosion1_texture = std::make_shared<Texture>(renderer_, asset_->get("explosion1.png"));
|
{
|
||||||
explosions_textures_.push_back(explosion1_texture);
|
explosions_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("explosion1.png")));
|
||||||
|
explosions_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("explosion2.png")));
|
||||||
auto explosion2_texture = std::make_shared<Texture>(renderer_, asset_->get("explosion2.png"));
|
explosions_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("explosion3.png")));
|
||||||
explosions_textures_.push_back(explosion2_texture);
|
explosions_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("explosion4.png")));
|
||||||
|
|
||||||
auto explosion3_texture = std::make_shared<Texture>(renderer_, asset_->get("explosion3.png"));
|
|
||||||
explosions_textures_.push_back(explosion3_texture);
|
|
||||||
|
|
||||||
auto explosion4_texture = std::make_shared<Texture>(renderer_, asset_->get("explosion4.png"));
|
|
||||||
explosions_textures_.push_back(explosion4_texture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Items
|
// Texturas - Items
|
||||||
{
|
{
|
||||||
auto item1 = std::make_shared<Texture>(renderer_, asset_->get("item_points1_disk.png"));
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_points1_disk.png")));
|
||||||
item_textures_.push_back(item1);
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_points2_gavina.png")));
|
||||||
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_points3_pacmar.png")));
|
||||||
auto item2 = std::make_shared<Texture>(renderer_, asset_->get("item_points2_gavina.png"));
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_clock.png")));
|
||||||
item_textures_.push_back(item2);
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_coffee.png")));
|
||||||
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("item_coffee_machine.png")));
|
||||||
auto item3 = std::make_shared<Texture>(renderer_, asset_->get("item_points3_pacmar.png"));
|
|
||||||
item_textures_.push_back(item3);
|
|
||||||
|
|
||||||
auto item4 = std::make_shared<Texture>(renderer_, asset_->get("item_clock.png"));
|
|
||||||
item_textures_.push_back(item4);
|
|
||||||
|
|
||||||
auto item5 = std::make_shared<Texture>(renderer_, asset_->get("item_coffee.png"));
|
|
||||||
item_textures_.push_back(item5);
|
|
||||||
|
|
||||||
auto item6 = std::make_shared<Texture>(renderer_, asset_->get("item_coffee_machine.png"));
|
|
||||||
item_textures_.push_back(item6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Player1
|
// Texturas - Player1
|
||||||
{
|
{
|
||||||
auto player1_texture = std::make_shared<Texture>(renderer_, asset_->get("player1.gif"));
|
player1_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player1.gif")));
|
||||||
player1_texture->addPalette(asset_->get("player1_pal1.gif"));
|
player1_textures_.back()->addPalette(asset_->get("player1_pal1.gif"));
|
||||||
player1_texture->addPalette(asset_->get("player1_pal2.gif"));
|
player1_textures_.back()->addPalette(asset_->get("player1_pal2.gif"));
|
||||||
player1_texture->addPalette(asset_->get("player1_pal3.gif"));
|
player1_textures_.back()->addPalette(asset_->get("player1_pal3.gif"));
|
||||||
player1_textures_.push_back(player1_texture);
|
|
||||||
|
|
||||||
auto player1_power_texture = std::make_shared<Texture>(renderer_, asset_->get("player_power.gif"));
|
player1_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player_power.gif")));
|
||||||
player1_power_texture->addPalette(asset_->get("player_power_pal.gif"));
|
player1_textures_.back()->addPalette(asset_->get("player_power_pal.gif"));
|
||||||
player1_textures_.push_back(player1_power_texture);
|
|
||||||
|
|
||||||
player_textures_.push_back(player1_textures_);
|
player_textures_.push_back(player1_textures_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturas - Player2
|
// Texturas - Player2
|
||||||
{
|
{
|
||||||
auto player2_texture = std::make_shared<Texture>(renderer_, asset_->get("player2.gif"));
|
player2_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player2.gif")));
|
||||||
player2_texture->addPalette(asset_->get("player2_pal1.gif"));
|
player2_textures_.back()->addPalette(asset_->get("player2_pal1.gif"));
|
||||||
player2_texture->addPalette(asset_->get("player2_pal2.gif"));
|
player2_textures_.back()->addPalette(asset_->get("player2_pal2.gif"));
|
||||||
player2_texture->addPalette(asset_->get("player2_pal3.gif"));
|
player2_textures_.back()->addPalette(asset_->get("player2_pal3.gif"));
|
||||||
player2_textures_.push_back(player2_texture);
|
|
||||||
|
|
||||||
auto player2_power_texture = std::make_shared<Texture>(renderer_, asset_->get("player_power.gif"));
|
player2_textures_.emplace_back(std::make_shared<Texture>(renderer_, asset_->get("player_power.gif")));
|
||||||
player2_power_texture->addPalette(asset_->get("player_power_pal.gif"));
|
player2_textures_.back()->addPalette(asset_->get("player_power_pal.gif"));
|
||||||
player2_power_texture->setPalette(1);
|
player2_textures_.back()->setPalette(1);
|
||||||
player2_textures_.push_back(player2_power_texture);
|
|
||||||
|
|
||||||
player_textures_.push_back(player2_textures_);
|
player_textures_.push_back(player2_textures_);
|
||||||
}
|
}
|
||||||
@@ -1192,50 +1129,55 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
{
|
{
|
||||||
if (checkCollision(player->getCollider(), item->getCollider()))
|
if (checkCollision(player->getCollider(), item->getCollider()))
|
||||||
{
|
{
|
||||||
switch (item->getClass())
|
switch (item->getType())
|
||||||
{
|
{
|
||||||
case ITEM_POINTS_1_DISK:
|
case ItemType::DISK:
|
||||||
{
|
{
|
||||||
player->addScore(1000);
|
player->addScore(1000);
|
||||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (p1000_sprite_->getWidth() / 2), player->getPosY(), p1000_sprite_);
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[0]->getWidth() / 2), player->getPosY(), game_text_textures_[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ITEM_POINTS_2_GAVINA:
|
case ItemType::GAVINA:
|
||||||
{
|
{
|
||||||
player->addScore(2500);
|
player->addScore(2500);
|
||||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (p2500_sprite_->getWidth() / 2), player->getPosY(), p2500_sprite_);
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[1]->getWidth() / 2), player->getPosY(), game_text_textures_[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ITEM_POINTS_3_PACMAR:
|
case ItemType::PACMAR:
|
||||||
{
|
{
|
||||||
player->addScore(5000);
|
player->addScore(5000);
|
||||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (p5000_sprite_->getWidth() / 2), player->getPosY(), p5000_sprite_);
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[2]->getWidth() / 2), player->getPosY(), game_text_textures_[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ITEM_CLOCK:
|
case ItemType::CLOCK:
|
||||||
{
|
{
|
||||||
enableTimeStopItem();
|
enableTimeStopItem();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ITEM_COFFEE:
|
case ItemType::COFFEE:
|
||||||
{
|
{
|
||||||
if (player->getCoffees() == 2)
|
if (player->getCoffees() == 2)
|
||||||
{
|
{
|
||||||
player->addScore(5000);
|
player->addScore(5000);
|
||||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (p5000_sprite_->getWidth() / 2), player->getPosY(), p5000_sprite_);
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[2]->getWidth() / 2), player->getPosY(), game_text_textures_[2]);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
player->giveExtraHit();
|
player->giveExtraHit();
|
||||||
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[4]->getWidth() / 2), player->getPosY(), game_text_textures_[4]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ITEM_COFFEE_MACHINE:
|
case ItemType::COFFEE_MACHINE:
|
||||||
{
|
{
|
||||||
player->setPowerUp();
|
player->setPowerUp();
|
||||||
coffee_machine_enabled_ = false;
|
coffee_machine_enabled_ = false;
|
||||||
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[3]->getWidth() / 2), player->getPosY(), game_text_textures_[3]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1274,9 +1216,9 @@ void Game::checkBulletBalloonCollision()
|
|||||||
|
|
||||||
// Suelta el item si se da el caso
|
// Suelta el item si se da el caso
|
||||||
const auto droppeditem = dropItem();
|
const auto droppeditem = dropItem();
|
||||||
if (droppeditem != ITEM_NULL && !demo_.recording)
|
if (droppeditem != ItemType::NONE && !demo_.recording)
|
||||||
{
|
{
|
||||||
if (droppeditem != ITEM_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(item_drop_sound_);
|
||||||
@@ -1380,7 +1322,7 @@ void Game::renderItems()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve un item al azar y luego segun sus probabilidades
|
// Devuelve un item al azar y luego segun sus probabilidades
|
||||||
int Game::dropItem()
|
ItemType Game::dropItem()
|
||||||
{
|
{
|
||||||
const auto lucky_number = rand() % 100;
|
const auto lucky_number = rand() % 100;
|
||||||
const auto item = rand() % 6;
|
const auto item = rand() % 6;
|
||||||
@@ -1390,28 +1332,28 @@ int Game::dropItem()
|
|||||||
case 0:
|
case 0:
|
||||||
if (lucky_number < helper_.item_disk_odds)
|
if (lucky_number < helper_.item_disk_odds)
|
||||||
{
|
{
|
||||||
return ITEM_POINTS_1_DISK;
|
return ItemType::DISK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
if (lucky_number < helper_.item_gavina_odds)
|
if (lucky_number < helper_.item_gavina_odds)
|
||||||
{
|
{
|
||||||
return ITEM_POINTS_2_GAVINA;
|
return ItemType::GAVINA;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
if (lucky_number < helper_.item_pacmar_odds)
|
if (lucky_number < helper_.item_pacmar_odds)
|
||||||
{
|
{
|
||||||
return ITEM_POINTS_3_PACMAR;
|
return ItemType::GAVINA;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
if (lucky_number < helper_.item_clock_odds)
|
if (lucky_number < helper_.item_clock_odds)
|
||||||
{
|
{
|
||||||
return ITEM_CLOCK;
|
return ItemType::CLOCK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1419,7 +1361,7 @@ int Game::dropItem()
|
|||||||
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 ITEM_COFFEE;
|
return ItemType::COFFEE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1436,7 +1378,7 @@ int Game::dropItem()
|
|||||||
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 ITEM_COFFEE_MACHINE;
|
return ItemType::COFFEE_MACHINE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1452,14 +1394,13 @@ int Game::dropItem()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ITEM_NULL;
|
return ItemType::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea un objeto item
|
// Crea un objeto item
|
||||||
void Game::createItem(int kind, float x, float y)
|
void Game::createItem(ItemType type, float x, float y)
|
||||||
{
|
{
|
||||||
auto item = std::make_unique<Item>(kind, x, y, &(param.game.play_area.rect), item_textures_[kind - 1], item_animations_[kind - 1]);
|
items_.emplace_back(std::make_unique<Item>(type, x, y, &(param.game.play_area.rect), item_textures_[static_cast<int>(type) - 1], item_animations_[static_cast<int>(type) - 1]));
|
||||||
items_.push_back(std::move(item));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vacia el vector de items
|
// Vacia el vector de items
|
||||||
@@ -1478,19 +1419,21 @@ void Game::freeItems()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto
|
// Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto
|
||||||
void Game::createItemScoreSprite(int x, int y, std::shared_ptr<SmartSprite> sprite)
|
void Game::createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture)
|
||||||
{
|
{
|
||||||
auto ss = new SmartSprite(nullptr);
|
smart_sprites_.emplace_back(std::make_unique<SmartSprite>(texture));
|
||||||
smart_sprites_.push_back(ss);
|
|
||||||
|
|
||||||
// Crea una copia del objeto
|
// Inicializa
|
||||||
*ss = *sprite;
|
smart_sprites_.back()->setPos({0, 0, texture->getWidth(), texture->getHeight()});
|
||||||
ss->setPosX(x);
|
smart_sprites_.back()->setSpriteClip(smart_sprites_.back()->getPos());
|
||||||
ss->setPosY(y);
|
smart_sprites_.back()->setPosX(x);
|
||||||
ss->setDestX(x);
|
smart_sprites_.back()->setPosY(y);
|
||||||
ss->setDestY(y - 25);
|
smart_sprites_.back()->setDestX(x);
|
||||||
ss->setEnabled(true);
|
smart_sprites_.back()->setDestY(y - 25);
|
||||||
ss->setFinishedCounter(100);
|
smart_sprites_.back()->setVelY(-0.5f);
|
||||||
|
smart_sprites_.back()->setAccelY(-0.1f);
|
||||||
|
smart_sprites_.back()->setEnabled(true);
|
||||||
|
smart_sprites_.back()->setFinishedCounter(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vacia el vector de smartsprites
|
// Vacia el vector de smartsprites
|
||||||
@@ -1511,31 +1454,30 @@ void Game::freeSmartSprites()
|
|||||||
// Crea un SmartSprite para arrojar el item café al recibir un impacto
|
// Crea un SmartSprite para arrojar el item café al recibir un impacto
|
||||||
void Game::throwCoffee(int x, int y)
|
void Game::throwCoffee(int x, int y)
|
||||||
{
|
{
|
||||||
auto ss = new SmartSprite(item_textures_[4]);
|
smart_sprites_.emplace_back(std::make_unique<SmartSprite>(item_textures_[4]));
|
||||||
smart_sprites_.push_back(ss);
|
|
||||||
|
|
||||||
ss->setPosX(x - 8);
|
smart_sprites_.back()->setPosX(x - 8);
|
||||||
ss->setPosY(y - 8);
|
smart_sprites_.back()->setPosY(y - 8);
|
||||||
ss->setWidth(param.game.item_size);
|
smart_sprites_.back()->setWidth(param.game.item_size);
|
||||||
ss->setHeight(param.game.item_size);
|
smart_sprites_.back()->setHeight(param.game.item_size);
|
||||||
ss->setVelX(-1.0f + ((rand() % 5) * 0.5f));
|
smart_sprites_.back()->setVelX(-1.0f + ((rand() % 5) * 0.5f));
|
||||||
ss->setVelY(-4.0f);
|
smart_sprites_.back()->setVelY(-4.0f);
|
||||||
ss->setAccelX(0.0f);
|
smart_sprites_.back()->setAccelX(0.0f);
|
||||||
ss->setAccelY(0.2f);
|
smart_sprites_.back()->setAccelY(0.2f);
|
||||||
ss->setDestX(x + (ss->getVelX() * 50));
|
smart_sprites_.back()->setDestX(x + (smart_sprites_.back()->getVelX() * 50));
|
||||||
ss->setDestY(param.game.height + 1);
|
smart_sprites_.back()->setDestY(param.game.height + 1);
|
||||||
ss->setEnabled(true);
|
smart_sprites_.back()->setEnabled(true);
|
||||||
ss->setFinishedCounter(1);
|
smart_sprites_.back()->setFinishedCounter(1);
|
||||||
ss->setSpriteClip(0, param.game.item_size, param.game.item_size, param.game.item_size);
|
smart_sprites_.back()->setSpriteClip(0, param.game.item_size, param.game.item_size, param.game.item_size);
|
||||||
ss->setRotate(true);
|
smart_sprites_.back()->setRotate(true);
|
||||||
ss->setRotateSpeed(10);
|
smart_sprites_.back()->setRotateSpeed(10);
|
||||||
ss->setRotateAmount(90.0);
|
smart_sprites_.back()->setRotateAmount(90.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los SmartSprites
|
// Actualiza los SmartSprites
|
||||||
void Game::updateSmartSprites()
|
void Game::updateSmartSprites()
|
||||||
{
|
{
|
||||||
for (auto ss : smart_sprites_)
|
for (auto &ss : smart_sprites_)
|
||||||
{
|
{
|
||||||
ss->update();
|
ss->update();
|
||||||
}
|
}
|
||||||
@@ -1544,7 +1486,7 @@ void Game::updateSmartSprites()
|
|||||||
// Pinta los SmartSprites activos
|
// Pinta los SmartSprites activos
|
||||||
void Game::renderSmartSprites()
|
void Game::renderSmartSprites()
|
||||||
{
|
{
|
||||||
for (auto ss : smart_sprites_)
|
for (auto &ss : smart_sprites_)
|
||||||
{
|
{
|
||||||
ss->render();
|
ss->render();
|
||||||
}
|
}
|
||||||
@@ -2541,8 +2483,12 @@ void Game::reloadTextures()
|
|||||||
texture->reLoad();
|
texture->reLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto &texture : game_text_textures_)
|
||||||
|
{
|
||||||
|
texture->reLoad();
|
||||||
|
}
|
||||||
|
|
||||||
bullet_texture_->reLoad();
|
bullet_texture_->reLoad();
|
||||||
game_text_texture_->reLoad();
|
|
||||||
background_->reloadTextures();
|
background_->reloadTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class Texture;
|
|||||||
enum class BulletType; // lines 26-26
|
enum class BulletType; // lines 26-26
|
||||||
struct JA_Music_t; // lines 27-27
|
struct JA_Music_t; // lines 27-27
|
||||||
struct JA_Sound_t; // lines 28-28
|
struct JA_Sound_t; // lines 28-28
|
||||||
|
enum class ItemType;
|
||||||
|
|
||||||
// Modo demo
|
// Modo demo
|
||||||
constexpr bool GAME_MODE_DEMO_OFF = false;
|
constexpr bool GAME_MODE_DEMO_OFF = false;
|
||||||
@@ -122,7 +123,7 @@ private:
|
|||||||
std::vector<std::shared_ptr<Balloon>> balloons_; // Vector con los globos
|
std::vector<std::shared_ptr<Balloon>> balloons_; // Vector con los globos
|
||||||
std::vector<std::unique_ptr<Bullet>> bullets_; // Vector con las balas
|
std::vector<std::unique_ptr<Bullet>> bullets_; // Vector con las balas
|
||||||
std::vector<std::unique_ptr<Item>> items_; // Vector con los items
|
std::vector<std::unique_ptr<Item>> items_; // Vector con los items
|
||||||
std::vector<SmartSprite *> smart_sprites_; // Vector con los smartsprites
|
std::vector<std::unique_ptr<SmartSprite>> smart_sprites_; // Vector con los smartsprites
|
||||||
|
|
||||||
std::shared_ptr<Texture> bullet_texture_; // Textura para las balas
|
std::shared_ptr<Texture> bullet_texture_; // Textura para las balas
|
||||||
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
|
||||||
@@ -132,7 +133,8 @@ private:
|
|||||||
std::vector<std::shared_ptr<Texture>> player2_textures_; // Vector con las texturas del jugador
|
std::vector<std::shared_ptr<Texture>> player2_textures_; // Vector con las texturas del jugador
|
||||||
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores;
|
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores;
|
||||||
|
|
||||||
std::shared_ptr<Texture> game_text_texture_; // Textura para los sprites con textos
|
std::vector<std::shared_ptr<Texture>> game_text_textures_; // Vector con las texturas para los sprites con textos
|
||||||
|
//std::vector<std::shared_ptr<SmartSprite>> game_text_sprites_; // Sprite con el textos que aparecen al coger items
|
||||||
|
|
||||||
std::vector<std::vector<std::string> *> item_animations_; // Vector con las animaciones de los items
|
std::vector<std::vector<std::string> *> item_animations_; // Vector con las animaciones de los items
|
||||||
std::vector<std::vector<std::string> *> player_animations_; // Vector con las animaciones del jugador
|
std::vector<std::vector<std::string> *> player_animations_; // Vector con las animaciones del jugador
|
||||||
@@ -146,10 +148,6 @@ private:
|
|||||||
|
|
||||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||||
|
|
||||||
std::shared_ptr<SmartSprite> p1000_sprite_; // Sprite con el texto 1.000
|
|
||||||
std::shared_ptr<SmartSprite> p2500_sprite_; // Sprite con el texto 2.500
|
|
||||||
std::shared_ptr<SmartSprite> p5000_sprite_; // Sprite con el texto 5.000
|
|
||||||
|
|
||||||
JA_Sound_t *balloon_sound_; // Sonido para la explosión del globo
|
JA_Sound_t *balloon_sound_; // Sonido para la explosión del globo
|
||||||
JA_Sound_t *bullet_sound_; // Sonido para los disparos
|
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 *player_collision_sound_; // Sonido para la colisión del jugador con un enemigo
|
||||||
@@ -315,16 +313,16 @@ private:
|
|||||||
void renderItems();
|
void renderItems();
|
||||||
|
|
||||||
// Devuelve un item en función del azar
|
// Devuelve un item en función del azar
|
||||||
int dropItem();
|
ItemType dropItem();
|
||||||
|
|
||||||
// Crea un objeto item
|
// Crea un objeto item
|
||||||
void createItem(int kind, float x, float y);
|
void createItem(ItemType type, float x, float y);
|
||||||
|
|
||||||
// Vacia el vector de items
|
// Vacia el vector de items
|
||||||
void freeItems();
|
void freeItems();
|
||||||
|
|
||||||
// Crea un objeto SmartSprite
|
// Crea un objeto SmartSprite
|
||||||
void createItemScoreSprite(int x, int y, std::shared_ptr<SmartSprite> sprite);
|
void createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture);
|
||||||
|
|
||||||
// Vacia el vector de smartsprites
|
// Vacia el vector de smartsprites
|
||||||
void freeSmartSprites();
|
void freeSmartSprites();
|
||||||
|
|||||||
@@ -5,16 +5,16 @@
|
|||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(int kind, float x, float y, SDL_Rect *play_area, std::shared_ptr<Texture> texture, std::vector<std::string> *animation)
|
Item::Item(ItemType type, float x, float y, SDL_Rect *play_area, std::shared_ptr<Texture> texture, std::vector<std::string> *animation)
|
||||||
: sprite_(std::make_unique<AnimatedSprite>(texture, "", animation)),
|
: sprite_(std::make_unique<AnimatedSprite>(texture, "", animation)),
|
||||||
accel_x_(0.0f),
|
accel_x_(0.0f),
|
||||||
floor_collision_(false),
|
floor_collision_(false),
|
||||||
kind_(kind),
|
type_(type),
|
||||||
enabled_(true),
|
enabled_(true),
|
||||||
play_area_(play_area),
|
play_area_(play_area),
|
||||||
time_to_live_(600)
|
time_to_live_(600)
|
||||||
{
|
{
|
||||||
if (kind == ITEM_COFFEE_MACHINE)
|
if (type == ItemType::COFFEE_MACHINE)
|
||||||
{
|
{
|
||||||
width_ = 28;
|
width_ = 28;
|
||||||
height_ = 37;
|
height_ = 37;
|
||||||
@@ -104,7 +104,7 @@ void Item::move()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si se sale por arriba rebota (excepto la maquina de café)
|
// Si se sale por arriba rebota (excepto la maquina de café)
|
||||||
if ((pos_y_ < param.game.play_area.rect.y) && !(kind_ == ITEM_COFFEE_MACHINE))
|
if ((pos_y_ < param.game.play_area.rect.y) && !(type_ == ItemType::COFFEE_MACHINE))
|
||||||
{
|
{
|
||||||
// Corrige
|
// Corrige
|
||||||
pos_y_ = param.game.play_area.rect.y;
|
pos_y_ = param.game.play_area.rect.y;
|
||||||
@@ -122,7 +122,7 @@ void Item::move()
|
|||||||
accel_x_ = 0;
|
accel_x_ = 0;
|
||||||
accel_y_ = 0;
|
accel_y_ = 0;
|
||||||
pos_y_ = play_area_->h - height_;
|
pos_y_ = play_area_->h - height_;
|
||||||
if (kind_ == ITEM_COFFEE_MACHINE)
|
if (type_ == ItemType::COFFEE_MACHINE)
|
||||||
{
|
{
|
||||||
floor_collision_ = true;
|
floor_collision_ = true;
|
||||||
}
|
}
|
||||||
@@ -190,9 +190,9 @@ int Item::getHeight()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Item::getClass()
|
ItemType Item::getType()
|
||||||
{
|
{
|
||||||
return kind_;
|
return type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
|
|||||||
@@ -10,13 +10,16 @@
|
|||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
// Tipos de objetos
|
// Tipos de objetos
|
||||||
constexpr int ITEM_POINTS_1_DISK = 1;
|
enum class ItemType : int
|
||||||
constexpr int ITEM_POINTS_2_GAVINA = 2;
|
{
|
||||||
constexpr int ITEM_POINTS_3_PACMAR = 3;
|
DISK = 1,
|
||||||
constexpr int ITEM_CLOCK = 4;
|
GAVINA = 2,
|
||||||
constexpr int ITEM_COFFEE = 5;
|
PACMAR = 3,
|
||||||
constexpr int ITEM_COFFEE_MACHINE = 6;
|
CLOCK = 4,
|
||||||
constexpr int ITEM_NULL = 7;
|
COFFEE = 5,
|
||||||
|
COFFEE_MACHINE = 6,
|
||||||
|
NONE = 7,
|
||||||
|
};
|
||||||
|
|
||||||
// Clase Item
|
// Clase Item
|
||||||
class Item
|
class Item
|
||||||
@@ -35,7 +38,7 @@ private:
|
|||||||
float accel_x_; // Aceleración en el eje X
|
float accel_x_; // Aceleración en el eje X
|
||||||
float accel_y_; // Aceleración en el eje Y
|
float accel_y_; // Aceleración en el eje Y
|
||||||
bool floor_collision_; // Indica si el objeto colisiona con el suelo
|
bool floor_collision_; // Indica si el objeto colisiona con el suelo
|
||||||
int kind_; // Especifica el tipo de objeto que es
|
ItemType type_; // Especifica el tipo de objeto que es
|
||||||
bool enabled_; // Especifica si el objeto está habilitado
|
bool enabled_; // Especifica si el objeto está habilitado
|
||||||
Circle collider_; // Circulo de colisión del objeto
|
Circle collider_; // Circulo de colisión del objeto
|
||||||
SDL_Rect *play_area_; // Rectangulo con la zona de juego
|
SDL_Rect *play_area_; // Rectangulo con la zona de juego
|
||||||
@@ -55,7 +58,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Item(int kind, float x, float y, SDL_Rect *play_area, std::shared_ptr<Texture> texture, std::vector<std::string> *animation);
|
Item(ItemType type, float x, float y, SDL_Rect *play_area, std::shared_ptr<Texture> texture, std::vector<std::string> *animation);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Item() = default;
|
~Item() = default;
|
||||||
@@ -85,7 +88,7 @@ public:
|
|||||||
int getHeight();
|
int getHeight();
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getClass();
|
ItemType getType();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
|
|||||||
@@ -1,166 +0,0 @@
|
|||||||
#ifdef JA_USESDLMIXER
|
|
||||||
#include "jail_audio.h"
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_mixer.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
struct JA_Sound_t {}; // Dummy structs
|
|
||||||
struct JA_Music_t {};
|
|
||||||
|
|
||||||
int JA_freq {48000};
|
|
||||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
|
||||||
Uint8 JA_channels {2};
|
|
||||||
int JA_musicVolume = 128;
|
|
||||||
int JA_soundVolume = 64;
|
|
||||||
bool JA_musicEnabled = true;
|
|
||||||
bool JA_soundEnabled = true;
|
|
||||||
|
|
||||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
|
||||||
JA_freq = freq;
|
|
||||||
JA_format = format;
|
|
||||||
JA_channels = channels;
|
|
||||||
Mix_OpenAudio(JA_freq, JA_format, JA_channels, 1024);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_Quit() {
|
|
||||||
Mix_CloseAudio();
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Music_t *JA_LoadMusic(const char* filename) {
|
|
||||||
return (JA_Music_t*)Mix_LoadMUS(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PlayMusic(JA_Music_t *music, const int loop)
|
|
||||||
{
|
|
||||||
if (!JA_musicEnabled) return;
|
|
||||||
Mix_PlayMusic((Mix_Music*)music, loop);
|
|
||||||
Mix_VolumeMusic(JA_musicVolume);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PauseMusic()
|
|
||||||
{
|
|
||||||
if (!JA_musicEnabled) return;
|
|
||||||
Mix_PauseMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_ResumeMusic()
|
|
||||||
{
|
|
||||||
if (!JA_musicEnabled) return;
|
|
||||||
Mix_ResumeMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_StopMusic()
|
|
||||||
{
|
|
||||||
if (!JA_musicEnabled) return;
|
|
||||||
Mix_HaltMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Music_state JA_GetMusicState()
|
|
||||||
{
|
|
||||||
if (!JA_musicEnabled) return JA_MUSIC_DISABLED;
|
|
||||||
|
|
||||||
if (Mix_PausedMusic()) {
|
|
||||||
return JA_MUSIC_PAUSED;
|
|
||||||
} else if (Mix_PlayingMusic()) {
|
|
||||||
return JA_MUSIC_PLAYING;
|
|
||||||
} else {
|
|
||||||
return JA_MUSIC_STOPPED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_DeleteMusic(JA_Music_t *music)
|
|
||||||
{
|
|
||||||
Mix_FreeMusic((Mix_Music*)music);
|
|
||||||
}
|
|
||||||
|
|
||||||
int JA_SetMusicVolume(int volume)
|
|
||||||
{
|
|
||||||
JA_musicVolume = volume;
|
|
||||||
Mix_VolumeMusic(JA_musicVolume);
|
|
||||||
return JA_musicVolume;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_EnableMusic(const bool value)
|
|
||||||
{
|
|
||||||
if (Mix_PlayingMusic()) Mix_HaltMusic();
|
|
||||||
JA_musicEnabled = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Sound_t *JA_LoadSound(const char* filename) {
|
|
||||||
JA_Sound_t *sound = (JA_Sound_t*)Mix_LoadWAV(filename);
|
|
||||||
return sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
|
||||||
if (!JA_soundEnabled) return -1;
|
|
||||||
const int channel = Mix_PlayChannel(-1, (Mix_Chunk*)sound, loop);
|
|
||||||
Mix_Volume(-1, JA_soundVolume);
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_DeleteSound(JA_Sound_t *sound)
|
|
||||||
{
|
|
||||||
Mix_FreeChunk((Mix_Chunk*)sound);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PauseChannel(const int channel)
|
|
||||||
{
|
|
||||||
if (!JA_soundEnabled) return;
|
|
||||||
Mix_Pause(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_ResumeChannel(const int channel)
|
|
||||||
{
|
|
||||||
if (!JA_soundEnabled) return;
|
|
||||||
Mix_Resume(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_StopChannel(const int channel)
|
|
||||||
{
|
|
||||||
if (!JA_soundEnabled) return;
|
|
||||||
Mix_HaltChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Channel_state JA_GetChannelState(const int channel)
|
|
||||||
{
|
|
||||||
if (!JA_soundEnabled) return JA_SOUND_DISABLED;
|
|
||||||
|
|
||||||
if (Mix_Paused(channel)) {
|
|
||||||
return JA_CHANNEL_PAUSED;
|
|
||||||
} else if (Mix_Playing(channel)) {
|
|
||||||
return JA_CHANNEL_PLAYING;
|
|
||||||
} else {
|
|
||||||
return JA_CHANNEL_FREE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int JA_SetSoundVolume(int volume)
|
|
||||||
{
|
|
||||||
JA_musicVolume = volume;
|
|
||||||
Mix_Volume(-1, JA_musicVolume);
|
|
||||||
return JA_musicVolume;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_EnableSound(const bool value)
|
|
||||||
{
|
|
||||||
Mix_HaltChannel(-1);
|
|
||||||
JA_soundEnabled = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int JA_SetVolume(int volume)
|
|
||||||
{
|
|
||||||
JA_SetSoundVolume(volume);
|
|
||||||
return JA_SetMusicVolume(volume);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -149,11 +149,11 @@ void Player::setInputEnteringName(InputType input)
|
|||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
case InputType::LEFT:
|
case InputType::LEFT:
|
||||||
enter_name_->decPos();
|
enter_name_->decPosition();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case InputType::RIGHT:
|
case InputType::RIGHT:
|
||||||
enter_name_->incPos();
|
enter_name_->incPosition();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case InputType::UP:
|
case InputType::UP:
|
||||||
@@ -763,7 +763,7 @@ int Player::getRecordNamePos() const
|
|||||||
{
|
{
|
||||||
if (enter_name_)
|
if (enter_name_)
|
||||||
{
|
{
|
||||||
return enter_name_->getPos();
|
return enter_name_->getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -200,8 +200,9 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
|||||||
SDL_ShowCursor(SDL_ENABLE);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
#endif
|
#endif
|
||||||
// Modifica el tamaño de la ventana
|
// Modifica el tamaño de la ventana
|
||||||
|
SDL_Point pos = getNewPosition();
|
||||||
SDL_SetWindowSize(window_, param.game.width * options.video.window.size, param.game.height * options.video.window.size);
|
SDL_SetWindowSize(window_, param.game.width * options.video.window.size, param.game.height * options.video.window.size);
|
||||||
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
SDL_SetWindowPosition(window_, pos.x, pos.y);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -495,3 +496,39 @@ bool Screen::notificationsAreActive() const
|
|||||||
{
|
{
|
||||||
return notify_->active();
|
return notify_->active();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
||||||
|
SDL_Point Screen::getNewPosition()
|
||||||
|
{
|
||||||
|
// Obtiene la posición actual de la ventana
|
||||||
|
SDL_Point current_position;
|
||||||
|
SDL_GetWindowPosition(window_, ¤t_position.x, ¤t_position.y);
|
||||||
|
|
||||||
|
// Obtiene las dimensiones actuales de la ventana
|
||||||
|
int current_width, current_height;
|
||||||
|
SDL_GetWindowSize(window_, ¤t_width, ¤t_height);
|
||||||
|
|
||||||
|
// Obtiene las dimesiones que tendrá la ventana
|
||||||
|
const int new_width = param.game.width * options.video.window.size;
|
||||||
|
const int new_height = param.game.height * options.video.window.size;
|
||||||
|
|
||||||
|
// Obtiene el centro de la ventana actual
|
||||||
|
SDL_Point center;
|
||||||
|
center.x = current_position.x + current_width / 2;
|
||||||
|
center.y = current_position.y + current_height / 2;
|
||||||
|
|
||||||
|
// Calcula la nueva posición a partir del centro y las nuevas diemsiones
|
||||||
|
SDL_Point new_pos;
|
||||||
|
new_pos.x = center.x - new_width / 2;
|
||||||
|
new_pos.y = center.y - new_height / 2;
|
||||||
|
|
||||||
|
// Obtiene las dimensiones del escritorio
|
||||||
|
SDL_DisplayMode DM;
|
||||||
|
SDL_GetCurrentDisplayMode(0, &DM);
|
||||||
|
|
||||||
|
// Evita que la ventana quede fuera del escritorio
|
||||||
|
new_pos.x = std::clamp(new_pos.x, 30, DM.w - new_width);
|
||||||
|
new_pos.y = std::clamp(new_pos.y, 30, DM.h - new_height);
|
||||||
|
|
||||||
|
return new_pos;
|
||||||
|
}
|
||||||
@@ -85,6 +85,9 @@ private:
|
|||||||
// Muestra información por pantalla
|
// Muestra información por pantalla
|
||||||
void displayInfo();
|
void displayInfo();
|
||||||
|
|
||||||
|
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
||||||
|
SDL_Point getNewPosition();
|
||||||
|
|
||||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera
|
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ void SmartSprite::checkMove()
|
|||||||
void SmartSprite::checkFinished()
|
void SmartSprite::checkFinished()
|
||||||
{
|
{
|
||||||
// Comprueba si ha llegado a su destino
|
// Comprueba si ha llegado a su destino
|
||||||
on_destination_ = (getPosX() == dest_x_ && getPosY() == dest_y_) ? true : false;
|
on_destination_ = (getPosX() == dest_x_ && getPosY() == dest_y_);
|
||||||
|
|
||||||
if (on_destination_)
|
if (on_destination_)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ Sprite::Sprite(SDL_Rect rect, std::shared_ptr<Texture> texture)
|
|||||||
sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||||
|
|
||||||
Sprite::Sprite(std::shared_ptr<Texture> texture)
|
Sprite::Sprite(std::shared_ptr<Texture> texture)
|
||||||
: texture_(texture) {}
|
: texture_(texture),
|
||||||
|
pos_({0, 0, texture_->getWidth(), texture_->getHeight()}),
|
||||||
|
sprite_clip_(pos_) {}
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void Sprite::render()
|
void Sprite::render()
|
||||||
|
|||||||
Reference in New Issue
Block a user