Compare commits
4 Commits
7434869894
...
a3a583deb7
| Author | SHA1 | Date | |
|---|---|---|---|
| a3a583deb7 | |||
| b263e0c4be | |||
| 3bf61fc758 | |||
| 2377815c02 |
BIN
data/gfx/player/player1_power.png
Normal file
BIN
data/gfx/player/player1_power.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 929 B |
BIN
data/gfx/player/player2_power.png
Normal file
BIN
data/gfx/player/player2_power.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 941 B |
Binary file not shown.
|
Before Width: | Height: | Size: 944 B |
Binary file not shown.
|
Before Width: | Height: | Size: 84 B |
@@ -6,35 +6,36 @@
|
|||||||
#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 "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_(Resource::get()->getTexture("game_buildings.png")),
|
buildings_texture_(Resource::get()->getTexture("game_buildings.png")),
|
||||||
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")),
|
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")),
|
||||||
bottom_clouds_texture_(Resource::get()->getTexture("game_clouds2.png")),
|
bottom_clouds_texture_(Resource::get()->getTexture("game_clouds2.png")),
|
||||||
grass_texture_(Resource::get()->getTexture("game_grass.png")),
|
grass_texture_(Resource::get()->getTexture("game_grass.png")),
|
||||||
gradients_texture_(Resource::get()->getTexture("game_sky_colors.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};
|
||||||
@@ -87,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_);
|
||||||
@@ -120,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();
|
||||||
|
|||||||
@@ -371,8 +371,12 @@ void 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);
|
||||||
@@ -381,7 +385,9 @@ void 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);
|
||||||
@@ -390,31 +396,45 @@ void 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);
|
||||||
@@ -427,29 +447,37 @@ void 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_one_coffee_palette.pal", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player1_one_coffee_palette.pal", AssetType::PALETTE);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player1_two_coffee_palette.pal", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player1_two_coffee_palette.pal", AssetType::PALETTE);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player1_all_white_palette.pal", 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_one_coffee_palette.pal", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player2_one_coffee_palette.pal", AssetType::PALETTE);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player2_two_coffee_palette.pal", AssetType::PALETTE);
|
Asset::get()->add(prefix + "/data/gfx/player/player2_two_coffee_palette.pal", AssetType::PALETTE);
|
||||||
Asset::get()->add(prefix + "/data/gfx/player/player2_all_white_palette.pal", 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_blue_palette.pal", 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::BITMAP);
|
Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::BITMAP);
|
||||||
|
|||||||
198
source/game.cpp
198
source/game.cpp
@@ -55,11 +55,11 @@ Game::Game(int player_id, int current_stage, bool demo)
|
|||||||
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>();
|
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 +69,10 @@ Game::Game(int player_id, int current_stage, bool demo)
|
|||||||
// 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 +92,13 @@ Game::Game(int player_id, int current_stage, bool demo)
|
|||||||
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 +115,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 +189,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 +201,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 +212,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 +280,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
|
||||||
@@ -347,7 +348,7 @@ void Game::loadMedia()
|
|||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||||
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
|
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
|
||||||
player_texture.emplace_back(Resource::get()->getTexture("player_power.gif"));
|
player_texture.emplace_back(Resource::get()->getTexture("player1_power.png"));
|
||||||
player_textures_.push_back(player_texture);
|
player_textures_.push_back(player_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,7 +356,7 @@ void Game::loadMedia()
|
|||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||||
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
|
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
|
||||||
player_texture.emplace_back(Resource::get()->getTexture("player_power.gif"));
|
player_texture.emplace_back(Resource::get()->getTexture("player2_power.png"));
|
||||||
player_textures_.push_back(player_texture);
|
player_textures_.push_back(player_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,99 +419,6 @@ void Game::unloadMedia()
|
|||||||
item_animations_.clear();
|
item_animations_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
||||||
{
|
{
|
||||||
@@ -666,7 +574,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_++;
|
||||||
}
|
}
|
||||||
@@ -1192,8 +1100,6 @@ void Game::renderItems()
|
|||||||
// Devuelve un item al azar y luego segun sus probabilidades
|
// Devuelve un item al azar y luego segun sus probabilidades
|
||||||
ItemType Game::dropItem()
|
ItemType Game::dropItem()
|
||||||
{
|
{
|
||||||
return ItemType::COFFEE_MACHINE;
|
|
||||||
|
|
||||||
const auto lucky_number = rand() % 100;
|
const auto lucky_number = rand() % 100;
|
||||||
const auto item = rand() % 6;
|
const auto item = rand() % 6;
|
||||||
|
|
||||||
@@ -1230,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
|
||||||
@@ -1245,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;
|
||||||
@@ -1444,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
|
||||||
{
|
{
|
||||||
@@ -1466,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();
|
||||||
@@ -1502,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
|
||||||
@@ -1692,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);
|
||||||
}
|
}
|
||||||
@@ -1722,7 +1628,7 @@ void Game::renderMessages()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
@@ -1752,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();
|
||||||
@@ -1825,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);
|
||||||
@@ -1840,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);
|
||||||
}
|
}
|
||||||
@@ -1867,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;
|
||||||
@@ -1883,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;
|
||||||
@@ -2031,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;
|
||||||
}
|
}
|
||||||
@@ -2244,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);
|
||||||
@@ -2304,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2332,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
|
||||||
@@ -147,13 +139,12 @@ 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
|
||||||
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
|
||||||
@@ -201,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();
|
||||||
|
|
||||||
|
|||||||
@@ -23,29 +23,21 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable::HiScoreTable()
|
HiScoreTable::HiScoreTable()
|
||||||
|
: 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>();
|
|
||||||
background_ = std::make_unique<Background>(renderer_);
|
|
||||||
text_ = std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"));
|
|
||||||
|
|
||||||
// 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();
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ enum class FadeMode : Uint8; // lines 11-11
|
|||||||
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
|
||||||
@@ -34,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
|
||||||
|
|
||||||
|
|||||||
@@ -621,7 +621,6 @@ void Player::updatePowerUp()
|
|||||||
{
|
{
|
||||||
--power_up_counter_;
|
--power_up_counter_;
|
||||||
power_up_ = power_up_counter_ > 0;
|
power_up_ = power_up_counter_ > 0;
|
||||||
power_sprite_->getTexture()->setPalette(id_ - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,11 +33,9 @@ Resource::Resource()
|
|||||||
loadTextures();
|
loadTextures();
|
||||||
loadTextFiles();
|
loadTextFiles();
|
||||||
loadAnimations();
|
loadAnimations();
|
||||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
loadDemoData();
|
||||||
|
|
||||||
std::cout << "\n** ADD PALETTES" << std::endl;
|
|
||||||
addPalettes();
|
addPalettes();
|
||||||
std::cout << "\n** PALETTES ADDED" << std::endl;
|
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -120,6 +118,12 @@ Animations &Resource::getAnimation(const std::string &name)
|
|||||||
throw std::runtime_error("Animación no encontrada: " + name);
|
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
|
// Carga los sonidos
|
||||||
void Resource::loadSounds()
|
void Resource::loadSounds()
|
||||||
{
|
{
|
||||||
@@ -225,26 +229,28 @@ void Resource::loadAnimations()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// Añade paletas a las texturas
|
||||||
void Resource::addPalettes()
|
void Resource::addPalettes()
|
||||||
{
|
{
|
||||||
// Jugador 1
|
// Jugador 1
|
||||||
std::cout << "\n>> PLAYER1" << std::endl;
|
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_one_coffee_palette.pal"));
|
||||||
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_two_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"));
|
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_all_white_palette.pal"));
|
||||||
|
|
||||||
// Jugador 2
|
// Jugador 2
|
||||||
std::cout << "\n>> PLAYER2" << std::endl;
|
|
||||||
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_one_coffee_palette.pal"));
|
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_two_coffee_palette.pal"));
|
||||||
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_all_white_palette.pal"));
|
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_all_white_palette.pal"));
|
||||||
|
|
||||||
// Player_power
|
|
||||||
std::cout << "\n>> PLAYER_POWER" << std::endl;
|
|
||||||
getTexture("player_power.gif")->addPaletteFromFile(Asset::get()->get("player_power_blue_palette.pal"));
|
|
||||||
|
|
||||||
// Fuentes
|
// Fuentes
|
||||||
std::cout << "\n>> FONTS" << std::endl;
|
|
||||||
getTexture("smb2.gif")->addPaletteFromFile(Asset::get()->get("smb2_palette1.pal"));
|
getTexture("smb2.gif")->addPaletteFromFile(Asset::get()->get("smb2_palette1.pal"));
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
#include "utils.h"
|
||||||
#include "animated_sprite.h"
|
#include "animated_sprite.h"
|
||||||
|
|
||||||
// Estructura para almacenar ficheros de sonido y su nombre
|
// Estructura para almacenar ficheros de sonido y su nombre
|
||||||
@@ -75,6 +76,7 @@ private:
|
|||||||
std::vector<ResourceTexture> textures_; // 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<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
||||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
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
|
// Carga los sonidos
|
||||||
void loadSounds();
|
void loadSounds();
|
||||||
@@ -91,6 +93,9 @@ private:
|
|||||||
// Carga las animaciones
|
// Carga las animaciones
|
||||||
void loadAnimations();
|
void loadAnimations();
|
||||||
|
|
||||||
|
// Carga los datos para el modo demostración
|
||||||
|
void loadDemoData();
|
||||||
|
|
||||||
// Añade paletas a las texturas
|
// Añade paletas a las texturas
|
||||||
void addPalettes();
|
void addPalettes();
|
||||||
|
|
||||||
@@ -126,4 +131,7 @@ public:
|
|||||||
|
|
||||||
// Obtiene la animación a partir de un nombre
|
// Obtiene la animación a partir de un nombre
|
||||||
Animations &getAnimation(const std::string &name);
|
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);
|
||||||
};
|
};
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#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 "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
|
||||||
@@ -16,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
|
||||||
@@ -34,8 +35,8 @@ Scoreboard *Scoreboard::get()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
Scoreboard::Scoreboard()
|
||||||
: renderer_(renderer),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
|
|
||||||
game_power_meter_texture_(Resource::get()->getTexture("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_)),
|
||||||
@@ -107,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();
|
||||||
|
|||||||
101
source/utils.cpp
101
source/utils.cpp
@@ -203,3 +203,104 @@ void printWithDots(const std::string &text1, const std::string &text2, const std
|
|||||||
|
|
||||||
std::cout << text3 << std::endl;
|
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
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||||
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
|
}
|
||||||
|
/*{ // 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 = DemoKeys();
|
||||||
|
dd.push_back(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;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
// 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 dk = DemoKeys();
|
||||||
|
SDL_RWread(file, &dk, sizeof(DemoKeys), 1);
|
||||||
|
dd.push_back(dk);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
SDL_RWclose(file);
|
||||||
|
|
||||||
|
// Mensaje de datos cargados a la carga de los datos
|
||||||
|
printWithDots("DemoData : ", file_name, "[ LOADED ]");
|
||||||
|
}
|
||||||
|
|
||||||
|
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,7 +230,6 @@ struct Param
|
|||||||
ParamNotification notification; // Opciones para las notificaciones
|
ParamNotification notification; // Opciones para las notificaciones
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
@@ -267,6 +281,14 @@ 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
|
// 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);
|
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user