Compare commits

6 Commits

Author SHA1 Message Date
59e2865a4a El game_text ara gasta PathSprites en lloc d'SmartSprites
fix: la paleta dels jugadors no s'iniciava correctament
2024-10-28 22:09:28 +01:00
787cb6366f Pasaeta de include-what-you-use
Acabada de perfilar la classe PathSprite
Menjeades declaracions de utils.h als fitxers que toca
2024-10-28 20:45:24 +01:00
0fe371653a commit de me ane cap a casa 2024-10-28 13:51:26 +01:00
2cffe8dfc9 Merge branch 'main' of https://gitea.sustancia.synology.me/JailDesigner/coffee_crisis_arcade_edition 2024-10-27 22:28:47 +01:00
1dd96cfaff Completada la classe PathSprite 2024-10-27 22:28:44 +01:00
d054e188b6 fix: alguns minibugs tontos 2024-10-27 19:04:05 +01:00
56 changed files with 996 additions and 774 deletions

View File

@@ -0,0 +1,8 @@
#!/bin/bash
SOURCEPATH=../source/
for i in "$SOURCEPATH"/*.cpp
do
include-what-you-use -D DEBUG -D VERBOSE -std=c++20 -Wall "$i"
done

View File

@@ -1,11 +1,11 @@
#include "animated_sprite.h"
#include <algorithm> // para copy
#include <fstream> // para basic_ostream, operator<<, basic_istream, basic...
#include <iostream> // para cout
#include <iterator> // para back_insert_iterator, back_inserter
#include <sstream> // para basic_stringstream
#include "texture.h" // para Texture
#include "utils.h"
#include <stddef.h> // Para size_t
#include <fstream> // Para basic_ostream, basic_istream, operator<<, basic...
#include <iostream> // Para cout, cerr
#include <sstream> // Para basic_stringstream
#include <stdexcept> // Para runtime_error
#include "texture.h" // Para Texture
#include "utils.h" // Para printWithDots
// Carga las animaciones en un vector(Animations) desde un fichero
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path)

View File

@@ -1,12 +1,11 @@
#pragma once
#include <SDL2/SDL_rect.h> // para SDL_Rect
#include <SDL2/SDL_stdinc.h> // para Uint8
#include <memory> // para shared_ptr
#include <string> // para string
#include <vector> // para vector
#include "moving_sprite.h" // para MovingSprite
class Texture;
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <memory> // Para shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "moving_sprite.h" // Para MovingSprite
class Texture; // lines 9-9
struct Animation
{

View File

@@ -1,12 +1,9 @@
#include "asset.h"
#include "utils.h"
#include <SDL2/SDL_rwops.h> // para SDL_RWFromFile, SDL_RWclose, SDL_RWops
#include <SDL2/SDL_stdinc.h> // para SDL_max
#include <stddef.h> // para size_t
#include <iostream> // para basic_ostream, operator<<, cout, endl
#include <fstream>
#include <string>
#include <algorithm> // Para std::find_if
#include <algorithm> // Para find_if, max
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream, endl
#include <iostream> // Para cout
#include <string> // Para allocator, char_traits, string, operator+, oper...
#include "utils.h" // Para getFileName, printWithDots
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Asset *Asset::asset_ = nullptr;

View File

@@ -1,14 +1,13 @@
#include "background.h"
#include <SDL2/SDL_blendmode.h> // para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <algorithm> // para clamp, max
#include "asset.h" // para Asset
#include "moving_sprite.h" // para MovingSprite
#include "param.h" // para param
#include "resource.h" // para Resource
#include "screen.h"
#include "sprite.h" // para Sprite
#include "texture.h" // para Texture
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <algorithm> // Para clamp, max
#include "moving_sprite.h" // Para MovingSprite
#include "param.h" // Para Param, ParamBackground, param
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
// Constructor
Background::Background()

View File

@@ -1,11 +1,10 @@
#include "balloon.h"
#include <cmath> // para abs
#include <algorithm> // para clamp
#include "animated_sprite.h" // para SpriteAnimated
#include "moving_sprite.h" // para MovingSprite
#include "param.h" // para param
#include "sprite.h" // para Sprite
#include "texture.h" // para Texture
#include <algorithm> // Para clamp
#include <cmath> // Para fabs
#include "animated_sprite.h" // Para AnimatedSprite
#include "param.h" // Para Param, param, ParamBalloon, ParamGame
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
// Constructor
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)

View File

@@ -1,13 +1,12 @@
#pragma once
#include <SDL2/SDL_stdinc.h> // para Uint8, Uint16, Uint32
#include <memory> // para shared_ptr, unique_ptr
#include <string> // para string
#include <vector> // para vector
#include "animated_sprite.h" // para SpriteAnimated
#include "utils.h" // para Circle
#include "param.h"
class Texture;
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint16, Uint32
#include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "animated_sprite.h" // Para AnimatedSprite
#include "utils.h" // Para Circle
class Texture; // lines 10-10
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
constexpr int MAX_BOUNCE = 10;

View File

@@ -1,8 +1,9 @@
#include "bullet.h"
#include <memory> // para unique_ptr, make_unique, shared_ptr
#include "param.h" // para param
#include "sprite.h" // para Sprite
class Texture;
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <memory> // Para unique_ptr, make_unique, shared_ptr
#include "param.h" // Para Param, ParamGame, param
#include "sprite.h" // Para Sprite
class Texture; // lines 5-5
// Constructor
Bullet::Bullet(int x, int y, BulletType bullet_type, bool powered_up, int owner, std::shared_ptr<Texture> texture)

View File

@@ -1,11 +1,10 @@
#pragma once
#include <SDL2/SDL_rect.h> // para SDL_Rect
#include <SDL2/SDL_stdinc.h> // para Uint8
#include <memory> // para shared_ptr, unique_ptr
#include "sprite.h" // para Sprite
#include "utils.h" // para Circle
class Texture;
#include <SDL2/SDL_stdinc.h> // Para Uint8
#include <memory> // Para shared_ptr, unique_ptr
#include "sprite.h" // Para Sprite
#include "utils.h" // Para Circle
class Texture; // lines 8-8
// Tipos de balas
enum class BulletType : Uint8
@@ -36,9 +35,9 @@ private:
std::unique_ptr<Sprite> sprite_; // Sprite con los gráficos y métodos de pintado
int pos_x_; // Posición en el eje X
int pos_y_; // Posición en el eje Y
int vel_x_; // Velocidad en el eje X
int pos_x_; // Posición en el eje X
int pos_y_; // Posición en el eje Y
int vel_x_; // Velocidad en el eje X
BulletType bullet_type_; // Tipo de objeto
int owner_; // Identificador del dueño del objeto

View File

@@ -1,12 +1,11 @@
#include "define_buttons.h"
#include <utility> // para move
#include "input.h" // para Input, InputType
#include "lang.h" // para getText
#include "options.h" // para options
#include "param.h" // para param
#include "section.h" // para Name, Options, name, options
#include "text.h" // para Text
#include "utils.h" // para OptionsController, Options, Param, ParamGame
#include <utility> // Para move
#include "input.h" // Para Input, InputType
#include "lang.h" // Para getText
#include "options.h" // Para OptionsController, Options, options
#include "param.h" // Para Param, param, ParamGame, ParamTitle
#include "section.h" // Para Name, Options, name, options
#include "text.h" // Para Text
// Constructor
DefineButtons::DefineButtons(std::unique_ptr<Text> text_)

View File

@@ -1,44 +1,46 @@
#include "director.h"
#include <SDL2/SDL.h> // para SDL_Init, SDL_Quit, SDL_INIT_EV...
#include <SDL2/SDL_audio.h> // para AUDIO_S16
#include <SDL2/SDL_blendmode.h> // para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // para SDL_GetError
#include <SDL2/SDL_gamecontroller.h> // para SDL_CONTROLLER_BUTTON_B, SDL_CO...
#include <SDL2/SDL_hints.h> // para SDL_SetHint, SDL_HINT_RENDER_DR...
#include <SDL2/SDL_scancode.h> // para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
#include <SDL2/SDL_stdinc.h> // para SDL_bool, Uint32
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <cstdlib> // para system
#include <errno.h> // para errno, EEXIST, EACCES, ENAMETOO...
#include <stdio.h> // para printf, perror
#include <string.h> // para strcmp
#include <sys/stat.h> // para mkdir, stat, S_IRWXU
#include <unistd.h> // para getuid
#include <cstdlib> // para exit, EXIT_FAILURE, rand, srand
#include <iostream> // para basic_ostream, operator<<, cout
#include <memory> // para make_unique, unique_ptr
#include <string> // para operator+, allocator, char_traits
#include "asset.h" // para Asset, AssetType
#include "dbgtxt.h" // para dbg_init
#include "game.h" // para Game, GAME_MODE_DEMO_OFF, GAME_...
#include "global_inputs.h" // para init
#include "hiscore_table.h" // para HiScoreTable
#include "input.h" // para Input, InputType
#include "instructions.h" // para Instructions
#include "intro.h" // para Intro
#include "jail_audio.h" // para JA_LoadMusic, JA_LoadSound, JA_...
#include "lang.h" // para Code, loadFromFile
#include "logo.h" // para Logo
#include "manage_hiscore_table.h" // para ManageHiScoreTable
#include "notifier.h" // para Notifier
#include "on_screen_help.h" // para OnScreenHelp
#include "options.h" // para options, loadOptionsFile, saveO...
#include "param.h" // para param, loadParamsFromFile
#include "resource.h" //for Resource
#include "screen.h" // para Screen
#include "section.h" // para Name, name, Options, options
#include "title.h" // para Title
#include "utils.h" // para MusicFile, SoundFile, Options
#include <SDL2/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_EV...
#include <SDL2/SDL_audio.h> // Para AUDIO_S16
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_gamecontroller.h> // Para SDL_CONTROLLER_BUTTON_B, SDL_CO...
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
#include <stdio.h> // Para printf, perror
#include <string.h> // Para strcmp
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
#include <unistd.h> // Para getuid
#include <cstdlib> // Para exit, EXIT_FAILURE, rand, srand
#include <iostream> // Para basic_ostream, operator<<, cout
#include <memory> // Para make_unique, unique_ptr, make_s...
#include <stdexcept> // Para runtime_error
#include <string> // Para operator+, allocator, char_traits
#include <vector> // Para vector
#include "asset.h" // Para Asset, AssetType
#include "dbgtxt.h" // Para dbg_init
#include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_...
#include "global_inputs.h" // Para init
#include "hiscore_table.h" // Para HiScoreTable
#include "input.h" // Para Input, InputType
#include "instructions.h" // Para Instructions
#include "intro.h" // Para Intro
#include "jail_audio.h" // Para JA_EnableMusic, JA_EnableSound
#include "lang.h" // Para Code, loadFromFile
#include "logo.h" // Para Logo
#include "manage_hiscore_table.h" // Para ManageHiScoreTable
#include "notifier.h" // Para Notifier
#include "on_screen_help.h" // Para OnScreenHelp
#include "options.h" // Para Options, options, OptionsContro...
#include "param.h" // Para Param, ParamGame, param, loadPa...
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, Options, name, options
#include "text.h" // Para Text
#include "title.h" // Para Title
#include "utils.h" // Para Overrides, overrides
#ifndef _WIN32
#include <pwd.h> // para getpwuid, passwd

View File

@@ -1,15 +1,12 @@
#pragma once
#include <SDL2/SDL_render.h> // para SDL_Renderer
#include <SDL2/SDL_video.h> // para SDL_Window
#include <string> // para string
#include <vector> // para vector
#include <SDL2/SDL_render.h> // Para SDL_Renderer
#include <SDL2/SDL_video.h> // Para SDL_Window
#include <string> // Para string
namespace lang
{
enum class Code : int;
}
struct ResourceMusic;
struct ResourceSound;
} // lines 9-9
// Textos
constexpr char WINDOW_CAPTION[] = "Coffee Crisis Arcade Edition";
@@ -18,8 +15,8 @@ class Director
{
private:
// Objetos y punteros
SDL_Window *window_; // La ventana donde dibujamos
SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Window *window_; // La ventana donde dibujamos
SDL_Renderer *renderer_; // El renderizador de la ventana
#ifndef VERBOSE
std::streambuf *orig_buf; // Puntero al buffer de flujo original para restaurar std::cout
#endif

View File

@@ -1,5 +1,6 @@
#include "enter_name.h"
#include <algorithm> // para max, min
#include <stddef.h> // Para size_t
#include <algorithm> // Para max, min
// Constructor
EnterName::EnterName()

View File

@@ -1,20 +1,6 @@
#include "explosions.h"
#include <utility> // para move
#include "animated_sprite.h" // para SpriteAnimated
class Texture; // lines 3-3
// Constructor
Explosions::Explosions()
{
textures_.clear();
explosions_.clear();
}
// Destructor
Explosions::~Explosions()
{
explosions_.clear();
}
#include "animated_sprite.h" // Para AnimatedSprite
class Texture; // lines 4-4
// Actualiza la lógica de la clase
void Explosions::update()

View File

@@ -1,10 +1,10 @@
#pragma once
#include <memory> // para shared_ptr, unique_ptr
#include <string> // para string
#include <vector> // para vector
class AnimatedSprite;
class Texture;
#include <memory> // Para unique_ptr, shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "animated_sprite.h" // Para AnimatedSprite
class Texture; // lines 7-7
struct ExplosionTexture
{
@@ -33,10 +33,10 @@ private:
public:
// Constructor
Explosions();
Explosions() = default;
// Destructor
~Explosions();
~Explosions() = default;
// Actualiza la lógica de la clase
void update();

View File

@@ -1,11 +1,10 @@
#include "fade.h"
#include <SDL2/SDL_blendmode.h> // para SDL_BLENDMODE_BLEND, SDL_BLENDMODE_NONE
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <stdlib.h> // para rand
#include <algorithm> // para min, max
#include "param.h" // para param
#include "screen.h"
#include "utils.h" // para Param, ParamGame, ParamFade
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND, SDL_BLENDMODE_NONE
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <stdlib.h> // Para rand
#include <algorithm> // Para min, max
#include "param.h" // Para Param, param, ParamGame, ParamFade
#include "screen.h" // Para Screen
// Constructor
Fade::Fade()

View File

@@ -1,43 +1,39 @@
#include "game.h"
#include <SDL2/SDL_blendmode.h> // para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_events.h> // para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
#include <SDL2/SDL_keycode.h> // para SDLK_1, SDLK_2, SDLK_3, SDLK_4
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_rwops.h> // para SDL_RWFromFile, SDL_RWclose, SDL_R...
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <SDL2/SDL_video.h> // para SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
#include <stdlib.h> // para rand
#include <algorithm> // para min, remove_if
#include <fstream> // para basic_ostream, operator<<, basic_i...
#include <iostream> // para cout
#include <numeric> // para accumulate
#include <utility> // para move
#include "asset.h" // para Asset
#include "background.h" // para Background
#include "balloon.h" // para Balloon, BALLOON_SCORE_1, BALLOON_...
#include "balloon_formations.h" // para Stage, BalloonFormationParams, Bal...
#include "bullet.h" // para Bullet, BulletType, BulletMoveStatus
#include "explosions.h" // para Explosions
#include "fade.h" // para Fade, FadeType
#include "global_inputs.h" // para check
#include "input.h" // para InputType, Input, INPUT_DO_NOT_ALL...
#include "item.h" // para Item, ItemType::COFFEE_MACHINE, ItemType::CLOCK
#include "jail_audio.h" // para JA_PlaySound
#include "lang.h" // para getText
#include "manage_hiscore_table.h" // para ManageHiScoreTable
#include "notifier.h" // para Notifier
#include "param.h" // para param
#include "player.h" // para Player, PlayerStatus
#include "resource.h" // para Resource
#include "scoreboard.h" // para Scoreboard, ScoreboardMode, SCOREB...
#include "screen.h" // para Screen
#include "section.h" // para Name, name, Options, options
#include "smart_sprite.h" // para SpriteSmart
#include "text.h" // para Text, TEXT_CENTER
#include "texture.h" // para Texture
struct JA_Music_t; // lines 35-35
struct JA_Sound_t; // lines 36-36
#include "dbgtxt.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
#include <SDL2/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
#include <stdlib.h> // Para rand, size_t
#include <algorithm> // Para find_if, clamp, min, remove_if
#include <iterator> // Para distance, size
#include <numeric> // Para accumulate
#include "asset.h" // Para Asset
#include "background.h" // Para Background
#include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VE...
#include "balloon_formations.h" // Para BalloonFormations, BalloonFormatio...
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
#include "explosions.h" // Para Explosions
#include "fade.h" // Para Fade, FadeType
#include "global_inputs.h" // Para check
#include "input.h" // Para InputType, Input, INPUT_DO_NOT_ALL...
#include "item.h" // Para Item, ItemType
#include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState
#include "lang.h" // Para getText
#include "manage_hiscore_table.h" // Para ManageHiScoreTable
#include "notifier.h" // Para Notifier
#include "param.h" // Para Param, param, ParamGame, ParamFade
#include "path_sprite.h" // Para PathSprite, PathType
#include "player.h" // Para Player, PlayerStatus
#include "resource.h" // Para Resource
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode, SCOREB...
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options
#include "smart_sprite.h" // Para SmartSprite
#include "text.h" // Para Text, TEXT_CENTER
#include "texture.h" // Para Texture
struct JA_Sound_t; // lines 40-40
// Constructor
Game::Game(int player_id, int current_stage, bool demo)
@@ -89,8 +85,11 @@ Game::Game(int player_id, int current_stage, bool demo)
setTotalPower();
// Crea los primeros globos
createTwoBigBalloons();
evaluateAndSetMenace();
if (!demo_.enabled)
{
createTwoBigBalloons();
evaluateAndSetMenace();
}
}
Game::~Game()
@@ -244,7 +243,7 @@ void Game::deployBalloonFormation()
last_balloon_deploy_ = formation;
const auto set = balloon_formations_->getStage(0).balloon_pool.set[formation];
const auto set = balloon_formations_->getStage(current_stage_).balloon_pool.set[formation];
const auto numEnemies = set.number_of_balloons;
for (int i = 0; i < numEnemies; ++i)
{
@@ -604,7 +603,8 @@ void Game::startAllBalloons()
void Game::reverseColorsToAllBalloons()
{
for (auto &balloon : balloons_)
balloon->useReverseColor();
if (balloon->isStopped())
balloon->useReverseColor();
}
// Cambia el color de todos los globos
@@ -651,25 +651,29 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
case ItemType::DISK:
{
player->addScore(1000);
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[0]->getWidth() / 2), player->getPosY(), game_text_textures_[0]);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[0]->getWidth()) / 2;
createPathSprite(x, game_text_textures_[0]);
break;
}
case ItemType::GAVINA:
{
player->addScore(2500);
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[1]->getWidth() / 2), player->getPosY(), game_text_textures_[1]);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[1]->getWidth()) / 2;
createPathSprite(x, game_text_textures_[1]);
break;
}
case ItemType::PACMAR:
{
player->addScore(5000);
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[2]->getWidth() / 2), player->getPosY(), game_text_textures_[2]);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[2]->getWidth()) / 2;
createPathSprite(x, game_text_textures_[2]);
break;
}
case ItemType::CLOCK:
{
enableTimeStopItem();
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[5]->getWidth() / 2), player->getPosY(), game_text_textures_[5]);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[5]->getWidth()) / 2;
createPathSprite(x, game_text_textures_[5]);
break;
}
case ItemType::COFFEE:
@@ -677,12 +681,14 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
if (player->getCoffees() == 2)
{
player->addScore(5000);
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[2]->getWidth() / 2), player->getPosY(), game_text_textures_[2]);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[2]->getWidth()) / 2;
createPathSprite(x, game_text_textures_[2]);
}
else
{
player->giveExtraHit();
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[4]->getWidth() / 2), player->getPosY(), game_text_textures_[4]);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[4]->getWidth()) / 2;
createPathSprite(x, game_text_textures_[4]);
}
break;
}
@@ -690,7 +696,8 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
{
player->setPowerUp();
coffee_machine_enabled_ = false;
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[3]->getWidth() / 2), player->getPosY(), game_text_textures_[3]);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[3]->getWidth()) / 2;
createPathSprite(x, game_text_textures_[3]);
break;
}
default:
@@ -889,32 +896,32 @@ void Game::freeItems()
items_.erase(items_.begin() + i);
}
// Crea un objeto SpriteSmart para mostrar la puntuación al coger un objeto
void Game::createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture)
// Crea un objeto PathSprite
void Game::createPathSprite(int x, std::shared_ptr<Texture> texture)
{
smart_sprites_.emplace_back(std::make_unique<SmartSprite>(texture));
path_sprites_.emplace_back(std::make_unique<PathSprite>(texture));
const auto w = texture->getWidth();
const auto h = texture->getHeight();
const int y0 = param.game.play_area.rect.h - h;
const int y1 = 160;
const int y2 = -h;
// Ajusta para que no se dibuje fuera de pantalla
x = std::clamp(x, 0, param.game.play_area.rect.w - w);
x = std::clamp(x, 2, param.game.play_area.rect.w - w - 2);
// Inicializa
smart_sprites_.back()->setPos({0, 0, w, h});
smart_sprites_.back()->setSpriteClip({0, 0, w, h});
smart_sprites_.back()->setPosX(x);
smart_sprites_.back()->setPosY(param.game.play_area.rect.h - h);
smart_sprites_.back()->setDestX(x);
smart_sprites_.back()->setDestY(y - 35);
smart_sprites_.back()->setVelY(-0.5f);
smart_sprites_.back()->setAccelY(-0.1f);
smart_sprites_.back()->setEnabled(true);
smart_sprites_.back()->setFinishedCounter(100);
path_sprites_.back()->setWidth(w);
path_sprites_.back()->setHeight(h);
path_sprites_.back()->setSpriteClip({0, 0, w, h});
path_sprites_.back()->addPath(y0, y1, PathType::VERTICAL, x, 100, easeOutQuint, 0);
path_sprites_.back()->addPath(y1, y2, PathType::VERTICAL, x, 80, easeInQuint, 0);
path_sprites_.back()->enable();
}
// Vacia el vector de smartsprites
void Game::freeSpriteSmarts()
void Game::freeSmartSprites()
{
if (!smart_sprites_.empty())
for (int i = smart_sprites_.size() - 1; i >= 0; --i)
@@ -922,6 +929,15 @@ void Game::freeSpriteSmarts()
smart_sprites_.erase(smart_sprites_.begin() + i);
}
// Vacia el vector de pathsprites
void Game::freePathSprites()
{
if (!path_sprites_.empty())
for (int i = path_sprites_.size() - 1; i >= 0; --i)
if (path_sprites_[i]->hasFinished())
path_sprites_.erase(path_sprites_.begin() + i);
}
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
void Game::throwCoffee(int x, int y)
{
@@ -945,18 +961,32 @@ void Game::throwCoffee(int x, int y)
smart_sprites_.back()->setRotateAmount(90.0);
}
// Actualiza los SpriteSmarts
void Game::updateSpriteSmarts()
// Actualiza los SmartSprites
void Game::updateSmartSprites()
{
for (auto &ss : smart_sprites_)
ss->update();
for (auto &sprite : smart_sprites_)
sprite->update();
}
// Pinta los SpriteSmarts activos
void Game::renderSpriteSmarts()
// Pinta los SmartSprites activos
void Game::renderSmartSprites()
{
for (auto &ss : smart_sprites_)
ss->render();
for (auto &sprite : smart_sprites_)
sprite->render();
}
// Actualiza los PathSprites
void Game::updatePathSprites()
{
for (auto &sprite : path_sprites_)
sprite->update();
}
// Pinta los PathSprites activos
void Game::renderPathSprites()
{
for (auto &sprite : path_sprites_)
sprite->render();
}
// Acciones a realizar cuando el jugador muere
@@ -1118,7 +1148,10 @@ void Game::update()
updateGameOver();
// Actualiza los SpriteSmarts
updateSpriteSmarts();
updateSmartSprites();
// Actualiza los PathSmarts
updatePathSprites();
// Actualiza los contadores de estado y efectos
updateTimeStopped();
@@ -1146,7 +1179,8 @@ void Game::update()
freeBullets();
freeBalloons();
freeItems();
freeSpriteSmarts();
freeSmartSprites();
freePathSprites();
}
// Comprueba si la música ha de estar sonando
@@ -1193,7 +1227,8 @@ void Game::fillCanvas()
// Dibuja los objetos
background_->render();
renderItems();
renderSpriteSmarts();
renderSmartSprites();
renderPathSprites();
explosions_->render();
renderBalloons();
renderBullets();
@@ -1502,7 +1537,7 @@ void Game::checkEvents()
}
#ifdef DEBUG
else if (event.type == SDL_KEYDOWN)
else if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
{
switch (event.key.keysym.sym)
{
@@ -1527,6 +1562,12 @@ void Game::checkEvents()
createItem(ItemType::CLOCK, players_.at(0)->getPosX(), players_.at(0)->getPosY() - 40);
break;
}
case SDLK_5: // Crea un PathSprite
{
const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2;
createPathSprite(x, game_text_textures_.at(3));
break;
}
default:
break;
}

View File

@@ -1,31 +1,31 @@
#pragma once
#include <SDL2/SDL_render.h> // para SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // para Uint32
#include <memory> // para shared_ptr, unique_ptr
#include <string> // para string
#include <vector> // para vector
#include "balloon.h" // para Balloon
#include "player.h" // para Player
#include "utils.h" // para DemoKeys, Color, HiScoreEntry
#include "options.h" // para options
class Asset;
class Background;
class BalloonFormations;
class Bullet;
class Explosions;
class Fade;
class Input;
class Item;
class Scoreboard;
class Screen;
class SmartSprite;
class Text;
class Texture;
enum class BulletType : Uint8; // lines 26-26
struct JA_Music_t; // lines 27-27
struct JA_Sound_t; // lines 28-28
enum class ItemType;
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
#include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "balloon.h" // Para Balloon
#include "manage_hiscore_table.h" // Para HiScoreEntry
#include "options.h" // Para Options, OptionsGame, options
#include "player.h" // Para Player
#include "utils.h" // Para Demo
class Asset; // lines 12-12
class Background; // lines 13-13
class BalloonFormations; // lines 14-14
class Bullet; // lines 15-15
class Explosions; // lines 16-16
class Fade; // lines 17-17
class Input; // lines 18-18
class Item; // lines 19-19
class PathSprite; // lines 20-20
class Scoreboard; // lines 21-21
class Screen; // lines 22-22
class SmartSprite; // lines 23-23
class Text; // lines 24-24
class Texture; // lines 25-25
enum class BulletType : Uint8; // lines 26-26
enum class ItemType; // lines 27-27
// Modo demo
constexpr bool GAME_MODE_DEMO_OFF = false;
@@ -129,6 +129,7 @@ private:
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<SmartSprite>> smart_sprites_; // Vector con los smartsprites
std::vector<std::unique_ptr<PathSprite>> path_sprites_; // Vector con los smartsprites
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
@@ -302,20 +303,29 @@ private:
// Vacia el vector de items
void freeItems();
// Crea un objeto SpriteSmart
void createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture);
// Crea un objeto PathSprite
void createPathSprite(int x, std::shared_ptr<Texture> texture);
// Vacia el vector de smartsprites
void freeSpriteSmarts();
void freeSmartSprites();
// Vacia el vector de pathsprites
void freePathSprites();
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
void throwCoffee(int x, int y);
// Actualiza los SpriteSmarts
void updateSpriteSmarts();
void updateSmartSprites();
// Pinta los SpriteSmarts activos
void renderSpriteSmarts();
void renderSmartSprites();
// Actualiza los PathSprites
void updatePathSprites();
// Pinta los PathSprites activos
void renderPathSprites();
// Acciones a realizar cuando el jugador muere
void killPlayer(std::shared_ptr<Player> &player);

View File

@@ -1,16 +1,13 @@
#include "game_logo.h"
#include <SDL2/SDL_render.h> // para SDL_FLIP_HORIZONTAL
#include <algorithm> // para max
#include "animated_sprite.h" // para SpriteAnimated
#include "asset.h" // para Asset
#include "jail_audio.h" // JA_PlaySound
#include "param.h" // para param
#include "resource.h" // para Resource
#include "screen.h" // para Screen
#include "smart_sprite.h" // para SpriteSmart
#include "sprite.h" // para Sprite
#include "texture.h" // para Texture
#include "utils.h" // para Param, ParamGame, ParamTitle
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL
#include <algorithm> // Para max
#include "animated_sprite.h" // Para AnimatedSprite
#include "jail_audio.h" // Para JA_PlaySound
#include "param.h" // Para Param, param, ParamGame, ParamTitle
#include "resource.h" // Para Resource
#include "smart_sprite.h" // Para SmartSprite
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
// Constructor
GameLogo::GameLogo(int x, int y)

View File

@@ -1,11 +1,10 @@
#pragma once
#include <memory> // para unique_ptr, shared_ptr
#include "animated_sprite.h"
#include "smart_sprite.h"
class Sprite;
class Texture;
struct JA_Sound_t; // lines 10-10
#include <memory> // Para unique_ptr, shared_ptr
#include "animated_sprite.h" // Para AnimatedSprite
#include "smart_sprite.h" // Para SmartSprite
#include "sprite.h" // Para Sprite
class Texture; // lines 7-7
// Clase GameLogo
class GameLogo

View File

@@ -1,14 +1,13 @@
#include "global_inputs.h"
#include <string> // para basic_string, operator+
#include "input.h" // para Input, inputs_e, INPUT_DO_NOT_ALLOW_REPEAT
#include "jail_audio.h" // para JA_EnableMusic, JA_EnableSound
#include "lang.h" // para getText
#include "notifier.h" // para Notifier
#include "options.h" // para options
#include "on_screen_help.h"
#include "screen.h" // para Screen
#include "section.h" // para SectionOptions, name, SectionName, options
#include "utils.h" // para OptionsAudio, Options, OptionsMusic, boolToOnOff
#include <string> // Para operator+, string
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_REPEAT
#include "jail_audio.h" // Para JA_EnableMusic, JA_EnableSound
#include "lang.h" // Para getText
#include "notifier.h" // Para Notifier
#include "on_screen_help.h" // Para OnScreenHelp
#include "options.h" // Para Options, OptionsAudio, options, OptionsM...
#include "section.h" // Para Name, Options, name, options
#include "utils.h" // Para boolToOnOff, stringInVector
namespace globalInputs
{

View File

@@ -1,25 +1,25 @@
#include "hiscore_table.h"
#include <SDL2/SDL_blendmode.h> // para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_events.h> // para SDL_PollEvent, SDL_Event, SDL_QUIT
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <SDL2/SDL_video.h> // para SDL_WINDOWEVENT_SIZE_CHANGED
#include <algorithm> // para max
#include <vector> // para vector
#include "asset.h" // para Asset
#include "background.h" // para Background
#include "fade.h" // para Fade, FadeMode, FadeType
#include "global_inputs.h" // para check
#include "input.h" // para Input
#include "jail_audio.h" // para JA_GetMusicState, JA_Music_state
#include "lang.h" // para getText
#include "options.h" // para options
#include "param.h" // para param
#include "resource.h" // para Resource
#include "screen.h" // para Screen
#include "section.h" // para Name, name, Options, options
#include "text.h" // para Text, TEXT_CENTER, TEXT_SHADOW, TEXT...
#include "utils.h" // para Param, ParamGame, Color, HiScoreEntry
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_QUIT
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
#include <algorithm> // Para max
#include <vector> // Para vector
#include "background.h" // Para Background
#include "fade.h" // Para Fade, FadeMode, FadeType
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state
#include "lang.h" // Para getText
#include "manage_hiscore_table.h" // Para HiScoreEntry
#include "options.h" // Para Options, OptionsGame, options
#include "param.h" // Para Param, param, ParamGame, ParamFade
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
#include "utils.h" // Para Color, Zone, fade_color, orange_color
// Constructor
HiScoreTable::HiScoreTable()

View File

@@ -1,27 +1,25 @@
#include "instructions.h"
#include <SDL2/SDL_blendmode.h> // para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_events.h> // para SDL_PollEvent, SDL_Event, SDL_QUIT
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <SDL2/SDL_video.h> // para SDL_WINDOWEVENT_SIZE_CHANGED
#include <algorithm> // para max
#include <utility> // para move
#include "asset.h" // para Asset
#include "fade.h" // para Fade, FadeMode, FadeType
#include "global_inputs.h" // para check
#include "input.h" // para Input
#include "jail_audio.h" // para JA_GetMusicState, JA_Music_state
#include "lang.h" // para getText
#include "param.h" // para param
#include "resource.h" // para Resource
#include "screen.h" // para Screen
#include "section.h" // para Name, name, Options, options
#include "sprite.h" // para Sprite
#include "text.h" // para Text, TEXT_CENTER, TEXT_COLOR, TEXT_...
#include "texture.h" // para Texture
#include "tiled_bg.h" // para TiledBG, TILED_MODE_STATIC
#include "utils.h" // para Param, ParamGame, Color, shdw_txt_color
struct JA_Music_t; // lines 22-22
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_QUIT
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
#include <algorithm> // Para max
#include <utility> // Para move
#include "fade.h" // Para Fade, FadeMode, FadeType
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state
#include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamGame, ParamFade
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR, TEXT_...
#include "texture.h" // Para Texture
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
#include "utils.h" // Para Color, shdw_txt_color, Zone, no_color
// Constructor
Instructions::Instructions()

View File

@@ -1,16 +1,15 @@
#pragma once
#include <SDL2/SDL_rect.h> // para SDL_Point, SDL_Rect
#include <SDL2/SDL_render.h> // para SDL_Texture, SDL_Renderer
#include <SDL2/SDL_stdinc.h> // para Uint32
#include <memory> // para unique_ptr, shared_ptr
#include <vector> // para vector
class Fade;
class Sprite;
class Text;
class Texture;
class TiledBG;
struct JA_Music_t; // lines 14-14
#include <SDL2/SDL_rect.h> // Para SDL_Point, SDL_Rect
#include <SDL2/SDL_render.h> // Para SDL_Texture, SDL_Renderer
#include <SDL2/SDL_stdinc.h> // Para Uint32
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
class Fade; // lines 8-8
class Sprite; // lines 9-9
class Text; // lines 10-10
class Texture; // lines 11-11
class TiledBG; // lines 12-12
/*
Esta clase gestiona un estado del programa. Se encarga de poner en pantalla

View File

@@ -1,23 +1,21 @@
#include "intro.h"
#include <SDL2/SDL_events.h> // para SDL_PollEvent, SDL_Event, SDL_QUIT, SDL...
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <SDL2/SDL_video.h> // para SDL_WINDOWEVENT_SIZE_CHANGED
#include <utility> // para move
#include "asset.h" // para Asset
#include "global_inputs.h" // para check
#include "input.h" // para Input
#include "jail_audio.h" // para JA_StopMusic, JA_PlayMusic
#include "lang.h" // para getText
#include "param.h" // para param
#include "resource.h" // para Resource
#include "screen.h" // para Screen
#include "section.h" // para Name, name, Options, options
#include "smart_sprite.h" // para SpriteSmart
#include "text.h" // para Text
#include "texture.h" // para Texture
#include "utils.h" // para Param, ParamGame, Zone, BLOCK, Color
#include "writer.h" // para Writer
struct JA_Music_t; // lines 19-19
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_QUIT, SDL...
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
#include <utility> // Para move
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "jail_audio.h" // Para JA_StopMusic, JA_PlayMusic
#include "lang.h" // Para getText
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options
#include "smart_sprite.h" // Para SmartSprite
#include "text.h" // Para Text
#include "texture.h" // Para Texture
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
#include "writer.h" // Para Writer
// Constructor
Intro::Intro()

View File

@@ -1,13 +1,12 @@
#pragma once
#include <SDL2/SDL_stdinc.h> // para Uint32, Uint8
#include <memory> // para unique_ptr, shared_ptr
#include <vector> // para vector
#include "smart_sprite.h" // para SpriteSmart
#include "writer.h" // para Writer
class Text;
class Texture;
struct JA_Music_t; // lines 11-11
#include <SDL2/SDL_stdinc.h> // Para Uint32
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
#include "smart_sprite.h" // Para SmartSprite
#include "writer.h" // Para Writer
class Text; // lines 8-8
class Texture; // lines 9-9
/*
Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia

View File

@@ -1,19 +1,17 @@
#include "logo.h"
#include <SDL2/SDL_events.h> // para SDL_PollEvent, SDL_Event, SDL_QUIT, SDL...
#include <SDL2/SDL_render.h> // para SDL_Renderer
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <SDL2/SDL_video.h> // para SDL_WINDOWEVENT_SIZE_CHANGED
#include <utility> // para move
#include "asset.h" // para Asset
#include "global_inputs.h" // para check
#include "input.h" // para Input
#include "jail_audio.h" // para JA_StopMusic
#include "param.h" // para param
#include "resource.h" // para Resource
#include "screen.h" // para Screen
#include "section.h" // para Name, name, Options, options
#include "sprite.h" // para Sprite
#include "texture.h" // para Texture
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_QUIT, SDL...
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
#include <utility> // Para move
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "jail_audio.h" // Para JA_StopMusic
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
// Constructor
Logo::Logo()

View File

@@ -7,9 +7,8 @@ Actualizando a la versión "Arcade Edition" en 08/05/2024
*/
#include <iostream> // para char_traits, basic_ostream, operator<<, cout
#include <memory> // para make_unique, unique_ptr
#include "director.h" // para Director
#include <memory> // Para make_unique, unique_ptr
#include "director.h" // Para Director
int main(int argc, char *argv[])
{

View File

@@ -1,10 +1,9 @@
#include "manage_hiscore_table.h"
#include <SDL2/SDL_error.h> // para SDL_GetError
#include <SDL2/SDL_rwops.h> // para SDL_RWread, SDL_RWwrite, SDL_RWFromFile
#include <stdlib.h> // para free, malloc
#include <algorithm> // para sort
#include <iostream> // para basic_ostream, char_traits, operator<<
#include "utils.h" // para HiScoreEntry
#include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_rwops.h> // Para SDL_RWread, SDL_RWwrite, SDL_RWFromFile
#include <algorithm> // Para sort
#include <iostream> // Para basic_ostream, operator<<, cout, endl
#include "utils.h" // Para HiScoreEntry, getFileName
// Resetea la tabla a los valores por defecto
void ManageHiScoreTable::clear()

View File

@@ -2,7 +2,6 @@
#include <string> // para string
#include <vector> // para vector
struct HiScoreEntry;
/*
Esta clase sirve para añadir elementos hiScoreEntry_r a un vector (tabla), de manera
@@ -12,6 +11,17 @@ struct HiScoreEntry;
leer y escribir la tabla a un fichero
*/
// Estructura para las entradas de la tabla de recirds
struct HiScoreEntry
{
std::string name; // Nombre
int score; // Puntuación
// Constructor
explicit HiScoreEntry(const std::string &n = "", int s = 0)
: name(n), score(s) {}
};
// Clase ManageHiScoreTable
class ManageHiScoreTable
{

View File

@@ -1,5 +1,6 @@
#include "moving_sprite.h"
#include "texture.h" // para Texture
#include <algorithm> // Para max
#include "texture.h" // Para Texture
// Constructor
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip)

View File

@@ -1,11 +1,10 @@
#pragma once
#include <SDL2/SDL_rect.h> // para SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // para SDL_RendererFlip
#include <SDL2/SDL_stdinc.h> // para Uint16
#include <memory> // para shared_ptr
#include "sprite.h" // para Sprite
class Texture;
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip
#include <memory> // Para shared_ptr
#include "sprite.h" // Para Sprite
class Texture; // lines 8-8
// Clase MovingSprite. Añade movimiento y efectos de rotación, zoom y flip al sprite
class MovingSprite : public Sprite

View File

@@ -1,14 +1,13 @@
#include "notifier.h"
#include <SDL2/SDL_blendmode.h> // para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <string> // para string
#include "jail_audio.h" // para JA_DeleteSound, JA_LoadSound, JA_Pla...
#include "param.h" // para param
#include "resource.h" // para Resource
#include "screen.h" // para Screen
#include "sprite.h" // para Sprite
#include "text.h" // para Text
#include "texture.h" // para Texture
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <string> // Para string
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
#include "param.h" // Para Param, param, ParamNotification, Par...
#include "screen.h" // Para Screen
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text
#include "texture.h" // Para Texture
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Notifier *Notifier::notifier_ = nullptr;
@@ -34,35 +33,25 @@ Notifier *Notifier::get()
// Constructor
Notifier::Notifier(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file)
: renderer_(Screen::get()->getRenderer()),
icon_texture_(!icon_file.empty() ? std::make_unique<Texture>(renderer_, icon_file) : nullptr),
text_(text),
bg_color_(param.notification.color),
wait_time_(150),
stack_(false),
sound_(JA_LoadSound(sound_file.c_str()))
{
// Inicializa variables
has_icons_ = !icon_file.empty();
// Crea objetos
icon_texture_ = has_icons_ ? std::make_unique<Texture>(renderer_, icon_file) : nullptr;
}
has_icons_(!icon_file.empty()),
sound_(JA_LoadSound(sound_file.c_str())) {}
// Destructor
Notifier::~Notifier()
{
// Libera la memoria de los objetos
JA_DeleteSound(sound_);
notifications_.clear();
}
// Dibuja las notificaciones por pantalla
void Notifier::render()
{
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
{
notifications_[i].sprite->render();
}
}
// Actualiza el estado de las notificaiones

View File

@@ -1,16 +1,14 @@
#include "on_screen_help.h"
#include <SDL2/SDL_blendmode.h> // para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <memory> // para make_unique, make_shared, unique_ptr
#include "asset.h" // para Asset
#include "lang.h" // para getText
#include "param.h" // para param
#include "resource.h" // para Resource
#include "screen.h" // para Screen
#include "sprite.h" // para Sprite
#include "text.h" // para Text
#include "texture.h" // para Texture
#include "utils.h" // para easeInOutSine, Param, ParamGame
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <memory> // Para make_unique, unique_ptr
#include "lang.h" // Para getText
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text
#include "utils.h" // Para easeInOutSine
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
OnScreenHelp *OnScreenHelp::onScreenHelp = nullptr;

View File

@@ -1,7 +1,93 @@
#pragma once
#include <string> // para string
struct Options;
#include <SDL2/SDL_gamecontroller.h> // Para SDL_GameControllerButton
#include <SDL2/SDL_stdinc.h> // Para Uint8
#include "manage_hiscore_table.h"
#include <vector> // Para vector
#include <string>
enum class InputType : int;
enum class ScreenFilter : int;
enum class ScreenVideoMode : int;
namespace lang
{
enum class Code : int;
}
// Dificultad del juego
enum class GameDifficulty
{
EASY = 0,
NORMAL = 1,
HARD = 2,
};
// Estructura para las opciones de la ventana
struct OptionsWindow
{
int size; // Contiene el valor por el que se multiplica el tamaño de la ventana
};
// Estructura con opciones para el video
struct OptionsVideo
{
OptionsWindow window; // Opciones para la ventana del programa
ScreenVideoMode mode; // Contiene el valor del modo de pantalla completa
ScreenFilter filter; // Filtro usado para el escalado de la imagen
bool v_sync; // Indica si se quiere usar vsync o no
bool integer_scale; // Indica si se va a usar el escalado entero
bool shaders; // Indica si se van a usar shaders para los filtros de video
};
// Estructura para las opciones de musica
struct OptionsMusic
{
bool enabled; // Indica si la musica suena o no
int volume; // Volumen al que suena la música
};
// Estructura para las opciones de sonido
struct OptionsSound
{
bool enabled; // Indica si los sonidos suenan o no
int volume; // Volumen al que suenan los sonidos
};
// Estructura para las opciones de audio
struct OptionsAudio
{
OptionsMusic music; // Opciones para la música
OptionsSound sound; // Opciones para los efectos de sonido
};
// Estructura para las opciones del juego
struct OptionsGame
{
GameDifficulty difficulty; // Dificultad del juego
lang::Code language; // Idioma usado en el juego
bool autofire; // Indica si el jugador ha de pulsar repetidamente para disparar o basta con mantener pulsado
std::vector<HiScoreEntry> hi_score_table; // Tabla con las mejores puntuaciones
};
// Estructura para los controles del juego
struct OptionsController
{
int index; // Indice en el vector de mandos
int player_id; // Jugador asociado al mando
Uint8 device_type; // Indica si se utilizará teclado o mando o ambos
std::string name; // Nombre del dispositivo
bool plugged; // Indica si el mando se encuentra conectado
std::vector<InputType> inputs; // Listado de inputs
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
};
// Estructura con todas las opciones de configuración del programa
struct Options
{
OptionsGame game; // Opciones para el propio juego
OptionsVideo video; // Opciones relativas a la clase screen
OptionsAudio audio; // Opciones para el audio
std::vector<OptionsController> controller; // Opciones con las asignaciones del mando para cada jugador
};
// Variables
extern Options options;

View File

@@ -1,7 +1,80 @@
#pragma once
#include <string> // para string
struct Param;
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <string> // Para string
#include <vector> // Para vector
#include "utils.h" // Para Color, Zone
// param.game
struct ParamGame
{
int width; // Ancho de la resolucion nativa del juego
int height; // Alto de la resolucion nativa del juego
int item_size; // Tamaño de los items del juego
Zone play_area; // Rectangulo con la posición de la zona de juego
Zone game_area; // Rectangulo con las dimensiones del juego
int enter_name_seconds; // Duración en segundos para introducir el nombre al finalizar la partida
};
// param.fade
struct ParamFade
{
int num_squares_width; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE
int num_squares_height; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE
int random_squares_delay; // Duración entre cada pintado de cuadrados
int random_squares_mult; // Cantidad de cuadrados que se pintaran cada vez
int post_duration; // Duración final del fade
int venetian_size; // Altura de los rectangulos para FadeType::VENETIAN
};
// param.title
struct ParamTitle
{
int press_start_position; // Posición del texto para empezar a jugar
int title_duration; // Tiempo de inactividad del titulo
int arcade_edition_position; // Posición del bitmap
int title_c_c_position; // Posición del bitmap
};
// param.background
struct ParamBackground
{
Color attenuate_color;
int attenuate_alpha;
};
struct ParamBalloon
{
float grav; // Aceleración en el eje Y. Modifica la velocidad
float vel; // Velocidad inicial que tienen al rebotar contra el suelo
// Constructor
explicit ParamBalloon(float grav_val = 0.0f, float vel_val = 0.0f)
: grav(grav_val), vel(vel_val) {}
};
// Estructura para las opciones de las notificaciones
struct ParamNotification
{
NotifyPosition pos_h; // Ubicación de las notificaciones en pantalla
NotifyPosition pos_v; // Ubicación de las notificaciones en pantalla
bool sound; // Indica si las notificaciones suenan
Color color; // Color de las notificaciones
};
// Estructura para almacenar todos los parámetros del juego
struct Param
{
ParamGame game; // Parametros relacionados con el juego
ParamFade fade; // Parametros para ajustar el fade
SDL_Rect scoreboard; // Posición y tamaño del marcador
ParamTitle title; // Parametros con ajustes para la sección Title
ParamBackground background; // Parametros que afectan a la clase Background
std::vector<ParamBalloon> balloon; // Parametros de velocidad y gravedad de cada tipo de globo
ParamNotification notification; // Opciones para las notificaciones
Param() { balloon.reserve(4); }
};
extern Param param;

124
source/path_sprite.cpp Normal file
View File

@@ -0,0 +1,124 @@
#include "path_sprite.h"
#include <bits/std_abs.h> // Para abs
#include <stdlib.h> // Para abs
#include <utility> // Para move
#include "moving_sprite.h" // Para MovingSprite
#include "utils.h" // Para easeOutQuint
#include <functional>
class Texture; // lines 3-3
// Constructor
PathSprite::PathSprite(std::shared_ptr<Texture> texture)
: AnimatedSprite(texture) {}
// Actualiza la posición y comprueba si ha llegado a su destino
void PathSprite::update()
{
if (enabled_)
{
moveThroughCurrentPath();
goToNextPathOrDie();
}
}
// Añade un recorrido
void PathSprite::addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction, int waiting_counter)
{
paths_.emplace_back(createPath(start, end, type, fixed_pos, steps, easingFunction), waiting_counter);
}
// Añade un recorrido
void PathSprite::addPath(std::vector<SDL_Point> spots, int waiting_counter)
{
paths_.emplace_back(std::move(spots), waiting_counter);
}
// Devuelve un vector con los puntos que conforman la ruta
std::vector<SDL_Point> PathSprite::createPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction)
{
std::vector<SDL_Point> v;
v.reserve(steps);
for (int i = 0; i < steps; ++i)
{
double t = static_cast<double>(i) / (steps - 1);
double value = start + (end - start) * easingFunction(t);
if (start > 0 && end < 0)
{
value = start - std::abs(end - start) * easingFunction(t);
}
else if (start < 0 && end > 0)
{
value = start + std::abs(end - start) * easingFunction(t);
}
switch (type)
{
case PathType::HORIZONTAL:
v.emplace_back(SDL_Point{static_cast<int>(value), fixed_pos});
break;
case PathType::VERTICAL:
v.emplace_back(SDL_Point{fixed_pos, static_cast<int>(value)});
break;
default:
break;
}
}
return v;
}
// Habilita el objeto
void PathSprite::enable()
{
enabled_ = true;
}
// Coloca el sprite en los diferentes puntos del recorrido
void PathSprite::moveThroughCurrentPath()
{
auto &path = paths_.at(current_path_);
// Establece la posición
const auto &p = path.spots.at(path.counter);
MovingSprite::setPos(p.x, p.y);
// Comprobar si ha terminado el recorrido
if (!path.on_destination)
{
++path.counter;
if (path.counter >= static_cast<int>(path.spots.size()))
{
path.on_destination = true;
path.counter = static_cast<int>(path.spots.size()) - 1;
}
}
// Comprobar si ha terminado la espera
if (path.on_destination)
{
if (path.waiting_counter == 0)
path.finished = true;
else
--path.waiting_counter;
}
}
// Cambia de recorrido o finaliza
void PathSprite::goToNextPathOrDie()
{
// Comprueba si ha terminado el recorrdo actual
if (paths_.at(current_path_).finished)
++current_path_;
// Comprueba si quedan mas recorridos
if (current_path_ >= static_cast<int>(paths_.size()))
enabled_ = false;
}
// Indica si ha terminado todos los recorridos
bool PathSprite::hasFinished()
{
return !enabled_;
}

68
source/path_sprite.h Normal file
View File

@@ -0,0 +1,68 @@
#pragma once
#include <SDL2/SDL_rect.h> // Para SDL_Point
#include <memory> // Para shared_ptr
#include <functional>
#include <vector> // Para vector
#include "animated_sprite.h" // Para AnimatedSprite
class Texture; // lines 5-5
enum class PathType
{
VERTICAL,
HORIZONTAL,
};
// Clase PathSprite
class PathSprite : public AnimatedSprite
{
private:
// Estructuras
struct Path
{
std::vector<SDL_Point> spots; // Puntos por los que se desplazará el sprite
int waiting_counter; // Tiempo de espera una vez en el destino
bool on_destination = false; // Indica si ha llegado al destino
bool finished = false; // Indica si ha terminado de esperarse
int counter = 0; // Contador interno
// Constructor
Path(const std::vector<SDL_Point> &spots_init, int waiting_counter_init)
: spots(spots_init), waiting_counter(waiting_counter_init) {}
};
// Variables
bool finished_ = false; // Indica si ya ha terminado
bool enabled_ = false; // Indica si el objeto está habilitado
int current_path_ = 0; // Path que se está recorriendo actualmente
std::vector<Path> paths_; // Caminos a recorrer por el sprite
// Coloca el sprite en los diferentes puntos del recorrido
void moveThroughCurrentPath();
// Cambia de recorrido o finaliza
void goToNextPathOrDie();
public:
// Constructor
explicit PathSprite(std::shared_ptr<Texture> texture);
// Destructor
~PathSprite() = default;
// Actualiza la posición del sprite
void update() override;
// Añade un recorrido
void addPath(std::vector<SDL_Point> spots, int waiting_counter);
void addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction, int waiting_counter);
// Devuelve un vector con los puntos que conforman la ruta
std::vector<SDL_Point> createPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction);
// Habilita el objeto
void enable();
// Indica si ha terminado todos los recorridos
bool hasFinished();
};

View File

@@ -1,14 +1,15 @@
#include "player.h"
#include <SDL2/SDL_render.h> // para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL...
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <stdlib.h> // para rand
#include <algorithm> // para max, min
#include "animated_sprite.h" // para SpriteAnimated
#include "input.h" // para inputs_e
#include "param.h" // para param
#include "texture.h" // para Texture
#include "scoreboard.h" // para Texture
#include "options.h"
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <stdlib.h> // Para rand
#include <algorithm> // Para max, min
#include "animated_sprite.h" // Para AnimatedSprite
#include "input.h" // Para InputType
#include "manage_hiscore_table.h" // Para HiScoreEntry
#include "options.h" // Para Options, OptionsGame, options
#include "param.h" // Para Param, ParamGame, param
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode
#include "texture.h" // Para Texture
// Constructor
Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations)
@@ -22,6 +23,7 @@ Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vect
demo_(demo)
{
// Configura objetos
player_sprite_->getTexture()->setPalette(coffees_);
power_sprite_->getTexture()->setAlpha(224);
power_up_desp_x_ = (power_sprite_->getWidth() - player_sprite_->getWidth()) / 2;
power_sprite_->setPosY(y - (power_sprite_->getHeight() - player_sprite_->getHeight()));

View File

@@ -1,17 +1,16 @@
#pragma once
#include <SDL2/SDL_rect.h> // para SDL_Rect
#include <SDL2/SDL_stdinc.h> // para Uint32
#include <memory> // para unique_ptr, shared_ptr
#include <string> // para string
#include <vector> // para vector
#include "animated_sprite.h" // para SpriteAnimated
#include "smart_sprite.h" // para SpriteAnimated
#include "enter_name.h" // para EnterName
#include "utils.h" // para Circle
class Texture;
enum class InputType : int;
enum class ScoreboardMode; // lines 12-12
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <SDL2/SDL_stdinc.h> // Para Uint32
#include <memory> // Para unique_ptr, shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "animated_sprite.h" // Para AnimatedSprite
#include "enter_name.h" // Para EnterName
#include "utils.h" // Para Circle
class Texture; // lines 12-12
enum class InputType : int; // lines 13-13
enum class ScoreboardMode; // lines 14-14
// Estados del jugador
enum class PlayerStatus

View File

@@ -1,9 +1,12 @@
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include "resource.h"
#include "asset.h"
#include "screen.h"
#include <algorithm> // Para find_if
#include <iostream> // Para basic_ostream, operator<<, endl, cout, cerr
#include <stdexcept> // Para runtime_error
#include "asset.h" // Para Asset, AssetType
#include "jail_audio.h" // Para JA_LoadMusic, JA_LoadSound
#include "screen.h" // Para Screen
struct JA_Music_t;
struct JA_Sound_t;
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Resource *Resource::resource_ = nullptr;

View File

@@ -1,14 +1,14 @@
#pragma once
#include <SDL2/SDL.h>
#include <vector>
#include <memory>
#include <string>
#include "jail_audio.h"
#include "texture.h"
#include "text.h"
#include "utils.h"
#include "animated_sprite.h"
#include <memory> // Para shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "animated_sprite.h" // Para AnimationsFileBuffer
#include "text.h" // Para TextFile
#include "texture.h" // Para Texture
#include "utils.h" // Para DemoData
struct JA_Music_t;
struct JA_Sound_t;
// Estructura para almacenar ficheros de sonido y su nombre
struct ResourceSound

View File

@@ -1,17 +1,15 @@
#include "scoreboard.h"
#include <SDL2/SDL_blendmode.h> // para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <math.h> // para roundf
#include <iomanip>
#include <sstream>
#include "asset.h" // para Asset
#include "lang.h" // para getText
#include "resource.h" // para Resource
#include "screen.h"
#include "sprite.h" // para Sprite
#include "text.h" // para Text
#include "texture.h" // para Texture
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <math.h> // Para roundf
#include <iomanip> // Para operator<<, setfill, setw
#include <sstream> // Para basic_ostream, basic_ostringstream
#include "lang.h" // Para getText
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Scoreboard *Scoreboard::scoreboard_ = nullptr;

View File

@@ -1,20 +1,20 @@
#include "screen.h"
#include <SDL2/SDL_events.h> // para SDL_DISABLE, SDL_ENABLE
#include <SDL2/SDL_mouse.h> // para SDL_ShowCursor
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <algorithm> // para max, min
#include <fstream> // para basic_ifstream, ifstream
#include <iterator> // para istreambuf_iterator, operator!=
#include <string> // para basic_string, operator+, to_string, cha...
#include <vector> // para vector
#include "asset.h" // para Asset
#include "dbgtxt.h" // para dbg_print
#include "global_inputs.h" // para servicePressedCounter
#include "input.h" // para Input, inputs_e, INPUT_DO_NOT_ALLOW_REPEAT
#include "notifier.h" // para Notify
#include "on_screen_help.h" // para OnScreenHelp
#include "options.h" // para options
#include <SDL2/SDL_events.h> // Para SDL_DISABLE, SDL_ENABLE
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <algorithm> // Para clamp, max, min
#include <fstream> // Para basic_ifstream, ifstream
#include <iterator> // Para istreambuf_iterator, operator==
#include <string> // Para allocator, operator+, to_string, char_t...
#include <vector> // Para vector
#include "asset.h" // Para Asset
#include "dbgtxt.h" // Para dbg_print
#include "global_inputs.h" // Para service_pressed_counter
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_RE...
#include "notifier.h" // Para Notifier
#include "on_screen_help.h" // Para OnScreenHelp
#include "options.h" // Para Options, OptionsVideo, options, Options...
#ifndef NO_SHADERS
#include "jail_shader.h" // para init, render

View File

@@ -1,14 +1,13 @@
#pragma once
#include <SDL2/SDL_blendmode.h> // para SDL_BlendMode
#include <SDL2/SDL_rect.h> // para SDL_Rect
#include <SDL2/SDL_render.h> // para SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // para Uint32
#include <SDL2/SDL_video.h> // para SDL_Window
#include <string> // para basic_string, string
#include "utils.h" // para Color
#include <memory>
#include "param.h" // para param
#include <SDL2/SDL_blendmode.h> // Para SDL_BlendMode
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // Para Uint32
#include <SDL2/SDL_video.h> // Para SDL_Window
#include <string> // Para string
#include "param.h" // Para Param, ParamGame, param
#include "utils.h" // Para Color
enum class ScreenFilter : int
{

View File

@@ -1,5 +1,6 @@
#include "smart_sprite.h"
class Texture;
#include "moving_sprite.h" // Para MovingSprite
class Texture; // lines 2-2
// Constructor
SmartSprite::SmartSprite(std::shared_ptr<Texture> texture)
@@ -127,6 +128,7 @@ bool SmartSprite::hasFinished() const
return finished_;
}
// Habilita el objeto
void SmartSprite::setEnabled(bool value)
{
enabled_ = value;

View File

@@ -53,5 +53,6 @@ public:
// Obtiene el valor de la variable
bool hasFinished() const;
// Habilita el objeto
void setEnabled(bool value);
};

View File

@@ -1,11 +1,11 @@
#include "text.h"
#include <SDL2/SDL_rect.h> // para SDL_Rect
#include <fstream> // para basic_ostream, basic_ifstream, basic_istream
#include <iostream> // para cout
#include "resource.h" // para Resource
#include "sprite.h" // para Sprite
#include "texture.h" // para Texture
#include "utils.h" // para Color
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <fstream> // Para basic_ifstream, basic_istream, basic_ostream
#include <iostream> // Para cerr
#include <stdexcept> // Para runtime_error
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
#include "utils.h" // Para Color, getFileName, printWithDots
// Llena una estructuta TextFile desde un fichero
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)

View File

@@ -1,12 +1,11 @@
#pragma once
#include <SDL2/SDL_render.h> // para SDL_Renderer
#include <SDL2/SDL_stdinc.h> // para Uint8
#include <memory> // para shared_ptr, unique_ptr
#include <string> // para string
#include "sprite.h" // para Sprite
#include "utils.h" // para Color
class Texture;
#include <SDL2/SDL_stdinc.h> // Para Uint8
#include <memory> // Para unique_ptr, shared_ptr
#include <string> // Para string
#include "sprite.h" // Para Sprite
#include "utils.h" // Para Color
class Texture; // lines 9-9
constexpr int TEXT_COLOR = 1;
constexpr int TEXT_SHADOW = 2;

View File

@@ -1,15 +1,16 @@
#include "texture.h"
#include "utils.h"
#include <SDL2/SDL_error.h> // para SDL_GetError
#include <SDL2/SDL_surface.h> // para SDL_CreateRGBSurfaceWithFormatFrom
#include <fcntl.h> // para SEEK_END, SEEK_SET
#include <stdio.h> // para fseek, fclose, fopen, fread, ftell, NULL
#include <stdlib.h> // para malloc, free, exit
#include <iostream> // para basic_ostream, operator<<, cout, endl
#include <fstream>
#include <sstream>
#include "gif.c" // para LoadGif, LoadPalette
#include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_surface.h> // Para SDL_CreateRGBSurfaceWithFormatFrom
#include <fcntl.h> // Para SEEK_END, SEEK_SET
#include <stdio.h> // Para fseek, fclose, fopen, fread, ftell, FILE
#include <stdlib.h> // Para free, malloc
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream
#include <iostream> // Para cerr, cout
#include <stdexcept> // Para runtime_error
#include "gif.c" // Para LoadGif, LoadPalette
#include "utils.h" // Para getFileName, printWithDots
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" // para stbi_failure_reason, stbi_image_free

View File

@@ -1,12 +1,11 @@
#include "tiled_bg.h"
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888
#include <stdlib.h> // para rand
#include <memory> // para unique_ptr, make_shared, make_unique
#include <cmath> // para sinf
#include "resource.h" // para Resource
#include "screen.h" // para Screen
#include "sprite.h" // para Sprite
#include "texture.h" // para Texture
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <stdlib.h> // Para rand
#include <cmath> // Para sin
#include <memory> // Para unique_ptr, make_unique
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "sprite.h" // Para Sprite
// Constructor
TiledBG::TiledBG(SDL_Rect pos, TiledBGMode mode)

View File

@@ -1,8 +1,7 @@
#pragma once
#include <SDL2/SDL_rect.h> // para SDL_Rect
#include <SDL2/SDL_render.h> // para SDL_Renderer, SDL_Texture
#include <string> // para string, basic_string
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
// Modos de funcionamiento para el tileado de fondo
enum class TiledBGMode : int

View File

@@ -1,26 +1,29 @@
#include "title.h"
#include <SDL2/SDL_events.h> // para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
#include <SDL2/SDL_keycode.h> // para SDLK_1, SDLK_2, SDLK_3
#include <SDL2/SDL_rect.h> // para SDL_Rect
#include <SDL2/SDL_render.h> // para SDL_Renderer
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
#include <string> // para char_traits, operator+, to_string, bas...
#include <utility> // para move
#include <vector> // para vector
#include "asset.h" // para Asset
#include "global_inputs.h" // para check
#include "input.h" // para Input, InputType, INPUT_DO_NOT_ALLOW_R...
#include "jail_audio.h" // para JA_GetMusicState, JA_Music_state, JA_P...
#include "lang.h" // para getText
#include "notifier.h" // para Notifier
#include "options.h" // para options
#include "param.h" // para param
#include "resource.h" // para Resource
#include "screen.h" // para Screen
#include "section.h" // para Options, options, Name, name
#include "texture.h" // para Texture
#include "utils.h" // para Param, OptionsController, Color, Param...
struct JA_Music_t; // lines 17-17
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
#include <SDL2/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <string> // Para char_traits, operator+, to_string, bas...
#include <utility> // Para move
#include <vector> // Para vector
#include "define_buttons.h" // Para DefineButtons
#include "fade.h" // Para Fade, FadeType
#include "game_logo.h" // Para GameLogo
#include "global_inputs.h" // Para check
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_R...
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state, JA_P...
#include "lang.h" // Para getText
#include "notifier.h" // Para Notifier
#include "options.h" // Para OptionsController, Options, options
#include "param.h" // Para Param, param, ParamGame, ParamTitle
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Options, options, name, Name
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
#include "texture.h" // Para Texture
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
#include "utils.h" // Para Color, Zone, fade_color, no_color, BLOCK
// Constructor
Title::Title()

View File

@@ -1,22 +1,15 @@
#pragma once
#include <SDL2/SDL_stdinc.h> // para Uint32
#include <memory> // para unique_ptr, shared_ptr
#include "define_buttons.h" // para DefineButtons
#include "fade.h" // para Fade
#include "game_logo.h" // para GameLogo
#include "sprite.h" // para Sprite
#include "text.h" // para Text
#include "tiled_bg.h" // para TiledBG
class Input; // lines 17-17
#include "section.h" // para Options, options, Name, name
class Screen; // lines 18-18
class Texture; // lines 20-20
namespace section
{
enum class Name;
}
struct JA_Music_t; // lines 21-21
#include <SDL2/SDL_stdinc.h> // Para Uint32
#include <memory> // Para unique_ptr, shared_ptr
#include "section.h" // Para Name
class DefineButtons;
class Fade;
class GameLogo;
class Sprite;
class Text;
class Texture; // lines 14-14
class TiledBG;
// Textos
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";

View File

@@ -1,13 +1,13 @@
#include "utils.h"
#include <filesystem>
#include <iostream>
#include <string>
#include <algorithm> // para min, clamp, find_if_not, transform
#include <cctype> // para tolower, isspace
#include <cmath> // para cos, pow, M_PI
#include <compare> // para operator<
struct JA_Music_t; // lines 7-7
struct JA_Sound_t; // lines 8-8
#include <SDL2/SDL_rwops.h> // Para SDL_RWFromFile, SDL_RWclose, SDL_RWread
#include <algorithm> // Para min, clamp, find_if_not, find, transform
#include <cctype> // Para tolower, isspace
#include <cmath> // Para cos, pow, M_PI
#include <compare> // Para operator<
#include <filesystem> // Para path
#include <iostream> // Para basic_ostream, cout, basic_ios, endl, ios
#include <stdexcept> // Para runtime_error
#include <string> // Para basic_string, string, char_traits, opera...
// Variables
Overrides overrides = Overrides();
@@ -182,6 +182,30 @@ double easeOutQuint(double t)
return 1 - std::pow(1 - t, 5);
}
// Función de suavizado
double easeInQuint(double t)
{
return pow(t, 5);
}
// Función de suavizado
double easeInOutQuint(double t)
{
return t < 0.5 ? 16 * pow(t, 5) : 1 - pow(-2 * t + 2, 5) / 2;
}
// Función de suavizado
double easeInQuad(double t)
{
return t * t;
}
// Función de suavizado
double easeOutQuad(double t)
{
return 1 - (1 - t) * (1 - t);
}
// Función de suavizado
double easeInOutSine(double t)
{

View File

@@ -1,34 +1,16 @@
#pragma once
#include <SDL2/SDL_gamecontroller.h> // para SDL_GameControllerButton
#include <SDL2/SDL_rect.h> // para SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // para SDL_Renderer
#include <SDL2/SDL_stdinc.h> // para Uint8
#include <stdint.h> // para int32_t
#include <string> // para string
#include <vector> // para vector
enum class InputType : int;
enum class ScreenFilter; // lines 14-14
enum class ScreenVideoMode; // lines 15-15
namespace lang
{
enum class Code : int;
}
struct JA_Music_t; // lines 12-12
struct JA_Sound_t; // lines 13-13
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // Para SDL_Renderer
#include <SDL2/SDL_stdinc.h> // Para Uint8
#include <stdint.h> // Para int32_t
#include <string> // Para string
#include <vector> // Para vector
// Constantes
constexpr int BLOCK = 8;
constexpr int TOTAL_DEMO_DATA = 2000;
// Dificultad del juego
enum class GameDifficulty
{
EASY = 0,
NORMAL = 1,
HARD = 2,
};
// Variables para que los argumentos del programa tengan mas peso que los definidos en otros lugares
struct Overrides
{
@@ -74,17 +56,6 @@ enum class NotifyPosition
RIGHT,
};
// Estructura para las entradas de la tabla de recirds
struct HiScoreEntry
{
std::string name; // Nombre
int score; // Puntuación
// Constructor
explicit HiScoreEntry(const std::string &n = "", int s = 0)
: name(n), score(s) {}
};
struct DemoKeys
{
Uint8 left;
@@ -117,74 +88,6 @@ struct Demo
: enabled(e), recording(r), counter(c), keys(k), data(d) {}
};
// Estructura para las opciones de la ventana
struct OptionsWindow
{
int size; // Contiene el valor por el que se multiplica el tamaño de la ventana
};
// Estructura con opciones para el video
struct OptionsVideo
{
OptionsWindow window; // Opciones para la ventana del programa
ScreenVideoMode mode; // Contiene el valor del modo de pantalla completa
ScreenFilter filter; // Filtro usado para el escalado de la imagen
bool v_sync; // Indica si se quiere usar vsync o no
bool integer_scale; // Indica si se va a usar el escalado entero
bool shaders; // Indica si se van a usar shaders para los filtros de video
};
// Estructura para las opciones de musica
struct OptionsMusic
{
bool enabled; // Indica si la musica suena o no
int volume; // Volumen al que suena la música
};
// Estructura para las opciones de sonido
struct OptionsSound
{
bool enabled; // Indica si los sonidos suenan o no
int volume; // Volumen al que suenan los sonidos
};
// Estructura para las opciones de audio
struct OptionsAudio
{
OptionsMusic music; // Opciones para la música
OptionsSound sound; // Opciones para los efectos de sonido
};
// Estructura para las opciones del juego
struct OptionsGame
{
GameDifficulty difficulty; // Dificultad del juego
lang::Code language; // Idioma usado en el juego
bool autofire; // Indica si el jugador ha de pulsar repetidamente para disparar o basta con mantener pulsado
std::vector<HiScoreEntry> hi_score_table; // Tabla con las mejores puntuaciones
};
// Estructura para los controles del juego
struct OptionsController
{
int index; // Indice en el vector de mandos
int player_id; // Jugador asociado al mando
Uint8 device_type; // Indica si se utilizará teclado o mando o ambos
std::string name; // Nombre del dispositivo
bool plugged; // Indica si el mando se encuentra conectado
std::vector<InputType> inputs; // Listado de inputs
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
};
// Estructura con todas las opciones de configuración del programa
struct Options
{
OptionsGame game; // Opciones para el propio juego
OptionsVideo video; // Opciones relativas a la clase screen
OptionsAudio audio; // Opciones para el audio
std::vector<OptionsController> controller; // Opciones con las asignaciones del mando para cada jugador
};
// Posiciones dentro de un rectangulo
struct Zone
{
@@ -197,80 +100,6 @@ struct Zone
int third_quarter_y; // Anclaje al 75% del eje X
};
// param.game
struct ParamGame
{
int width; // Ancho de la resolucion nativa del juego
int height; // Alto de la resolucion nativa del juego
int item_size; // Tamaño de los items del juego
Zone play_area; // Rectangulo con la posición de la zona de juego
Zone game_area; // Rectangulo con las dimensiones del juego
int enter_name_seconds; // Duración en segundos para introducir el nombre al finalizar la partida
};
// param.fade
struct ParamFade
{
int num_squares_width; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE
int num_squares_height; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE
int random_squares_delay; // Duración entre cada pintado de cuadrados
int random_squares_mult; // Cantidad de cuadrados que se pintaran cada vez
int post_duration; // Duración final del fade
int venetian_size; // Altura de los rectangulos para FadeType::VENETIAN
};
// param.title
struct ParamTitle
{
int press_start_position; // Posición del texto para empezar a jugar
int title_duration; // Tiempo de inactividad del titulo
int arcade_edition_position; // Posición del bitmap
int title_c_c_position; // Posición del bitmap
};
// param.background
struct ParamBackground
{
Color attenuate_color;
int attenuate_alpha;
};
struct ParamBalloon
{
float grav; // Aceleración en el eje Y. Modifica la velocidad
float vel; // Velocidad inicial que tienen al rebotar contra el suelo
// Constructor
explicit ParamBalloon(float grav_val = 0.0f, float vel_val = 0.0f)
: grav(grav_val), vel(vel_val) {}
};
// Estructura para las opciones de las notificaciones
struct ParamNotification
{
NotifyPosition pos_h; // Ubicación de las notificaciones en pantalla
NotifyPosition pos_v; // Ubicación de las notificaciones en pantalla
bool sound; // Indica si las notificaciones suenan
Color color; // Color de las notificaciones
};
// Estructura para almacenar todos los parámetros del juego
struct Param
{
ParamGame game; // Parametros relacionados con el juego
ParamFade fade; // Parametros para ajustar el fade
SDL_Rect scoreboard; // Posición y tamaño del marcador
ParamTitle title; // Parametros con ajustes para la sección Title
ParamBackground background; // Parametros que afectan a la clase Background
std::vector<ParamBalloon> balloon; // Parametros de velocidad y gravedad de cada tipo de globo
ParamNotification notification; // Opciones para las notificaciones
Param()
{
balloon.reserve(4); // Reservar espacio para 4 elementos
}
};
// Calcula el cuadrado de la distancia entre dos puntos
double distanceSquared(int x1, int y1, int x2, int y2);
@@ -312,8 +141,10 @@ std::string trim(const std::string &str);
// Función de suavizado
double easeOutQuint(double t);
// Función de suavizado
double easeInQuint(double t);
double easeInOutQuint(double t);
double easeInQuad(double t);
double easeOutQuad(double t);
double easeInOutSine(double t);
// Comprueba si una vector contiene una cadena