Compare commits
9 Commits
c11a868289
...
2024-10-14
| Author | SHA1 | Date | |
|---|---|---|---|
| 9825c7fb9b | |||
| d0a6e4c572 | |||
| 7c876e1d4d | |||
| 809c10048e | |||
| babf02226c | |||
| 46540ad7c3 | |||
| ba7c44ad06 | |||
| 46b19ee82f | |||
| b2122ac239 |
8
Makefile
8
Makefile
@@ -25,8 +25,8 @@ INCLUDES:= -I$(DIR_SOURCES)
|
||||
ifeq ($(OS),Windows_NT)
|
||||
FixPath = $(subst /,\,$1)
|
||||
SOURCES := source/*.cpp
|
||||
CXXFLAGS:= -std=c++14 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
|
||||
CXXFLAGS_DEBUG:= -std=c++14 -Wall -g
|
||||
CXXFLAGS:= -std=c++20 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
|
||||
CXXFLAGS_DEBUG:= -std=c++20 -Wall -g
|
||||
LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32
|
||||
RM = del /Q
|
||||
MKD:= mkdir
|
||||
@@ -34,8 +34,8 @@ else
|
||||
FixPath = $1
|
||||
SOURCES := $(shell find $(DIR_SOURCES) -name '*.cpp')
|
||||
SOURCES := source/*.cpp
|
||||
CXXFLAGS:= -std=c++14 -Wall -Os -ffunction-sections -fdata-sections
|
||||
CXXFLAGS_DEBUG:= -std=c++14 -Wall -g
|
||||
CXXFLAGS:= -std=c++20 -Wall -Os -ffunction-sections -fdata-sections
|
||||
CXXFLAGS_DEBUG:= -std=c++20 -Wall -g
|
||||
LDFLAGS := -lSDL2
|
||||
RM = rm -f
|
||||
MKD:= mkdir -p
|
||||
|
||||
176
cppcheck-result
176
cppcheck-result
@@ -1,176 +0,0 @@
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:264:0: style: The function 'getNumFrames' is never used. [unusedFunction]
|
||||
int AnimatedSprite::getNumFrames()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:270:0: style: The function 'setCurrentFrame' is never used. [unusedFunction]
|
||||
void AnimatedSprite::setCurrentFrame(int num)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:287:0: style: The function 'setAnimationCounter' is never used. [unusedFunction]
|
||||
void AnimatedSprite::setAnimationCounter(std::string name, int num)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:293:0: style: The function 'setAnimationSpeed' is never used. [unusedFunction]
|
||||
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:305:0: style: The function 'setAnimationLoop' is never used. [unusedFunction]
|
||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:317:0: style: The function 'setAnimationCompleted' is never used. [unusedFunction]
|
||||
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:335:0: style: The function 'getAnimationClip' is never used. [unusedFunction]
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:529:0: style: The function 'setAnimationFrames' is never used. [unusedFunction]
|
||||
void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/background.cpp:239:0: style: The function 'setSrcRect' is never used. [unusedFunction]
|
||||
void Background::setSrcRect(SDL_Rect value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/background.cpp:245:0: style: The function 'setDstRect' is never used. [unusedFunction]
|
||||
void Background::setDstRect(SDL_Rect value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:681:0: style: The function 'setBlink' is never used. [unusedFunction]
|
||||
void Balloon::setBlink(bool value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:687:0: style: The function 'isBlinking' is never used. [unusedFunction]
|
||||
bool Balloon::isBlinking() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:699:0: style: The function 'isVisible' is never used. [unusedFunction]
|
||||
bool Balloon::isVisible() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:735:0: style: The function 'getStoppedTimer' is never used. [unusedFunction]
|
||||
Uint16 Balloon::getStoppedTimer() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1000:0: style: The function 'decBalloonSpeed' is never used. [unusedFunction]
|
||||
void Game::decBalloonSpeed()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1169:0: style: The function 'popAllBalloons' is never used. [unusedFunction]
|
||||
void Game::popAllBalloons()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1226:0: style: The function 'countBalloons' is never used. [unusedFunction]
|
||||
int Game::countBalloons()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:319:0: style: The function 'checkAnyInput' is never used. [unusedFunction]
|
||||
bool Input::checkAnyInput(int device, int controller_index)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:498:0: style: The function 'printBindings' is never used. [unusedFunction]
|
||||
void Input::printBindings(int device, int controller_index) const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:531:0: style: The function 'getIndexByName' is never used. [unusedFunction]
|
||||
int Input::getIndexByName(std::string name) const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:575:0: style: The function 'to_inputs_e' is never used. [unusedFunction]
|
||||
InputType Input::to_inputs_e(std::string name) const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:114:0: style: The function 'getZoomW' is never used. [unusedFunction]
|
||||
float MovingSprite::getZoomW() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:120:0: style: The function 'getZoomH' is never used. [unusedFunction]
|
||||
float MovingSprite::getZoomH() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:126:0: style: The function 'getAngle' is never used. [unusedFunction]
|
||||
double MovingSprite::getAngle() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:196:0: style: The function 'setAngle' is never used. [unusedFunction]
|
||||
void MovingSprite::setAngle(double value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:208:0: style: The function 'decAngle' is never used. [unusedFunction]
|
||||
void MovingSprite::decAngle(double value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:214:0: style: The function 'getRotate' is never used. [unusedFunction]
|
||||
bool MovingSprite::getRotate() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:220:0: style: The function 'getRotateSpeed' is never used. [unusedFunction]
|
||||
Uint16 MovingSprite::getRotateSpeed() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:256:0: style: The function 'disableRotate' is never used. [unusedFunction]
|
||||
void MovingSprite::disableRotate()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:286:0: style: The function 'flip' is never used. [unusedFunction]
|
||||
void MovingSprite::flip()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:292:0: style: The function 'getFlip' is never used. [unusedFunction]
|
||||
SDL_RendererFlip MovingSprite::getFlip()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:414:0: style: The function 'hasDied' is never used. [unusedFunction]
|
||||
bool Player::hasDied() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:523:0: style: The function 'getStatusPlaying' is never used. [unusedFunction]
|
||||
PlayerStatus Player::getStatusPlaying() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:535:0: style: The function 'setScoreMultiplier' is never used. [unusedFunction]
|
||||
void Player::setScoreMultiplier(float value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:568:0: style: The function 'getInvulnerableCounter' is never used. [unusedFunction]
|
||||
int Player::getInvulnerableCounter() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:574:0: style: The function 'setInvulnerableCounter' is never used. [unusedFunction]
|
||||
void Player::setInvulnerableCounter(int value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:611:0: style: The function 'getPowerUpCounter' is never used. [unusedFunction]
|
||||
int Player::getPowerUpCounter() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:617:0: style: The function 'setPowerUpCounter' is never used. [unusedFunction]
|
||||
void Player::setPowerUpCounter(int value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:666:0: style: The function 'enableInput' is never used. [unusedFunction]
|
||||
void Player::enableInput()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:672:0: style: The function 'disableInput' is never used. [unusedFunction]
|
||||
void Player::disableInput()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:697:0: style: The function 'setPlayerTextures' is never used. [unusedFunction]
|
||||
void Player::setPlayerTextures(std::vector<std::shared_ptr<Texture>> texture)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:248:0: style: The function 'setWindowSize' is never used. [unusedFunction]
|
||||
void Screen::setWindowSize(int size)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:271:0: style: The function 'setBorderColor' is never used. [unusedFunction]
|
||||
void Screen::setBorderColor(Color color)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:55:0: style: The function 'getDestX' is never used. [unusedFunction]
|
||||
int SmartSprite::getDestX() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:61:0: style: The function 'getDestY' is never used. [unusedFunction]
|
||||
int SmartSprite::getDestY() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:148:0: style: The function 'isOnDestination' is never used. [unusedFunction]
|
||||
bool SmartSprite::isOnDestination() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.cpp:159:0: style: The function 'incPosY' is never used. [unusedFunction]
|
||||
void Sprite::incPosY(int value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:264:0: style: The function 'setFixedWidth' is never used. [unusedFunction]
|
||||
void Text::setFixedWidth(bool value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:236:0: style: The function 'getSDLTexture' is never used. [unusedFunction]
|
||||
SDL_Texture *Texture::getSDLTexture()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:242:0: style: The function 'newSurface' is never used. [unusedFunction]
|
||||
Surface Texture::newSurface(int w, int h)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:184:0: style: The function 'toLower' is never used. [unusedFunction]
|
||||
std::string toLower(std::string str)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:200:0: style: The function 'getSound' is never used. [unusedFunction]
|
||||
JA_Sound_t *getSound(std::vector<SoundFile> sounds, std::string name)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:228:0: style: The function 'sortHiScoreTable' is never used. [unusedFunction]
|
||||
HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:239:0: style: The function 'DrawCircle' is never used. [unusedFunction]
|
||||
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:278:0: style: The function 'lightenColor' is never used. [unusedFunction]
|
||||
Color lightenColor(Color color, int amount)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:288:0: style: The function 'DarkenColor' is never used. [unusedFunction]
|
||||
Color DarkenColor(Color color, int amount)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:316:0: style: The function 'easeOutQuint' is never used. [unusedFunction]
|
||||
double easeOutQuint(double t)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/writer.cpp:101:0: style: The function 'IsEnabled' is never used. [unusedFunction]
|
||||
bool Writer::IsEnabled() const
|
||||
^
|
||||
nofile:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 configurations. Use --force to check all configurations. For more details, use --enable=information. [toomanyconfigs]
|
||||
|
||||
@@ -1,557 +0,0 @@
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:60:11: warning: The class 'MovingSprite' defines member function with name 'getPosX' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
float getPosX() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:29:9: note: Parent function 'Sprite::getPosX'
|
||||
int getPosX() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:60:11: note: Derived function 'MovingSprite::getPosX'
|
||||
float getPosX() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:61:11: warning: The class 'MovingSprite' defines member function with name 'getPosY' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
float getPosY() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:30:9: note: Parent function 'Sprite::getPosY'
|
||||
int getPosY() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:61:11: note: Derived function 'MovingSprite::getPosY'
|
||||
float getPosY() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:31:5: performance: Variable 'executable_path_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
executable_path_ = executable_path.substr(0, executable_path.find_last_of("\\/"));
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:13:2: performance: Variable 'sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
sprite_ = std::make_unique<AnimatedSprite>(texture, "", animation);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/bullet.cpp:23:5: performance: Variable 'sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
sprite_ = std::make_unique<Sprite>(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/define_buttons.h:49:5: style: Class 'DefineButtons' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
DefineButtons(std::unique_ptr<Text> text);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/fade.h:57:2: style: Class 'Fade' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Fade(SDL_Renderer *renderer);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/hiscore_table.h:73:2: style: Class 'HiScoreTable' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
HiScoreTable(JA_Music_t *music);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/instructions.h:83:2: style: Class 'Instructions' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Instructions(JA_Music_t *music);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/writer.h:30:2: style: Class 'Writer' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Writer(std::shared_ptr<Text> text);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/intro.h:55:2: style: Class 'Intro' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Intro(JA_Music_t *music);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.h:27:5: style: Class 'ManageHiScoreTable' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
ManageHiScoreTable(std::vector<HiScoreEntry> *table);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/title.h:98:2: style: Class 'Title' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Title(JA_Music_t *music);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:301:19: style: Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]
|
||||
flags = flags | SDL_RENDERER_PRESENTVSYNC;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:481:39: performance: Function parameter 'filepath' should be passed by const reference. [passedByValue]
|
||||
void Director::loadParams(std::string filepath)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:506:47: performance: Function parameter 'folder' should be passed by const reference. [passedByValue]
|
||||
void Director::createSystemFolder(std::string folder)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:572:12: performance: Range variable 'l' should be declared as const reference. [iterateByValue]
|
||||
for (auto l : list)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:590:12: performance: Range variable 'l' should be declared as const reference. [iterateByValue]
|
||||
for (auto l : list)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:487:54: style: Parameter 'argv' can be declared as const array [constParameter]
|
||||
void Director::checkProgramArguments(int argc, char *argv[])
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/enemy_formations.cpp:455:7: style: Variable 'incX' is assigned a value that is never used. [unreadVariable]
|
||||
incX = BALLOON_WIDTH_1 + 1;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.h:275:7: style: Unused private function: 'Game::decBalloonSpeed' [unusedPrivateFunction]
|
||||
void decBalloonSpeed();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.h:287:7: style: Unused private function: 'Game::popAllBalloons' [unusedPrivateFunction]
|
||||
void popAllBalloons();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.h:299:6: style: Unused private function: 'Game::countBalloons' [unusedPrivateFunction]
|
||||
int countBalloons();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2421:13: style: Condition 'i<STAGE_COUNTER' is always true [knownConditionTrueFalse]
|
||||
else if (i< STAGE_COUNTER)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2407:20: note: Assuming that condition 'i<STAGE_COUNTER' is not redundant
|
||||
for (int i = 0; i < STAGE_COUNTER; ++i)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2421:13: note: Condition 'i<STAGE_COUNTER' is always true
|
||||
else if (i< STAGE_COUNTER)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:180:13: style: Local variable 'player' shadows outer variable [shadowVariable]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:136:7: note: Shadowed declaration
|
||||
auto player = getPlayer(player_id);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:180:13: note: Shadow variable
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:247:9: style: Local variable 'player' shadows outer variable [shadowVariable]
|
||||
auto player = getPlayer(otherPlayer);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:136:7: note: Shadowed declaration
|
||||
auto player = getPlayer(player_id);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:247:9: note: Shadow variable
|
||||
auto player = getPlayer(otherPlayer);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:251:14: style: Local variable 'player' shadows outer variable [shadowVariable]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:136:7: note: Shadowed declaration
|
||||
auto player = getPlayer(player_id);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:251:14: note: Shadow variable
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:600:37: performance: Function parameter 'file_path' should be passed by const reference. [passedByValue]
|
||||
bool Game::loadDemoFile(std::string file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA])
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2687:45: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
void Game::addScoreToScoreBoard(std::string name, int score)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:180:13: style: Variable 'player' can be declared as reference to const [constVariableReference]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:764:13: style: Variable 'player' can be declared as reference to const [constVariableReference]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1171:13: style: Variable 'balloon' can be declared as reference to const [constVariableReference]
|
||||
for (auto &balloon : balloons_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1230:13: style: Variable 'balloon' can be declared as reference to const [constVariableReference]
|
||||
for (auto &balloon : balloons_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1680:13: style: Variable 'balloon' can be declared as reference to const [constVariableReference]
|
||||
for (auto &balloon : balloons_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2350:13: style: Variable 'balloon' can be declared as reference to const [constVariableReference]
|
||||
for (auto &balloon : balloons_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2451:14: style: Variable 'player' can be declared as reference to const [constVariableReference]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2467:13: style: Variable 'player' can be declared as reference to const [constVariableReference]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2479:13: style: Variable 'player' can be declared as reference to const [constVariableReference]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2491:13: style: Variable 'player' can be declared as reference to const [constVariableReference]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2663:13: style: Variable 'player' can be declared as reference to const [constVariableReference]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2732:13: style: Variable 'player' can be declared as reference to const [constVariableReference]
|
||||
for (auto &player : players_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1234:4: style: Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]
|
||||
num++;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1684:20: style: Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]
|
||||
menace_current_ += balloon->getMenace();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2354:10: style: Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]
|
||||
power += balloon->getPower();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2735:3: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]
|
||||
{
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:604:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable]
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:673:37: performance: Function parameter 'file_path' should be passed by const reference. [passedByValue]
|
||||
bool Game::saveDemoFile(std::string file_path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:676:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable]
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/game_logo.cpp:19:5: performance: Variable 'dust_texture_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
dust_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"));
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.h:94:2: style: Class 'Input' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Input(std::string game_controller_db_path);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:12:30: performance: Function parameter 'game_controller_db_path' should be passed by const reference. [passedByValue]
|
||||
void Input::init(std::string game_controller_db_path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:30:26: performance: Function parameter 'game_controller_db_path' should be passed by const reference. [passedByValue]
|
||||
Input::Input(std::string game_controller_db_path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:531:39: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
int Input::getIndexByName(std::string name) const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:575:42: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
InputType Input::to_inputs_e(std::string name) const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:441:32: style: Variable 'separator' is assigned a value that is never used. [unreadVariable]
|
||||
const std::string separator(" #");
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/intro.cpp:416:13: style: Variable 'text' can be declared as reference to const [constVariableReference]
|
||||
for (auto &text : texts_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/item.cpp:11:2: performance: Variable 'sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
sprite_ = std::make_unique<AnimatedSprite>(texture, "", animation);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/item.cpp:14:2: performance: Variable 'time_to_live_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
time_to_live_ = 600;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:89:26: style: C-style pointer casting [cstyleCast]
|
||||
char *name = (char *)malloc(nameSize + 1);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:53:38: performance: Function parameter 'a' should be passed by const reference. [passedByValue]
|
||||
bool operator()(HiScoreEntry a, HiScoreEntry b) const { return a.score > b.score; }
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:53:54: performance: Function parameter 'b' should be passed by const reference. [passedByValue]
|
||||
bool operator()(HiScoreEntry a, HiScoreEntry b) const { return a.score > b.score; }
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:60:51: performance: Function parameter 'file_path' should be passed by const reference. [passedByValue]
|
||||
bool ManageHiScoreTable::loadFromFile(std::string file_path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:116:49: performance: Function parameter 'file_path' should be passed by const reference. [passedByValue]
|
||||
bool ManageHiScoreTable::saveToFile(std::string file_path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:65:32: style: Variable 'filename' is assigned a value that is never used. [unreadVariable]
|
||||
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:119:32: style: Variable 'fileName' is assigned a value that is never used. [unreadVariable]
|
||||
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:32:2: performance: Variable 'flip_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
flip_ = SDL_FLIP_NONE;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:87:21: warning: The class 'MovingSprite' defines member function with name 'getPosX' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
float MovingSprite::getPosX() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:29:9: note: Parent function 'Sprite::getPosX'
|
||||
int getPosX() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:87:21: note: Derived function 'MovingSprite::getPosX'
|
||||
float MovingSprite::getPosX() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:93:21: warning: The class 'MovingSprite' defines member function with name 'getPosY' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
float MovingSprite::getPosY() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:30:9: note: Parent function 'Sprite::getPosY'
|
||||
int getPosY() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:93:21: note: Derived function 'MovingSprite::getPosY'
|
||||
float MovingSprite::getPosY() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/notify.cpp:17:5: performance: Variable 'bgColor' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
bgColor = param.notification.color;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/notify.cpp:13:120: performance: Function parameter 'soundFile' should be passed by const reference. [passedByValue]
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/options.cpp:243:29: performance: Function parameter 'var' should be passed by const reference. [passedByValue]
|
||||
bool setOptions(std::string var, std::string value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/options.cpp:243:46: performance: Function parameter 'value' should be passed by const reference. [passedByValue]
|
||||
bool setOptions(std::string var, std::string value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/options.cpp:89:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable]
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/options.cpp:153:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable]
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:155:28: performance: Function parameter 'var' should be passed by const reference. [passedByValue]
|
||||
bool setParams(std::string var, std::string value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:155:45: performance: Function parameter 'value' should be passed by const reference. [passedByValue]
|
||||
bool setParams(std::string var, std::string value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:101:48: warning: Either the condition 'pos<=(int)line.size()' is redundant or 'pos' can have the value line.size(). Expression 'line[pos]' cause access out of bounds. [containerOutOfBounds]
|
||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:101:16: note: Assuming that condition 'pos<=(int)line.size()' is not redundant
|
||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:101:48: note: Access out of bounds
|
||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:117:49: warning: Either the condition 'pos<=(int)line.size()' is redundant or 'pos' can have the value line.size(). Expression 'line[pos]' cause access out of bounds. [containerOutOfBounds]
|
||||
while (pos <= (int)line.size() && (int)line[pos] <= 32)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:117:17: note: Assuming that condition 'pos<=(int)line.size()' is not redundant
|
||||
while (pos <= (int)line.size() && (int)line[pos] <= 32)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:117:49: note: Access out of bounds
|
||||
while (pos <= (int)line.size() && (int)line[pos] <= 32)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:130:50: warning: Either the condition 'pos<=(int)line.size()' is redundant or 'pos' can have the value line.size(). Expression 'line[pos]' cause access out of bounds. [containerOutOfBounds]
|
||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:130:18: note: Assuming that condition 'pos<=(int)line.size()' is not redundant
|
||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:130:50: note: Access out of bounds
|
||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:84:11: performance: Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]
|
||||
line = line.substr(0, line.find("#"));
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:14:9: warning: Member variable 'Player::controller_index_' is not initialized in the constructor. [uninitMemberVar]
|
||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vector<std::shared_ptr<Texture>> texture, std::vector<std::vector<std::string> *> animations)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:17:2: performance: Variable 'player_sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
player_sprite_ = std::make_unique<AnimatedSprite>(texture[0], "", animations[0]);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:18:2: performance: Variable 'power_sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
power_sprite_ = std::make_unique<AnimatedSprite>(texture[1], "", animations[1]);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:241:22: style: The statement 'if (status_walking_!=status) status_walking_=status' is logically equivalent to 'status_walking_=status'. [duplicateConditionalAssign]
|
||||
if (status_walking_ != status)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:243:19: note: Assignment 'status_walking_=status'
|
||||
status_walking_ = status;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:241:22: note: Condition 'status_walking_!=status' is redundant
|
||||
if (status_walking_ != status)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:251:21: style: The statement 'if (status_firing_!=status) status_firing_=status' is logically equivalent to 'status_firing_=status'. [duplicateConditionalAssign]
|
||||
if (status_firing_ != status)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:253:18: note: Assignment 'status_firing_=status'
|
||||
status_firing_ = status;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:251:21: note: Condition 'status_firing_!=status' is redundant
|
||||
if (status_firing_ != status)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:697:70: performance: Function parameter 'texture' should be passed by const reference. [passedByValue]
|
||||
void Player::setPlayerTextures(std::vector<std::shared_ptr<Texture>> texture)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:747:34: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
void Player::setName(std::string name)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:753:40: performance: Function parameter 'record_name' should be passed by const reference. [passedByValue]
|
||||
void Player::setRecordName(std::string record_name)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:40:2: performance: Variable 'game_power_meter_texture_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
game_power_meter_texture_ = nullptr;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:41:2: performance: Variable 'power_meter_sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
power_meter_sprite_ = nullptr;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:42:2: performance: Variable 'text_scoreboard_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
text_scoreboard_ = nullptr;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.h:106:2: style: Class 'Scoreboard' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Scoreboard(SDL_Renderer *renderer);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:326:13: style: Local variable 'rect_' shadows outer variable [shadowVariable]
|
||||
SDL_Rect rect_ = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.h:71:11: note: Shadowed declaration
|
||||
SDL_Rect rect_; // Posición y dimensiones del marcador
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:326:13: note: Shadow variable
|
||||
SDL_Rect rect_ = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:133:50: performance: Function parameter 'name_' should be passed by const reference. [passedByValue]
|
||||
void Scoreboard::setName(int panel_, std::string name_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:139:56: performance: Function parameter 'record_name_' should be passed by const reference. [passedByValue]
|
||||
void Scoreboard::setRecordName(int panel_, std::string record_name_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:187:45: performance: Function parameter 'name_' should be passed by const reference. [passedByValue]
|
||||
void Scoreboard::setHiScoreName(std::string name_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:50:5: performance: Variable 'src_rect_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
src_rect_ = {0, 0, param.game.width, param.game.height};
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:51:5: performance: Variable 'dst_rect_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
dst_rect_ = {0, 0, param.game.width, param.game.height};
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:52:5: performance: Variable 'border_color_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
border_color_ = {0, 0, 0};
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:66:5: performance: Variable 'fps_ticks_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
fps_ticks_ = 0;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:458:43: performance: Function parameter 'text1' should be passed by const reference. [passedByValue]
|
||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:458:62: performance: Function parameter 'text2' should be passed by const reference. [passedByValue]
|
||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:188:24: style: Variable 'options.video.mode' is reassigned a value before the old one has been used. [redundantAssignment]
|
||||
options.video.mode = ScreenVideoMode::WINDOW;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:186:24: note: options.video.mode is assigned
|
||||
options.video.mode = videoMode;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:188:24: note: options.video.mode is overwritten
|
||||
options.video.mode = ScreenVideoMode::WINDOW;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:82:49: performance: Function parameter 'text_file' should be passed by const reference. [passedByValue]
|
||||
Text::Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:106:24: performance: Function parameter 'text_file' should be passed by const reference. [passedByValue]
|
||||
Text::Text(std::string text_file, std::shared_ptr<Texture> texture)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:149:44: performance: Function parameter 'text' should be passed by const reference. [passedByValue]
|
||||
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:172:51: performance: Function parameter 'text' should be passed by const reference. [passedByValue]
|
||||
void Text::writeColored(int x, int y, std::string text, Color color, int kerning, int lenght)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:180:52: performance: Function parameter 'text' should be passed by const reference. [passedByValue]
|
||||
void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shadow_distance, int kerning, int lenght)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:189:52: performance: Function parameter 'text' should be passed by const reference. [passedByValue]
|
||||
void Text::writeCentered(int x, int y, std::string text, int kerning, int lenght)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:196:59: performance: Function parameter 'text' should be passed by const reference. [passedByValue]
|
||||
void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:238:30: performance: Function parameter 'text' should be passed by const reference. [passedByValue]
|
||||
int Text::lenght(std::string text, int kerning) const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:270:35: performance: Function parameter 'path' should be passed by const reference. [passedByValue]
|
||||
void Text::addPalette(std::string path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:24:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable]
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1).c_str();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.h:36:13: style: Unused private function: 'Texture::newSurface' [unusedPrivateFunction]
|
||||
Surface newSurface(int w, int h);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:79:17: style: Condition 'req_format==STBI_rgb' is always false [knownConditionTrueFalse]
|
||||
if (req_format == STBI_rgb)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:60:19: note: Assignment 'req_format=STBI_rgb_alpha', assigned value is 4
|
||||
int req_format = STBI_rgb_alpha;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:79:17: note: Condition 'req_format==STBI_rgb' is always false
|
||||
if (req_format == STBI_rgb)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:99:66: style: C-style pointer casting [cstyleCast]
|
||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:244:18: style: C-style pointer casting [cstyleCast]
|
||||
Surface surf = (Surface)malloc(sizeof(surface_s));
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:247:15: style: C-style pointer casting [cstyleCast]
|
||||
surf->data = (Uint8 *)malloc(w * h);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:279:18: style: C-style pointer casting [cstyleCast]
|
||||
Uint8 *buffer = (Uint8 *)malloc(size);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:290:21: style: C-style pointer casting [cstyleCast]
|
||||
Surface surface = (Surface)malloc(sizeof(surface_s));
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:315:37: style: C-style pointer casting [cstyleCast]
|
||||
SDL_LockTexture(texture_, nullptr, (void **)&pixels, &pitch);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:343:18: style: C-style pointer casting [cstyleCast]
|
||||
Uint8 *buffer = (Uint8 *)malloc(size);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:14:54: performance: Function parameter 'path' should be passed by const reference. [passedByValue]
|
||||
Texture::Texture(SDL_Renderer *renderer, std::string path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:57:40: performance: Function parameter 'path' should be passed by const reference. [passedByValue]
|
||||
bool Texture::loadFromFile(std::string path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:364:38: performance: Function parameter 'path' should be passed by const reference. [passedByValue]
|
||||
void Texture::addPalette(std::string path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:41:4: performance: Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]
|
||||
addPalette(path_.c_str());
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:59:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable]
|
||||
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/title.cpp:318:12: style: Local variable 'num_controllers_' shadows outer variable [shadowVariable]
|
||||
const int num_controllers_ = input_->getNumControllers();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/title.h:70:6: note: Shadowed declaration
|
||||
int num_controllers_; // Número de mandos conectados
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/title.cpp:318:12: note: Shadow variable
|
||||
const int num_controllers_ = input_->getNumControllers();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:187:19: style: C-style pointer casting [cstyleCast]
|
||||
char *lower = (char *)malloc(str.size() + 1);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:166:31: performance: Function parameter 'str' should be passed by const reference. [passedByValue]
|
||||
bool stringToBool(std::string str)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:184:33: performance: Function parameter 'str' should be passed by const reference. [passedByValue]
|
||||
std::string toLower(std::string str)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:200:45: performance: Function parameter 'sounds' should be passed by const reference. [passedByValue]
|
||||
JA_Sound_t *getSound(std::vector<SoundFile> sounds, std::string name)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:200:65: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
JA_Sound_t *getSound(std::vector<SoundFile> sounds, std::string name)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:202:15: performance: Range variable 's' should be declared as const reference. [iterateByValue]
|
||||
for (auto s : sounds)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:214:45: performance: Function parameter 'music' should be passed by const reference. [passedByValue]
|
||||
JA_Music_t *getMusic(std::vector<MusicFile> music, std::string name)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:214:64: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
JA_Music_t *getMusic(std::vector<MusicFile> music, std::string name)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:216:15: performance: Range variable 'm' should be declared as const reference. [iterateByValue]
|
||||
for (auto m : music)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:228:44: performance: Function parameter 'entry1' should be passed by const reference. [passedByValue]
|
||||
HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:228:65: performance: Function parameter 'entry2' should be passed by const reference. [passedByValue]
|
||||
HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:32:29: style: Parameter 'a' can be declared as reference to const [constParameterReference]
|
||||
bool checkCollision(Circle &a, Circle &b)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:32:40: style: Parameter 'b' can be declared as reference to const [constParameterReference]
|
||||
bool checkCollision(Circle &a, Circle &b)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:50:29: style: Parameter 'a' can be declared as reference to const [constParameterReference]
|
||||
bool checkCollision(Circle &a, SDL_Rect &b)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:50:42: style: Parameter 'b' can be declared as reference to const [constParameterReference]
|
||||
bool checkCollision(Circle &a, SDL_Rect &b)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:95:31: style: Parameter 'a' can be declared as reference to const [constParameterReference]
|
||||
bool checkCollision(SDL_Rect &a, SDL_Rect &b)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:95:44: style: Parameter 'b' can be declared as reference to const [constParameterReference]
|
||||
bool checkCollision(SDL_Rect &a, SDL_Rect &b)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:135:32: style: Parameter 'p' can be declared as reference to const [constParameterReference]
|
||||
bool checkCollision(SDL_Point &p, SDL_Rect &r)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:135:45: style: Parameter 'r' can be declared as reference to const [constParameterReference]
|
||||
bool checkCollision(SDL_Point &p, SDL_Rect &r)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:205:9: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]
|
||||
{
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:219:9: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]
|
||||
{
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/writer.cpp:11:2: performance: Variable 'caption_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
caption_ = "";
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/writer.cpp:81:37: performance: Function parameter 'text' should be passed by const reference. [passedByValue]
|
||||
void Writer::setCaption(std::string text)
|
||||
^
|
||||
nofile:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 configurations. Use --force to check all configurations. For more details, use --enable=information. [toomanyconfigs]
|
||||
|
||||
@@ -4,7 +4,7 @@ SOURCEPATH=../source/
|
||||
|
||||
for i in "$SOURCEPATH"/*.cpp
|
||||
do
|
||||
include-what-you-use -D DEBUG -D VERBOSE -std=c++14 -Wall "$i"
|
||||
include-what-you-use -D DEBUG -D VERBOSE -std=c++20 -Wall "$i"
|
||||
read -p "Presiona cualquier tecla para continuar..."
|
||||
clear
|
||||
done
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "animated_sprite.h"
|
||||
#include <algorithm> // for copy
|
||||
#include <fstream> // for basic_ostream, operator<<, basic_istream, basic...
|
||||
#include <iostream> // for cout
|
||||
#include <iterator> // for back_insert_iterator, back_inserter
|
||||
#include <sstream> // for basic_stringstream
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
@@ -37,7 +39,7 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
|
||||
buffer.counter = 0;
|
||||
buffer.current_frame = 0;
|
||||
buffer.completed = false;
|
||||
buffer.name = "";
|
||||
buffer.name.clear();
|
||||
buffer.speed = 5;
|
||||
buffer.loop = 0;
|
||||
buffer.frames.clear();
|
||||
@@ -159,18 +161,15 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file, std::vector<std::string> *buffer)
|
||||
: MovingSprite(texture)
|
||||
: MovingSprite(texture),
|
||||
current_animation_(0)
|
||||
{
|
||||
// Carga las animaciones
|
||||
if (file != "")
|
||||
if (!file.empty())
|
||||
{
|
||||
AnimatedFile as = loadAnimationFromFile(texture, file);
|
||||
|
||||
// Copia los datos de las animaciones
|
||||
/*for (auto animation : as.animations)
|
||||
{
|
||||
animations_.push_back(animation);
|
||||
}*/
|
||||
std::copy(as.animations.begin(), as.animations.end(), std::back_inserter(animations_));
|
||||
}
|
||||
|
||||
@@ -178,18 +177,13 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::stri
|
||||
{
|
||||
loadFromVector(buffer);
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
current_animation_ = 0;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(const AnimatedFile *animation)
|
||||
: MovingSprite(animation->texture)
|
||||
: MovingSprite(animation->texture),
|
||||
current_animation_(0)
|
||||
{
|
||||
// Inicializa variables
|
||||
current_animation_ = 0;
|
||||
|
||||
// Copia los datos de las animaciones
|
||||
std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_));
|
||||
}
|
||||
@@ -366,7 +360,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
buffer.counter = 0;
|
||||
buffer.current_frame = 0;
|
||||
buffer.completed = false;
|
||||
buffer.name = "";
|
||||
buffer.name.clear();
|
||||
buffer.speed = 5;
|
||||
buffer.loop = 0;
|
||||
buffer.frames.clear();
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string, basic_string
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "moving_sprite.h" // for MovingSprite
|
||||
#include "texture.h"
|
||||
#include <memory>
|
||||
class Texture;
|
||||
|
||||
struct Animation
|
||||
{
|
||||
@@ -37,11 +37,11 @@ protected:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = "", std::vector<std::string> *buffer = nullptr);
|
||||
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = std::string(), std::vector<std::string> *buffer = nullptr);
|
||||
explicit AnimatedSprite(const AnimatedFile *animation);
|
||||
|
||||
// Destructor
|
||||
~AnimatedSprite();
|
||||
virtual ~AnimatedSprite();
|
||||
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "background.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <algorithm> // for max, min
|
||||
#include <string> // for basic_string
|
||||
#include "asset.h" // for Asset
|
||||
#include "param.h" // for param
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <algorithm> // for clamp, max
|
||||
#include "asset.h" // for Asset
|
||||
#include "moving_sprite.h" // for MovingSprite
|
||||
#include "param.h" // for param
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Background::Background(SDL_Renderer *renderer)
|
||||
@@ -103,18 +105,19 @@ void Background::update()
|
||||
// Incrementa el contador
|
||||
counter_++;
|
||||
|
||||
// Compone todos los elementos del fondo en la textura
|
||||
fillCanvas();
|
||||
}
|
||||
|
||||
// Dibuja el gradiente de fondo
|
||||
void Background::renderGradient()
|
||||
{
|
||||
// Dibuja el gradiente 2
|
||||
// Dibuja el gradiente de detras
|
||||
gradients_texture_->setAlpha(255);
|
||||
gradient_sprite_->setSpriteClip(gradient_rect_[(gradient_number_ + 1) % 4]);
|
||||
gradient_sprite_->render();
|
||||
|
||||
// Dibuja el gradiente 1 con una opacidad cada vez menor
|
||||
// Dibuja el gradiente de delante con una opacidad cada vez menor
|
||||
gradients_texture_->setAlpha(alpha_);
|
||||
gradient_sprite_->setSpriteClip(gradient_rect_[gradient_number_]);
|
||||
gradient_sprite_->render();
|
||||
@@ -123,36 +126,36 @@ void Background::renderGradient()
|
||||
// Dibuja las nubes de arriba
|
||||
void Background::renderTopClouds()
|
||||
{
|
||||
// Dibuja el primer conjunto de nubes
|
||||
// Dibuja el primer conjunto de nubes, las de detras
|
||||
top_clouds_texture_->setAlpha(255);
|
||||
top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||
top_clouds_sprite_a_->render();
|
||||
top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||
top_clouds_sprite_a_->render();
|
||||
top_clouds_sprite_b_->render();
|
||||
|
||||
// Dibuja el segundo conjunto de nubes
|
||||
// Dibuja el segundo conjunto de nubes, las de delante
|
||||
top_clouds_texture_->setAlpha(alpha_);
|
||||
top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[gradient_number_]);
|
||||
top_clouds_sprite_a_->render();
|
||||
top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[gradient_number_]);
|
||||
top_clouds_sprite_a_->render();
|
||||
top_clouds_sprite_b_->render();
|
||||
}
|
||||
|
||||
// Dibuja las nubes de abajo
|
||||
void Background::renderBottomClouds()
|
||||
{
|
||||
// Dibuja el primer conjunto de nubes
|
||||
// Dibuja el primer conjunto de nubes, las de detras
|
||||
bottom_clouds_texture_->setAlpha(255);
|
||||
bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||
bottom_clouds_sprite_a_->render();
|
||||
bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||
bottom_clouds_sprite_a_->render();
|
||||
bottom_clouds_sprite_b_->render();
|
||||
|
||||
// Dibuja el segundo conjunto de nubes
|
||||
// Dibuja el segundo conjunto de nubes, las de delante
|
||||
bottom_clouds_texture_->setAlpha(alpha_);
|
||||
bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[gradient_number_]);
|
||||
bottom_clouds_sprite_a_->render();
|
||||
bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[gradient_number_]);
|
||||
bottom_clouds_sprite_a_->render();
|
||||
bottom_clouds_sprite_b_->render();
|
||||
}
|
||||
|
||||
@@ -217,9 +220,7 @@ void Background::setGradientNumber(int value)
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setTransition(float value)
|
||||
{
|
||||
value = std::min(value, 1.0f);
|
||||
value = std::max(value, 0.0f);
|
||||
transition_ = value;
|
||||
transition_ = std::clamp(value, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
@@ -265,13 +266,10 @@ void Background::setColor(Color color)
|
||||
void Background::setAlpha(int alpha)
|
||||
{
|
||||
// Evita que se asignen valores fuera de rango
|
||||
alpha_ = std::min(alpha, 255);
|
||||
alpha_ = std::max(alpha, 0);
|
||||
alpha_ = std::clamp(alpha, 0, 255);
|
||||
|
||||
// Guarda el valor actual
|
||||
// Guarda el valor actual y establece el nuevo valor
|
||||
alpha_color_text_temp_ = alpha_color_text_;
|
||||
|
||||
// Establece el nuevo valor
|
||||
alpha_color_text_ = alpha_;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include "utils.h" // for Color
|
||||
#include "moving_sprite.h"
|
||||
#include "sprite.h"
|
||||
#include "texture.h"
|
||||
#include <memory>
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
#include "utils.h" // for Color
|
||||
class MovingSprite;
|
||||
class Sprite;
|
||||
class Texture;
|
||||
|
||||
/*
|
||||
Esta clase es la encargada de dibujar el fondo que aparece durante la sección
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "balloon.h"
|
||||
#include <math.h> // for abs
|
||||
#include <cmath> // for abs
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "moving_sprite.h" // for MovingSprite
|
||||
#include "param.h" // for param
|
||||
@@ -12,12 +12,20 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
pos_x_(x),
|
||||
pos_y_(y),
|
||||
vel_x_(vel_x),
|
||||
being_created_(creation_timer > 0),
|
||||
blinking_(false),
|
||||
enabled_(true),
|
||||
invulnerable_(creation_timer > 0),
|
||||
stopped_(true),
|
||||
visible_(true),
|
||||
creation_counter_(creation_timer),
|
||||
creation_counter_ini_(creation_timer),
|
||||
stopped_counter_(0),
|
||||
kind_(kind),
|
||||
counter_(0),
|
||||
travel_y_(1.0f),
|
||||
speed_(speed)
|
||||
{
|
||||
enabled_ = true;
|
||||
|
||||
switch (kind_)
|
||||
{
|
||||
@@ -243,21 +251,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
updateColliders();
|
||||
|
||||
// Inicializa variables
|
||||
stopped_ = true;
|
||||
stopped_counter_ = 0;
|
||||
blinking_ = false;
|
||||
visible_ = true;
|
||||
invulnerable_ = true;
|
||||
being_created_ = true;
|
||||
|
||||
// Actualiza valores
|
||||
being_created_ = creation_counter_ == 0 ? false : true;
|
||||
invulnerable_ = being_created_ == false ? false : true;
|
||||
|
||||
counter_ = 0;
|
||||
travel_y_ = 1.0f;
|
||||
}
|
||||
|
||||
// Centra el globo en la posición X
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
#include "utils.h" // for Circle
|
||||
#include "animated_sprite.h"
|
||||
#include "texture.h"
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "utils.h" // for Circle
|
||||
class Texture;
|
||||
|
||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||
constexpr int MAX_BOUNCE = 10;
|
||||
|
||||
718
source/balloon_formations.cpp
Normal file
718
source/balloon_formations.cpp
Normal file
@@ -0,0 +1,718 @@
|
||||
#include "balloon_formations.h"
|
||||
#include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE
|
||||
#include "param.h" // for param
|
||||
#include "utils.h" // for ParamGame, Param, Zone, BLOCK
|
||||
|
||||
// Constructor
|
||||
BalloonFormations::BalloonFormations()
|
||||
{
|
||||
initBalloonFormations();
|
||||
initBalloonFormationPools();
|
||||
initGameStages();
|
||||
}
|
||||
|
||||
// Inicializa las formaciones enemigas
|
||||
void BalloonFormations::initBalloonFormations()
|
||||
{
|
||||
constexpr int y4 = -BLOCK;
|
||||
const int x4_0 = param.game.play_area.rect.x;
|
||||
const int x4_100 = param.game.play_area.rect.w - BALLOON_WIDTH_4;
|
||||
|
||||
constexpr int y3 = -BLOCK;
|
||||
const int x3_0 = param.game.play_area.rect.x;
|
||||
const int x3_100 = param.game.play_area.rect.w - BALLOON_WIDTH_3;
|
||||
|
||||
constexpr int y2 = -BLOCK;
|
||||
const int x2_0 = param.game.play_area.rect.x;
|
||||
const int x2_100 = param.game.play_area.rect.w - BALLOON_WIDTH_2;
|
||||
|
||||
constexpr int y1 = -BLOCK;
|
||||
const int x1_0 = param.game.play_area.rect.x;
|
||||
const int x1_50 = param.game.play_area.center_x - (BALLOON_WIDTH_1 / 2);
|
||||
const int x1_100 = param.game.play_area.rect.w - BALLOON_WIDTH_1;
|
||||
|
||||
// Inicializa a cero las variables
|
||||
for (int i = 0; i < NUMBER_OF_BALLOON_FORMATIONS; i++)
|
||||
{
|
||||
balloon_formation_[i].number_of_balloons = 0;
|
||||
for (int j = 0; j < MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION; j++)
|
||||
{
|
||||
balloon_formation_[i].init[j].x = 0;
|
||||
balloon_formation_[i].init[j].y = 0;
|
||||
balloon_formation_[i].init[j].vel_x = 0;
|
||||
balloon_formation_[i].init[j].kind = 0;
|
||||
balloon_formation_[i].init[j].creation_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const int creation_time = 300;
|
||||
int inc_x = 0;
|
||||
int inc_time = 0;
|
||||
int j = 0;
|
||||
|
||||
// #00 - Dos enemigos BALLOON4 uno a cada extremo
|
||||
j = 0;
|
||||
balloon_formation_[j].number_of_balloons = 2;
|
||||
inc_x = x4_100;
|
||||
inc_time = 0;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x4_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y4;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
||||
}
|
||||
|
||||
// #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro
|
||||
j = 1;
|
||||
balloon_formation_[j].number_of_balloons = 2;
|
||||
inc_x = param.game.play_area.center_x;
|
||||
inc_time = 0;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = param.game.play_area.first_quarter_x - (BALLOON_WIDTH_4 / 2) + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y4;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
||||
}
|
||||
|
||||
// #02 - Cuatro enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
||||
j = 2;
|
||||
balloon_formation_[j].number_of_balloons = 4;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y2;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #03 - Cuatro enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
||||
j = 3;
|
||||
balloon_formation_[j].number_of_balloons = 4;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x2_100 - (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y2;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha
|
||||
j = 4;
|
||||
balloon_formation_[j].number_of_balloons = 3;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda
|
||||
j = 5;
|
||||
balloon_formation_[j].number_of_balloons = 3;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha
|
||||
j = 6;
|
||||
balloon_formation_[j].number_of_balloons = 3;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda
|
||||
j = 7;
|
||||
balloon_formation_[j].number_of_balloons = 3;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha
|
||||
j = 8;
|
||||
balloon_formation_[j].number_of_balloons = 6;
|
||||
inc_x = BALLOON_WIDTH_1 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x1_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y1;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda
|
||||
j = 9;
|
||||
balloon_formation_[j].number_of_balloons = 6;
|
||||
inc_x = BALLOON_WIDTH_1 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x1_100 - (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y1;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #10 - Tres enemigos BALLOON4 seguidos desde la izquierda
|
||||
j = 10;
|
||||
balloon_formation_[j].number_of_balloons = 3;
|
||||
inc_x = BALLOON_WIDTH_4 + 1;
|
||||
inc_time = 15;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x4_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y4;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #11 - Tres enemigos BALLOON4 seguidos desde la derecha
|
||||
j = 11;
|
||||
balloon_formation_[j].number_of_balloons = 3;
|
||||
inc_x = BALLOON_WIDTH_4 + 1;
|
||||
inc_time = 15;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x4_100 - (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y4;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #12 - Seis enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
||||
j = 12;
|
||||
balloon_formation_[j].number_of_balloons = 6;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y2;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #13 - Seis enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
||||
j = 13;
|
||||
balloon_formation_[j].number_of_balloons = 6;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x2_100 - (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y2;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados
|
||||
j = 14;
|
||||
balloon_formation_[j].number_of_balloons = 5;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados
|
||||
j = 15;
|
||||
balloon_formation_[j].number_of_balloons = 5;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos
|
||||
j = 16;
|
||||
balloon_formation_[j].number_of_balloons = 5;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos
|
||||
j = 17;
|
||||
balloon_formation_[j].number_of_balloons = 5;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos
|
||||
j = 18;
|
||||
balloon_formation_[j].number_of_balloons = 12;
|
||||
inc_x = BALLOON_WIDTH_1 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x1_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y1;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos
|
||||
j = 19;
|
||||
balloon_formation_[j].number_of_balloons = 12;
|
||||
inc_x = BALLOON_WIDTH_1 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x1_100 - (i * inc_x);
|
||||
balloon_formation_[j].init[i].y = y1;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos
|
||||
j = 20;
|
||||
balloon_formation_[j].number_of_balloons = 4;
|
||||
inc_x = BALLOON_WIDTH_4 + 1;
|
||||
inc_time = 0;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||
if (i < half)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x4_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x4_100 - ((i - half) * inc_x);
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
}
|
||||
balloon_formation_[j].init[i].y = y4;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||
balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
||||
}
|
||||
|
||||
// #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos
|
||||
j = 21;
|
||||
balloon_formation_[j].number_of_balloons = 10;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 3;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||
if (i < half)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x2_100 - ((i - half) * inc_x);
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||
}
|
||||
balloon_formation_[j].init[i].y = y2;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||
}
|
||||
|
||||
// #22 - Diez enemigos BALLOON3. Hacia la derecha/izquierda. Separados. Simetricos
|
||||
j = 22;
|
||||
balloon_formation_[j].number_of_balloons = 10;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||
if (i < half)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||
}
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
}
|
||||
|
||||
// #23 - Diez enemigos BALLOON3. Hacia la derecha. Juntos. Simetricos
|
||||
j = 23;
|
||||
balloon_formation_[j].number_of_balloons = 10;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||
if (i < half)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||
}
|
||||
balloon_formation_[j].init[i].y = y3;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||
}
|
||||
|
||||
// #24 - Treinta enemigos BALLOON1. Del centro hacia los extremos. Juntos. Simetricos
|
||||
j = 24;
|
||||
balloon_formation_[j].number_of_balloons = 30;
|
||||
inc_time = 5;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||
if (i < half)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x1_50;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x1_50;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * (i - half));
|
||||
}
|
||||
balloon_formation_[j].init[i].y = y1;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||
}
|
||||
|
||||
// #25 - Treinta enemigos BALLOON1. Del centro hacia adentro. Juntos. Simetricos
|
||||
j = 25;
|
||||
balloon_formation_[j].number_of_balloons = 30;
|
||||
inc_time = 5;
|
||||
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||
{
|
||||
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||
if (i < half)
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x1_50 + 20;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
balloon_formation_[j].init[i].x = x1_50 - 20;
|
||||
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||
}
|
||||
balloon_formation_[j].init[i].y = y1;
|
||||
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||
}
|
||||
|
||||
// Crea las mismas formaciones pero con hexagonos a partir de la posición 50 del vector
|
||||
for (int k = 0; k < j + 1; k++)
|
||||
{
|
||||
balloon_formation_[k + 50].number_of_balloons = balloon_formation_[k].number_of_balloons;
|
||||
for (int i = 0; i < balloon_formation_[k + 50].number_of_balloons; i++)
|
||||
{
|
||||
balloon_formation_[k + 50].init[i].x = balloon_formation_[k].init[i].x;
|
||||
balloon_formation_[k + 50].init[i].y = balloon_formation_[k].init[i].y;
|
||||
balloon_formation_[k + 50].init[i].vel_x = balloon_formation_[k].init[i].vel_x;
|
||||
balloon_formation_[k + 50].init[i].creation_counter = balloon_formation_[k].init[i].creation_counter;
|
||||
balloon_formation_[k + 50].init[i].kind = balloon_formation_[k].init[i].kind + 4;
|
||||
}
|
||||
}
|
||||
|
||||
// TEST
|
||||
balloon_formation_[99].number_of_balloons = 4;
|
||||
|
||||
balloon_formation_[99].init[0].x = 10;
|
||||
balloon_formation_[99].init[0].y = y1;
|
||||
balloon_formation_[99].init[0].vel_x = 0;
|
||||
balloon_formation_[99].init[0].kind = BALLOON_1;
|
||||
balloon_formation_[99].init[0].creation_counter = 200;
|
||||
|
||||
balloon_formation_[99].init[1].x = 50;
|
||||
balloon_formation_[99].init[1].y = y1;
|
||||
balloon_formation_[99].init[1].vel_x = 0;
|
||||
balloon_formation_[99].init[1].kind = BALLOON_2;
|
||||
balloon_formation_[99].init[1].creation_counter = 200;
|
||||
|
||||
balloon_formation_[99].init[2].x = 90;
|
||||
balloon_formation_[99].init[2].y = y1;
|
||||
balloon_formation_[99].init[2].vel_x = 0;
|
||||
balloon_formation_[99].init[2].kind = BALLOON_3;
|
||||
balloon_formation_[99].init[2].creation_counter = 200;
|
||||
|
||||
balloon_formation_[99].init[3].x = 140;
|
||||
balloon_formation_[99].init[3].y = y1;
|
||||
balloon_formation_[99].init[3].vel_x = 0;
|
||||
balloon_formation_[99].init[3].kind = BALLOON_4;
|
||||
balloon_formation_[99].init[3].creation_counter = 200;
|
||||
}
|
||||
|
||||
// Inicializa los conjuntos de formaciones
|
||||
void BalloonFormations::initBalloonFormationPools()
|
||||
{
|
||||
// EnemyPool #0
|
||||
balloon_formation_pool_[0].set[0] = &balloon_formation_[0];
|
||||
balloon_formation_pool_[0].set[1] = &balloon_formation_[1];
|
||||
balloon_formation_pool_[0].set[2] = &balloon_formation_[2];
|
||||
balloon_formation_pool_[0].set[3] = &balloon_formation_[3];
|
||||
balloon_formation_pool_[0].set[4] = &balloon_formation_[4];
|
||||
balloon_formation_pool_[0].set[5] = &balloon_formation_[5];
|
||||
balloon_formation_pool_[0].set[6] = &balloon_formation_[6];
|
||||
balloon_formation_pool_[0].set[7] = &balloon_formation_[7];
|
||||
balloon_formation_pool_[0].set[8] = &balloon_formation_[8];
|
||||
balloon_formation_pool_[0].set[9] = &balloon_formation_[9];
|
||||
|
||||
// EnemyPool #1
|
||||
balloon_formation_pool_[1].set[0] = &balloon_formation_[10];
|
||||
balloon_formation_pool_[1].set[1] = &balloon_formation_[11];
|
||||
balloon_formation_pool_[1].set[2] = &balloon_formation_[12];
|
||||
balloon_formation_pool_[1].set[3] = &balloon_formation_[13];
|
||||
balloon_formation_pool_[1].set[4] = &balloon_formation_[14];
|
||||
balloon_formation_pool_[1].set[5] = &balloon_formation_[15];
|
||||
balloon_formation_pool_[1].set[6] = &balloon_formation_[16];
|
||||
balloon_formation_pool_[1].set[7] = &balloon_formation_[17];
|
||||
balloon_formation_pool_[1].set[8] = &balloon_formation_[18];
|
||||
balloon_formation_pool_[1].set[9] = &balloon_formation_[19];
|
||||
|
||||
// EnemyPool #2
|
||||
balloon_formation_pool_[2].set[0] = &balloon_formation_[0];
|
||||
balloon_formation_pool_[2].set[1] = &balloon_formation_[1];
|
||||
balloon_formation_pool_[2].set[2] = &balloon_formation_[2];
|
||||
balloon_formation_pool_[2].set[3] = &balloon_formation_[3];
|
||||
balloon_formation_pool_[2].set[4] = &balloon_formation_[4];
|
||||
balloon_formation_pool_[2].set[5] = &balloon_formation_[55];
|
||||
balloon_formation_pool_[2].set[6] = &balloon_formation_[56];
|
||||
balloon_formation_pool_[2].set[7] = &balloon_formation_[57];
|
||||
balloon_formation_pool_[2].set[8] = &balloon_formation_[58];
|
||||
balloon_formation_pool_[2].set[9] = &balloon_formation_[59];
|
||||
|
||||
// EnemyPool #3
|
||||
balloon_formation_pool_[3].set[0] = &balloon_formation_[50];
|
||||
balloon_formation_pool_[3].set[1] = &balloon_formation_[51];
|
||||
balloon_formation_pool_[3].set[2] = &balloon_formation_[52];
|
||||
balloon_formation_pool_[3].set[3] = &balloon_formation_[53];
|
||||
balloon_formation_pool_[3].set[4] = &balloon_formation_[54];
|
||||
balloon_formation_pool_[3].set[5] = &balloon_formation_[5];
|
||||
balloon_formation_pool_[3].set[6] = &balloon_formation_[6];
|
||||
balloon_formation_pool_[3].set[7] = &balloon_formation_[7];
|
||||
balloon_formation_pool_[3].set[8] = &balloon_formation_[8];
|
||||
balloon_formation_pool_[3].set[9] = &balloon_formation_[9];
|
||||
|
||||
// EnemyPool #4
|
||||
balloon_formation_pool_[4].set[0] = &balloon_formation_[60];
|
||||
balloon_formation_pool_[4].set[1] = &balloon_formation_[61];
|
||||
balloon_formation_pool_[4].set[2] = &balloon_formation_[62];
|
||||
balloon_formation_pool_[4].set[3] = &balloon_formation_[63];
|
||||
balloon_formation_pool_[4].set[4] = &balloon_formation_[64];
|
||||
balloon_formation_pool_[4].set[5] = &balloon_formation_[65];
|
||||
balloon_formation_pool_[4].set[6] = &balloon_formation_[66];
|
||||
balloon_formation_pool_[4].set[7] = &balloon_formation_[67];
|
||||
balloon_formation_pool_[4].set[8] = &balloon_formation_[68];
|
||||
balloon_formation_pool_[4].set[9] = &balloon_formation_[69];
|
||||
|
||||
// EnemyPool #5
|
||||
balloon_formation_pool_[5].set[0] = &balloon_formation_[10];
|
||||
balloon_formation_pool_[5].set[1] = &balloon_formation_[61];
|
||||
balloon_formation_pool_[5].set[2] = &balloon_formation_[12];
|
||||
balloon_formation_pool_[5].set[3] = &balloon_formation_[63];
|
||||
balloon_formation_pool_[5].set[4] = &balloon_formation_[14];
|
||||
balloon_formation_pool_[5].set[5] = &balloon_formation_[65];
|
||||
balloon_formation_pool_[5].set[6] = &balloon_formation_[16];
|
||||
balloon_formation_pool_[5].set[7] = &balloon_formation_[67];
|
||||
balloon_formation_pool_[5].set[8] = &balloon_formation_[18];
|
||||
balloon_formation_pool_[5].set[9] = &balloon_formation_[69];
|
||||
|
||||
// EnemyPool #6
|
||||
balloon_formation_pool_[6].set[0] = &balloon_formation_[60];
|
||||
balloon_formation_pool_[6].set[1] = &balloon_formation_[11];
|
||||
balloon_formation_pool_[6].set[2] = &balloon_formation_[62];
|
||||
balloon_formation_pool_[6].set[3] = &balloon_formation_[13];
|
||||
balloon_formation_pool_[6].set[4] = &balloon_formation_[64];
|
||||
balloon_formation_pool_[6].set[5] = &balloon_formation_[15];
|
||||
balloon_formation_pool_[6].set[6] = &balloon_formation_[66];
|
||||
balloon_formation_pool_[6].set[7] = &balloon_formation_[17];
|
||||
balloon_formation_pool_[6].set[8] = &balloon_formation_[68];
|
||||
balloon_formation_pool_[6].set[9] = &balloon_formation_[19];
|
||||
|
||||
// EnemyPool #7
|
||||
balloon_formation_pool_[7].set[0] = &balloon_formation_[20];
|
||||
balloon_formation_pool_[7].set[1] = &balloon_formation_[21];
|
||||
balloon_formation_pool_[7].set[2] = &balloon_formation_[22];
|
||||
balloon_formation_pool_[7].set[3] = &balloon_formation_[23];
|
||||
balloon_formation_pool_[7].set[4] = &balloon_formation_[24];
|
||||
balloon_formation_pool_[7].set[5] = &balloon_formation_[65];
|
||||
balloon_formation_pool_[7].set[6] = &balloon_formation_[66];
|
||||
balloon_formation_pool_[7].set[7] = &balloon_formation_[67];
|
||||
balloon_formation_pool_[7].set[8] = &balloon_formation_[68];
|
||||
balloon_formation_pool_[7].set[9] = &balloon_formation_[69];
|
||||
|
||||
// EnemyPool #8
|
||||
balloon_formation_pool_[8].set[0] = &balloon_formation_[70];
|
||||
balloon_formation_pool_[8].set[1] = &balloon_formation_[71];
|
||||
balloon_formation_pool_[8].set[2] = &balloon_formation_[72];
|
||||
balloon_formation_pool_[8].set[3] = &balloon_formation_[73];
|
||||
balloon_formation_pool_[8].set[4] = &balloon_formation_[74];
|
||||
balloon_formation_pool_[8].set[5] = &balloon_formation_[15];
|
||||
balloon_formation_pool_[8].set[6] = &balloon_formation_[16];
|
||||
balloon_formation_pool_[8].set[7] = &balloon_formation_[17];
|
||||
balloon_formation_pool_[8].set[8] = &balloon_formation_[18];
|
||||
balloon_formation_pool_[8].set[9] = &balloon_formation_[19];
|
||||
|
||||
// EnemyPool #9
|
||||
balloon_formation_pool_[9].set[0] = &balloon_formation_[20];
|
||||
balloon_formation_pool_[9].set[1] = &balloon_formation_[21];
|
||||
balloon_formation_pool_[9].set[2] = &balloon_formation_[22];
|
||||
balloon_formation_pool_[9].set[3] = &balloon_formation_[23];
|
||||
balloon_formation_pool_[9].set[4] = &balloon_formation_[24];
|
||||
balloon_formation_pool_[9].set[5] = &balloon_formation_[70];
|
||||
balloon_formation_pool_[9].set[6] = &balloon_formation_[71];
|
||||
balloon_formation_pool_[9].set[7] = &balloon_formation_[72];
|
||||
balloon_formation_pool_[9].set[8] = &balloon_formation_[73];
|
||||
balloon_formation_pool_[9].set[9] = &balloon_formation_[74];
|
||||
}
|
||||
|
||||
// Inicializa las fases del juego
|
||||
void BalloonFormations::initGameStages()
|
||||
{
|
||||
// STAGE 1
|
||||
stage_[0].number = 1;
|
||||
stage_[0].power_to_complete = 200;
|
||||
stage_[0].min_menace = 7 + (4 * 1);
|
||||
stage_[0].max_menace = 7 + (4 * 3);
|
||||
stage_[0].balloon_pool = &balloon_formation_pool_[0];
|
||||
|
||||
// STAGE 2
|
||||
stage_[1].number = 2;
|
||||
stage_[1].power_to_complete = 300;
|
||||
stage_[1].min_menace = 7 + (4 * 2);
|
||||
stage_[1].max_menace = 7 + (4 * 4);
|
||||
stage_[1].balloon_pool = &balloon_formation_pool_[1];
|
||||
|
||||
// STAGE 3
|
||||
stage_[2].number = 3;
|
||||
stage_[2].power_to_complete = 600;
|
||||
stage_[2].min_menace = 7 + (4 * 3);
|
||||
stage_[2].max_menace = 7 + (4 * 5);
|
||||
stage_[2].balloon_pool = &balloon_formation_pool_[2];
|
||||
|
||||
// STAGE 4
|
||||
stage_[3].number = 4;
|
||||
stage_[3].power_to_complete = 600;
|
||||
stage_[3].min_menace = 7 + (4 * 3);
|
||||
stage_[3].max_menace = 7 + (4 * 5);
|
||||
stage_[3].balloon_pool = &balloon_formation_pool_[3];
|
||||
|
||||
// STAGE 5
|
||||
stage_[4].number = 5;
|
||||
stage_[4].power_to_complete = 600;
|
||||
stage_[4].min_menace = 7 + (4 * 4);
|
||||
stage_[4].max_menace = 7 + (4 * 6);
|
||||
stage_[4].balloon_pool = &balloon_formation_pool_[4];
|
||||
|
||||
// STAGE 6
|
||||
stage_[5].number = 6;
|
||||
stage_[5].power_to_complete = 600;
|
||||
stage_[5].min_menace = 7 + (4 * 4);
|
||||
stage_[5].max_menace = 7 + (4 * 6);
|
||||
stage_[5].balloon_pool = &balloon_formation_pool_[5];
|
||||
|
||||
// STAGE 7
|
||||
stage_[6].number = 7;
|
||||
stage_[6].power_to_complete = 650;
|
||||
stage_[6].min_menace = 7 + (4 * 5);
|
||||
stage_[6].max_menace = 7 + (4 * 7);
|
||||
stage_[6].balloon_pool = &balloon_formation_pool_[6];
|
||||
|
||||
// STAGE 8
|
||||
stage_[7].number = 8;
|
||||
stage_[7].power_to_complete = 750;
|
||||
stage_[7].min_menace = 7 + (4 * 5);
|
||||
stage_[7].max_menace = 7 + (4 * 7);
|
||||
stage_[7].balloon_pool = &balloon_formation_pool_[7];
|
||||
|
||||
// STAGE 9
|
||||
stage_[8].number = 9;
|
||||
stage_[8].power_to_complete = 850;
|
||||
stage_[8].min_menace = 7 + (4 * 6);
|
||||
stage_[8].max_menace = 7 + (4 * 8);
|
||||
stage_[8].balloon_pool = &balloon_formation_pool_[8];
|
||||
|
||||
// STAGE 10
|
||||
stage_[9].number = 10;
|
||||
stage_[9].power_to_complete = 950;
|
||||
stage_[9].min_menace = 7 + (4 * 7);
|
||||
stage_[9].max_menace = 7 + (4 * 10);
|
||||
stage_[9].balloon_pool = &balloon_formation_pool_[9];
|
||||
}
|
||||
|
||||
// Devuelve una fase
|
||||
Stage BalloonFormations::getStage(int index) const
|
||||
{
|
||||
return stage_[index];
|
||||
}
|
||||
63
source/balloon_formations.h
Normal file
63
source/balloon_formations.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
constexpr int NUMBER_OF_BALLOON_FORMATIONS = 100;
|
||||
constexpr int MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION = 50;
|
||||
|
||||
// Estructuras
|
||||
struct BalloonFormationParams
|
||||
{
|
||||
int x; // Posición en el eje X donde crear al enemigo
|
||||
int y; // Posición en el eje Y donde crear al enemigo
|
||||
float vel_x; // Velocidad inicial en el eje X
|
||||
int kind; // Tipo de enemigo
|
||||
int creation_counter; // Temporizador para la creación del enemigo
|
||||
};
|
||||
|
||||
struct BalloonFormationUnit // Contiene la información de una formación enemiga
|
||||
{
|
||||
int number_of_balloons; // Cantidad de enemigos que forman la formación
|
||||
BalloonFormationParams init[MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación
|
||||
};
|
||||
|
||||
struct BalloonFormationPool
|
||||
{
|
||||
BalloonFormationUnit *set[10]; // Conjunto de formaciones de globos
|
||||
};
|
||||
|
||||
struct Stage // Contiene todas las variables relacionadas con una fase
|
||||
{
|
||||
BalloonFormationPool *balloon_pool; // El conjunto de formaciones de globos de la fase
|
||||
int power_to_complete; // Cantidad de poder que se necesita para completar la fase
|
||||
int max_menace; // Umbral máximo de amenaza de la fase
|
||||
int min_menace; // Umbral mínimo de amenaza de la fase
|
||||
int number; // Número de fase
|
||||
};
|
||||
|
||||
// Clase BalloonFormations, para gestionar las formaciones de globos
|
||||
class BalloonFormations
|
||||
{
|
||||
private:
|
||||
// Variables
|
||||
Stage stage_[10]; // Variable con los datos de cada pantalla
|
||||
BalloonFormationUnit balloon_formation_[NUMBER_OF_BALLOON_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||
BalloonFormationPool balloon_formation_pool_[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||
|
||||
// Inicializa las formaciones enemigas
|
||||
void initBalloonFormations();
|
||||
|
||||
// Inicializa los conjuntos de formaciones
|
||||
void initBalloonFormationPools();
|
||||
|
||||
// Inicializa las fases del juego
|
||||
void initGameStages();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
BalloonFormations();
|
||||
|
||||
// Destructor
|
||||
~BalloonFormations() = default;
|
||||
|
||||
// Devuelve una fase
|
||||
Stage getStage(int index) const;
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "bullet.h"
|
||||
#include "param.h" // for param
|
||||
#include "sprite.h" // for Sprite
|
||||
#include <memory> // for std::unique_ptr
|
||||
#include <memory> // for unique_ptr, make_unique, shared_ptr
|
||||
#include "param.h" // for param
|
||||
#include "sprite.h" // for Sprite
|
||||
class Texture;
|
||||
|
||||
// Constantes evaluables en tiempo de compilación
|
||||
constexpr int BULLET_WIDTH = 12;
|
||||
constexpr int BULLET_HEIGHT = 12;
|
||||
constexpr int BULLET_VELY = -3;
|
||||
@@ -23,10 +23,9 @@ Bullet::Bullet(int x, int y, BulletType kind, bool powered_up, int owner, SDL_Re
|
||||
owner_(owner),
|
||||
play_area_(play_area)
|
||||
{
|
||||
vel_x_ = (kind_ == BulletType::LEFT) ? BULLET_VELX_LEFT
|
||||
: (kind_ == BulletType::RIGHT) ? BULLET_VELX_RIGHT
|
||||
: 0;
|
||||
|
||||
vel_x_ = (kind_ == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind_ == BulletType::RIGHT) ? BULLET_VELX_RIGHT
|
||||
: 0;
|
||||
|
||||
auto sprite_offset = powered_up ? 3 : 0;
|
||||
auto kind_index = static_cast<int>(kind);
|
||||
sprite_->setSpriteClip((kind_index + sprite_offset) * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
@@ -67,12 +66,12 @@ BulletMoveStatus Bullet::move()
|
||||
|
||||
bool Bullet::isEnabled() const
|
||||
{
|
||||
return kind_ != BulletType::NULL_TYPE;
|
||||
return kind_ != BulletType::NONE;
|
||||
}
|
||||
|
||||
void Bullet::disable()
|
||||
{
|
||||
kind_ = BulletType::NULL_TYPE;
|
||||
kind_ = BulletType::NONE;
|
||||
}
|
||||
|
||||
int Bullet::getPosX() const
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <memory> // for unique_ptr
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "utils.h" // for Circle
|
||||
#include "texture.h" // lines 9-9
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "utils.h" // for Circle
|
||||
class Texture;
|
||||
|
||||
// Enumeración para los diferentes tipos de balas
|
||||
enum class BulletType
|
||||
@@ -13,7 +13,7 @@ enum class BulletType
|
||||
UP,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
NULL_TYPE
|
||||
NONE
|
||||
};
|
||||
|
||||
// Enumeración para los resultados del movimiento de la bala
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "define_buttons.h"
|
||||
#include "lang.h" // for getText
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#include "section.h" // for name, SectionName, options, SectionOptions
|
||||
#include "text.h" // for Text
|
||||
#include "utils.h" // for OptionsController, Options, Param, ParamGame
|
||||
#include <utility> // for move
|
||||
#include "input.h" // for Input, InputType
|
||||
#include "lang.h" // for getText
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#include "section.h" // for Name, Options, name, options
|
||||
#include "text.h" // for Text
|
||||
#include "utils.h" // for OptionsController, Options, Param, ParamGame
|
||||
|
||||
// Constructor
|
||||
DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_ControllerButtonEvent
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "input.h" // for inputs_e
|
||||
#include "text.h"
|
||||
#include <memory>
|
||||
#include <SDL2/SDL_events.h> // for SDL_ControllerButtonEvent
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
class Input;
|
||||
class Text;
|
||||
enum class InputType : int;
|
||||
|
||||
struct DefineButtonsButton
|
||||
{
|
||||
|
||||
@@ -5,43 +5,44 @@
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_CONTROLLER_BUTTON_B, SDL_CO...
|
||||
#include <SDL2/SDL_hints.h> // for SDL_SetHint, SDL_HINT_RENDER_DR...
|
||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_DOWN, SDL_SCANCODE_E
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
||||
#include <SDL2/SDL_stdinc.h> // for SDL_bool, Uint32
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <errno.h> // for errno, EACCES, EEXIST, ENAMETOO...
|
||||
#include <stdio.h> // for printf, perror, size_t
|
||||
#include <errno.h> // for errno, EEXIST, EACCES, ENAMETOO...
|
||||
#include <stdio.h> // for printf, perror
|
||||
#include <string.h> // for strcmp
|
||||
#include <sys/stat.h> // for stat, mkdir, S_IRWXU
|
||||
#include <sys/stat.h> // for mkdir, stat, S_IRWXU
|
||||
#include <unistd.h> // for getuid
|
||||
#include <cstdlib> // for exit, EXIT_FAILURE, rand, srand
|
||||
#include <iostream> // for basic_ostream, operator<<, cout
|
||||
#include <string> // for basic_string, operator+, allocator
|
||||
#include "asset.h" // for Asset, assetType
|
||||
#include <memory> // for make_unique, unique_ptr
|
||||
#include <string> // for operator+, allocator, char_traits
|
||||
#include "asset.h" // for Asset, AssetType
|
||||
#include "dbgtxt.h" // for dbg_init
|
||||
#include "game.h" // for Game, GAME_MODE_DEMO_OFF, GAME_...
|
||||
#include "global_inputs.h"
|
||||
#include "hiscore_table.h" // for HiScoreTable
|
||||
#include "input.h" // for inputs_e, Input
|
||||
#include "instructions.h" // for Instructions
|
||||
#include "intro.h" // for Intro
|
||||
#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound
|
||||
#include "logo.h" // for Logo
|
||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
||||
#include "on_screen_help.h" // for OnScreenHelp
|
||||
#include "options.h" // for options, loadOptionsFile, saveO...
|
||||
#include "param.h" // for param, loadParamsFromFile
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for SectionName, name, options, SectionOptions
|
||||
#include "title.h" // for Title
|
||||
#include "utils.h" // for MusicFile, SoundFile, opt...
|
||||
#include <memory>
|
||||
#include "global_inputs.h" // for init
|
||||
#include "hiscore_table.h" // for HiScoreTable
|
||||
#include "input.h" // for Input, InputType
|
||||
#include "instructions.h" // for Instructions
|
||||
#include "intro.h" // for Intro
|
||||
#include "jail_audio.h" // for JA_LoadMusic, JA_LoadSound, JA_...
|
||||
#include "lang.h" // for Code, loadFromFile
|
||||
#include "logo.h" // for Logo
|
||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
||||
#include "on_screen_help.h" // for OnScreenHelp
|
||||
#include "options.h" // for options, loadOptionsFile, saveO...
|
||||
#include "param.h" // for param, loadParamsFromFile
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for Name, name, Options, options
|
||||
#include "title.h" // for Title
|
||||
#include "utils.h" // for MusicFile, SoundFile, Options
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h> // for getpwuid, passwd
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Director::Director(int argc, char *argv[])
|
||||
Director::Director(int argc, const char *argv[])
|
||||
{
|
||||
#ifdef RECORDING
|
||||
section::name = section::Name::GAME;
|
||||
@@ -160,8 +161,8 @@ void Director::initInput()
|
||||
Input::get()->bindKey(InputType::RESET, SDL_SCANCODE_F10);
|
||||
|
||||
// Asigna botones a inputs
|
||||
const int numGamePads = Input::get()->getNumControllers();
|
||||
for (int i = 0; i < numGamePads; ++i)
|
||||
const int num_gamepads = Input::get()->getNumControllers();
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
{
|
||||
// Mando - Movimiento del jugador
|
||||
Input::get()->bindGameControllerButton(i, InputType::UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||
@@ -188,7 +189,7 @@ void Director::initInput()
|
||||
}
|
||||
|
||||
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
||||
for (int i = 0; i < numGamePads; ++i)
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
for (int index = 0; index < (int)options.controller.size(); ++index)
|
||||
if (Input::get()->getControllerName(i) == options.controller[index].name)
|
||||
{
|
||||
@@ -200,7 +201,7 @@ void Director::initInput()
|
||||
}
|
||||
|
||||
// Asigna botones a inputs desde otros inputs
|
||||
for (int i = 0; i < numGamePads; ++i)
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
{
|
||||
Input::get()->bindGameControllerButton(i, InputType::EXIT, InputType::START);
|
||||
Input::get()->bindGameControllerButton(i, InputType::RESET, InputType::FIRE_CENTER);
|
||||
@@ -213,7 +214,7 @@ void Director::initInput()
|
||||
}
|
||||
|
||||
// Guarda las asignaciones de botones en las opciones
|
||||
for (int i = 0; i < numGamePads; ++i)
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
{
|
||||
options.controller[i].name = Input::get()->getControllerName(i);
|
||||
for (int j = 0; j < (int)options.controller[i].inputs.size(); ++j)
|
||||
@@ -340,7 +341,7 @@ bool Director::setFileList()
|
||||
#ifdef MACOS_BUNDLE
|
||||
const std::string prefix = "/../Resources";
|
||||
#else
|
||||
const std::string prefix = "";
|
||||
const std::string prefix;
|
||||
#endif
|
||||
|
||||
// Ficheros de configuración
|
||||
@@ -484,15 +485,15 @@ void Director::loadParams(const std::string &file_path)
|
||||
}
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
void Director::checkProgramArguments(int argc, char *argv[])
|
||||
void Director::checkProgramArguments(int argc, const char *argv[])
|
||||
{
|
||||
// Establece la ruta del programa
|
||||
executable_path_ = argv[0];
|
||||
|
||||
// Valores por defecto
|
||||
param_file_argument_ = "";
|
||||
param_file_argument_.clear();
|
||||
|
||||
// Comprueba el resto de parametros
|
||||
// Comprueba el resto de parámetros
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (strcmp(argv[i], "--320x240") == 0)
|
||||
@@ -566,17 +567,15 @@ void Director::createSystemFolder(const std::string &folder)
|
||||
void Director::loadSounds()
|
||||
{
|
||||
// Obtiene la lista con las rutas a los ficheros de sonidos
|
||||
std::vector<std::string> list = Asset::get()->getListByType(AssetType::SOUND);
|
||||
auto list = Asset::get()->getListByType(AssetType::SOUND);
|
||||
sounds_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
const size_t lastIndex = l.find_last_of("/") + 1;
|
||||
const std::string name = l.substr(lastIndex, std::string::npos);
|
||||
SoundFile temp;
|
||||
temp.name = name; // Añade el nombre del fichero
|
||||
temp.file = JA_LoadSound(l.c_str()); // Carga el fichero de audio
|
||||
sounds_.push_back(temp);
|
||||
auto last_index = l.find_last_of('/') + 1;
|
||||
auto name = l.substr(last_index);
|
||||
|
||||
sounds_.emplace_back(SoundFile{name, JA_LoadSound(l.c_str())});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,78 +583,69 @@ void Director::loadSounds()
|
||||
void Director::loadMusics()
|
||||
{
|
||||
// Obtiene la lista con las rutas a los ficheros musicales
|
||||
std::vector<std::string> list = Asset::get()->getListByType(AssetType::MUSIC);
|
||||
auto list = Asset::get()->getListByType(AssetType::MUSIC);
|
||||
musics_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
const size_t lastIndex = l.find_last_of("/") + 1;
|
||||
const std::string name = l.substr(lastIndex, std::string::npos);
|
||||
MusicFile temp;
|
||||
temp.name = name; // Añade el nombre del fichero
|
||||
temp.file = JA_LoadMusic(l.c_str()); // Carga el fichero de audio
|
||||
musics_.push_back(temp);
|
||||
auto last_index = l.find_last_of('/') + 1;
|
||||
auto name = l.substr(last_index);
|
||||
|
||||
musics_.emplace_back(MusicFile{name, JA_LoadMusic(l.c_str())});
|
||||
}
|
||||
}
|
||||
|
||||
// Ejecuta la sección con el logo
|
||||
void Director::runLogo()
|
||||
{
|
||||
auto logo = new Logo();
|
||||
auto logo = std::make_unique<Logo>();
|
||||
logo->run();
|
||||
delete logo;
|
||||
}
|
||||
|
||||
// Ejecuta la sección con la secuencia de introducción
|
||||
void Director::runIntro()
|
||||
{
|
||||
auto intro = new Intro(getMusic(musics_, "intro.ogg"));
|
||||
auto intro = std::make_unique<Intro>(getMusic(musics_, "intro.ogg"));
|
||||
intro->run();
|
||||
delete intro;
|
||||
}
|
||||
|
||||
// Ejecuta la sección con el titulo del juego
|
||||
// Ejecuta la sección con el título del juego
|
||||
void Director::runTitle()
|
||||
{
|
||||
auto title = new Title(getMusic(musics_, "title.ogg"));
|
||||
auto title = std::make_unique<Title>(getMusic(musics_, "title.ogg"));
|
||||
title->run();
|
||||
delete title;
|
||||
}
|
||||
|
||||
// Ejecuta la sección donde se juega al juego
|
||||
void Director::runGame()
|
||||
{
|
||||
const auto playerID = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
|
||||
constexpr auto currentStage = 0;
|
||||
auto game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg"));
|
||||
const auto player_id = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
|
||||
constexpr auto current_stage = 0;
|
||||
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg"));
|
||||
game->run();
|
||||
delete game;
|
||||
}
|
||||
|
||||
// Ejecuta la sección donde se muestran las instrucciones
|
||||
void Director::runInstructions()
|
||||
{
|
||||
auto instructions = new Instructions(getMusic(musics_, "title.ogg"));
|
||||
auto instructions = std::make_unique<Instructions>(getMusic(musics_, "title.ogg"));
|
||||
instructions->run();
|
||||
delete instructions;
|
||||
}
|
||||
|
||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||
void Director::runHiScoreTable()
|
||||
{
|
||||
auto hiScoreTable = new HiScoreTable(getMusic(musics_, "title.ogg"));
|
||||
hiScoreTable->run();
|
||||
delete hiScoreTable;
|
||||
auto hi_score_table = std::make_unique<HiScoreTable>(getMusic(musics_, "title.ogg"));
|
||||
hi_score_table->run();
|
||||
}
|
||||
|
||||
// Ejecuta el juego en modo demo
|
||||
void Director::runDemoGame()
|
||||
{
|
||||
const auto playerID = (rand() % 2) + 1;
|
||||
constexpr auto currentStage = 0;
|
||||
auto game = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, nullptr);
|
||||
const auto player_id = (rand() % 2) + 1;
|
||||
constexpr auto current_stage = 0;
|
||||
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_ON, nullptr);
|
||||
game->run();
|
||||
delete game;
|
||||
}
|
||||
|
||||
int Director::run()
|
||||
@@ -702,8 +692,8 @@ int Director::run()
|
||||
}
|
||||
}
|
||||
|
||||
const int returnCode = section::options == section::Options::QUIT_NORMAL ? 0 : 1;
|
||||
return returnCode;
|
||||
const int return_code = section::options == section::Options::QUIT_NORMAL ? 0 : 1;
|
||||
return return_code;
|
||||
}
|
||||
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "lang.h" // for lang_e
|
||||
#include "utils.h" // for MusicFile, SoundFile
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
namespace lang { enum class Code : int; }
|
||||
struct MusicFile;
|
||||
struct SoundFile;
|
||||
|
||||
// Textos
|
||||
constexpr char WINDOW_CAPTION[] = "Coffee Crisis Arcade Edition";
|
||||
@@ -46,7 +47,7 @@ private:
|
||||
void loadMusics();
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
void checkProgramArguments(int argc, char *argv[]);
|
||||
void checkProgramArguments(int argc, const char *argv[]);
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
void createSystemFolder(const std::string &folder);
|
||||
@@ -77,7 +78,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Director(int argc, char *argv[]);
|
||||
Director(int argc, const char *argv[]);
|
||||
|
||||
// Destructor
|
||||
~Director();
|
||||
|
||||
@@ -1,719 +0,0 @@
|
||||
#include "enemy_formations.h"
|
||||
#include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE
|
||||
#include "param.h" // for param
|
||||
#include "utils.h" // for ParamGame, Param, Zone, BLOCK
|
||||
|
||||
// Constructor
|
||||
EnemyFormations::EnemyFormations()
|
||||
{
|
||||
initEnemyFormations();
|
||||
initEnemyPools();
|
||||
initGameStages();
|
||||
}
|
||||
|
||||
// Inicializa las formaciones enemigas
|
||||
void EnemyFormations::initEnemyFormations()
|
||||
{
|
||||
constexpr int y4 = -BLOCK;
|
||||
const int x4_0 = param.game.play_area.rect.x;
|
||||
const int x4_100 = param.game.play_area.rect.w - BALLOON_WIDTH_4;
|
||||
|
||||
constexpr int y3 = -BLOCK;
|
||||
const int x3_0 = param.game.play_area.rect.x;
|
||||
const int x3_100 = param.game.play_area.rect.w - BALLOON_WIDTH_3;
|
||||
|
||||
constexpr int y2 = -BLOCK;
|
||||
const int x2_0 = param.game.play_area.rect.x;
|
||||
const int x2_100 = param.game.play_area.rect.w - BALLOON_WIDTH_2;
|
||||
|
||||
constexpr int y1 = -BLOCK;
|
||||
const int x1_0 = param.game.play_area.rect.x;
|
||||
const int x1_50 = param.game.play_area.center_x - (BALLOON_WIDTH_1 / 2);
|
||||
const int x1_100 = param.game.play_area.rect.w - BALLOON_WIDTH_1;
|
||||
|
||||
// Inicializa a cero las variables
|
||||
for (int i = 0; i < NUMBER_OF_ENEMY_FORMATIONS; i++)
|
||||
{
|
||||
enemy_formation_[i].number_of_enemies = 0;
|
||||
for (int j = 0; j < MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION; j++)
|
||||
{
|
||||
enemy_formation_[i].init[j].x = 0;
|
||||
enemy_formation_[i].init[j].y = 0;
|
||||
enemy_formation_[i].init[j].vel_x = 0;
|
||||
enemy_formation_[i].init[j].kind = 0;
|
||||
enemy_formation_[i].init[j].creation_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const int creation_time = 300;
|
||||
int inc_x = 0;
|
||||
int inc_time = 0;
|
||||
int j = 0;
|
||||
|
||||
// #00 - Dos enemigos BALLOON4 uno a cada extremo
|
||||
j = 0;
|
||||
enemy_formation_[j].number_of_enemies = 2;
|
||||
inc_x = x4_100;
|
||||
inc_time = 0;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x4_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y4;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
||||
enemy_formation_[j].init[i].kind = BALLOON_4;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
||||
}
|
||||
|
||||
// #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro
|
||||
j = 1;
|
||||
enemy_formation_[j].number_of_enemies = 2;
|
||||
inc_x = param.game.play_area.center_x;
|
||||
inc_time = 0;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = param.game.play_area.first_quarter_x - (BALLOON_WIDTH_4 / 2) + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y4;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
||||
enemy_formation_[j].init[i].kind = BALLOON_4;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
||||
}
|
||||
|
||||
// #02 - Cuatro enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
||||
j = 2;
|
||||
enemy_formation_[j].number_of_enemies = 4;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y2;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_2;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #03 - Cuatro enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
||||
j = 3;
|
||||
enemy_formation_[j].number_of_enemies = 4;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_100 - (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y2;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_2;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha
|
||||
j = 4;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda
|
||||
j = 5;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha
|
||||
j = 6;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda
|
||||
j = 7;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha
|
||||
j = 8;
|
||||
enemy_formation_[j].number_of_enemies = 6;
|
||||
inc_x = BALLOON_WIDTH_1 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y1;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_1;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda
|
||||
j = 9;
|
||||
enemy_formation_[j].number_of_enemies = 6;
|
||||
inc_x = BALLOON_WIDTH_1 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_100 - (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y1;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_1;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #10 - Tres enemigos BALLOON4 seguidos desde la izquierda
|
||||
j = 10;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
inc_x = BALLOON_WIDTH_4 + 1;
|
||||
inc_time = 15;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x4_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y4;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_4;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #11 - Tres enemigos BALLOON4 seguidos desde la derecha
|
||||
j = 11;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
inc_x = BALLOON_WIDTH_4 + 1;
|
||||
inc_time = 15;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x4_100 - (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y4;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_4;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #12 - Seis enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
||||
j = 12;
|
||||
enemy_formation_[j].number_of_enemies = 6;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y2;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_2;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #13 - Seis enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
||||
j = 13;
|
||||
enemy_formation_[j].number_of_enemies = 6;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_100 - (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y2;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_2;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados
|
||||
j = 14;
|
||||
enemy_formation_[j].number_of_enemies = 5;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados
|
||||
j = 15;
|
||||
enemy_formation_[j].number_of_enemies = 5;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos
|
||||
j = 16;
|
||||
enemy_formation_[j].number_of_enemies = 5;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos
|
||||
j = 17;
|
||||
enemy_formation_[j].number_of_enemies = 5;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos
|
||||
j = 18;
|
||||
enemy_formation_[j].number_of_enemies = 12;
|
||||
inc_x = BALLOON_WIDTH_1 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y1;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_1;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos
|
||||
j = 19;
|
||||
enemy_formation_[j].number_of_enemies = 12;
|
||||
inc_x = BALLOON_WIDTH_1 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_100 - (i * inc_x);
|
||||
enemy_formation_[j].init[i].y = y1;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_1;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||
}
|
||||
|
||||
// #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos
|
||||
j = 20;
|
||||
enemy_formation_[j].number_of_enemies = 4;
|
||||
inc_x = BALLOON_WIDTH_4 + 1;
|
||||
inc_time = 0;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
const int half = enemy_formation_[j].number_of_enemies / 2;
|
||||
if (i < half)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x4_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x4_100 - ((i - half) * inc_x);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
}
|
||||
enemy_formation_[j].init[i].y = y4;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_4;
|
||||
enemy_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
||||
}
|
||||
|
||||
// #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos
|
||||
j = 21;
|
||||
enemy_formation_[j].number_of_enemies = 10;
|
||||
inc_x = BALLOON_WIDTH_2 + 1;
|
||||
inc_time = 3;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
const int half = enemy_formation_[j].number_of_enemies / 2;
|
||||
if (i < half)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_100 - ((i - half) * inc_x);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||
}
|
||||
enemy_formation_[j].init[i].y = y2;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_2;
|
||||
}
|
||||
|
||||
// #22 - Diez enemigos BALLOON3. Hacia la derecha/izquierda. Separados. Simetricos
|
||||
j = 22;
|
||||
enemy_formation_[j].number_of_enemies = 10;
|
||||
inc_x = BALLOON_WIDTH_3 * 2;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
const int half = enemy_formation_[j].number_of_enemies / 2;
|
||||
if (i < half)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||
}
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
}
|
||||
|
||||
// #23 - Diez enemigos BALLOON3. Hacia la derecha. Juntos. Simetricos
|
||||
j = 23;
|
||||
enemy_formation_[j].number_of_enemies = 10;
|
||||
inc_x = BALLOON_WIDTH_3 + 1;
|
||||
inc_time = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
const int half = enemy_formation_[j].number_of_enemies / 2;
|
||||
if (i < half)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||
}
|
||||
enemy_formation_[j].init[i].y = y3;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_3;
|
||||
}
|
||||
|
||||
// #24 - Treinta enemigos BALLOON1. Del centro hacia los extremos. Juntos. Simetricos
|
||||
j = 24;
|
||||
enemy_formation_[j].number_of_enemies = 30;
|
||||
inc_x = 0;
|
||||
inc_time = 5;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
const int half = enemy_formation_[j].number_of_enemies / 2;
|
||||
if (i < half)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_50;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_50;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * (i - half));
|
||||
}
|
||||
enemy_formation_[j].init[i].y = y1;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_1;
|
||||
}
|
||||
|
||||
// #25 - Treinta enemigos BALLOON1. Del centro hacia adentro. Juntos. Simetricos
|
||||
j = 25;
|
||||
enemy_formation_[j].number_of_enemies = 30;
|
||||
inc_time = 5;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
const int half = enemy_formation_[j].number_of_enemies / 2;
|
||||
if (i < half)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_50 + 20;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_50 - 20;
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||
}
|
||||
enemy_formation_[j].init[i].y = y1;
|
||||
enemy_formation_[j].init[i].kind = BALLOON_1;
|
||||
}
|
||||
|
||||
// Crea las mismas formaciones pero con hexagonos a partir de la posición 50 del vector
|
||||
for (int k = 0; k < j + 1; k++)
|
||||
{
|
||||
enemy_formation_[k + 50].number_of_enemies = enemy_formation_[k].number_of_enemies;
|
||||
for (int i = 0; i < enemy_formation_[k + 50].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[k + 50].init[i].x = enemy_formation_[k].init[i].x;
|
||||
enemy_formation_[k + 50].init[i].y = enemy_formation_[k].init[i].y;
|
||||
enemy_formation_[k + 50].init[i].vel_x = enemy_formation_[k].init[i].vel_x;
|
||||
enemy_formation_[k + 50].init[i].creation_counter = enemy_formation_[k].init[i].creation_counter;
|
||||
enemy_formation_[k + 50].init[i].kind = enemy_formation_[k].init[i].kind + 4;
|
||||
}
|
||||
}
|
||||
|
||||
// TEST
|
||||
enemy_formation_[99].number_of_enemies = 4;
|
||||
|
||||
enemy_formation_[99].init[0].x = 10;
|
||||
enemy_formation_[99].init[0].y = y1;
|
||||
enemy_formation_[99].init[0].vel_x = 0;
|
||||
enemy_formation_[99].init[0].kind = BALLOON_1;
|
||||
enemy_formation_[99].init[0].creation_counter = 200;
|
||||
|
||||
enemy_formation_[99].init[1].x = 50;
|
||||
enemy_formation_[99].init[1].y = y1;
|
||||
enemy_formation_[99].init[1].vel_x = 0;
|
||||
enemy_formation_[99].init[1].kind = BALLOON_2;
|
||||
enemy_formation_[99].init[1].creation_counter = 200;
|
||||
|
||||
enemy_formation_[99].init[2].x = 90;
|
||||
enemy_formation_[99].init[2].y = y1;
|
||||
enemy_formation_[99].init[2].vel_x = 0;
|
||||
enemy_formation_[99].init[2].kind = BALLOON_3;
|
||||
enemy_formation_[99].init[2].creation_counter = 200;
|
||||
|
||||
enemy_formation_[99].init[3].x = 140;
|
||||
enemy_formation_[99].init[3].y = y1;
|
||||
enemy_formation_[99].init[3].vel_x = 0;
|
||||
enemy_formation_[99].init[3].kind = BALLOON_4;
|
||||
enemy_formation_[99].init[3].creation_counter = 200;
|
||||
}
|
||||
|
||||
// Inicializa los conjuntos de formaciones
|
||||
void EnemyFormations::initEnemyPools()
|
||||
{
|
||||
// EnemyPool #0
|
||||
enemy_pool_[0].set[0] = &enemy_formation_[0];
|
||||
enemy_pool_[0].set[1] = &enemy_formation_[1];
|
||||
enemy_pool_[0].set[2] = &enemy_formation_[2];
|
||||
enemy_pool_[0].set[3] = &enemy_formation_[3];
|
||||
enemy_pool_[0].set[4] = &enemy_formation_[4];
|
||||
enemy_pool_[0].set[5] = &enemy_formation_[5];
|
||||
enemy_pool_[0].set[6] = &enemy_formation_[6];
|
||||
enemy_pool_[0].set[7] = &enemy_formation_[7];
|
||||
enemy_pool_[0].set[8] = &enemy_formation_[8];
|
||||
enemy_pool_[0].set[9] = &enemy_formation_[9];
|
||||
|
||||
// EnemyPool #1
|
||||
enemy_pool_[1].set[0] = &enemy_formation_[10];
|
||||
enemy_pool_[1].set[1] = &enemy_formation_[11];
|
||||
enemy_pool_[1].set[2] = &enemy_formation_[12];
|
||||
enemy_pool_[1].set[3] = &enemy_formation_[13];
|
||||
enemy_pool_[1].set[4] = &enemy_formation_[14];
|
||||
enemy_pool_[1].set[5] = &enemy_formation_[15];
|
||||
enemy_pool_[1].set[6] = &enemy_formation_[16];
|
||||
enemy_pool_[1].set[7] = &enemy_formation_[17];
|
||||
enemy_pool_[1].set[8] = &enemy_formation_[18];
|
||||
enemy_pool_[1].set[9] = &enemy_formation_[19];
|
||||
|
||||
// EnemyPool #2
|
||||
enemy_pool_[2].set[0] = &enemy_formation_[0];
|
||||
enemy_pool_[2].set[1] = &enemy_formation_[1];
|
||||
enemy_pool_[2].set[2] = &enemy_formation_[2];
|
||||
enemy_pool_[2].set[3] = &enemy_formation_[3];
|
||||
enemy_pool_[2].set[4] = &enemy_formation_[4];
|
||||
enemy_pool_[2].set[5] = &enemy_formation_[55];
|
||||
enemy_pool_[2].set[6] = &enemy_formation_[56];
|
||||
enemy_pool_[2].set[7] = &enemy_formation_[57];
|
||||
enemy_pool_[2].set[8] = &enemy_formation_[58];
|
||||
enemy_pool_[2].set[9] = &enemy_formation_[59];
|
||||
|
||||
// EnemyPool #3
|
||||
enemy_pool_[3].set[0] = &enemy_formation_[50];
|
||||
enemy_pool_[3].set[1] = &enemy_formation_[51];
|
||||
enemy_pool_[3].set[2] = &enemy_formation_[52];
|
||||
enemy_pool_[3].set[3] = &enemy_formation_[53];
|
||||
enemy_pool_[3].set[4] = &enemy_formation_[54];
|
||||
enemy_pool_[3].set[5] = &enemy_formation_[5];
|
||||
enemy_pool_[3].set[6] = &enemy_formation_[6];
|
||||
enemy_pool_[3].set[7] = &enemy_formation_[7];
|
||||
enemy_pool_[3].set[8] = &enemy_formation_[8];
|
||||
enemy_pool_[3].set[9] = &enemy_formation_[9];
|
||||
|
||||
// EnemyPool #4
|
||||
enemy_pool_[4].set[0] = &enemy_formation_[60];
|
||||
enemy_pool_[4].set[1] = &enemy_formation_[61];
|
||||
enemy_pool_[4].set[2] = &enemy_formation_[62];
|
||||
enemy_pool_[4].set[3] = &enemy_formation_[63];
|
||||
enemy_pool_[4].set[4] = &enemy_formation_[64];
|
||||
enemy_pool_[4].set[5] = &enemy_formation_[65];
|
||||
enemy_pool_[4].set[6] = &enemy_formation_[66];
|
||||
enemy_pool_[4].set[7] = &enemy_formation_[67];
|
||||
enemy_pool_[4].set[8] = &enemy_formation_[68];
|
||||
enemy_pool_[4].set[9] = &enemy_formation_[69];
|
||||
|
||||
// EnemyPool #5
|
||||
enemy_pool_[5].set[0] = &enemy_formation_[10];
|
||||
enemy_pool_[5].set[1] = &enemy_formation_[61];
|
||||
enemy_pool_[5].set[2] = &enemy_formation_[12];
|
||||
enemy_pool_[5].set[3] = &enemy_formation_[63];
|
||||
enemy_pool_[5].set[4] = &enemy_formation_[14];
|
||||
enemy_pool_[5].set[5] = &enemy_formation_[65];
|
||||
enemy_pool_[5].set[6] = &enemy_formation_[16];
|
||||
enemy_pool_[5].set[7] = &enemy_formation_[67];
|
||||
enemy_pool_[5].set[8] = &enemy_formation_[18];
|
||||
enemy_pool_[5].set[9] = &enemy_formation_[69];
|
||||
|
||||
// EnemyPool #6
|
||||
enemy_pool_[6].set[0] = &enemy_formation_[60];
|
||||
enemy_pool_[6].set[1] = &enemy_formation_[11];
|
||||
enemy_pool_[6].set[2] = &enemy_formation_[62];
|
||||
enemy_pool_[6].set[3] = &enemy_formation_[13];
|
||||
enemy_pool_[6].set[4] = &enemy_formation_[64];
|
||||
enemy_pool_[6].set[5] = &enemy_formation_[15];
|
||||
enemy_pool_[6].set[6] = &enemy_formation_[66];
|
||||
enemy_pool_[6].set[7] = &enemy_formation_[17];
|
||||
enemy_pool_[6].set[8] = &enemy_formation_[68];
|
||||
enemy_pool_[6].set[9] = &enemy_formation_[19];
|
||||
|
||||
// EnemyPool #7
|
||||
enemy_pool_[7].set[0] = &enemy_formation_[20];
|
||||
enemy_pool_[7].set[1] = &enemy_formation_[21];
|
||||
enemy_pool_[7].set[2] = &enemy_formation_[22];
|
||||
enemy_pool_[7].set[3] = &enemy_formation_[23];
|
||||
enemy_pool_[7].set[4] = &enemy_formation_[24];
|
||||
enemy_pool_[7].set[5] = &enemy_formation_[65];
|
||||
enemy_pool_[7].set[6] = &enemy_formation_[66];
|
||||
enemy_pool_[7].set[7] = &enemy_formation_[67];
|
||||
enemy_pool_[7].set[8] = &enemy_formation_[68];
|
||||
enemy_pool_[7].set[9] = &enemy_formation_[69];
|
||||
|
||||
// EnemyPool #8
|
||||
enemy_pool_[8].set[0] = &enemy_formation_[70];
|
||||
enemy_pool_[8].set[1] = &enemy_formation_[71];
|
||||
enemy_pool_[8].set[2] = &enemy_formation_[72];
|
||||
enemy_pool_[8].set[3] = &enemy_formation_[73];
|
||||
enemy_pool_[8].set[4] = &enemy_formation_[74];
|
||||
enemy_pool_[8].set[5] = &enemy_formation_[15];
|
||||
enemy_pool_[8].set[6] = &enemy_formation_[16];
|
||||
enemy_pool_[8].set[7] = &enemy_formation_[17];
|
||||
enemy_pool_[8].set[8] = &enemy_formation_[18];
|
||||
enemy_pool_[8].set[9] = &enemy_formation_[19];
|
||||
|
||||
// EnemyPool #9
|
||||
enemy_pool_[9].set[0] = &enemy_formation_[20];
|
||||
enemy_pool_[9].set[1] = &enemy_formation_[21];
|
||||
enemy_pool_[9].set[2] = &enemy_formation_[22];
|
||||
enemy_pool_[9].set[3] = &enemy_formation_[23];
|
||||
enemy_pool_[9].set[4] = &enemy_formation_[24];
|
||||
enemy_pool_[9].set[5] = &enemy_formation_[70];
|
||||
enemy_pool_[9].set[6] = &enemy_formation_[71];
|
||||
enemy_pool_[9].set[7] = &enemy_formation_[72];
|
||||
enemy_pool_[9].set[8] = &enemy_formation_[73];
|
||||
enemy_pool_[9].set[9] = &enemy_formation_[74];
|
||||
}
|
||||
|
||||
// Inicializa las fases del juego
|
||||
void EnemyFormations::initGameStages()
|
||||
{
|
||||
// STAGE 1
|
||||
stage_[0].number = 1;
|
||||
stage_[0].power_to_complete = 200;
|
||||
stage_[0].min_menace = 7 + (4 * 1);
|
||||
stage_[0].max_menace = 7 + (4 * 3);
|
||||
stage_[0].enemy_pool = &enemy_pool_[0];
|
||||
|
||||
// STAGE 2
|
||||
stage_[1].number = 2;
|
||||
stage_[1].power_to_complete = 300;
|
||||
stage_[1].min_menace = 7 + (4 * 2);
|
||||
stage_[1].max_menace = 7 + (4 * 4);
|
||||
stage_[1].enemy_pool = &enemy_pool_[1];
|
||||
|
||||
// STAGE 3
|
||||
stage_[2].number = 3;
|
||||
stage_[2].power_to_complete = 600;
|
||||
stage_[2].min_menace = 7 + (4 * 3);
|
||||
stage_[2].max_menace = 7 + (4 * 5);
|
||||
stage_[2].enemy_pool = &enemy_pool_[2];
|
||||
|
||||
// STAGE 4
|
||||
stage_[3].number = 4;
|
||||
stage_[3].power_to_complete = 600;
|
||||
stage_[3].min_menace = 7 + (4 * 3);
|
||||
stage_[3].max_menace = 7 + (4 * 5);
|
||||
stage_[3].enemy_pool = &enemy_pool_[3];
|
||||
|
||||
// STAGE 5
|
||||
stage_[4].number = 5;
|
||||
stage_[4].power_to_complete = 600;
|
||||
stage_[4].min_menace = 7 + (4 * 4);
|
||||
stage_[4].max_menace = 7 + (4 * 6);
|
||||
stage_[4].enemy_pool = &enemy_pool_[4];
|
||||
|
||||
// STAGE 6
|
||||
stage_[5].number = 6;
|
||||
stage_[5].power_to_complete = 600;
|
||||
stage_[5].min_menace = 7 + (4 * 4);
|
||||
stage_[5].max_menace = 7 + (4 * 6);
|
||||
stage_[5].enemy_pool = &enemy_pool_[5];
|
||||
|
||||
// STAGE 7
|
||||
stage_[6].number = 7;
|
||||
stage_[6].power_to_complete = 650;
|
||||
stage_[6].min_menace = 7 + (4 * 5);
|
||||
stage_[6].max_menace = 7 + (4 * 7);
|
||||
stage_[6].enemy_pool = &enemy_pool_[6];
|
||||
|
||||
// STAGE 8
|
||||
stage_[7].number = 8;
|
||||
stage_[7].power_to_complete = 750;
|
||||
stage_[7].min_menace = 7 + (4 * 5);
|
||||
stage_[7].max_menace = 7 + (4 * 7);
|
||||
stage_[7].enemy_pool = &enemy_pool_[7];
|
||||
|
||||
// STAGE 9
|
||||
stage_[8].number = 9;
|
||||
stage_[8].power_to_complete = 850;
|
||||
stage_[8].min_menace = 7 + (4 * 6);
|
||||
stage_[8].max_menace = 7 + (4 * 8);
|
||||
stage_[8].enemy_pool = &enemy_pool_[8];
|
||||
|
||||
// STAGE 10
|
||||
stage_[9].number = 10;
|
||||
stage_[9].power_to_complete = 950;
|
||||
stage_[9].min_menace = 7 + (4 * 7);
|
||||
stage_[9].max_menace = 7 + (4 * 10);
|
||||
stage_[9].enemy_pool = &enemy_pool_[9];
|
||||
}
|
||||
|
||||
// Devuelve una fase
|
||||
Stage EnemyFormations::getStage(int index) const
|
||||
{
|
||||
return stage_[index];
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
constexpr int NUMBER_OF_ENEMY_FORMATIONS = 100;
|
||||
constexpr int MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION = 50;
|
||||
|
||||
// Estructuras
|
||||
struct EnemyFormationInit
|
||||
{
|
||||
int x; // Posición en el eje X donde crear al enemigo
|
||||
int y; // Posición en el eje Y donde crear al enemigo
|
||||
float vel_x; // Velocidad inicial en el eje X
|
||||
int kind; // Tipo de enemigo
|
||||
int creation_counter; // Temporizador para la creación del enemigo
|
||||
};
|
||||
|
||||
struct EnemyFormationUnit // Contiene la información de una formación enemiga
|
||||
{
|
||||
int number_of_enemies; // Cantidad de enemigos que forman la formación
|
||||
EnemyFormationInit init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación
|
||||
};
|
||||
|
||||
struct EnemyFormationPool
|
||||
{
|
||||
EnemyFormationUnit *set[10]; // Conjunto de formaciones enemigas
|
||||
};
|
||||
|
||||
struct Stage // Contiene todas las variables relacionadas con una fase
|
||||
{
|
||||
EnemyFormationPool *enemy_pool; // El conjunto de formaciones enemigas de la fase
|
||||
int power_to_complete; // Cantidad de poder que se necesita para completar la fase
|
||||
int max_menace; // Umbral máximo de amenaza de la fase
|
||||
int min_menace; // Umbral mínimo de amenaza de la fase
|
||||
int number; // Número de fase
|
||||
};
|
||||
|
||||
// Clase EnemyFormations, para gestionar las formaciones enemigas
|
||||
class EnemyFormations
|
||||
{
|
||||
private:
|
||||
// Variables
|
||||
Stage stage_[10]; // Variable con los datos de cada pantalla
|
||||
EnemyFormationUnit enemy_formation_[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||
EnemyFormationPool enemy_pool_[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||
|
||||
// Inicializa las formaciones enemigas
|
||||
void initEnemyFormations();
|
||||
|
||||
// Inicializa los conjuntos de formaciones
|
||||
void initEnemyPools();
|
||||
|
||||
// Inicializa las fases del juego
|
||||
void initGameStages();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
EnemyFormations();
|
||||
|
||||
// Destructor
|
||||
~EnemyFormations() = default;
|
||||
|
||||
// Devuelve una fase
|
||||
Stage getStage(int index) const;
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "explosions.h"
|
||||
#include <utility> // for move
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
class Texture;
|
||||
class Texture; // lines 3-3
|
||||
|
||||
// Constructor
|
||||
Explosions::Explosions()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "animated_sprite.h"
|
||||
#include <memory>
|
||||
#include "texture.h"
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
struct ExplosionTexture
|
||||
{
|
||||
|
||||
278
source/game.cpp
278
source/game.cpp
@@ -1,38 +1,41 @@
|
||||
#include "game.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_keycode.h> // for SDLK_1, SDLK_2, SDLK_3, SDLK_h
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||
#include <SDL2/SDL_keycode.h> // for SDLK_1, SDLK_2, SDLK_3, SDLK_4
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_R...
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for min
|
||||
#include <fstream> // for basic_ifstream
|
||||
#include <iostream> // for char_traits, basic_istream, ifstream
|
||||
#include <algorithm> // for min, remove_if
|
||||
#include <fstream> // for basic_ostream, operator<<, basic_i...
|
||||
#include <iostream> // for cout
|
||||
#include <numeric> // for accumulate
|
||||
#include <utility> // for move
|
||||
#include "asset.h" // for Asset
|
||||
#include "background.h" // for Background
|
||||
#include "balloon.h" // for Balloon, BALLOON_SPEED_1, BALLOON_...
|
||||
#include "bullet.h" // for Bullet, BulletType::LEFT, BulletType::RIGHT
|
||||
#include "enemy_formations.h" // for Stage, EnemyFormations, enemyIni...
|
||||
#include "balloon.h" // for Balloon, BALLOON_SCORE_1, BALLOON_...
|
||||
#include "balloon_formations.h" // for Stage, BalloonFormationParams, Bal...
|
||||
#include "bullet.h" // for Bullet, BulletType, BulletMoveStatus
|
||||
#include "explosions.h" // for Explosions
|
||||
#include "fade.h" // for Fade, FadeType::RANDOM_SQUARE, FADE_VEN...
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
#include "input.h" // for inputs_e, Input, INPUT_DO_NOT_ALLO...
|
||||
#include "fade.h" // for Fade, FadeType
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for InputType, Input, INPUT_DO_NOT_ALL...
|
||||
#include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
|
||||
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
|
||||
#include "lang.h" // for getText
|
||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#include "player.h" // for Player, PlayerStatus::PLAYING, PLA...
|
||||
#include "scoreboard.h" // for Scoreboard, scoreboard_modes_e
|
||||
#include "player.h" // for Player, PlayerStatus
|
||||
#include "scoreboard.h" // for Scoreboard, ScoreboardMode, SCOREB...
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for Name, name, Options, options
|
||||
#include "smart_sprite.h" // for SmartSprite
|
||||
#include "text.h" // for Text, TEXT_CENTER
|
||||
#include "texture.h" // for Texture
|
||||
#include "dbgtxt.h"
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
struct JA_Music_t; // lines 35-35
|
||||
struct JA_Sound_t; // lines 36-36
|
||||
|
||||
// Constructor
|
||||
Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music)
|
||||
@@ -56,7 +59,7 @@ Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music)
|
||||
|
||||
background_ = std::make_unique<Background>(renderer_);
|
||||
explosions_ = std::make_unique<Explosions>();
|
||||
enemy_formations_ = std::make_unique<EnemyFormations>();
|
||||
balloon_formations_ = std::make_unique<BalloonFormations>();
|
||||
|
||||
// Carga los recursos
|
||||
loadMedia();
|
||||
@@ -133,20 +136,20 @@ void Game::init(int player_id)
|
||||
players_.push_back(std::move(player2));
|
||||
|
||||
// Obtiene mediante "playerID" el jugador que va a empezar jugar
|
||||
auto player = getPlayer(player_id);
|
||||
auto main_player = getPlayer(player_id);
|
||||
|
||||
// Cambia el estado del jugador seleccionado
|
||||
player->setStatusPlaying(PlayerStatus::PLAYING);
|
||||
main_player->setStatusPlaying(PlayerStatus::PLAYING);
|
||||
|
||||
// Como es el principio del juego, empieza sin inmunidad
|
||||
player->setInvulnerable(false);
|
||||
main_player->setInvulnerable(false);
|
||||
|
||||
// Variables relacionadas con la dificultad
|
||||
switch (difficulty_)
|
||||
{
|
||||
case GameDifficulty::EASY:
|
||||
{
|
||||
default_enemy_speed_ = BALLOON_SPEED_1;
|
||||
default_balloon_speed_ = BALLOON_SPEED_1;
|
||||
difficulty_score_multiplier_ = 0.5f;
|
||||
difficulty_color_ = difficulty_easy_color;
|
||||
scoreboard_->setColor(difficulty_color_);
|
||||
@@ -155,7 +158,7 @@ void Game::init(int player_id)
|
||||
|
||||
case GameDifficulty::NORMAL:
|
||||
{
|
||||
default_enemy_speed_ = BALLOON_SPEED_1;
|
||||
default_balloon_speed_ = BALLOON_SPEED_1;
|
||||
difficulty_score_multiplier_ = 1.0f;
|
||||
difficulty_color_ = difficulty_normal_color;
|
||||
scoreboard_->setColor(scoreboard_color);
|
||||
@@ -164,7 +167,7 @@ void Game::init(int player_id)
|
||||
|
||||
case GameDifficulty::HARD:
|
||||
{
|
||||
default_enemy_speed_ = BALLOON_SPEED_5;
|
||||
default_balloon_speed_ = BALLOON_SPEED_5;
|
||||
difficulty_score_multiplier_ = 1.5f;
|
||||
difficulty_color_ = difficulty_hard_color;
|
||||
scoreboard_->setColor(difficulty_color_);
|
||||
@@ -177,7 +180,7 @@ void Game::init(int player_id)
|
||||
|
||||
// Variables para el marcador
|
||||
scoreboard_->setPos({param.scoreboard.x, param.scoreboard.y, param.scoreboard.w, param.scoreboard.h});
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
scoreboard_->setName(player->getScoreBoardPanel(), player->getName());
|
||||
if (player->isWaiting())
|
||||
@@ -204,9 +207,9 @@ void Game::init(int player_id)
|
||||
time_stopped_ = false;
|
||||
time_stopped_counter_ = 0;
|
||||
counter_ = 0;
|
||||
last_enemy_deploy_ = 0;
|
||||
enemy_deploy_counter_ = 0;
|
||||
balloon_speed_ = default_enemy_speed_;
|
||||
last_ballon_deploy_ = 0;
|
||||
balloon_deploy_counter_ = 0;
|
||||
balloon_speed_ = default_balloon_speed_;
|
||||
helper_.need_coffee = false;
|
||||
helper_.need_coffee_machine = false;
|
||||
helper_.need_power_ball = false;
|
||||
@@ -237,15 +240,15 @@ void Game::init(int player_id)
|
||||
// Actualiza el numero de globos explotados según la fase de la demo
|
||||
for (int i = 0; i < current_stage_; ++i)
|
||||
{
|
||||
balloons_popped_ += enemy_formations_->getStage(i).power_to_complete;
|
||||
balloons_popped_ += balloon_formations_->getStage(i).power_to_complete;
|
||||
}
|
||||
|
||||
// Activa o no al otro jugador
|
||||
if (rand() % 2 == 0)
|
||||
{
|
||||
const auto otherPlayer = player_id == 1 ? 2 : 1;
|
||||
auto player = getPlayer(otherPlayer);
|
||||
player->setStatusPlaying(PlayerStatus::PLAYING);
|
||||
const auto other_player_id = player_id == 1 ? 2 : 1;
|
||||
auto other_player = getPlayer(other_player_id);
|
||||
other_player->setStatusPlaying(PlayerStatus::PLAYING);
|
||||
}
|
||||
|
||||
for (auto &player : players_)
|
||||
@@ -273,7 +276,7 @@ void Game::init(int player_id)
|
||||
total_power_to_complete_game_ = 0;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
total_power_to_complete_game_ += enemy_formations_->getStage(i).power_to_complete;
|
||||
total_power_to_complete_game_ += balloon_formations_->getStage(i).power_to_complete;
|
||||
}
|
||||
|
||||
// Modo grabar demo
|
||||
@@ -598,12 +601,13 @@ void Game::unloadMedia()
|
||||
}
|
||||
|
||||
// Carga el fichero de datos para la demo
|
||||
bool Game::loadDemoFile(std::string file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA])
|
||||
bool Game::loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA])
|
||||
{
|
||||
// Indicador de éxito en la carga
|
||||
auto success = true;
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
|
||||
#endif
|
||||
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
|
||||
if (!file)
|
||||
{ // El fichero no existe
|
||||
@@ -671,10 +675,12 @@ bool Game::loadDemoFile(std::string file_path, DemoKeys (*data_file)[TOTAL_DEMO_
|
||||
|
||||
#ifdef RECORDING
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool Game::saveDemoFile(std::string file_path)
|
||||
bool Game::saveDemoFile(const std::string &file_path)
|
||||
{
|
||||
auto success = true;
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
#endif // VERBOSE
|
||||
|
||||
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
||||
if (file)
|
||||
@@ -704,10 +710,10 @@ bool Game::saveDemoFile(std::string file_path)
|
||||
#endif // RECORDING
|
||||
|
||||
// Crea una formación de enemigos
|
||||
void Game::deployEnemyFormation()
|
||||
void Game::deployBalloonFormation()
|
||||
{
|
||||
// Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última
|
||||
if (enemy_deploy_counter_ == 0)
|
||||
if (balloon_deploy_counter_ == 0)
|
||||
{
|
||||
|
||||
// En este punto se decide entre crear una powerball o una formación enemiga
|
||||
@@ -717,7 +723,7 @@ void Game::deployEnemyFormation()
|
||||
createPowerBall();
|
||||
|
||||
// Da un poco de margen para que se creen mas enemigos
|
||||
enemy_deploy_counter_ = 300;
|
||||
balloon_deploy_counter_ = 300;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -728,26 +734,26 @@ void Game::deployEnemyFormation()
|
||||
auto set = rand() % 10;
|
||||
|
||||
// Evita repetir la ultima formación enemiga desplegada
|
||||
if (set == last_enemy_deploy_)
|
||||
if (set == last_ballon_deploy_)
|
||||
{
|
||||
++set %= 10;
|
||||
}
|
||||
|
||||
last_enemy_deploy_ = set;
|
||||
last_ballon_deploy_ = set;
|
||||
|
||||
const Stage stage = enemy_formations_->getStage(current_stage_);
|
||||
const auto numEnemies = stage.enemy_pool->set[set]->number_of_enemies;
|
||||
const Stage stage = balloon_formations_->getStage(current_stage_);
|
||||
const auto numEnemies = stage.balloon_pool->set[set]->number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
createBalloon(stage.enemy_pool->set[set]->init[i].x,
|
||||
stage.enemy_pool->set[set]->init[i].y,
|
||||
stage.enemy_pool->set[set]->init[i].kind,
|
||||
stage.enemy_pool->set[set]->init[i].vel_x,
|
||||
createBalloon(stage.balloon_pool->set[set]->init[i].x,
|
||||
stage.balloon_pool->set[set]->init[i].y,
|
||||
stage.balloon_pool->set[set]->init[i].kind,
|
||||
stage.balloon_pool->set[set]->init[i].vel_x,
|
||||
balloon_speed_,
|
||||
stage.enemy_pool->set[set]->init[i].creation_counter);
|
||||
stage.balloon_pool->set[set]->init[i].creation_counter);
|
||||
}
|
||||
|
||||
enemy_deploy_counter_ = 300;
|
||||
balloon_deploy_counter_ = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -762,7 +768,7 @@ void Game::increaseStageCurrentPower(int power)
|
||||
void Game::updateHiScore()
|
||||
{
|
||||
// Si la puntuación actual es mayor que la máxima puntuación
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
if (player->getScore() > hi_score_.score)
|
||||
{
|
||||
@@ -826,7 +832,7 @@ void Game::renderPlayers()
|
||||
// Comprueba si hay cambio de fase y actualiza las variables
|
||||
void Game::updateStage()
|
||||
{
|
||||
if (current_power_ >= enemy_formations_->getStage(current_stage_).power_to_complete)
|
||||
if (current_power_ >= balloon_formations_->getStage(current_stage_).power_to_complete)
|
||||
{
|
||||
// Cambio de fase
|
||||
current_stage_++;
|
||||
@@ -851,7 +857,7 @@ void Game::updateStage()
|
||||
}
|
||||
JA_PlaySound(stage_change_sound_);
|
||||
stage_bitmap_counter_ = 0;
|
||||
balloon_speed_ = default_enemy_speed_;
|
||||
balloon_speed_ = default_balloon_speed_;
|
||||
setBalloonSpeed(balloon_speed_);
|
||||
screen_->flash(flash_color, 5);
|
||||
screen_->shake();
|
||||
@@ -970,7 +976,7 @@ void Game::setBalloonSpeed(float speed)
|
||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||
void Game::updateBalloonSpeed()
|
||||
{
|
||||
const float percent = (float)current_power_ / (float)enemy_formations_->getStage(current_stage_).power_to_complete;
|
||||
const float percent = (float)current_power_ / (float)balloon_formations_->getStage(current_stage_).power_to_complete;
|
||||
float old_balloon_speed = balloon_speed_;
|
||||
|
||||
// Comprueba si se ha de modificar la velocidad de los globos
|
||||
@@ -1013,7 +1019,7 @@ void Game::popBalloon(std::shared_ptr<Balloon> balloon)
|
||||
{
|
||||
destroyAllBalloons();
|
||||
power_ball_enabled_ = false;
|
||||
enemy_deploy_counter_ = 20;
|
||||
balloon_deploy_counter_ = 20;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1103,20 +1109,6 @@ void Game::destroyBalloon(std::shared_ptr<Balloon> &balloon)
|
||||
evaluateAndSetMenace();
|
||||
}
|
||||
|
||||
// Explosiona todos los globos
|
||||
void Game::popAllBalloons()
|
||||
{
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
if (balloon->canBePopped())
|
||||
{
|
||||
popBalloon(balloon);
|
||||
}
|
||||
}
|
||||
|
||||
JA_PlaySound(balloon_sound_);
|
||||
}
|
||||
|
||||
// Destruye todos los globos
|
||||
void Game::destroyAllBalloons()
|
||||
{
|
||||
@@ -1128,7 +1120,7 @@ void Game::destroyAllBalloons()
|
||||
}
|
||||
}
|
||||
|
||||
enemy_deploy_counter_ = 300;
|
||||
balloon_deploy_counter_ = 300;
|
||||
JA_PlaySound(power_ball_sound_);
|
||||
screen_->flash(flash_color, 5);
|
||||
screen_->shake();
|
||||
@@ -1160,22 +1152,6 @@ void Game::startAllBalloons()
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el número de globos activos
|
||||
int Game::countBalloons()
|
||||
{
|
||||
auto num = 0;
|
||||
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
if (balloon->isEnabled())
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
// Vacia del vector de globos los globos que ya no sirven
|
||||
void Game::freeBalloons()
|
||||
{
|
||||
@@ -1614,14 +1590,8 @@ void Game::killPlayer(std::shared_ptr<Player> &player)
|
||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||
void Game::evaluateAndSetMenace()
|
||||
{
|
||||
menace_current_ = 0;
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
if (balloon->isEnabled())
|
||||
{
|
||||
menace_current_ += balloon->getMenace();
|
||||
}
|
||||
}
|
||||
menace_current_ = std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
|
||||
{ return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
@@ -1672,11 +1642,11 @@ void Game::updateTimeStoppedCounter()
|
||||
}
|
||||
|
||||
// Actualiza la variable enemyDeployCounter
|
||||
void Game::updateEnemyDeployCounter()
|
||||
void Game::updateBalloonDeployCounter()
|
||||
{
|
||||
if (enemy_deploy_counter_ > 0)
|
||||
if (balloon_deploy_counter_ > 0)
|
||||
{
|
||||
enemy_deploy_counter_--;
|
||||
--balloon_deploy_counter_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1777,7 +1747,7 @@ void Game::update()
|
||||
|
||||
// Actualiza los contadores de estado y efectos
|
||||
updateTimeStoppedCounter();
|
||||
updateEnemyDeployCounter();
|
||||
updateBalloonDeployCounter();
|
||||
|
||||
// Actualiza el ayudante
|
||||
updateHelper();
|
||||
@@ -1888,7 +1858,7 @@ void Game::updateMenace()
|
||||
return;
|
||||
}
|
||||
|
||||
const auto stage = enemy_formations_->getStage(current_stage_);
|
||||
const auto stage = balloon_formations_->getStage(current_stage_);
|
||||
const float percent = current_power_ / stage.power_to_complete;
|
||||
const int difference = stage.max_menace - stage.min_menace;
|
||||
|
||||
@@ -1899,7 +1869,7 @@ void Game::updateMenace()
|
||||
if (menace_current_ < menace_threshold_)
|
||||
{
|
||||
// Crea una formación de enemigos
|
||||
deployEnemyFormation();
|
||||
deployBalloonFormation();
|
||||
|
||||
// Recalcula el nivel de amenaza con el nuevo globo
|
||||
evaluateAndSetMenace();
|
||||
@@ -2195,8 +2165,8 @@ void Game::renderMessages()
|
||||
// STAGE NUMBER
|
||||
if (stage_bitmap_counter_ < STAGE_COUNTER)
|
||||
{
|
||||
const auto stage_number = enemy_formations_->getStage(current_stage_).number;
|
||||
std::string text = "";
|
||||
const auto stage_number = balloon_formations_->getStage(current_stage_).number;
|
||||
std::string text;
|
||||
|
||||
if (stage_number == 10)
|
||||
{ // Ultima fase
|
||||
@@ -2275,28 +2245,14 @@ void Game::run()
|
||||
// Indica si se puede crear una powerball
|
||||
bool Game::canPowerBallBeCreated()
|
||||
{
|
||||
if ((!power_ball_enabled_) && (calculateScreenPower() > POWERBALL_SCREENPOWER_MINIMUM) && (power_ball_counter_ == 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return (!power_ball_enabled_) && (calculateScreenPower() > POWERBALL_SCREENPOWER_MINIMUM) && (power_ball_counter_ == 0);
|
||||
}
|
||||
|
||||
// Calcula el poder actual de los globos en pantalla
|
||||
int Game::calculateScreenPower()
|
||||
{
|
||||
auto power = 0;
|
||||
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
if (balloon->isEnabled())
|
||||
{
|
||||
power += balloon->getPower();
|
||||
}
|
||||
}
|
||||
|
||||
return power;
|
||||
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
|
||||
{ return sum + (balloon->isEnabled() ? balloon->getPower() : 0); });
|
||||
}
|
||||
|
||||
// Inicializa las variables que contienen puntos de ruta para mover objetos
|
||||
@@ -2315,22 +2271,19 @@ void Game::initPaths()
|
||||
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);
|
||||
|
||||
for (int i = 0; i < STAGE_COUNTER; ++i)
|
||||
for (int i = 0; i < first_part; ++i)
|
||||
{
|
||||
if (i < first_part)
|
||||
{
|
||||
stage_bitmap_path_[i] = (sin[(int)((i * 1.8f) + 90)] * (distance) + center_point);
|
||||
}
|
||||
stage_bitmap_path_[i] = (sin[(int)((i * 1.8f) + 90)] * (distance) + center_point);
|
||||
}
|
||||
|
||||
else if (i < second_part)
|
||||
{
|
||||
stage_bitmap_path_[i] = (int)center_point;
|
||||
}
|
||||
for (int i = first_part; i < second_part; ++i)
|
||||
{
|
||||
stage_bitmap_path_[i] = (int)center_point;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
stage_bitmap_path_[i] = (sin[(int)(((i - 149) * 1.8f) + 90)] * (center_point + 17) - 17);
|
||||
}
|
||||
for (int i = second_part; i < STAGE_COUNTER; ++i)
|
||||
{
|
||||
stage_bitmap_path_[i] = (sin[(int)(((i - 149) * 1.8f) + 90)] * (center_point + 17) - 17);
|
||||
}
|
||||
|
||||
// Letrero de GetReady
|
||||
@@ -2338,33 +2291,28 @@ void Game::initPaths()
|
||||
|
||||
const float start1 = param.game.play_area.rect.x - size;
|
||||
const float finish1 = param.game.play_area.center_x - (size / 2);
|
||||
|
||||
const float start2 = finish1;
|
||||
const float finish2 = param.game.play_area.rect.w;
|
||||
|
||||
const float distance1 = finish1 - start1;
|
||||
const float distance2 = finish2 - start2;
|
||||
const float distance2 = finish2 - finish1;
|
||||
|
||||
for (int i = 0; i < STAGE_COUNTER; ++i)
|
||||
for (int i = 0; i < first_part; ++i)
|
||||
{
|
||||
if (i < first_part)
|
||||
{
|
||||
get_ready_bitmap_path_[i] = sin[(int)(i * 1.8f)];
|
||||
get_ready_bitmap_path_[i] *= distance1;
|
||||
get_ready_bitmap_path_[i] -= size;
|
||||
}
|
||||
get_ready_bitmap_path_[i] = sin[(int)(i * 1.8f)];
|
||||
get_ready_bitmap_path_[i] *= distance1;
|
||||
get_ready_bitmap_path_[i] -= size;
|
||||
}
|
||||
|
||||
else if (i < second_part)
|
||||
{
|
||||
get_ready_bitmap_path_[i] = (int)finish1;
|
||||
}
|
||||
for (int i = first_part; i < second_part; ++i)
|
||||
{
|
||||
get_ready_bitmap_path_[i] = (int)finish1;
|
||||
}
|
||||
|
||||
else if (i < STAGE_COUNTER)
|
||||
{
|
||||
get_ready_bitmap_path_[i] = sin[(int)((i - second_part) * 1.8f)];
|
||||
get_ready_bitmap_path_[i] *= distance2;
|
||||
get_ready_bitmap_path_[i] += finish1;
|
||||
}
|
||||
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] *= distance2;
|
||||
get_ready_bitmap_path_[i] += finish1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2389,7 +2337,7 @@ void Game::updateHelper()
|
||||
// Solo ofrece ayuda cuando la amenaza es elevada
|
||||
if (menace_current_ > 15)
|
||||
{
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
helper_.need_coffee = (player->getCoffees() == 0);
|
||||
helper_.need_coffee_machine = (!player->isPowerUp());
|
||||
@@ -2405,7 +2353,7 @@ void Game::updateHelper()
|
||||
bool Game::allPlayersAreWaitingOrGameOver()
|
||||
{
|
||||
auto success = true;
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
success &= player->isWaiting() || player->isGameOver();
|
||||
}
|
||||
@@ -2417,7 +2365,7 @@ bool Game::allPlayersAreWaitingOrGameOver()
|
||||
bool Game::allPlayersAreGameOver()
|
||||
{
|
||||
auto success = true;
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
success &= player->isGameOver();
|
||||
}
|
||||
@@ -2429,7 +2377,7 @@ bool Game::allPlayersAreGameOver()
|
||||
bool Game::allPlayersAreNotPlaying()
|
||||
{
|
||||
auto success = true;
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
success &= !player->isPlaying();
|
||||
}
|
||||
@@ -2496,16 +2444,16 @@ void Game::checkEvents()
|
||||
case SDLK_2:
|
||||
{
|
||||
const auto set = 0;
|
||||
const auto stage = enemy_formations_->getStage(0);
|
||||
const auto numEnemies = stage.enemy_pool->set[set]->number_of_enemies;
|
||||
const auto stage = balloon_formations_->getStage(0);
|
||||
const auto numEnemies = stage.balloon_pool->set[set]->number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
createBalloon(stage.enemy_pool->set[set]->init[i].x,
|
||||
stage.enemy_pool->set[set]->init[i].y,
|
||||
stage.enemy_pool->set[set]->init[i].kind,
|
||||
stage.enemy_pool->set[set]->init[i].vel_x,
|
||||
createBalloon(stage.balloon_pool->set[set]->init[i].x,
|
||||
stage.balloon_pool->set[set]->init[i].y,
|
||||
stage.balloon_pool->set[set]->init[i].kind,
|
||||
stage.balloon_pool->set[set]->init[i].vel_x,
|
||||
balloon_speed_,
|
||||
stage.enemy_pool->set[set]->init[i].creation_counter);
|
||||
stage.balloon_pool->set[set]->init[i].creation_counter);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -2601,15 +2549,15 @@ void Game::reloadTextures()
|
||||
// Actualiza el marcador
|
||||
void Game::updateScoreboard()
|
||||
{
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
scoreboard_->setScore(player->getScoreBoardPanel(), player->getScore());
|
||||
scoreboard_->setMult(player->getScoreBoardPanel(), player->getScoreMultiplier());
|
||||
}
|
||||
|
||||
// Resto de marcador
|
||||
scoreboard_->setStage(enemy_formations_->getStage(current_stage_).number);
|
||||
scoreboard_->setPower((float)current_power_ / (float)enemy_formations_->getStage(current_stage_).power_to_complete);
|
||||
scoreboard_->setStage(balloon_formations_->getStage(current_stage_).number);
|
||||
scoreboard_->setPower((float)current_power_ / (float)balloon_formations_->getStage(current_stage_).power_to_complete);
|
||||
scoreboard_->setHiScore(hi_score_.score);
|
||||
scoreboard_->setHiScoreName(hi_score_.name);
|
||||
|
||||
@@ -2625,7 +2573,7 @@ void Game::pause(bool value)
|
||||
}
|
||||
|
||||
// Añade una puntuación a la tabla de records
|
||||
void Game::addScoreToScoreBoard(std::string name, int score)
|
||||
void Game::addScoreToScoreBoard(const std::string &name, int score)
|
||||
{
|
||||
const auto entry = (HiScoreEntry){trim(name), score};
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(&options.game.hi_score_table);
|
||||
@@ -2670,7 +2618,7 @@ void Game::checkPlayersStatusPlaying()
|
||||
// Obtiene un jugador a partir de su "id"
|
||||
std::shared_ptr<Player> Game::getPlayer(int id)
|
||||
{
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
if (player->getId() == id)
|
||||
{
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "section.h" // for SectionOptions
|
||||
#include "balloon.h" // for Balloon
|
||||
#include "player.h" // for Player
|
||||
#include "utils.h" // for DemoKeys, Color, HiScoreEntry
|
||||
#include <memory>
|
||||
#include "asset.h" // lines 11-11
|
||||
#include "background.h" // lines 12-12
|
||||
#include "balloon.h" // lines 13-13
|
||||
#include "bullet.h" // lines 14-14
|
||||
#include "enemy_formations.h" // lines 15-15
|
||||
#include "explosions.h" // lines 16-16
|
||||
#include "fade.h" // lines 17-17
|
||||
#include "input.h" // lines 18-18
|
||||
#include "item.h" // lines 19-19
|
||||
#include "player.h" // lines 20-20
|
||||
#include "scoreboard.h" // lines 21-21
|
||||
#include "screen.h" // lines 22-22
|
||||
#include "smart_sprite.h" // lines 23-23
|
||||
#include "text.h" // lines 24-24
|
||||
#include "texture.h" // lines 24-24
|
||||
enum class BulletType;
|
||||
struct JA_Music_t; // lines 26-26
|
||||
struct JA_Sound_t; // lines 27-27
|
||||
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; // lines 26-26
|
||||
struct JA_Music_t; // lines 27-27
|
||||
struct JA_Sound_t; // lines 28-28
|
||||
|
||||
// Modo demo
|
||||
constexpr bool GAME_MODE_DEMO_OFF = false;
|
||||
@@ -114,9 +112,9 @@ private:
|
||||
Input *input_; // Manejador de entrada
|
||||
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
|
||||
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<Explosions> explosions_; // Objeto para dibujar explosiones
|
||||
std::unique_ptr<EnemyFormations> enemy_formations_; // Objeto para gestionar las oleadas enemigas
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<Explosions> explosions_; // Objeto para dibujar explosiones
|
||||
std::unique_ptr<BalloonFormations> balloon_formations_; // Objeto para gestionar las oleadas enemigas
|
||||
|
||||
SDL_Texture *canvas_; // Textura para dibujar la zona de juego
|
||||
|
||||
@@ -186,10 +184,10 @@ private:
|
||||
int time_stopped_counter_; // Temporizador para llevar la cuenta del tiempo detenido
|
||||
int counter_; // Contador para el juego
|
||||
int balloons_popped_; // Lleva la cuenta de los globos explotados
|
||||
int last_enemy_deploy_; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||
int enemy_deploy_counter_; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
||||
int last_ballon_deploy_; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||
int balloon_deploy_counter_; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
||||
float balloon_speed_; // Velocidad a la que se mueven los enemigos
|
||||
float default_enemy_speed_; // Velocidad base de los enemigos, sin incrementar
|
||||
float default_balloon_speed_; // Velocidad base de los enemigos, sin incrementar
|
||||
Helper helper_; // Variable para gestionar las ayudas
|
||||
bool power_ball_enabled_; // Indica si hay una powerball ya activa
|
||||
int power_ball_counter_; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
||||
@@ -227,13 +225,13 @@ private:
|
||||
void unloadMedia();
|
||||
|
||||
// Carga el fichero de datos para la demo
|
||||
bool loadDemoFile(std::string file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA]);
|
||||
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(std::string file_path);
|
||||
bool saveDemoFile(const std::string &file_path);
|
||||
#endif
|
||||
// Crea una formación de enemigos
|
||||
void deployEnemyFormation();
|
||||
void deployBalloonFormation();
|
||||
|
||||
// Aumenta el poder de la fase
|
||||
void increaseStageCurrentPower(int power);
|
||||
@@ -277,9 +275,6 @@ private:
|
||||
// Explosiona un globo. Lo destruye
|
||||
void destroyBalloon(std::shared_ptr<Balloon> &balloon);
|
||||
|
||||
// Explosiona todos los globos
|
||||
void popAllBalloons();
|
||||
|
||||
// Destruye todos los globos
|
||||
void destroyAllBalloons();
|
||||
|
||||
@@ -289,9 +284,6 @@ private:
|
||||
// Pone en marcha todos los globos
|
||||
void startAllBalloons();
|
||||
|
||||
// Obtiene el número de globos activos
|
||||
int countBalloons();
|
||||
|
||||
// Vacia el vector de globos
|
||||
void freeBalloons();
|
||||
|
||||
@@ -368,7 +360,7 @@ private:
|
||||
void incTimeStoppedCounter(int value);
|
||||
|
||||
// Actualiza la variable EnemyDeployCounter
|
||||
void updateEnemyDeployCounter();
|
||||
void updateBalloonDeployCounter();
|
||||
|
||||
// Actualiza y comprueba el valor de la variable
|
||||
void updateTimeStoppedCounter();
|
||||
@@ -437,7 +429,7 @@ private:
|
||||
void checkMusicStatus();
|
||||
|
||||
// Añade una puntuación a la tabla de records
|
||||
void addScoreToScoreBoard(std::string name, int score);
|
||||
void addScoreToScoreBoard(const std::string &name, int score);
|
||||
|
||||
// Saca del estado de GAME OVER al jugador si el otro está activo
|
||||
void checkAndUpdatePlayerStatus(int active_player_index, int inactive_player_index);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "game_logo.h"
|
||||
#include <SDL2/SDL_render.h> // for SDL_FLIP_HORIZONTAL
|
||||
#include <algorithm> // for max
|
||||
#include <string> // for basic_string
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "asset.h" // for Asset
|
||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound
|
||||
@@ -13,25 +13,24 @@
|
||||
|
||||
// Constructor
|
||||
GameLogo::GameLogo(int x, int y)
|
||||
: x_(x), y_(y)
|
||||
: dust_texture_(std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"))),
|
||||
coffee_texture_(std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"))),
|
||||
crisis_texture_(std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png"))),
|
||||
arcade_edition_texture_(std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"))),
|
||||
|
||||
dust_left_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Asset::get()->get("title_dust.ani"))),
|
||||
dust_right_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Asset::get()->get("title_dust.ani"))),
|
||||
|
||||
coffee_sprite_(std::make_unique<SmartSprite>(coffee_texture_)),
|
||||
crisis_sprite_(std::make_unique<SmartSprite>(crisis_texture_)),
|
||||
|
||||
arcade_edition_sprite_(std::make_unique<Sprite>((param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight(), arcade_edition_texture_)),
|
||||
|
||||
crash_sound_(JA_LoadSound(Asset::get()->get("title.wav").c_str())),
|
||||
|
||||
x_(x),
|
||||
y_(y)
|
||||
{
|
||||
// Crea los objetos
|
||||
dust_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"));
|
||||
coffee_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"));
|
||||
crisis_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png"));
|
||||
arcade_edition_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"));
|
||||
|
||||
coffee_sprite_ = std::make_unique<SmartSprite>(coffee_texture_);
|
||||
crisis_sprite_ = std::make_unique<SmartSprite>(crisis_texture_);
|
||||
|
||||
arcade_edition_sprite_ = std::make_unique<Sprite>((param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight(), arcade_edition_texture_);
|
||||
|
||||
dust_left_sprite_ = std::make_unique<AnimatedSprite>(dust_texture_, Asset::get()->get("title_dust.ani"));
|
||||
dust_right_sprite_ = std::make_unique<AnimatedSprite>(dust_texture_, Asset::get()->get("title_dust.ani"));
|
||||
|
||||
// Sonidos
|
||||
crash_sound_ = JA_LoadSound(Asset::get()->get("title.wav").c_str());
|
||||
|
||||
// Inicializa las variables
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -1,25 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <memory>
|
||||
#include "texture.h"
|
||||
#include "animated_sprite.h"
|
||||
#include "smart_sprite.h"
|
||||
#include "sprite.h"
|
||||
|
||||
struct JA_Sound_t;
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
class AnimatedSprite;
|
||||
class SmartSprite;
|
||||
class Sprite;
|
||||
class Texture;
|
||||
struct JA_Sound_t; // lines 10-10
|
||||
|
||||
// Clase GameLogo
|
||||
class GameLogo
|
||||
{
|
||||
private:
|
||||
enum class Status
|
||||
{
|
||||
DISABLED,
|
||||
MOVING,
|
||||
SHAKING,
|
||||
FINISHED,
|
||||
};
|
||||
|
||||
struct Shake
|
||||
{
|
||||
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
||||
int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
||||
int counter; // Contador para el retraso
|
||||
int lenght; // Cantidad de desplazamientos a realizar
|
||||
int remaining; // Cantidad de desplazamientos pendientes a realizar
|
||||
int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
std::shared_ptr<Texture> dust_texture_; // Textura con los graficos del polvo
|
||||
std::shared_ptr<Texture> coffee_texture_; // Textura con los graficos de la palabra "COFFEE"
|
||||
std::shared_ptr<Texture> crisis_texture_; // Textura con los graficos de la plabra "CRISIS"
|
||||
std::shared_ptr<Texture> dust_texture_; // Textura con los graficos del polvo
|
||||
std::shared_ptr<Texture> coffee_texture_; // Textura con los graficos de la palabra "COFFEE"
|
||||
std::shared_ptr<Texture> crisis_texture_; // Textura con los graficos de la plabra "CRISIS"
|
||||
std::shared_ptr<Texture> arcade_edition_texture_; // Textura con los graficos de "Arcade Edition"
|
||||
|
||||
std::unique_ptr<AnimatedSprite> dust_left_sprite_; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||
std::unique_ptr<AnimatedSprite> dust_left_sprite_; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||
std::unique_ptr<AnimatedSprite> dust_right_sprite_; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||
|
||||
std::unique_ptr<SmartSprite> coffee_sprite_; // Sprite con la palabra "COFFEE" para la pantalla de titulo
|
||||
@@ -33,23 +49,8 @@ private:
|
||||
int x_; // Posición donde dibujar el logo
|
||||
int y_; // Posición donde dibujar el logo
|
||||
|
||||
enum class Status
|
||||
{
|
||||
DISABLED,
|
||||
MOVING,
|
||||
SHAKING,
|
||||
FINISHED,
|
||||
} status_; // Estado en el que se encuentra la clase
|
||||
|
||||
struct Shake
|
||||
{
|
||||
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
||||
int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
||||
int counter; // Contador para el retraso
|
||||
int lenght; // Cantidad de desplazamientos a realizar
|
||||
int remaining; // Cantidad de desplazamientos pendientes a realizar
|
||||
int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento
|
||||
} shake_; // Estructura para generar el efecto de agitación
|
||||
Status status_; // Estado en el que se encuentra la clase
|
||||
Shake shake_; // Estructura para generar el efecto de agitación
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "hiscore_table.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_QUIT
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
|
||||
@@ -7,15 +8,17 @@
|
||||
#include <vector> // for vector
|
||||
#include "asset.h" // for Asset
|
||||
#include "background.h" // for Background
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
#include "fade.h" // for Fade, FadeMode, FadeType
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
|
||||
#include "lang.h" // for getText
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_SHADOW, TEXT_COLOR
|
||||
#include "utils.h" // for Param, ParamGame, HiScoreEntry
|
||||
#include "section.h" // for Name, name, Options, options
|
||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_SHADOW, TEXT...
|
||||
#include "utils.h" // for Param, ParamGame, Color, HiScoreEntry
|
||||
|
||||
// Constructor
|
||||
HiScoreTable::HiScoreTable(JA_Music_t *music)
|
||||
@@ -129,7 +132,7 @@ void HiScoreTable::fillTexture()
|
||||
const auto score = format(options.game.hi_score_table[i].score);
|
||||
const auto score_lenght = score.size();
|
||||
const auto num_dots = 25 - name_lenght - score_lenght;
|
||||
std::string dots = "";
|
||||
std::string dots;
|
||||
for (int j = 0; j < (int)num_dots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
@@ -255,7 +258,7 @@ std::string HiScoreTable::format(int number)
|
||||
const std::string score = std::to_string(number);
|
||||
|
||||
auto index = (int)score.size() - 1;
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
auto i = 0;
|
||||
while (index >= 0)
|
||||
{
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16, Uint32
|
||||
#include <memory>
|
||||
#include <string> // for string
|
||||
#include "fade.h"
|
||||
#include "section.h" // for SectionOptions
|
||||
#include "background.h"
|
||||
#include "text.h"
|
||||
|
||||
struct JA_Music_t;
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16, Uint32, Uint8
|
||||
#include <memory> // for unique_ptr
|
||||
#include <string> // for string
|
||||
class Background; // lines 8-8
|
||||
class Fade; // lines 9-9
|
||||
class Text; // lines 10-10
|
||||
enum class FadeMode : Uint8; // lines 11-11
|
||||
struct JA_Music_t; // lines 12-12
|
||||
|
||||
/*
|
||||
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
Input *Input::input_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto input con esta función estática
|
||||
void Input::init(std::string game_controller_db_path)
|
||||
void Input::init(const std::string &game_controller_db_path)
|
||||
{
|
||||
Input::input_ = new Input(game_controller_db_path);
|
||||
}
|
||||
@@ -27,12 +27,10 @@ Input *Input::get()
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Input::Input(std::string game_controller_db_path)
|
||||
: game_controller_db_path_(game_controller_db_path)
|
||||
Input::Input(const std::string &game_controller_db_path)
|
||||
: game_controller_db_path_(game_controller_db_path),
|
||||
enabled_(true)
|
||||
{
|
||||
// Inicializa variables
|
||||
enabled_ = true;
|
||||
|
||||
// Busca si hay mandos conectados
|
||||
discoverGameControllers();
|
||||
|
||||
@@ -434,12 +432,11 @@ bool Input::discoverGameControllers()
|
||||
for (int i = 0; i < num_gamepads_; i++)
|
||||
{
|
||||
// Abre el mando y lo añade a la lista
|
||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||
auto pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
{
|
||||
connected_controllers_.push_back(pad);
|
||||
const std::string separator(" #");
|
||||
std::string name = SDL_GameControllerNameForIndex(i);
|
||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||
#ifdef VERBOSE
|
||||
{
|
||||
std::cout << name << std::endl;
|
||||
@@ -528,7 +525,7 @@ SDL_GameControllerButton Input::getControllerBinding(int controller_index, Input
|
||||
}
|
||||
|
||||
// Obtiene el indice a partir del nombre del mando
|
||||
int Input::getIndexByName(std::string name) const
|
||||
int Input::getIndexByName(const std::string &name) const
|
||||
{
|
||||
for (int i = 0; i < num_gamepads_; ++i)
|
||||
{
|
||||
@@ -572,7 +569,7 @@ std::string Input::to_string(InputType input) const
|
||||
}
|
||||
|
||||
// Convierte un std::string a InputType
|
||||
InputType Input::to_inputs_e(std::string name) const
|
||||
InputType Input::to_inputs_e(const std::string &name) const
|
||||
{
|
||||
if (name == "input_fire_left")
|
||||
{
|
||||
@@ -602,16 +599,6 @@ InputType Input::to_inputs_e(std::string name) const
|
||||
return InputType::NONE;
|
||||
}
|
||||
|
||||
// Activa todos los inputs. Sirve para evitar inputs sin repeticiones pero que ya vienen pulsados cuando checkInput no estaba monitorizando
|
||||
/*void Input::allActive(int controller_index)
|
||||
{
|
||||
for (int i = 0; i < (int)button_inputs_.size(); ++i)
|
||||
{
|
||||
controller_bindings_[controller_index][i].active = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Comprueba el eje del mando
|
||||
bool Input::checkAxisInput(InputType input, int controller_index) const
|
||||
{
|
||||
|
||||
@@ -91,14 +91,14 @@ private:
|
||||
bool checkAxisInput(InputType input, int controller_index = 0) const;
|
||||
|
||||
// Constructor
|
||||
Input(std::string game_controller_db_path);
|
||||
explicit Input(const std::string &game_controller_db_path);
|
||||
|
||||
// Destructor
|
||||
~Input() = default;
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
static void init(std::string game_controller_db_path);
|
||||
static void init(const std::string &game_controller_db_path);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
static void destroy();
|
||||
@@ -150,11 +150,8 @@ public:
|
||||
std::string to_string(InputType input) const;
|
||||
|
||||
// Convierte un std::string a InputType
|
||||
InputType to_inputs_e(std::string name) const;
|
||||
InputType to_inputs_e(const std::string &name) const;
|
||||
|
||||
// Obtiene el indice a partir del nombre del mando
|
||||
int getIndexByName(std::string name) const;
|
||||
|
||||
// Activa todos los inputs. Sirve para evitar inputs sin repeticiones pero que ya vienen pulsados cuando checkInput no estaba monitorizando
|
||||
//void allActive(int index);
|
||||
int getIndexByName(const std::string &name) const;
|
||||
};
|
||||
@@ -1,25 +1,26 @@
|
||||
#include "instructions.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_QUIT
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
|
||||
#include <algorithm> // for max
|
||||
#include <string> // for basic_string
|
||||
#include <utility> // for move
|
||||
#include "asset.h" // for Asset
|
||||
#include "fade.h" // for Fade, FadeType::FULLSCREEN, FadeMode::IN
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
#include "fade.h" // for Fade, FadeMode, FadeType
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
|
||||
#include "lang.h" // for getText
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for name, SectionName, options, SectionOptions
|
||||
#include "section.h" // for Name, name, Options, options
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR, TEXT_SHADOW
|
||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR, TEXT_...
|
||||
#include "texture.h" // for Texture
|
||||
#include "tiled_bg.h" // for Tiledbg, TILED_MODE_STATIC
|
||||
#include "utils.h" // for Param, ParamGame, Color, shdwT...
|
||||
struct JA_Music_t;
|
||||
#include "utils.h" // for Param, ParamGame, Color, shdw_txt_color
|
||||
struct JA_Music_t; // lines 22-22
|
||||
|
||||
// Constructor
|
||||
Instructions::Instructions(JA_Music_t *music)
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
#include "fade.h"
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "texture.h"
|
||||
#include "tiled_bg.h"
|
||||
struct JA_Music_t;
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
#include <vector> // for vector
|
||||
class Fade;
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
class Tiledbg;
|
||||
struct JA_Music_t; // lines 14-14
|
||||
|
||||
/*
|
||||
Esta clase gestiona un estado del programa. Se encarga de poner en pantalla
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "intro.h"
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
|
||||
#include <string> // for basic_string
|
||||
#include "asset.h" // for Asset
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic
|
||||
#include "lang.h" // for getText
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for name, SectionName, options, SectionOptions
|
||||
#include "smart_sprite.h" // for SmartSprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for ParamGame, Param, Zone, BLOCK
|
||||
#include "writer.h" // for Writer
|
||||
struct JA_Music_t;
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_QUIT, SDL...
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
|
||||
#include <utility> // for move
|
||||
#include "asset.h" // for Asset
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic
|
||||
#include "lang.h" // for getText
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for Name, name, Options, options
|
||||
#include "smart_sprite.h" // for SmartSprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for Param, ParamGame, Zone, BLOCK, Color
|
||||
#include "writer.h" // for Writer
|
||||
struct JA_Music_t; // lines 19-19
|
||||
|
||||
// Constructor
|
||||
Intro::Intro(JA_Music_t *music)
|
||||
@@ -408,12 +408,12 @@ void Intro::render()
|
||||
Screen::get()->clean(bg_color);
|
||||
|
||||
// Dibuja los objetos
|
||||
for (auto &bitmap : bitmaps_)
|
||||
for (const auto &bitmap : bitmaps_)
|
||||
{
|
||||
bitmap->render();
|
||||
}
|
||||
|
||||
for (auto &text : texts_)
|
||||
for (const auto &text : texts_)
|
||||
{
|
||||
text->render();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
#include "smart_sprite.h"
|
||||
#include "texture.h"
|
||||
#include "text.h"
|
||||
#include "writer.h"
|
||||
struct JA_Music_t;
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
#include <vector> // for vector
|
||||
#include "smart_sprite.h" // for SmartSprite
|
||||
#include "writer.h" // for Writer
|
||||
class Text;
|
||||
class Texture;
|
||||
struct JA_Music_t; // lines 11-11
|
||||
|
||||
/*
|
||||
Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia
|
||||
|
||||
@@ -6,15 +6,14 @@ class Texture;
|
||||
|
||||
// Constructor
|
||||
Item::Item(int kind, float x, float y, SDL_Rect *play_area, std::shared_ptr<Texture> texture, std::vector<std::string> *animation)
|
||||
: kind_(kind), play_area_(play_area)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, "", animation)),
|
||||
accel_x_(0.0f),
|
||||
floor_collision_(false),
|
||||
kind_(kind),
|
||||
enabled_(true),
|
||||
play_area_(play_area),
|
||||
time_to_live_(600)
|
||||
{
|
||||
sprite_ = std::make_unique<AnimatedSprite>(texture, "", animation);
|
||||
|
||||
enabled_ = true;
|
||||
time_to_live_ = 600;
|
||||
accel_x_ = 0.0f;
|
||||
floor_collision_ = false;
|
||||
|
||||
if (kind == ITEM_COFFEE_MACHINE)
|
||||
{
|
||||
width_ = 28;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
#include "utils.h" // for Circle
|
||||
#include "animated_sprite.h"
|
||||
#include "texture.h"
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "utils.h" // for Circle
|
||||
class Texture;
|
||||
|
||||
// Tipos de objetos
|
||||
constexpr int ITEM_POINTS_1_DISK = 1;
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
#include "logo.h"
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
|
||||
#include <string> // for basic_string
|
||||
#include "asset.h" // for Asset
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_StopMusic
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for name, SectionName, options, SectionOptions
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_QUIT, SDL...
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
|
||||
#include <utility> // for move
|
||||
#include "asset.h" // for Asset
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_StopMusic
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for Name, name, Options, options
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Logo::Logo()
|
||||
@@ -114,12 +115,12 @@ void Logo::updateJAILGAMES()
|
||||
{
|
||||
for (int i = 0; i < (int)jail_sprite_.size(); ++i)
|
||||
{
|
||||
if (jail_sprite_[i]->getPosX() != dest_.x)
|
||||
if (jail_sprite_[i]->getIntPosX() != dest_.x)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
jail_sprite_[i]->incPosX(-SPEED);
|
||||
if (jail_sprite_[i]->getPosX() < dest_.x)
|
||||
if (jail_sprite_[i]->getIntPosX() < dest_.x)
|
||||
{
|
||||
jail_sprite_[i]->setPosX(dest_.x);
|
||||
}
|
||||
@@ -127,7 +128,7 @@ void Logo::updateJAILGAMES()
|
||||
else
|
||||
{
|
||||
jail_sprite_[i]->incPosX(SPEED);
|
||||
if (jail_sprite_[i]->getPosX() > dest_.x)
|
||||
if (jail_sprite_[i]->getIntPosX() > dest_.x)
|
||||
{
|
||||
jail_sprite_[i]->setPosX(dest_.x);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
#include "utils.h" // for Color
|
||||
#include "sprite.h"
|
||||
#include "texture.h"
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
#include <vector> // for vector
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "utils.h" // for Color
|
||||
class Texture;
|
||||
|
||||
/*
|
||||
Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
|
||||
|
||||
@@ -7,25 +7,22 @@ Actualizando a la versión "Arcade Edition" en 08/05/2024
|
||||
|
||||
*/
|
||||
|
||||
#include <iostream> // for basic_ostream, char_traits, operator<<, cout
|
||||
#include <string> // for basic_string, operator<<, string
|
||||
#include <iostream> // for char_traits, basic_ostream, operator<<, cout
|
||||
#include <memory> // for make_unique, unique_ptr
|
||||
#include "director.h" // for Director
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::cout << "Game start" << std::endl;
|
||||
std::cout << "Game start" << std::endl;
|
||||
|
||||
// Crea el objeto Director
|
||||
Director *director = new Director(argc, argv);
|
||||
// Crea el objeto Director
|
||||
auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv));
|
||||
|
||||
// Bucle principal
|
||||
const auto exit = director->run();
|
||||
// Bucle principal
|
||||
const auto exit = director->run();
|
||||
|
||||
// Destruye el objeto Director
|
||||
delete director;
|
||||
const auto endType = exit == 0 ? "keyboard" : "controller";
|
||||
std::cout << "\nGame end with " << endType << std::endl;
|
||||
|
||||
const auto endType = exit == 0 ? "keyboard" : "controller";
|
||||
std::cout << "\nGame end with " << endType << std::endl;
|
||||
|
||||
return exit;
|
||||
return exit;
|
||||
}
|
||||
|
||||
@@ -50,25 +50,25 @@ void ManageHiScoreTable::sort()
|
||||
{
|
||||
struct
|
||||
{
|
||||
bool operator()(HiScoreEntry a, HiScoreEntry b) const { return a.score > b.score; }
|
||||
bool operator()(const HiScoreEntry &a, const HiScoreEntry &b) const { return a.score > b.score; }
|
||||
} custom_less;
|
||||
|
||||
std::sort(table_->begin(), table_->end(), custom_less);
|
||||
}
|
||||
|
||||
// Carga la tabla con los datos de un fichero
|
||||
bool ManageHiScoreTable::loadFromFile(std::string file_path)
|
||||
bool ManageHiScoreTable::loadFromFile(const std::string &file_path)
|
||||
{
|
||||
clear();
|
||||
|
||||
auto success = true;
|
||||
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
|
||||
|
||||
if (file)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Reading file: " << filename.c_str() << std::endl;
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << file_name.c_str() << std::endl;
|
||||
#endif
|
||||
for (int i = 0; i < (int)table_->size(); ++i)
|
||||
{
|
||||
@@ -86,7 +86,7 @@ bool ManageHiScoreTable::loadFromFile(std::string file_path)
|
||||
break;
|
||||
}
|
||||
|
||||
char *name = (char *)malloc(nameSize + 1);
|
||||
char *name = static_cast<char *>(malloc(nameSize + 1));
|
||||
if (SDL_RWread(file, name, sizeof(char) * nameSize, 1) == 0)
|
||||
{
|
||||
success = false;
|
||||
@@ -113,10 +113,12 @@ bool ManageHiScoreTable::loadFromFile(std::string file_path)
|
||||
}
|
||||
|
||||
// Guarda la tabla en un fichero
|
||||
bool ManageHiScoreTable::saveToFile(std::string file_path)
|
||||
bool ManageHiScoreTable::saveToFile(const std::string &file_path)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
#endif
|
||||
auto success = true;
|
||||
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
||||
|
||||
if (file)
|
||||
@@ -131,7 +133,7 @@ bool ManageHiScoreTable::saveToFile(std::string file_path)
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Writing file: " << fileName.c_str() << std::endl;
|
||||
std::cout << "Writing file: " << file_name.c_str() << std::endl;
|
||||
#endif
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
@@ -139,7 +141,7 @@ bool ManageHiScoreTable::saveToFile(std::string file_path)
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Error: Unable to save " << fileName.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||
std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||
#endif
|
||||
}
|
||||
return success;
|
||||
|
||||
@@ -36,8 +36,8 @@ public:
|
||||
void add(HiScoreEntry entry);
|
||||
|
||||
// Carga la tabla con los datos de un fichero
|
||||
bool loadFromFile(std::string file_path);
|
||||
bool loadFromFile(const std::string &file_path);
|
||||
|
||||
// Guarda la tabla en un fichero
|
||||
bool saveToFile(std::string file_path);
|
||||
bool saveToFile(const std::string &file_path);
|
||||
};
|
||||
@@ -9,12 +9,12 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float vx, float vy, f
|
||||
vx_(vx),
|
||||
vy_(vy),
|
||||
ax_(ax),
|
||||
ay_(ay)
|
||||
ay_(ay),
|
||||
zoom_w_(1),
|
||||
zoom_h_(1),
|
||||
counter_(0),
|
||||
flip_(SDL_FLIP_NONE)
|
||||
{
|
||||
// Establece el zoom W,H del sprite
|
||||
zoom_w_ = 1;
|
||||
zoom_h_ = 1;
|
||||
|
||||
// Establece los valores de rotacion
|
||||
rotate_.enabled = false;
|
||||
rotate_.speed = 0;
|
||||
@@ -22,14 +22,7 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float vx, float vy, f
|
||||
rotate_.amount = 0.0f;
|
||||
rotate_.center = nullptr;
|
||||
|
||||
// Contador interno
|
||||
counter_ = 0;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
sprite_clip_ = (SDL_Rect){0, 0, w, h};
|
||||
|
||||
// Establece el tipo de volteado
|
||||
flip_ = SDL_FLIP_NONE;
|
||||
};
|
||||
|
||||
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16
|
||||
#include <memory>
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h"
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16
|
||||
#include <memory> // for shared_ptr
|
||||
#include "sprite.h" // for Sprite
|
||||
class Texture;
|
||||
|
||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||
class MovingSprite : public Sprite
|
||||
@@ -41,6 +41,9 @@ public:
|
||||
explicit MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, std::shared_ptr<Texture> texture = nullptr);
|
||||
explicit MovingSprite(std::shared_ptr<Texture> texture = nullptr);
|
||||
|
||||
// Destructor
|
||||
virtual ~MovingSprite() = default;
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
|
||||
|
||||
@@ -1,31 +1,27 @@
|
||||
#include "notify.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <string> // for basic_string, char_traits, string
|
||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||
#include "options.h" // for options
|
||||
#include "param.h"
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <string> // for string
|
||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||
#include "param.h" // for param
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile)
|
||||
: renderer(renderer)
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, const std::string &soundFile)
|
||||
: renderer(renderer),
|
||||
text(std::make_unique<Text>(bitmapFile, textFile, renderer)),
|
||||
bgColor(param.notification.color),
|
||||
waitTime(150),
|
||||
stack(false),
|
||||
sound(JA_LoadSound(soundFile.c_str()))
|
||||
{
|
||||
// Inicializa variables
|
||||
bgColor = param.notification.color;
|
||||
waitTime = 150;
|
||||
stack = false;
|
||||
hasIcons = iconFile == "" ? false : true;
|
||||
hasIcons = !iconFile.empty();
|
||||
|
||||
// Crea objetos
|
||||
if (hasIcons)
|
||||
{
|
||||
iconTexture = std::make_unique<Texture>(renderer, iconFile);
|
||||
}
|
||||
text = std::make_unique<Text>(bitmapFile, textFile, renderer);
|
||||
sound = JA_LoadSound(soundFile.c_str());
|
||||
iconTexture = hasIcons ? std::make_unique<Texture>(renderer, iconFile) : nullptr;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -150,18 +146,19 @@ void Notify::clearFinishedNotifications()
|
||||
void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
{
|
||||
// Cuenta el número de textos a mostrar
|
||||
const int numTexts = (text1 != "") + (text2 != "");
|
||||
const int numTexts = !text1.empty() + !text2.empty();
|
||||
|
||||
// Si no hay texto, acaba
|
||||
if (numTexts == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Si solo hay un texto, lo coloca en la primera variable
|
||||
else if (numTexts == 1)
|
||||
if (numTexts == 1)
|
||||
{
|
||||
text1 = text1 + text2;
|
||||
text2 = "";
|
||||
text1 += text2;
|
||||
text2.clear();
|
||||
}
|
||||
|
||||
// Si las notificaciones no se apilan, elimina las anteriores
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <string> // for basic_string, string
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
#include "utils.h" // for Color
|
||||
#include "text.h"
|
||||
#include "texture.h"
|
||||
#include "sprite.h"
|
||||
struct JA_Sound_t;
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for Color
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
struct JA_Sound_t; // lines 12-12
|
||||
|
||||
class Notify
|
||||
{
|
||||
@@ -65,9 +65,9 @@ private:
|
||||
Color bgColor; // Color de fondo de las notificaciones
|
||||
int waitTime; // Tiempo que se ve la notificación
|
||||
std::vector<Notification> notifications; // La lista de notificaciones activas
|
||||
JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación
|
||||
bool stack; // Indica si las notificaciones se apilan
|
||||
bool hasIcons; // Indica si el notificador tiene textura para iconos
|
||||
JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void clearFinishedNotifications();
|
||||
@@ -77,7 +77,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile);
|
||||
Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, const std::string &soundFile);
|
||||
|
||||
// Destructor
|
||||
~Notify();
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
void update();
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void showText(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||
void showText(std::string text1 = std::string(), std::string text2 = std::string(), int icon = -1);
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool active();
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
#include "on_screen_help.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <memory> // for make_unique, unique_ptr
|
||||
#include <string> // for basic_string
|
||||
#include "asset.h" // for Asset
|
||||
#include "lang.h" // for getText
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for easeInOutSine, ParamGame, Param
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <memory> // for make_unique, make_shared, unique_ptr
|
||||
#include "asset.h" // for Asset
|
||||
#include "lang.h" // for getText
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for easeInOutSine, Param, ParamGame
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
OnScreenHelp *OnScreenHelp::onScreenHelp = nullptr;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
#include "sprite.h" // lines 10-10
|
||||
#include "text.h"
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||
#include <vector> // for vector
|
||||
class Sprite;
|
||||
class Text;
|
||||
|
||||
enum class OnScreenHelpStatus
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
Options options;
|
||||
|
||||
// Declaraciones
|
||||
bool setOptions(std::string var, std::string value);
|
||||
bool setOptions(const std::string &var, const std::string &value);
|
||||
|
||||
// Inicializa las opciones del programa
|
||||
void initOptions()
|
||||
@@ -86,7 +86,9 @@ bool loadOptionsFile(std::string file_path)
|
||||
bool success = true;
|
||||
|
||||
// Variables para manejar el fichero
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
#endif
|
||||
std::ifstream file(file_path);
|
||||
|
||||
// Si el fichero se puede abrir
|
||||
@@ -150,7 +152,9 @@ bool loadOptionsFile(std::string file_path)
|
||||
// Guarda el fichero de configuración
|
||||
bool saveOptionsFile(std::string file_path)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
#endif
|
||||
std::ofstream file(file_path);
|
||||
|
||||
if (!file.good())
|
||||
@@ -240,10 +244,10 @@ bool saveOptionsFile(std::string file_path)
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setOptions(std::string var, std::string value)
|
||||
bool setOptions(const std::string &var, const std::string &value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
auto success = true;
|
||||
|
||||
// Opciones de video
|
||||
if (var == "video.mode")
|
||||
@@ -389,7 +393,7 @@ bool setOptions(std::string var, std::string value)
|
||||
}
|
||||
|
||||
// Lineas vacias o que empiezan por comentario
|
||||
else if (var == "" || var.substr(0, 1) == "#")
|
||||
else if (var.empty() || var.starts_with("#"))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
#include "param.h"
|
||||
#include <fstream> // for char_traits, basic_ostream, basic_ifstream, basi...
|
||||
#include <iostream> // for cout
|
||||
#include "utils.h" // for Param, ParamGame, Zone, ParamBalloon
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include "utils.h" // for Param, ParamGame, Zone, ParamBalloon
|
||||
|
||||
Param param;
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setParams(std::string var, std::string value);
|
||||
bool setParams(const std::string &var, const std::string &value);
|
||||
|
||||
// Calcula variables a partir de otras variables
|
||||
void precalculateZones();
|
||||
@@ -40,7 +43,7 @@ void initParam()
|
||||
param.title.title_c_c_position = 11;
|
||||
|
||||
// BACKGROUND
|
||||
param.background.attenuate_color = {255, 255, 255};
|
||||
param.background.attenuate_color = (Color){255, 255, 255};
|
||||
param.background.attenuate_alpha = 32;
|
||||
|
||||
// BALLOONS
|
||||
@@ -52,16 +55,24 @@ void initParam()
|
||||
param.balloon_3.grav = 0.10f;
|
||||
param.balloon_4.vel = 4.95f;
|
||||
param.balloon_4.grav = 0.10f;
|
||||
|
||||
// NOTIFICATION
|
||||
param.notification.pos_v = NotifyPosition::TOP;
|
||||
param.notification.pos_h = NotifyPosition::LEFT;
|
||||
param.notification.sound = false;
|
||||
param.notification.color.r = 48;
|
||||
param.notification.color.g = 48;
|
||||
param.notification.color.b = 48;
|
||||
}
|
||||
|
||||
// Establece valores para los parametros a partir de un fichero de texto
|
||||
void loadParamsFromFile(std::string filePath)
|
||||
/*void loadParamsFromFile(std::string file_path)
|
||||
{
|
||||
// Pone valores por defecto a las variables
|
||||
initParam();
|
||||
|
||||
// Variables para manejar el fichero
|
||||
std::ifstream file(filePath);
|
||||
std::ifstream file(file_path);
|
||||
std::string line;
|
||||
std::string param1;
|
||||
std::string param2;
|
||||
@@ -70,18 +81,25 @@ void loadParamsFromFile(std::string filePath)
|
||||
if (file.good())
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << filename << std::endl;
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << file_name << std::endl;
|
||||
#endif
|
||||
// Procesa cada linea del fichero
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Reinicia variables
|
||||
param1 = "";
|
||||
param2 = "";
|
||||
param1.clear();
|
||||
param2.clear();
|
||||
|
||||
// Elimina los comentarios
|
||||
line = line.substr(0, line.find("#"));
|
||||
// Elimina los comentarios al final de una linea
|
||||
{
|
||||
// line = line.substr(0, line.find("#"));
|
||||
auto pos = line.find("#");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
line.resize(pos);
|
||||
}
|
||||
}
|
||||
|
||||
// Ignora los espacios en blanco
|
||||
int pos = 0;
|
||||
@@ -145,17 +163,61 @@ void loadParamsFromFile(std::string filePath)
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
else
|
||||
std::cout << "Failed to load file: " << filePath << std::endl;
|
||||
std::cout << "Failed to load file: " << file_path << std::endl;
|
||||
#endif
|
||||
|
||||
precalculateZones();
|
||||
}*/
|
||||
void loadParamsFromFile(const std::string &file_path)
|
||||
{
|
||||
// Inicializa los parámetros con valores por defecto
|
||||
initParam();
|
||||
|
||||
// Abre el archivo
|
||||
std::ifstream file(file_path);
|
||||
if (!file.is_open())
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cerr << "Error: No se pudo abrir el archivo " << file_path << std::endl;
|
||||
#endif
|
||||
throw std::runtime_error("No se pudo abrir el archivo: " + file_path);
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << file_name << std::endl;
|
||||
#endif
|
||||
|
||||
std::string line, param1, param2;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Elimina comentarios
|
||||
auto comment_pos = line.find('#');
|
||||
if (comment_pos != std::string::npos)
|
||||
{
|
||||
line.resize(comment_pos);
|
||||
}
|
||||
|
||||
// Usa un stream para separar palabras
|
||||
std::istringstream iss(line);
|
||||
if (iss >> param1 >> param2)
|
||||
{
|
||||
setParams(param1, param2);
|
||||
}
|
||||
}
|
||||
|
||||
// Cierra el archivo
|
||||
file.close();
|
||||
|
||||
// Realiza cálculos adicionales después de cargar los parámetros
|
||||
precalculateZones();
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setParams(std::string var, std::string value)
|
||||
bool setParams(const std::string &var, const std::string &value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
auto success = true;
|
||||
|
||||
// GAME
|
||||
if (var == "game.width")
|
||||
|
||||
@@ -6,4 +6,4 @@ struct Param;
|
||||
extern Param param;
|
||||
|
||||
// Establece valores para los parametros a partir de un fichero de texto
|
||||
void loadParamsFromFile(std::string file_path);
|
||||
void loadParamsFromFile(const std::string &file_path);
|
||||
@@ -12,30 +12,29 @@
|
||||
|
||||
// Constructor
|
||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vector<std::shared_ptr<Texture>> texture, std::vector<std::vector<std::string> *> animations)
|
||||
: player_sprite_(std::make_unique<AnimatedSprite>(texture[0], "", animations[0])),
|
||||
power_sprite_(std::make_unique<AnimatedSprite>(texture[1], "", animations[1])),
|
||||
enter_name_(std::make_unique<EnterName>()),
|
||||
play_area_(play_area),
|
||||
id_(id),
|
||||
pos_x_(x),
|
||||
pos_y_(y),
|
||||
default_pos_x_(x),
|
||||
default_pos_y_(y),
|
||||
status_playing_(PlayerStatus::WAITING),
|
||||
scoreboard_panel_(0),
|
||||
name_(std::string()),
|
||||
controller_index_(0),
|
||||
demo_(demo)
|
||||
{
|
||||
// Reserva memoria para los objetos
|
||||
player_sprite_ = std::make_unique<AnimatedSprite>(texture[0], "", animations[0]);
|
||||
power_sprite_ = std::make_unique<AnimatedSprite>(texture[1], "", animations[1]);
|
||||
power_sprite_->getTexture()->setAlpha(224);
|
||||
enter_name_ = std::make_unique<EnterName>();
|
||||
|
||||
// Rectangulo con la zona de juego
|
||||
play_area_ = play_area;
|
||||
|
||||
// Establece la posición inicial del jugador
|
||||
default_pos_x_ = pos_x_ = x;
|
||||
default_pos_y_ = pos_y_ = y;
|
||||
|
||||
// Establece los offsets para el sprite de PowerUp
|
||||
power_up_desp_x_ = (power_sprite_->getWidth() - player_sprite_->getWidth()) / 2;
|
||||
power_sprite_->setPosY(y - (power_sprite_->getHeight() - player_sprite_->getHeight()));
|
||||
|
||||
// Inicializa variables
|
||||
id_ = id;
|
||||
demo_ = demo;
|
||||
status_playing_ = PlayerStatus::WAITING;
|
||||
scoreboard_panel_ = 0;
|
||||
name_ = "";
|
||||
setRecordName(enter_name_->getName());
|
||||
init();
|
||||
}
|
||||
@@ -237,21 +236,13 @@ void Player::render()
|
||||
// Establece el estado del jugador cuando camina
|
||||
void Player::setWalkingStatus(PlayerStatus status)
|
||||
{
|
||||
// Si cambiamos de estado, reiniciamos la animación
|
||||
if (status_walking_ != status)
|
||||
{
|
||||
status_walking_ = status;
|
||||
}
|
||||
status_walking_ = status;
|
||||
}
|
||||
|
||||
// Establece el estado del jugador cuando dispara
|
||||
void Player::setFiringStatus(PlayerStatus status)
|
||||
{
|
||||
// Si cambiamos de estado, reiniciamos la animación
|
||||
if (status_firing_ != status)
|
||||
{
|
||||
status_firing_ = status;
|
||||
}
|
||||
status_firing_ = status;
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
@@ -694,7 +685,7 @@ void Player::shiftColliders()
|
||||
}
|
||||
|
||||
// Pone las texturas del jugador
|
||||
void Player::setPlayerTextures(std::vector<std::shared_ptr<Texture>> texture)
|
||||
void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture)
|
||||
{
|
||||
player_sprite_->setTexture(texture[0]);
|
||||
power_sprite_->setTexture(texture[1]);
|
||||
@@ -736,7 +727,7 @@ int Player::getScoreBoardPanel() const
|
||||
void Player::decContinueCounter()
|
||||
{
|
||||
continue_ticks_ = SDL_GetTicks();
|
||||
continue_counter_--;
|
||||
--continue_counter_;
|
||||
if (continue_counter_ < 0)
|
||||
{
|
||||
setStatusPlaying(PlayerStatus::GAME_OVER);
|
||||
@@ -744,13 +735,13 @@ void Player::decContinueCounter()
|
||||
}
|
||||
|
||||
// Establece el nombre del jugador
|
||||
void Player::setName(std::string name)
|
||||
void Player::setName(const std::string &name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
// Establece el nombre del jugador para la tabla de mejores puntuaciones
|
||||
void Player::setRecordName(std::string record_name)
|
||||
void Player::setRecordName(const std::string &record_name)
|
||||
{
|
||||
record_name_ = record_name.substr(0, 8);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for unique_ptr
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "enter_name.h" // for EnterName
|
||||
#include "utils.h" // for Circle
|
||||
#include "texture.h" // lines 12-12
|
||||
enum class ScoreboardMode;
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "enter_name.h" // for EnterName
|
||||
#include "utils.h" // for Circle
|
||||
class Texture;
|
||||
enum class InputType : int;
|
||||
enum class ScoreboardMode; // lines 12-12
|
||||
|
||||
// Estados del jugador
|
||||
enum class PlayerStatus
|
||||
@@ -118,7 +119,7 @@ public:
|
||||
void render();
|
||||
|
||||
// Pone las texturas del jugador
|
||||
void setPlayerTextures(std::vector<std::shared_ptr<Texture>> texture);
|
||||
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture);
|
||||
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void setInput(InputType input);
|
||||
@@ -271,10 +272,10 @@ public:
|
||||
void decContinueCounter();
|
||||
|
||||
// Establece el nombre del jugador
|
||||
void setName(std::string name);
|
||||
void setName(const std::string &name);
|
||||
|
||||
// Establece el nombre del jugador para la tabla de mejores puntuaciones
|
||||
void setRecordName(std::string record_name);
|
||||
void setRecordName(const std::string &record_name);
|
||||
|
||||
// Obtiene el nombre del jugador
|
||||
std::string getName() const;
|
||||
|
||||
@@ -34,42 +34,39 @@ Scoreboard *Scoreboard::get()
|
||||
|
||||
// Constructor
|
||||
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
||||
: renderer_(renderer)
|
||||
: renderer_(renderer),
|
||||
|
||||
game_power_meter_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_power_meter.png"))),
|
||||
power_meter_sprite_(std::make_unique<Sprite>(game_power_meter_texture_)),
|
||||
text_scoreboard_(std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer)),
|
||||
|
||||
stage_(1),
|
||||
hi_score_(0),
|
||||
power_(0),
|
||||
hi_score_name_(std::string()),
|
||||
color_({0, 0, 0}),
|
||||
rect_({0, 0, 320, 40}),
|
||||
ticks_(SDL_GetTicks()),
|
||||
counter_(0)
|
||||
{
|
||||
// Inicializa punteros
|
||||
game_power_meter_texture_ = nullptr;
|
||||
power_meter_sprite_ = nullptr;
|
||||
text_scoreboard_ = nullptr;
|
||||
|
||||
// Inicializa variables
|
||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||
{
|
||||
name_[i] = "";
|
||||
record_name_[i] = "";
|
||||
name_[i].clear();
|
||||
record_name_[i].clear();
|
||||
selector_pos_[i] = 0;
|
||||
score_[i] = 0;
|
||||
mult_[i] = 0;
|
||||
continue_counter_[i] = 0;
|
||||
}
|
||||
stage_ = 1;
|
||||
hi_score_ = 0;
|
||||
power_ = 0;
|
||||
hi_score_name_ = "";
|
||||
color_ = {0, 0, 0};
|
||||
rect_ = {0, 0, 320, 40};
|
||||
|
||||
panel_[SCOREBOARD_LEFT_PANEL].mode = ScoreboardMode::SCORE;
|
||||
panel_[SCOREBOARD_RIGHT_PANEL].mode = ScoreboardMode::SCORE;
|
||||
panel_[SCOREBOARD_CENTER_PANEL].mode = ScoreboardMode::STAGE_INFO;
|
||||
ticks_ = SDL_GetTicks();
|
||||
counter_ = 0;
|
||||
|
||||
// Recalcula las anclas de los elementos
|
||||
recalculateAnchors();
|
||||
|
||||
// Crea objetos
|
||||
game_power_meter_texture_ = std::make_shared<Texture>(renderer_, Asset::get()->get("game_power_meter.png"));
|
||||
power_meter_sprite_ = std::make_unique<Sprite>(slot4_2_.x - 20, slot4_2_.y, 40, 7, game_power_meter_texture_);
|
||||
text_scoreboard_ = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer_);
|
||||
power_meter_sprite_->setPos({slot4_2_.x - 20, slot4_2_.y, 40, 7});
|
||||
|
||||
// Crea la textura de fondo
|
||||
background_ = nullptr;
|
||||
@@ -130,13 +127,13 @@ void Scoreboard::render()
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setName(int panel_, std::string name_)
|
||||
void Scoreboard::setName(int panel_, const std::string &name_)
|
||||
{
|
||||
this->name_[panel_] = name_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setRecordName(int panel_, std::string record_name_)
|
||||
void Scoreboard::setRecordName(int panel_, const std::string &record_name_)
|
||||
{
|
||||
this->record_name_[panel_] = record_name_;
|
||||
}
|
||||
@@ -184,7 +181,7 @@ void Scoreboard::setPower(float power_)
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setHiScoreName(std::string name_)
|
||||
void Scoreboard::setHiScoreName(const std::string &name_)
|
||||
{
|
||||
hi_score_name_ = name_;
|
||||
}
|
||||
@@ -323,7 +320,7 @@ void Scoreboard::fillPanelTextures()
|
||||
|
||||
// ENTER NAME
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(106));
|
||||
SDL_Rect rect_ = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
|
||||
SDL_Rect rect = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
|
||||
SDL_SetRenderDrawColor(renderer_, 0xFF, 0xFF, 0xEB, 255);
|
||||
for (int j = 0; j < (int)record_name_[i].size(); ++j)
|
||||
{
|
||||
@@ -331,16 +328,16 @@ void Scoreboard::fillPanelTextures()
|
||||
{ // La letra seleccionada se pinta de forma intermitente
|
||||
if (counter_ % 3 > 0)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer_, rect_.x, rect_.y + rect_.h, rect_.x + rect_.w, rect_.y + rect_.h);
|
||||
text_scoreboard_->write(rect_.x, rect_.y, record_name_[i].substr(j, 1));
|
||||
SDL_RenderDrawLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
||||
text_scoreboard_->write(rect.x, rect.y, record_name_[i].substr(j, 1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_RenderDrawLine(renderer_, rect_.x, rect_.y + rect_.h, rect_.x + rect_.w, rect_.y + rect_.h);
|
||||
text_scoreboard_->write(rect_.x, rect_.y, record_name_[i].substr(j, 1));
|
||||
SDL_RenderDrawLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
||||
text_scoreboard_->write(rect.x, rect.y, record_name_[i].substr(j, 1));
|
||||
}
|
||||
rect_.x += 7;
|
||||
rect.x += 7;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for unique_ptr
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for Color
|
||||
#include "sprite.h" // lines 11-11
|
||||
#include "text.h" // lines 12-12
|
||||
#include "texture.h" // lines 13-13
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for Color
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
|
||||
// Defines
|
||||
constexpr int SCOREBOARD_LEFT_PANEL = 0;
|
||||
@@ -50,9 +50,9 @@ private:
|
||||
|
||||
std::shared_ptr<Texture> game_power_meter_texture_; // Textura con el marcador de poder de la fase
|
||||
std::unique_ptr<Sprite> power_meter_sprite_; // Sprite para el medidor de poder de la fase
|
||||
std::unique_ptr<Text> text_scoreboard_; // Fuente para el marcador del juego
|
||||
std::unique_ptr<Text> text_scoreboard_; // Fuente para el marcador del juego
|
||||
|
||||
SDL_Texture *background_; // Textura para dibujar el marcador
|
||||
SDL_Texture *background_; // Textura para dibujar el marcador
|
||||
std::vector<SDL_Texture *> panel_texture_; // Texturas para dibujar cada panel
|
||||
|
||||
// Variables
|
||||
@@ -103,7 +103,7 @@ private:
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados
|
||||
|
||||
// Constructor
|
||||
Scoreboard(SDL_Renderer *renderer);
|
||||
explicit Scoreboard(SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Scoreboard();
|
||||
@@ -125,10 +125,10 @@ public:
|
||||
void render();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setName(int panel, std::string name);
|
||||
void setName(int panel, const std::string &name);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRecordName(int panel, std::string record_name);
|
||||
void setRecordName(int panel, const std::string &record_name);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSelectorPos(int panel, int pos);
|
||||
@@ -152,7 +152,7 @@ public:
|
||||
void setPower(float power);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setHiScoreName(std::string name);
|
||||
void setHiScoreName(const std::string &name);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setColor(Color color);
|
||||
|
||||
@@ -44,12 +44,27 @@ Screen *Screen::get()
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
: window_(window), renderer_(renderer)
|
||||
: window_(window),
|
||||
renderer_(renderer),
|
||||
|
||||
notify_(std::make_unique<Notify>(renderer_, std::string(), Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Asset::get()->get("notify.wav"))),
|
||||
game_canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
shader_canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
|
||||
src_rect_({0, 0, param.game.width, param.game.height}),
|
||||
dst_rect_({0, 0, param.game.width, param.game.height}),
|
||||
border_color_({0x00, 0x00, 0x00}),
|
||||
attenuate_effect_(false),
|
||||
fps_ticks_(0),
|
||||
fps_counter_(0),
|
||||
fps_(0),
|
||||
#ifdef DEBUG
|
||||
show_info_(true)
|
||||
#else
|
||||
show_info_(false)
|
||||
#endif
|
||||
{
|
||||
// Inicializa variables
|
||||
src_rect_ = {0, 0, param.game.width, param.game.height};
|
||||
dst_rect_ = {0, 0, param.game.width, param.game.height};
|
||||
border_color_ = {0, 0, 0};
|
||||
flash_effect_.enabled = false;
|
||||
flash_effect_.counter = 0;
|
||||
flash_effect_.lenght = 0;
|
||||
@@ -62,29 +77,10 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
shake_effect_.remaining = 0;
|
||||
shake_effect_.originalPos = 0;
|
||||
shake_effect_.originalWidth = param.game.width;
|
||||
attenuate_effect_ = false;
|
||||
fps_ticks_ = 0;
|
||||
fps_counter_ = 0;
|
||||
fps_ = 0;
|
||||
#ifdef DEBUG
|
||||
show_info_ = true;
|
||||
#else
|
||||
show_info_ = false;
|
||||
#endif
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
info_resolution_ = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
||||
|
||||
// Crea los objetos
|
||||
notify_ = std::make_unique<Notify>(renderer_, "", Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Asset::get()->get("notify_.wav"));
|
||||
|
||||
// Define el color del borde para el modo de pantalla completa
|
||||
border_color_ = {0x00, 0x00, 0x00};
|
||||
|
||||
// Crea las textura donde se dibujan los graficos del juego
|
||||
game_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
shader_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options.video.mode);
|
||||
|
||||
@@ -183,9 +179,10 @@ void Screen::blit()
|
||||
// Establece el modo de video
|
||||
void Screen::setVideoMode(ScreenVideoMode videoMode)
|
||||
{
|
||||
options.video.mode = videoMode;
|
||||
#ifdef ARCADE
|
||||
options.video.mode = ScreenVideoMode::WINDOW;
|
||||
#else
|
||||
options.video.mode = videoMode;
|
||||
#endif
|
||||
|
||||
switch (options.video.mode)
|
||||
@@ -455,7 +452,7 @@ void Screen::attenuate(bool value)
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
||||
void Screen::showNotification(const std::string &text1, const std::string &text2, int icon)
|
||||
{
|
||||
notify_->showText(text1, text2, icon);
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public:
|
||||
void attenuate(bool value);
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||
void showNotification(const std::string &text1 = std::string(), const std::string &text2 = std::string(), int icon = -1);
|
||||
|
||||
// Indica si hay alguna notificación activa en pantalla
|
||||
bool notificationsAreActive() const;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "texture.h"
|
||||
#include <memory>
|
||||
#include <memory> // for shared_ptr
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
class Texture;
|
||||
|
||||
// Clase SmartSprite
|
||||
class SmartSprite : public AnimatedSprite
|
||||
|
||||
@@ -21,13 +21,13 @@ void Sprite::render()
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosX() const
|
||||
int Sprite::getIntPosX() const
|
||||
{
|
||||
return pos_.x;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosY() const
|
||||
int Sprite::getIntPosY() const
|
||||
{
|
||||
return pos_.y;
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ public:
|
||||
explicit Sprite(std::shared_ptr<Texture> texture = nullptr);
|
||||
|
||||
// Destructor
|
||||
~Sprite() = default;
|
||||
virtual ~Sprite() = default;
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
virtual void render();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosX() const;
|
||||
int getPosY() const;
|
||||
int getIntPosX() const;
|
||||
int getIntPosY() const;
|
||||
int getWidth() const;
|
||||
int getHeight() const;
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "text.h"
|
||||
#include <fstream> // for char_traits, basic_ostream, basic_ifstream, ope...
|
||||
#include <iostream> // for cout
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for Color
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
|
||||
#include <iostream> // for cout
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for Color
|
||||
|
||||
// Llena una estructuta TextFile desde un fichero
|
||||
TextFile LoadTextFile(std::string file_path)
|
||||
@@ -21,7 +22,9 @@ TextFile LoadTextFile(std::string file_path)
|
||||
}
|
||||
|
||||
// Abre el fichero para leer los valores
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1).c_str();
|
||||
#endif
|
||||
std::ifstream file(file_path);
|
||||
|
||||
if (file.is_open() && file.good())
|
||||
@@ -55,7 +58,7 @@ TextFile LoadTextFile(std::string file_path)
|
||||
|
||||
// Cierra el fichero
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Text loaded: " << file_name.c_str() << std::endl;
|
||||
std::cout << "Text loaded: " << file_name << std::endl;
|
||||
#endif
|
||||
file.close();
|
||||
}
|
||||
@@ -64,7 +67,7 @@ TextFile LoadTextFile(std::string file_path)
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
||||
std::cout << "Warning: Unable to open " << file_name << " file" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -79,7 +82,7 @@ TextFile LoadTextFile(std::string file_path)
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Text::Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer)
|
||||
Text::Text(const std::string &bitmap_file, const std::string &text_file, SDL_Renderer *renderer)
|
||||
{
|
||||
// Carga los offsets desde el fichero
|
||||
auto tf = LoadTextFile(text_file);
|
||||
@@ -103,7 +106,7 @@ Text::Text(std::string bitmap_file, std::string text_file, SDL_Renderer *rendere
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Text::Text(std::string text_file, std::shared_ptr<Texture> texture)
|
||||
Text::Text(const std::string &text_file, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
// Carga los offsets desde el fichero
|
||||
auto tf = LoadTextFile(text_file);
|
||||
@@ -146,7 +149,7 @@ Text::Text(TextFile *text_file, std::shared_ptr<Texture> texture)
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
|
||||
{
|
||||
auto shift = 0;
|
||||
|
||||
@@ -169,7 +172,7 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
}
|
||||
|
||||
// Escribe el texto con colores
|
||||
void Text::writeColored(int x, int y, std::string text, Color color, int kerning, int lenght)
|
||||
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght)
|
||||
{
|
||||
sprite_->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x, y, text, kerning, lenght);
|
||||
@@ -177,7 +180,7 @@ void Text::writeColored(int x, int y, std::string text, Color color, int kerning
|
||||
}
|
||||
|
||||
// Escribe el texto con sombra
|
||||
void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shadow_distance, int kerning, int lenght)
|
||||
void Text::writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance, int kerning, int lenght)
|
||||
{
|
||||
sprite_->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x + shadow_distance, y + shadow_distance, text, kerning, lenght);
|
||||
@@ -186,14 +189,14 @@ void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shad
|
||||
}
|
||||
|
||||
// Escribe el texto centrado en un punto x
|
||||
void Text::writeCentered(int x, int y, std::string text, int kerning, int lenght)
|
||||
void Text::writeCentered(int x, int y, const std::string &text, int kerning, int lenght)
|
||||
{
|
||||
x -= (Text::lenght(text, kerning) / 2);
|
||||
write(x, y, text, kerning, lenght);
|
||||
}
|
||||
|
||||
// Escribe texto con extras
|
||||
void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght)
|
||||
void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght)
|
||||
{
|
||||
const auto centered = ((flags & TEXT_CENTER) == TEXT_CENTER);
|
||||
const auto shadowed = ((flags & TEXT_SHADOW) == TEXT_SHADOW);
|
||||
@@ -235,7 +238,7 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Col
|
||||
}
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
int Text::lenght(std::string text, int kerning) const
|
||||
int Text::lenght(const std::string &text, int kerning) const
|
||||
{
|
||||
auto shift = 0;
|
||||
|
||||
@@ -267,7 +270,7 @@ void Text::setFixedWidth(bool value)
|
||||
}
|
||||
|
||||
// Carga una paleta de colores para el texto
|
||||
void Text::addPalette(std::string path)
|
||||
void Text::addPalette(const std::string &path)
|
||||
{
|
||||
texture_->addPalette(path);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <string> // for string
|
||||
#include <memory>
|
||||
#include "utils.h"
|
||||
#include "sprite.h"
|
||||
#include "texture.h"
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "utils.h" // for Color
|
||||
class Texture;
|
||||
|
||||
constexpr int TEXT_COLOR = 1;
|
||||
constexpr int TEXT_SHADOW = 2;
|
||||
@@ -33,41 +33,41 @@ class Text
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::unique_ptr<Sprite> sprite_; // Objeto con los graficos para el texto
|
||||
std::unique_ptr<Sprite> sprite_; // Objeto con los graficos para el texto
|
||||
std::shared_ptr<Texture> texture_; // Textura con los bitmaps del texto
|
||||
|
||||
// Variables
|
||||
int box_width_; // Anchura de la caja de cada caracter en el png
|
||||
int box_height_; // Altura de la caja de cada caracter en el png
|
||||
bool fixed_width_; // Indica si el texto se ha de escribir con longitud fija en todas las letras
|
||||
int box_width_; // Anchura de la caja de cada caracter en el png
|
||||
int box_height_; // Altura de la caja de cada caracter en el png
|
||||
bool fixed_width_; // Indica si el texto se ha de escribir con longitud fija en todas las letras
|
||||
TextOffset offset_[128]; // Vector con las posiciones y ancho de cada letra
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer);
|
||||
Text(std::string text_file, std::shared_ptr<Texture> texture);
|
||||
Text(const std::string &bitmap_file, const std::string &text_file, SDL_Renderer *renderer);
|
||||
Text(const std::string &text_file, std::shared_ptr<Texture> texture);
|
||||
Text(TextFile *text_file, std::shared_ptr<Texture> texture);
|
||||
|
||||
// Destructor
|
||||
~Text() = default;
|
||||
|
||||
// Escribe el texto en pantalla
|
||||
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto con colores
|
||||
void writeColored(int x, int y, std::string text, Color color, int kerning = 1, int lenght = -1);
|
||||
void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto con sombra
|
||||
void writeShadowed(int x, int y, std::string text, Color color, Uint8 shadow_distance = 1, int kerning = 1, int lenght = -1);
|
||||
void writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance = 1, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto centrado en un punto x
|
||||
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
void writeCentered(int x, int y, const std::string &text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe texto con extras
|
||||
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, Color textColor = {255, 255, 255}, Uint8 shadow_distance = 1, Color shadow_color = {0, 0, 0}, int lenght = -1);
|
||||
void writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning = 1, Color textColor = Color(), Uint8 shadow_distance = 1, Color shadow_color = Color(), int lenght = -1);
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
int lenght(std::string text, int kerning = 1) const;
|
||||
int lenght(const std::string &text, int kerning = 1) const;
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
int getCharacterSize() const;
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
void setFixedWidth(bool value);
|
||||
|
||||
// Carga una paleta de colores para el texto
|
||||
void addPalette(std::string path);
|
||||
void addPalette(const std::string &path);
|
||||
|
||||
// Establece una paleta de colores para el texto
|
||||
void setPalette(int index);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "stb_image.h" // for stbi_failure_reason, stbi_image_free
|
||||
|
||||
// Constructor
|
||||
Texture::Texture(SDL_Renderer *renderer, std::string path)
|
||||
Texture::Texture(SDL_Renderer *renderer, const std::string &path)
|
||||
: renderer_(renderer), path_(path)
|
||||
{
|
||||
// Inicializa
|
||||
@@ -23,7 +23,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path)
|
||||
palettes_.clear();
|
||||
|
||||
// Carga el fichero en la textura
|
||||
if (path_ != "")
|
||||
if (!path_.empty())
|
||||
{
|
||||
// Obtiene la extensión
|
||||
const std::string extension = path_.substr(path_.find_last_of(".") + 1);
|
||||
@@ -37,8 +37,8 @@ Texture::Texture(SDL_Renderer *renderer, std::string path)
|
||||
// .gif
|
||||
else if (extension == "gif")
|
||||
{
|
||||
surface_ = loadSurface(path_.c_str());
|
||||
addPalette(path_.c_str());
|
||||
surface_ = loadSurface(path_);
|
||||
addPalette(path_);
|
||||
setPaletteColor(0, 0, 0x00000000);
|
||||
createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
|
||||
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
|
||||
@@ -54,13 +54,12 @@ Texture::~Texture()
|
||||
}
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool Texture::loadFromFile(std::string path)
|
||||
bool Texture::loadFromFile(const std::string &path)
|
||||
{
|
||||
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
||||
int req_format = STBI_rgb_alpha;
|
||||
int width, height, orig_format;
|
||||
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
||||
if (data == nullptr)
|
||||
if (!data)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Loading image failed: " << stbi_failure_reason() << std::endl;
|
||||
@@ -70,19 +69,20 @@ bool Texture::loadFromFile(std::string path)
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Image loaded: " << file_name.c_str() << std::endl;
|
||||
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
||||
std::cout << "Image loaded: " << file_name << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
int depth, pitch;
|
||||
Uint32 pixel_format;
|
||||
if (req_format == STBI_rgb)
|
||||
/*if (req_format == STBI_rgb)
|
||||
{
|
||||
depth = 24;
|
||||
pitch = 3 * width; // 3 bytes por pixel * pixels por linea
|
||||
pixel_format = SDL_PIXELFORMAT_RGB24;
|
||||
}
|
||||
else
|
||||
else*/
|
||||
{ // STBI_rgb_alpha (RGBA)
|
||||
depth = 32;
|
||||
pitch = 4 * width;
|
||||
@@ -96,11 +96,11 @@ bool Texture::loadFromFile(std::string path)
|
||||
SDL_Texture *newTexture = nullptr;
|
||||
|
||||
// Carga la imagen desde una ruta específica
|
||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
||||
auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void *>(data), width, height, depth, pitch, pixel_format);
|
||||
if (loadedSurface == nullptr)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Unable to load image " << path.c_str() << std::endl;
|
||||
std::cout << "Unable to load image " << path << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -110,7 +110,7 @@ bool Texture::loadFromFile(std::string path)
|
||||
if (newTexture == nullptr)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << std::endl;
|
||||
std::cout << "Unable to create texture from " << path << "! SDL Error: " << SDL_GetError() << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -137,9 +137,9 @@ bool Texture::createBlank(int width, int height, SDL_PixelFormatEnum format, SDL
|
||||
texture_ = SDL_CreateTexture(renderer_, format, access, width, height);
|
||||
if (!texture_)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -239,14 +239,14 @@ SDL_Texture *Texture::getSDLTexture()
|
||||
}
|
||||
|
||||
// Crea una nueva surface
|
||||
Surface Texture::newSurface(int w, int h)
|
||||
/*Surface Texture::newSurface(int w, int h)
|
||||
{
|
||||
Surface surf = (Surface)malloc(sizeof(surface_s));
|
||||
Surface surf = static_cast<Surface>(malloc(sizeof(surface_s)));
|
||||
surf->w = w;
|
||||
surf->h = h;
|
||||
surf->data = (Uint8 *)malloc(w * h);
|
||||
surf->data = static_cast<Uint8 *>(malloc(w * h));
|
||||
return surf;
|
||||
}
|
||||
}*/
|
||||
|
||||
// Elimina una surface
|
||||
void Texture::deleteSurface(Surface surface)
|
||||
@@ -265,29 +265,29 @@ void Texture::deleteSurface(Surface surface)
|
||||
}
|
||||
|
||||
// Crea una surface desde un fichero .gif
|
||||
Surface Texture::loadSurface(const char *file_name)
|
||||
Surface Texture::loadSurface(const std::string &file_name)
|
||||
{
|
||||
FILE *f = fopen(file_name, "rb");
|
||||
FILE *f = fopen(file_name.c_str(), "rb");
|
||||
if (!f)
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
Uint8 *buffer = (Uint8 *)malloc(size);
|
||||
Uint8 *buffer = static_cast<Uint8 *>(malloc(size));
|
||||
fread(buffer, size, 1, f);
|
||||
fclose(f);
|
||||
|
||||
Uint16 w, h;
|
||||
Uint8 *pixels = LoadGif(buffer, &w, &h);
|
||||
if (pixels == NULL)
|
||||
if (pixels == nullptr)
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Surface surface = (Surface)malloc(sizeof(surface_s));
|
||||
Surface surface = static_cast<Surface>(malloc(sizeof(surface_s)));
|
||||
surface->w = w;
|
||||
surface->h = h;
|
||||
surface->data = pixels;
|
||||
@@ -312,7 +312,7 @@ void Texture::flipSurface()
|
||||
// Vuelca los datos
|
||||
Uint32 *pixels;
|
||||
int pitch;
|
||||
SDL_LockTexture(texture_, nullptr, (void **)&pixels, &pitch);
|
||||
SDL_LockTexture(texture_, nullptr, reinterpret_cast<void **>(&pixels), &pitch);
|
||||
for (int i = 0; i < width_ * height_; ++i)
|
||||
{
|
||||
pixels[i] = palettes_[paletteIndex_][surface_->data[i]];
|
||||
@@ -327,11 +327,11 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color)
|
||||
}
|
||||
|
||||
// Carga una paleta desde un fichero
|
||||
std::vector<Uint32> Texture::loadPal(const char *file_name)
|
||||
std::vector<Uint32> Texture::loadPal(const std::string &file_name)
|
||||
{
|
||||
std::vector<Uint32> palette;
|
||||
|
||||
FILE *f = fopen(file_name, "rb");
|
||||
FILE *f = fopen(file_name.c_str(), "rb");
|
||||
if (!f)
|
||||
{
|
||||
return palette;
|
||||
@@ -340,12 +340,12 @@ std::vector<Uint32> Texture::loadPal(const char *file_name)
|
||||
fseek(f, 0, SEEK_END);
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
Uint8 *buffer = (Uint8 *)malloc(size);
|
||||
Uint8 *buffer = static_cast<Uint8 *>(malloc(size));
|
||||
fread(buffer, size, 1, f);
|
||||
fclose(f);
|
||||
|
||||
Uint32 *pal = LoadPalette(buffer);
|
||||
if (pal == nullptr)
|
||||
const auto *pal = LoadPalette(buffer);
|
||||
if (!pal)
|
||||
{
|
||||
return palette;
|
||||
}
|
||||
@@ -361,9 +361,9 @@ std::vector<Uint32> Texture::loadPal(const char *file_name)
|
||||
}
|
||||
|
||||
// Añade una paleta a la lista
|
||||
void Texture::addPalette(std::string path)
|
||||
void Texture::addPalette(const std::string &path)
|
||||
{
|
||||
palettes_.push_back(loadPal(path.c_str()));
|
||||
palettes_.push_back(loadPal(path));
|
||||
setPaletteColor((int)palettes_.size() - 1, 0, 0x00000000);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,29 +33,29 @@ private:
|
||||
int paletteIndex_; // Indice de la paleta en uso
|
||||
|
||||
// Crea una nueva surface
|
||||
Surface newSurface(int w, int h);
|
||||
//Surface newSurface(int w, int h);
|
||||
|
||||
// Elimina una surface
|
||||
void deleteSurface(Surface surface);
|
||||
|
||||
// Crea una surface desde un fichero .gif
|
||||
Surface loadSurface(const char *file_name);
|
||||
Surface loadSurface(const std::string &file_name);
|
||||
|
||||
// Vuelca la surface en la textura
|
||||
void flipSurface();
|
||||
|
||||
// Carga una paleta desde un fichero
|
||||
std::vector<Uint32> loadPal(const char *file_name);
|
||||
std::vector<Uint32> loadPal(const std::string &file_name);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit Texture(SDL_Renderer *renderer, std::string path = "");
|
||||
explicit Texture(SDL_Renderer *renderer, const std::string &path = std::string());
|
||||
|
||||
// Destructor
|
||||
~Texture();
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool loadFromFile(std::string path);
|
||||
bool loadFromFile(const std::string &path);
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool createBlank(int width, int height, SDL_PixelFormatEnum format = SDL_PIXELFORMAT_RGBA8888, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
SDL_Texture *getSDLTexture();
|
||||
|
||||
// Añade una paleta a la lista
|
||||
void addPalette(std::string path);
|
||||
void addPalette(const std::string &path);
|
||||
|
||||
// Establece un color de la paleta
|
||||
void setPaletteColor(int palette, int index, Uint32 color);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include "tiled_bg.h"
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_stdinc.h> // for SDL_sinf
|
||||
#include <stdlib.h> // for rand
|
||||
#include "screen.h" // for Screen
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_stdinc.h> // for SDL_sinf
|
||||
#include <stdlib.h> // for rand
|
||||
#include <memory> // for unique_ptr, make_shared, make_unique
|
||||
#include "screen.h" // for Screen
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Tiledbg::Tiledbg(std::string texture_path, SDL_Rect pos, int mode)
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
#include "title.h"
|
||||
#include <SDL2/SDL_keycode.h> // for SDLK_1, SDLK_2, SDLK_3
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <string> // for allocator, basic_string, char_traits
|
||||
#include <vector> // for vector
|
||||
#include "asset.h" // for Asset
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
#include "input.h" // for Input, inputs_e, INPUT_DO_NOT_ALLOW_RE...
|
||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_P...
|
||||
#include "lang.h" // for getText
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for SectionOptions, options, SectionName, name
|
||||
|
||||
struct JA_Music_t;
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||
#include <SDL2/SDL_keycode.h> // for SDLK_1, SDLK_2, SDLK_3
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <string> // for char_traits, operator+, to_string, bas...
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
#include "asset.h" // for Asset
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input, InputType, INPUT_DO_NOT_ALLOW_R...
|
||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_P...
|
||||
#include "lang.h" // for getText
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for Options, options, Name, name
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for Param, OptionsController, Color, Param...
|
||||
struct JA_Music_t; // lines 17-17
|
||||
|
||||
// Constructor
|
||||
Title::Title(JA_Music_t *music)
|
||||
@@ -315,9 +319,9 @@ void Title::resetCounter()
|
||||
// Intercambia la asignación de mandos a los jugadores
|
||||
void Title::swapControllers()
|
||||
{
|
||||
const int num_controllers_ = input_->getNumControllers();
|
||||
const auto num_controllers = input_->getNumControllers();
|
||||
|
||||
if (num_controllers_ == 0)
|
||||
if (num_controllers == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -330,7 +334,7 @@ void Title::swapControllers()
|
||||
int playerControllerIndex[MAX_CONTROLLERS];
|
||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||
{
|
||||
text[i] = "";
|
||||
text[i].clear();
|
||||
playerControllerIndex[i] = -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory>
|
||||
#include "define_buttons.h"
|
||||
#include "fade.h"
|
||||
#include "game_logo.h"
|
||||
#include "text.h"
|
||||
#include "tiled_bg.h"
|
||||
#include "utils.h" // for Section
|
||||
#include "sprite.h"
|
||||
#include "texture.h"
|
||||
#include "section.h"
|
||||
|
||||
class Asset;
|
||||
class Input;
|
||||
class Screen;
|
||||
class Sprite;
|
||||
class Texture;
|
||||
struct JA_Music_t;
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
#include "define_buttons.h" // for DefineButtons
|
||||
#include "fade.h" // for Fade
|
||||
#include "game_logo.h" // for GameLogo
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text
|
||||
#include "tiled_bg.h" // for Tiledbg
|
||||
class Input; // lines 17-17
|
||||
class Screen; // lines 18-18
|
||||
class Texture; // lines 20-20
|
||||
namespace section { enum class Name; }
|
||||
struct JA_Music_t; // lines 21-21
|
||||
|
||||
// Textos
|
||||
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
|
||||
|
||||
207
source/utils.cpp
207
source/utils.cpp
@@ -1,11 +1,10 @@
|
||||
#include "utils.h"
|
||||
#include <stdlib.h> // for free, malloc
|
||||
#include <algorithm> // for max, min
|
||||
#include <cctype> // for isspace
|
||||
#include <iterator> // for distance
|
||||
#include <cmath>
|
||||
struct JA_Music_t; // lines 3-3
|
||||
struct JA_Sound_t; // lines 4-4
|
||||
#include <algorithm> // for min, clamp, find_if_not, transform
|
||||
#include <cctype> // for tolower, isspace
|
||||
#include <cmath> // for cos, pow, M_PI
|
||||
#include <compare> // for operator<
|
||||
struct JA_Music_t; // lines 7-7
|
||||
struct JA_Sound_t; // lines 8-8
|
||||
|
||||
// Colores
|
||||
const Color bg_color = {0x27, 0x27, 0x36};
|
||||
@@ -29,210 +28,112 @@ double distanceSquared(int x1, int y1, int x2, int y2)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre dos circulos
|
||||
bool checkCollision(Circle &a, Circle &b)
|
||||
bool checkCollision(const Circle &a, const Circle &b)
|
||||
{
|
||||
// Calcula el radio total al cuadrado
|
||||
int total_radius_squared = a.r + b.r;
|
||||
total_radius_squared = total_radius_squared * total_radius_squared;
|
||||
int total_radius_squared = (a.r + b.r) * (a.r + b.r);
|
||||
|
||||
// Si la distancia entre el centro de los circulos es inferior a la suma de sus radios
|
||||
if (distanceSquared(a.x, a.y, b.x, b.y) < (total_radius_squared))
|
||||
{
|
||||
// Los circulos han colisionado
|
||||
return true;
|
||||
}
|
||||
|
||||
// En caso contrario
|
||||
return false;
|
||||
// Comprueba si la distancia entre los centros de los círculos es inferior a la suma de sus radios
|
||||
return distanceSquared(a.x, a.y, b.x, b.y) < total_radius_squared;
|
||||
}
|
||||
|
||||
// Detector de colisiones entre un circulo y un rectangulo
|
||||
bool checkCollision(Circle &a, SDL_Rect &b)
|
||||
bool checkCollision(const Circle &a, const SDL_Rect &b)
|
||||
{
|
||||
// Closest point on collision box
|
||||
int cX, cY;
|
||||
// Encuentra el punto más cercano en el rectángulo
|
||||
int cX = std::clamp(a.x, b.x, b.x + b.w);
|
||||
int cY = std::clamp(a.y, b.y, b.y + b.h);
|
||||
|
||||
// Find closest x offset
|
||||
if (a.x < b.x)
|
||||
{
|
||||
cX = b.x;
|
||||
}
|
||||
else if (a.x > b.x + b.w)
|
||||
{
|
||||
cX = b.x + b.w;
|
||||
}
|
||||
else
|
||||
{
|
||||
cX = a.x;
|
||||
}
|
||||
|
||||
// Find closest y offset
|
||||
if (a.y < b.y)
|
||||
{
|
||||
cY = b.y;
|
||||
}
|
||||
else if (a.y > b.y + b.h)
|
||||
{
|
||||
cY = b.y + b.h;
|
||||
}
|
||||
else
|
||||
{
|
||||
cY = a.y;
|
||||
}
|
||||
|
||||
// If the closest point is inside the Circle
|
||||
if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r)
|
||||
{
|
||||
// This box and the Circle have collided
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the shapes have not collided
|
||||
return false;
|
||||
// Si el punto más cercano está dentro del círculo
|
||||
return distanceSquared(a.x, a.y, cX, cY) < a.r * a.r;
|
||||
}
|
||||
|
||||
// Detector de colisiones entre dos rectangulos
|
||||
bool checkCollision(SDL_Rect &a, SDL_Rect &b)
|
||||
bool checkCollision(const SDL_Rect &a, const SDL_Rect &b)
|
||||
{
|
||||
// Calcula las caras del rectangulo a
|
||||
const int leftA = a.x;
|
||||
const int rightA = a.x + a.w;
|
||||
const int topA = a.y;
|
||||
const int bottomA = a.y + a.h;
|
||||
const int leftA = a.x, rightA = a.x + a.w, topA = a.y, bottomA = a.y + a.h;
|
||||
const int leftB = b.x, rightB = b.x + b.w, topB = b.y, bottomB = b.y + b.h;
|
||||
|
||||
// Calcula las caras del rectangulo b
|
||||
const int leftB = b.x;
|
||||
const int rightB = b.x + b.w;
|
||||
const int topB = b.y;
|
||||
const int bottomB = b.y + b.h;
|
||||
|
||||
// Si cualquiera de las caras de a está fuera de b
|
||||
if (bottomA <= topB)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (topA >= bottomB)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rightA <= leftB)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (leftA >= rightB)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Si ninguna de las caras está fuera de b
|
||||
return true;
|
||||
}
|
||||
|
||||
// Detector de colisiones entre un punto y un rectangulo
|
||||
bool checkCollision(SDL_Point &p, SDL_Rect &r)
|
||||
bool checkCollision(const SDL_Point &p, const SDL_Rect &r)
|
||||
{
|
||||
// Comprueba si el punto está a la izquierda del rectangulo
|
||||
if (p.x < r.x)
|
||||
{
|
||||
if (p.x < r.x || p.x > r.x + r.w)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba si el punto está a la derecha del rectangulo
|
||||
if (p.x > r.x + r.w)
|
||||
{
|
||||
if (p.y < r.y || p.y > r.y + r.h)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba si el punto está por encima del rectangulo
|
||||
if (p.y < r.y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba si el punto está por debajo del rectangulo
|
||||
if (p.y > r.y + r.h)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Si no está fuera, es que está dentro
|
||||
return true;
|
||||
}
|
||||
|
||||
// Convierte una cadena en un valor booleano
|
||||
bool stringToBool(std::string str)
|
||||
bool stringToBool(const std::string &str)
|
||||
{
|
||||
return str == "true" ? true : false;
|
||||
return str == "true";
|
||||
}
|
||||
|
||||
// Convierte un valor booleano en una cadena
|
||||
std::string boolToString(bool value)
|
||||
{
|
||||
return value == true ? "true" : "false";
|
||||
return value ? "true" : "false";
|
||||
}
|
||||
|
||||
// Convierte un valor booleano en una cadena "on" o "off"
|
||||
std::string boolToOnOff(bool value)
|
||||
{
|
||||
return value == true ? "on" : "off";
|
||||
return value ? "on" : "off";
|
||||
}
|
||||
|
||||
// Convierte una cadena a minusculas
|
||||
std::string toLower(std::string str)
|
||||
std::string toLower(const std::string &str)
|
||||
{
|
||||
const char *original = str.c_str();
|
||||
char *lower = (char *)malloc(str.size() + 1);
|
||||
for (int i = 0; i < (int)str.size(); ++i)
|
||||
{
|
||||
char c = original[i];
|
||||
lower[i] = (c >= 65 && c <= 90) ? c + 32 : c;
|
||||
}
|
||||
lower[str.size()] = 0;
|
||||
std::string nova(lower);
|
||||
free(lower);
|
||||
return nova;
|
||||
std::string result = str;
|
||||
std::transform(result.begin(), result.end(), result.begin(),
|
||||
[](unsigned char c)
|
||||
{ return std::tolower(c); });
|
||||
return result;
|
||||
}
|
||||
|
||||
// Obtiene el fichero de sonido a partir de un nombre
|
||||
JA_Sound_t *getSound(std::vector<SoundFile> sounds, std::string name)
|
||||
JA_Sound_t *getSound(const std::vector<SoundFile> &sounds, const std::string &name)
|
||||
{
|
||||
for (auto s : sounds)
|
||||
for (const auto &s : sounds)
|
||||
{
|
||||
if (s.name == name)
|
||||
{
|
||||
return s.file;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Obtiene el fichero de música a partir de un nombre
|
||||
JA_Music_t *getMusic(std::vector<MusicFile> music, std::string name)
|
||||
JA_Music_t *getMusic(const std::vector<MusicFile> &music, const std::string &name)
|
||||
{
|
||||
for (auto m : music)
|
||||
for (const auto &m : music)
|
||||
{
|
||||
if (m.name == name)
|
||||
{
|
||||
return m.file;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Ordena las entradas de la tabla de records
|
||||
HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2)
|
||||
HiScoreEntry sortHiScoreTable(const HiScoreEntry &entry1, const HiScoreEntry &entry2)
|
||||
{
|
||||
if (entry1.score > entry2.score)
|
||||
{
|
||||
return entry1;
|
||||
}
|
||||
|
||||
return entry2;
|
||||
return (entry1.score > entry2.score) ? entry1 : entry2;
|
||||
}
|
||||
|
||||
// Dibuja un circulo
|
||||
@@ -275,41 +176,31 @@ void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_
|
||||
}
|
||||
|
||||
// Aclara el color
|
||||
Color lightenColor(Color color, int amount)
|
||||
Color lightenColor(const Color &color, int amount)
|
||||
{
|
||||
Color newColor;
|
||||
newColor.r = std::min(255, (int)color.r + amount);
|
||||
newColor.g = std::min(255, (int)color.g + amount);
|
||||
newColor.b = std::min(255, (int)color.b + amount);
|
||||
newColor.r = std::min(255, color.r + amount);
|
||||
newColor.g = std::min(255, color.g + amount);
|
||||
newColor.b = std::min(255, color.b + amount);
|
||||
return newColor;
|
||||
}
|
||||
|
||||
// Oscurece el color
|
||||
Color DarkenColor(Color color, int amount)
|
||||
Color DarkenColor(const Color &color, int amount)
|
||||
{
|
||||
Color newColor;
|
||||
newColor.r = std::max(0, (int)color.r - amount);
|
||||
newColor.g = std::max(0, (int)color.g - amount);
|
||||
newColor.b = std::max(0, (int)color.b - amount);
|
||||
newColor.r = std::min(255, color.r - +amount);
|
||||
newColor.g = std::min(255, color.g - +amount);
|
||||
newColor.b = std::min(255, color.b - +amount);
|
||||
return newColor;
|
||||
}
|
||||
|
||||
// Quita los espacioes en un string
|
||||
std::string trim(const std::string &str)
|
||||
{
|
||||
auto start = str.begin();
|
||||
while (start != str.end() && std::isspace(*start))
|
||||
{
|
||||
start++;
|
||||
}
|
||||
|
||||
auto end = str.end();
|
||||
do
|
||||
{
|
||||
end--;
|
||||
} while (std::distance(start, end) > 0 && std::isspace(*end));
|
||||
|
||||
return std::string(start, end + 1);
|
||||
auto start = std::find_if_not(str.begin(), str.end(), ::isspace);
|
||||
auto end = std::find_if_not(str.rbegin(), str.rend(), ::isspace).base();
|
||||
return (start < end ? std::string(start, end) : std::string());
|
||||
}
|
||||
|
||||
// Función de suavizado
|
||||
|
||||
@@ -3,16 +3,19 @@
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint32
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <stdint.h> // for int32_t
|
||||
#include <string> // for string, basic_string
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "input.h" // for inputs_e
|
||||
#include "lang.h"
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
enum class ScreenFilter;
|
||||
enum class ScreenVideoMode;
|
||||
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
|
||||
|
||||
// Dificultad del juego
|
||||
enum class GameDifficulty
|
||||
@@ -23,7 +26,7 @@ enum class GameDifficulty
|
||||
};
|
||||
|
||||
// Tamaño de bloque
|
||||
#define BLOCK 8
|
||||
constexpr int BLOCK = 8;
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct Circle
|
||||
@@ -35,6 +38,7 @@ struct Circle
|
||||
struct Color
|
||||
{
|
||||
Uint8 r, g, b;
|
||||
constexpr Color(int red = 255, int green = 255, int blue = 255) : r(red), g(green), b(blue) {}
|
||||
};
|
||||
|
||||
// Posiciones de las notificaciones
|
||||
@@ -47,13 +51,6 @@ enum class NotifyPosition
|
||||
RIGHT,
|
||||
};
|
||||
|
||||
// Estructura para saber la seccion y subseccion del programa
|
||||
/*struct Section
|
||||
{
|
||||
section::Name name;
|
||||
section::Options options;
|
||||
};*/
|
||||
|
||||
// Estructura para las entradas de la tabla de recirds
|
||||
struct HiScoreEntry
|
||||
{
|
||||
@@ -114,7 +111,7 @@ struct OptionsAudio
|
||||
struct OptionsGame
|
||||
{
|
||||
GameDifficulty difficulty; // Dificultad del juego
|
||||
lang::Code language; // Idioma usado en el 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
|
||||
};
|
||||
@@ -235,19 +232,19 @@ struct MusicFile
|
||||
double distanceSquared(int x1, int y1, int x2, int y2);
|
||||
|
||||
// Detector de colisiones entre dos circulos
|
||||
bool checkCollision(Circle &a, Circle &b);
|
||||
bool checkCollision(const Circle &a, const Circle &b);
|
||||
|
||||
// Detector de colisiones entre un circulo y un rectangulo
|
||||
bool checkCollision(Circle &a, SDL_Rect &b);
|
||||
bool checkCollision(const Circle &a, const SDL_Rect &b);
|
||||
|
||||
// Detector de colisiones entre un dos rectangulos
|
||||
bool checkCollision(SDL_Rect &a, SDL_Rect &b);
|
||||
bool checkCollision(const SDL_Rect &a, const SDL_Rect &b);
|
||||
|
||||
// Detector de colisiones entre un punto y un rectangulo
|
||||
bool checkCollision(SDL_Point &p, SDL_Rect &r);
|
||||
bool checkCollision(const SDL_Point &p, const SDL_Rect &r);
|
||||
|
||||
// Convierte una cadena en un valor booleano
|
||||
bool stringToBool(std::string str);
|
||||
bool stringToBool(const std::string &str);
|
||||
|
||||
// Convierte un valor booleano en una cadena
|
||||
std::string boolToString(bool value);
|
||||
@@ -256,25 +253,25 @@ std::string boolToString(bool value);
|
||||
std::string boolToOnOff(bool value);
|
||||
|
||||
// Convierte una cadena a minusculas
|
||||
std::string toLower(std::string str);
|
||||
std::string toLower(const std::string &str);
|
||||
|
||||
// Obtiene el fichero de sonido a partir de un nombre
|
||||
JA_Sound_t *getSound(std::vector<SoundFile> sounds, std::string name);
|
||||
JA_Sound_t *getSound(const std::vector<SoundFile> &sounds, const std::string &name);
|
||||
|
||||
// Obtiene el fichero de música a partir de un nombre
|
||||
JA_Music_t *getMusic(std::vector<MusicFile> music, std::string name);
|
||||
JA_Music_t *getMusic(const std::vector<MusicFile> &music, const std::string &name);
|
||||
|
||||
// Ordena las entradas de la tabla de records
|
||||
HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2);
|
||||
HiScoreEntry sortHiScoreTable(const HiScoreEntry &entry1, const HiScoreEntry &entry2);
|
||||
|
||||
// Dibuja un circulo
|
||||
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius);
|
||||
|
||||
// Aclara el color
|
||||
Color lightenColor(Color color, int amount);
|
||||
Color lightenColor(const Color &color, int amount);
|
||||
|
||||
// Oscurece el color
|
||||
Color DarkenColor(Color color, int amount);
|
||||
Color DarkenColor(const Color &color, int amount);
|
||||
|
||||
// Quita los espacioes en un string
|
||||
std::string trim(const std::string &str);
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
#include "writer.h"
|
||||
#include "text.h" // for Text
|
||||
|
||||
// Constructor
|
||||
Writer::Writer(std::shared_ptr<Text> text)
|
||||
: text_(text)
|
||||
{
|
||||
// Inicializa variables
|
||||
pos_x_ = 0;
|
||||
pos_y_ = 0;
|
||||
kerning_ = 0;
|
||||
caption_ = "";
|
||||
speed_ = 0;
|
||||
writing_counter_ = 0;
|
||||
index_ = 0;
|
||||
lenght_ = 0;
|
||||
completed_ = false;
|
||||
enabled_ = false;
|
||||
enabled_counter_ = 0;
|
||||
finished_ = false;
|
||||
}
|
||||
: text_(text),
|
||||
pos_x_(0),
|
||||
pos_y_(0),
|
||||
kerning_(0),
|
||||
caption_(std::string()),
|
||||
speed_(0),
|
||||
writing_counter_(0),
|
||||
index_(0),
|
||||
lenght_(0),
|
||||
completed_(false),
|
||||
enabled_(false),
|
||||
enabled_counter_(0),
|
||||
finished_(false) {}
|
||||
|
||||
// Actualiza el objeto
|
||||
void Writer::update()
|
||||
@@ -45,7 +43,11 @@ void Writer::update()
|
||||
else
|
||||
{
|
||||
// Completado
|
||||
enabled_counter_ > 0 ? enabled_counter_-- : finished_ = true;
|
||||
finished_ = enabled_counter_ <= 0;
|
||||
if (!finished_)
|
||||
{
|
||||
enabled_counter_--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +80,7 @@ void Writer::setKerning(int value)
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Writer::setCaption(std::string text)
|
||||
void Writer::setCaption(const std::string &text)
|
||||
{
|
||||
caption_ = text;
|
||||
lenght_ = text.length();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // for string, basic_string
|
||||
#include <memory>
|
||||
#include "text.h"
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
class Text;
|
||||
|
||||
// Clase Writer. Pinta texto en pantalla letra a letra a partir de una cadena y un bitmap
|
||||
// Clase Writer. Pinta texto en pantalla letra a letra a partir de una cadena y un objeto Text
|
||||
class Writer
|
||||
{
|
||||
private:
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
void setKerning(int value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setCaption(std::string text);
|
||||
void setCaption(const std::string &text);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpeed(int value);
|
||||
|
||||
Reference in New Issue
Block a user