Compare commits
43 Commits
b060f21696
...
2024-10-20
| Author | SHA1 | Date | |
|---|---|---|---|
| 2cb22ed013 | |||
| a3a583deb7 | |||
| b263e0c4be | |||
| 3bf61fc758 | |||
| 2377815c02 | |||
| 7434869894 | |||
| 848d61b5c0 | |||
| cbc9b3f071 | |||
| 8bca5095da | |||
| a4b4e188cd | |||
| f23dcae5b6 | |||
| b879673bc2 | |||
| a8701dbebc | |||
| afe835914e | |||
| 808f1595e9 | |||
| 8e8346b2ab | |||
| 1da8f33a5e | |||
| 50a376e582 | |||
| 59de566c5b | |||
| db884cb422 | |||
| 5585f996cb | |||
| 24556eeaa8 | |||
| dbffda491f | |||
| 53f5f3f8b0 | |||
| e0faa0890e | |||
| de6508c37c | |||
| e99c2c5265 | |||
| 942924c65c | |||
| 089da99b5b | |||
| 3fdd60c9e2 | |||
| 3b9885ab03 | |||
| 39a8c992e1 | |||
| 9825c7fb9b | |||
| d0a6e4c572 | |||
| 7c876e1d4d | |||
| 809c10048e | |||
| babf02226c | |||
| 46540ad7c3 | |||
| ba7c44ad06 | |||
| 46b19ee82f | |||
| b2122ac239 | |||
| c11a868289 | |||
| 22d457285d |
1
.gitignore
vendored
@@ -15,3 +15,4 @@ thumbs.db
|
||||
*score.bin
|
||||
coffee_crisis*
|
||||
debug.txt
|
||||
cppcheck-result*
|
||||
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
@@ -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,770 +0,0 @@
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:14:11: warning: The class 'MovingSprite' defines member variable with name 'x_' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
float x_; // Posición en el eje X
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:11:9: note: Parent variable 'Sprite::x_'
|
||||
int x_; // Posición en el eje X donde dibujar el sprite
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:14:11: note: Derived variable 'MovingSprite::x_'
|
||||
float x_; // Posición en el eje X
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:15:11: warning: The class 'MovingSprite' defines member variable with name 'y_' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
float y_; // Posición en el eje Y
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:12:9: note: Parent variable 'Sprite::y_'
|
||||
int y_; // Posición en el eje Y donde dibujar el sprite
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:15:11: note: Derived variable 'MovingSprite::y_'
|
||||
float y_; // Posición en el eje Y
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:51:10: warning: The class 'MovingSprite' defines member function with name 'render' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
void render();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:30:10: note: Parent function 'Sprite::render'
|
||||
void render();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:51:10: note: Derived function 'MovingSprite::render'
|
||||
void render();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:54: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:33:9: note: Parent function 'Sprite::getPosX'
|
||||
int getPosX() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:54:11: note: Derived function 'MovingSprite::getPosX'
|
||||
float getPosX() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:55: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:34:9: note: Parent function 'Sprite::getPosY'
|
||||
int getPosY() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:55:11: note: Derived function 'MovingSprite::getPosY'
|
||||
float getPosY() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:122:14: warning: The class 'MovingSprite' defines member function with name 'getRect' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
SDL_Rect getRect();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:44:14: note: Parent function 'Sprite::getRect'
|
||||
SDL_Rect getRect() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:122:14: note: Derived function 'MovingSprite::getRect'
|
||||
SDL_Rect getRect();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:519:22: warning: The class 'AnimatedSprite' defines member function with name 'update' also defined in its parent class 'MovingSprite'. [duplInheritedMember]
|
||||
void AnimatedSprite::update()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:45:10: note: Parent function 'MovingSprite::update'
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:519:22: note: Derived function 'AnimatedSprite::update'
|
||||
void AnimatedSprite::update()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.h:52:5: style: Class 'Texture' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Texture(SDL_Renderer *renderer, std::string path = "");
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:23:5: style: Class 'Sprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, std::shared_ptr<Texture> texture = nullptr);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:24:5: style: Class 'Sprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Sprite(SDL_Rect rect, std::shared_ptr<Texture> texture = nullptr);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:36:5: style: Class 'MovingSprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
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);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:40:5: style: Class 'AnimatedSprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:41:5: style: Class 'AnimatedSprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
AnimatedSprite(AnimatedFile *animation);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:159:78: performance: Function parameter 'file' should be passed by const reference. [passedByValue]
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, std::string file, std::vector<std::string> *buffer)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:208:42: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
int AnimatedSprite::getIndex(std::string name)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:212:12: performance: Range variable 'a' should be declared as const reference. [iterateByValue]
|
||||
for (auto a : animations_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:287:54: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
void AnimatedSprite::setAnimationCounter(std::string name, int num)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:293:52: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:305:51: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:317:56: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:335:55: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:493:54: performance: Function parameter 'name' should be passed by const reference. [passedByValue]
|
||||
void AnimatedSprite::setCurrentAnimation(std::string name)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:186:46: style: Parameter 'animation' can be declared as pointer to const [constParameterPointer]
|
||||
AnimatedSprite::AnimatedSprite(AnimatedFile *animation)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:172:16: style: Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]
|
||||
animations_.push_back(animation);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:197:15: style: Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]
|
||||
animations_.push_back(a);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:18: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/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/asset.h:48:2: style: Class 'Asset' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Asset(std::string path);
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:11:30: performance: Function parameter 'executable_path' should be passed by const reference. [passedByValue]
|
||||
void Asset::init(std::string executable_path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:29:26: performance: Function parameter 'executable_path' should be passed by const reference. [passedByValue]
|
||||
Asset::Asset(std::string executable_path)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:36:29: performance: Function parameter 'file' should be passed by const reference. [passedByValue]
|
||||
void Asset::add(std::string file, AssetType type, bool required, bool absolute)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:49:36: performance: Function parameter 'text' should be passed by const reference. [passedByValue]
|
||||
std::string Asset::get(std::string text) const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:51:15: performance: Range variable 'f' should be declared as const reference. [iterateByValue]
|
||||
for (auto f : file_list_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:86:19: performance: Range variable 'f' should be declared as const reference. [iterateByValue]
|
||||
for (auto f : file_list_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:101:23: performance: Range variable 'f' should be declared as const reference. [iterateByValue]
|
||||
for (auto f : file_list_)
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:120:35: performance: Function parameter 'path' should be passed by const reference. [passedByValue]
|
||||
bool Asset::checkFile(std::string path) const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:123:24: style: Variable 'result' is assigned a value that is never used. [unreadVariable]
|
||||
std::string result = "ERROR";
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:126:33: 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/asset.cpp:131:16: style: Variable 'result' is assigned a value that is never used. [unreadVariable]
|
||||
result = "OK";
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/background.cpp:14:5: performance: Variable 'buildings_texture_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
buildings_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("game_buildings.png"));
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/background.h:110:3: style: Class 'Background' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
Background(SDL_Renderer *renderer);
|
||||
^
|
||||
/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/animated_sprite.h:88:10: warning: The class 'AnimatedSprite' defines member function with name 'update' also defined in its parent class 'MovingSprite'. [duplInheritedMember]
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:45:10: note: Parent function 'MovingSprite::update'
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:88:10: note: Derived function 'AnimatedSprite::update'
|
||||
void update();
|
||||
^
|
||||
/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/smart_sprite.h:35:7: warning: The class 'SmartSprite' defines member function with name 'update' also defined in its parent class 'AnimatedSprite'. [duplInheritedMember]
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:88:10: note: Parent function 'AnimatedSprite::update'
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.h:35:7: note: Derived function 'SmartSprite::update'
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.h:35:7: warning: The class 'SmartSprite' defines member function with name 'update' also defined in its parent class 'MovingSprite'. [duplInheritedMember]
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:45:10: note: Parent function 'MovingSprite::update'
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.h:35:7: note: Derived function 'SmartSprite::update'
|
||||
void update();
|
||||
^
|
||||
/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/smart_sprite.h:26:2: style: Class 'SmartSprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
|
||||
SmartSprite(std::shared_ptr<Texture> texture);
|
||||
^
|
||||
/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:30:2: performance: Variable 'currentFlip_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
currentFlip_ = SDL_FLIP_NONE;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:69:20: warning: The class 'MovingSprite' defines member function with name 'render' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
void MovingSprite::render()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:30:10: note: Parent function 'Sprite::render'
|
||||
void render();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:69:20: note: Derived function 'MovingSprite::render'
|
||||
void MovingSprite::render()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:78: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:33:9: note: Parent function 'Sprite::getPosX'
|
||||
int getPosX() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:78:21: note: Derived function 'MovingSprite::getPosX'
|
||||
float MovingSprite::getPosX() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:84: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:34:9: note: Parent function 'Sprite::getPosY'
|
||||
int getPosY() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:84:21: note: Derived function 'MovingSprite::getPosY'
|
||||
float MovingSprite::getPosY() const
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:298:24: warning: The class 'MovingSprite' defines member function with name 'getRect' also defined in its parent class 'Sprite'. [duplInheritedMember]
|
||||
SDL_Rect MovingSprite::getRect()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:44:14: note: Parent function 'Sprite::getRect'
|
||||
SDL_Rect getRect() const;
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:298:24: note: Derived function 'MovingSprite::getRect'
|
||||
SDL_Rect MovingSprite::getRect()
|
||||
^
|
||||
/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/smart_sprite.cpp:26:19: warning: The class 'SmartSprite' defines member function with name 'update' also defined in its parent class 'AnimatedSprite'. [duplInheritedMember]
|
||||
void SmartSprite::update()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:88:10: note: Parent function 'AnimatedSprite::update'
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:26:19: note: Derived function 'SmartSprite::update'
|
||||
void SmartSprite::update()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:26:19: warning: The class 'SmartSprite' defines member function with name 'update' also defined in its parent class 'MovingSprite'. [duplInheritedMember]
|
||||
void SmartSprite::update()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:45:10: note: Parent function 'MovingSprite::update'
|
||||
void update();
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:26:19: note: Derived function 'SmartSprite::update'
|
||||
void SmartSprite::update()
|
||||
^
|
||||
/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.cpp:8:2: performance: Variable 'spriteClip_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
|
||||
spriteClip_ = {0, 0, w, h};
|
||||
^
|
||||
/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]
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
## GAME
|
||||
game.item_size 20
|
||||
game.width 320
|
||||
game.height 240
|
||||
game.play_area.rect.x 0
|
||||
game.play_area.rect.y 0
|
||||
game.play_area.rect.w 320
|
||||
game.play_area.rect.h 200
|
||||
game.item_size 20 # Tamaño de los items del juego
|
||||
game.width 320 # Ancho de la resolucion nativa del juego
|
||||
game.height 240 # Alto de la resolucion nativa del juego
|
||||
game.play_area.rect.x 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.y 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.w 320 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.h 200 # Rectangulo con la posición de la zona de juego
|
||||
game.enter_name_seconds 30 # Duración en segundos para introducir el nombre al finalizar la partida
|
||||
|
||||
## FADE
|
||||
fade.num_squares_width 160
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
## GAME
|
||||
game.item_size 20
|
||||
game.width 320
|
||||
game.height 256
|
||||
game.play_area.rect.x 0
|
||||
game.play_area.rect.y 0
|
||||
game.play_area.rect.w 320
|
||||
game.play_area.rect.h 216
|
||||
game.item_size 20 # Tamaño de los items del juego
|
||||
game.width 320 # Ancho de la resolucion nativa del juego
|
||||
game.height 256 # Alto de la resolucion nativa del juego
|
||||
game.play_area.rect.x 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.y 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.w 320 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.h 216 # Rectangulo con la posición de la zona de juego
|
||||
game.enter_name_seconds 30 # Duración en segundos para introducir el nombre al finalizar la partida
|
||||
|
||||
## FADE
|
||||
fade.num_squares_width 160
|
||||
|
||||
|
Before Width: | Height: | Size: 84 B After Width: | Height: | Size: 84 B |
|
Before Width: | Height: | Size: 935 B |
BIN
data/gfx/game_text/game_text_1000_points.png
Normal file
|
After Width: | Height: | Size: 337 B |
BIN
data/gfx/game_text/game_text_2500_points.png
Normal file
|
After Width: | Height: | Size: 376 B |
BIN
data/gfx/game_text/game_text_5000_points.png
Normal file
|
After Width: | Height: | Size: 364 B |
BIN
data/gfx/game_text/game_text_one_hit.png
Normal file
|
After Width: | Height: | Size: 487 B |
BIN
data/gfx/game_text/game_text_powerup.png
Normal file
|
After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 772 B |
BIN
data/gfx/player/player1_power.png
Normal file
|
After Width: | Height: | Size: 929 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
|
Before Width: | Height: | Size: 772 B |
BIN
data/gfx/player/player2_power.png
Normal file
|
After Width: | Height: | Size: 941 B |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
|
Before Width: | Height: | Size: 944 B |
|
Before Width: | Height: | Size: 84 B |
@@ -281,7 +281,7 @@ MODE FORA DE LINEA
|
||||
TAULER DE PUNTS
|
||||
|
||||
## 94 - NOTIFICACIONES
|
||||
Torna a polsar per eixir ...
|
||||
Torna a polsar per eixir
|
||||
|
||||
## 95 - DEFINE BUTTONS
|
||||
Disparar cap a l'esquerra
|
||||
@@ -344,4 +344,7 @@ Eixir
|
||||
Per favor
|
||||
|
||||
## 115 - MARCADOR
|
||||
espere
|
||||
espere
|
||||
|
||||
## 116 - NOTIFICACIONES
|
||||
Torna a polsar per apagar el sistema
|
||||
@@ -344,4 +344,7 @@ Exit
|
||||
Please
|
||||
|
||||
## 115 - MARCADOR
|
||||
wait
|
||||
wait
|
||||
|
||||
## 116 - NOTIFICACIONES
|
||||
Press again to shutdown system
|
||||
@@ -344,4 +344,7 @@ Salir
|
||||
Por favor
|
||||
|
||||
## 115 - MARCADOR
|
||||
espere
|
||||
espere
|
||||
|
||||
## 94 - NOTIFICACIONES
|
||||
Pulsa otra vez para apagar el sistema
|
||||
@@ -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,198 +1,60 @@
|
||||
#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
|
||||
#include "utils.h"
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string file_path)
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
Animations loadAnimationsFromFile(const std::string &file_path)
|
||||
{
|
||||
// Inicializa variables
|
||||
AnimatedFile af;
|
||||
af.texture = texture;
|
||||
auto frames_per_row = 0;
|
||||
auto frame_width = 0;
|
||||
auto frame_height = 0;
|
||||
auto max_tiles = 0;
|
||||
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
#endif
|
||||
std::vector<std::string> buffer;
|
||||
std::ifstream file(file_path);
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||
}
|
||||
|
||||
std::string line;
|
||||
printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||
|
||||
// El fichero se puede abrir
|
||||
if (file.good())
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Procesa el fichero linea a linea
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Animation loaded: " << file_name << std::endl;
|
||||
#endif
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
Animation buffer;
|
||||
buffer.counter = 0;
|
||||
buffer.current_frame = 0;
|
||||
buffer.completed = false;
|
||||
buffer.name = "";
|
||||
buffer.speed = 5;
|
||||
buffer.loop = 0;
|
||||
buffer.frames.clear();
|
||||
|
||||
do
|
||||
{
|
||||
std::getline(file, line);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != static_cast<int>(line.npos))
|
||||
{
|
||||
if (line.substr(0, pos) == "name")
|
||||
{
|
||||
buffer.name = line.substr(pos + 1, line.length());
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "speed")
|
||||
{
|
||||
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "loop")
|
||||
{
|
||||
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frames")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||
std::string tmp;
|
||||
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const auto num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
|
||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||
buffer.frames.push_back(rect);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
// Añade la animación al vector de animaciones
|
||||
af.animations.push_back(buffer);
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
else
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != (int)line.npos)
|
||||
{
|
||||
if (line.substr(0, pos) == "frames_per_row")
|
||||
{
|
||||
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_width")
|
||||
{
|
||||
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_height")
|
||||
{
|
||||
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
if (frames_per_row == 0 && frame_width > 0)
|
||||
{
|
||||
frames_per_row = texture->getWidth() / frame_width;
|
||||
}
|
||||
|
||||
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
|
||||
{
|
||||
const auto w = texture->getWidth() / frame_width;
|
||||
const auto h = texture->getHeight() / frame_height;
|
||||
max_tiles = w * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
}
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
||||
#endif
|
||||
buffer.push_back(line);
|
||||
}
|
||||
|
||||
return af;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file, std::vector<std::string> *buffer)
|
||||
: MovingSprite(texture)
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path)
|
||||
: MovingSprite(texture),
|
||||
current_animation_(0)
|
||||
{
|
||||
// Carga las animaciones
|
||||
if (file != "")
|
||||
if (!file_path.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_));
|
||||
animations_ = loadFromFile(file_path);
|
||||
}
|
||||
}
|
||||
|
||||
else if (buffer)
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const Animations &animations)
|
||||
: MovingSprite(texture),
|
||||
current_animation_(0)
|
||||
{
|
||||
if (!animations.empty())
|
||||
{
|
||||
loadFromVector(buffer);
|
||||
loadFromVector(animations);
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
current_animation_ = 0;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(const AnimatedFile *animation)
|
||||
: MovingSprite(animation->texture)
|
||||
{
|
||||
// Inicializa variables
|
||||
current_animation_ = 0;
|
||||
|
||||
// Copia los datos de las animaciones
|
||||
std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_));
|
||||
}
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture)
|
||||
: MovingSprite(texture),
|
||||
current_animation_(0) {}
|
||||
|
||||
// Destructor
|
||||
AnimatedSprite::~AnimatedSprite()
|
||||
@@ -213,9 +75,7 @@ int AnimatedSprite::getIndex(const std::string &name)
|
||||
return index;
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -339,152 +199,6 @@ SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
||||
return animations_[indexA].frames[indexF];
|
||||
}
|
||||
|
||||
// Carga la animación desde un vector
|
||||
bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
{
|
||||
// Inicializa variables
|
||||
auto frames_per_row = 0;
|
||||
auto frame_width = 0;
|
||||
auto frame_height = 0;
|
||||
auto max_tiles = 0;
|
||||
|
||||
// Indicador de éxito en el proceso
|
||||
auto success = true;
|
||||
std::string line;
|
||||
|
||||
// Recorre todo el vector
|
||||
auto index = 0;
|
||||
while (index < (int)source->size())
|
||||
{
|
||||
// Lee desde el vector
|
||||
line = source->at(index);
|
||||
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
Animation buffer;
|
||||
buffer.counter = 0;
|
||||
buffer.current_frame = 0;
|
||||
buffer.completed = false;
|
||||
buffer.name = "";
|
||||
buffer.speed = 5;
|
||||
buffer.loop = 0;
|
||||
buffer.frames.clear();
|
||||
|
||||
do
|
||||
{
|
||||
// Aumenta el indice para leer la siguiente linea
|
||||
index++;
|
||||
line = source->at(index);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != static_cast<int>(line.npos))
|
||||
{
|
||||
if (line.substr(0, pos) == "name")
|
||||
{
|
||||
buffer.name = line.substr(pos + 1, line.length());
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "speed")
|
||||
{
|
||||
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "loop")
|
||||
{
|
||||
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frames")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||
std::string tmp;
|
||||
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const int num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
|
||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||
buffer.frames.push_back(rect);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
#endif
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
// Añade la animación al vector de animaciones
|
||||
animations_.push_back(buffer);
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
else
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != (int)line.npos)
|
||||
{
|
||||
if (line.substr(0, pos) == "frames_per_row")
|
||||
{
|
||||
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_width")
|
||||
{
|
||||
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_height")
|
||||
{
|
||||
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
#endif
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
if (frames_per_row == 0 && frame_width > 0)
|
||||
{
|
||||
frames_per_row = texture_->getWidth() / frame_width;
|
||||
}
|
||||
|
||||
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
|
||||
{
|
||||
const int w = texture_->getWidth() / frame_width;
|
||||
const int h = texture_->getHeight() / frame_height;
|
||||
max_tiles = w * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
||||
index++;
|
||||
}
|
||||
|
||||
// Pone un valor por defecto
|
||||
setPos((SDL_Rect){0, 0, frame_width, frame_height});
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(const std::string &name)
|
||||
{
|
||||
@@ -539,4 +253,279 @@ void AnimatedSprite::resetAnimation()
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
}
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
std::vector<Animation> AnimatedSprite::loadFromFile(const std::string &file_path)
|
||||
{
|
||||
// Inicializa variables
|
||||
std::vector<Animation> animations;
|
||||
auto frames_per_row = 0;
|
||||
auto frame_width = 0;
|
||||
auto frame_height = 0;
|
||||
auto max_tiles = 0;
|
||||
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::ifstream file(file_path);
|
||||
std::string line;
|
||||
|
||||
// El fichero se puede abrir
|
||||
if (file.good())
|
||||
{
|
||||
// Procesa el fichero linea a linea
|
||||
std::cout << "Animation loaded: " << file_name << std::endl;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
Animation animation = Animation();
|
||||
|
||||
do
|
||||
{
|
||||
std::getline(file, line);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != static_cast<int>(line.npos))
|
||||
{
|
||||
if (line.substr(0, pos) == "name")
|
||||
{
|
||||
animation.name = line.substr(pos + 1, line.length());
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "speed")
|
||||
{
|
||||
animation.speed = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "loop")
|
||||
{
|
||||
animation.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frames")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||
std::string tmp;
|
||||
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const auto num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
|
||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||
animation.frames.push_back(rect);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
// Añade la animación al vector de animaciones
|
||||
animations.push_back(animation);
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
else
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != (int)line.npos)
|
||||
{
|
||||
if (line.substr(0, pos) == "frames_per_row")
|
||||
{
|
||||
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_width")
|
||||
{
|
||||
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_height")
|
||||
{
|
||||
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
if (frames_per_row == 0 && frame_width > 0)
|
||||
{
|
||||
frames_per_row = texture_->getWidth() / frame_width;
|
||||
}
|
||||
|
||||
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
|
||||
{
|
||||
const auto w = texture_->getWidth() / frame_width;
|
||||
const auto h = texture_->getHeight() / frame_height;
|
||||
max_tiles = w * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
}
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
||||
}
|
||||
|
||||
// Pone un valor por defecto
|
||||
setWidth(frame_width);
|
||||
setHeight(frame_height);
|
||||
|
||||
return animations;
|
||||
}
|
||||
|
||||
// Carga la animación desde un vector
|
||||
bool AnimatedSprite::loadFromVector(const Animations &source)
|
||||
{
|
||||
// Inicializa variables
|
||||
auto frames_per_row = 0;
|
||||
auto frame_width = 0;
|
||||
auto frame_height = 0;
|
||||
auto max_tiles = 0;
|
||||
|
||||
// Indicador de éxito en el proceso
|
||||
auto success = true;
|
||||
std::string line;
|
||||
|
||||
// Recorre todo el vector
|
||||
auto index = 0;
|
||||
while (index < (int)source.size())
|
||||
{
|
||||
// Lee desde el vector
|
||||
line = source.at(index);
|
||||
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
Animation animation = Animation();
|
||||
|
||||
do
|
||||
{
|
||||
// Aumenta el indice para leer la siguiente linea
|
||||
index++;
|
||||
line = source.at(index);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != static_cast<int>(line.npos))
|
||||
{
|
||||
if (line.substr(0, pos) == "name")
|
||||
{
|
||||
animation.name = line.substr(pos + 1, line.length());
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "speed")
|
||||
{
|
||||
animation.speed = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "loop")
|
||||
{
|
||||
animation.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frames")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||
std::string tmp;
|
||||
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const int num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
|
||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||
animation.frames.push_back(rect);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
// Añade la animación al vector de animaciones
|
||||
animations_.push_back(animation);
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
else
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != (int)line.npos)
|
||||
{
|
||||
if (line.substr(0, pos) == "frames_per_row")
|
||||
{
|
||||
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_width")
|
||||
{
|
||||
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_height")
|
||||
{
|
||||
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
if (frames_per_row == 0 && frame_width > 0)
|
||||
{
|
||||
frames_per_row = texture_->getWidth() / frame_width;
|
||||
}
|
||||
|
||||
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
|
||||
{
|
||||
const int w = texture_->getWidth() / frame_width;
|
||||
const int h = texture_->getHeight() / frame_height;
|
||||
max_tiles = w * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
||||
index++;
|
||||
}
|
||||
|
||||
// Pone un valor por defecto
|
||||
setWidth(frame_width);
|
||||
setHeight(frame_height);
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
@@ -17,16 +17,14 @@ struct Animation
|
||||
bool completed; // Indica si ha finalizado la animación
|
||||
int current_frame; // Frame actual
|
||||
int counter; // Contador para las animaciones
|
||||
|
||||
Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {}
|
||||
};
|
||||
|
||||
struct AnimatedFile
|
||||
{
|
||||
std::vector<Animation> animations; // Vector con las diferentes animaciones
|
||||
std::shared_ptr<Texture> texture; // Textura con los graficos para el sprite
|
||||
};
|
||||
using Animations = std::vector<std::string>;
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string filePath);
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
Animations loadAnimationsFromFile(const std::string &file_path);
|
||||
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
@@ -35,17 +33,27 @@ protected:
|
||||
std::vector<Animation> animations_; // Vector con las diferentes animaciones
|
||||
int current_animation_; // Animacion activa
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = "", std::vector<std::string> *buffer = nullptr);
|
||||
explicit AnimatedSprite(const AnimatedFile *animation);
|
||||
|
||||
// Destructor
|
||||
~AnimatedSprite();
|
||||
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
std::vector<Animation> loadFromFile(const std::string &file_path);
|
||||
|
||||
// Carga la animación desde un vector
|
||||
bool loadFromVector(const Animations &source);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture, const Animations &animations);
|
||||
explicit AnimatedSprite(std::shared_ptr<Texture> texture);
|
||||
|
||||
// Destructor
|
||||
virtual ~AnimatedSprite();
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update() override;
|
||||
|
||||
// Obtiene el número de frames de la animación actual
|
||||
int getNumFrames();
|
||||
|
||||
@@ -77,16 +85,10 @@ public:
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int getIndex(const std::string &name);
|
||||
|
||||
// Carga la animación desde un vector
|
||||
bool loadFromVector(std::vector<std::string> *source);
|
||||
|
||||
// Establece la animacion actual
|
||||
void setCurrentAnimation(const std::string &name = "default");
|
||||
void setCurrentAnimation(int index = 0);
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update() override;
|
||||
|
||||
// OLD - Establece el rectangulo para un frame de una animación
|
||||
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "asset.h"
|
||||
#include "utils.h"
|
||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWops
|
||||
#include <SDL2/SDL_stdinc.h> // for SDL_max
|
||||
#include <stddef.h> // for size_t
|
||||
@@ -27,8 +28,8 @@ Asset *Asset::get()
|
||||
|
||||
// Constructor
|
||||
Asset::Asset(const std::string &executable_path)
|
||||
: executable_path_(executable_path.substr(0, executable_path.find_last_of("\\/")))
|
||||
{
|
||||
executable_path_ = executable_path.substr(0, executable_path.find_last_of("\\/"));
|
||||
longest_name_ = 0;
|
||||
}
|
||||
|
||||
@@ -59,9 +60,7 @@ std::string Asset::get(const std::string &text) const
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -70,12 +69,10 @@ bool Asset::check() const
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "\n** Checking files" << std::endl;
|
||||
std::cout << "\n** CHECKING FILES" << std::endl;
|
||||
|
||||
std::cout << "Executable path is: " << executable_path_ << std::endl;
|
||||
std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
|
||||
#endif
|
||||
// std::cout << "Executable path is: " << executable_path_ << std::endl;
|
||||
// std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
|
||||
|
||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||
for (int type = 0; type < static_cast<int>(AssetType::MAX_ASSET_TYPE); ++type)
|
||||
@@ -94,9 +91,7 @@ bool Asset::check() const
|
||||
// Si hay ficheros de ese tipo, comprueba si existen
|
||||
if (any)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "\n>> " << getTypeName(static_cast<AssetType>(type)).c_str() << " FILES" << std::endl;
|
||||
#endif
|
||||
|
||||
for (const auto &f : file_list_)
|
||||
{
|
||||
@@ -105,13 +100,13 @@ bool Asset::check() const
|
||||
success &= checkFile(f.file);
|
||||
}
|
||||
}
|
||||
if (success)
|
||||
std::cout << " All files are OK." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Resultado
|
||||
#ifdef VERBOSE
|
||||
std::cout << (success ? "\n** All files OK.\n" : "\n** A file is missing. Exiting.\n") << std::endl;
|
||||
#endif
|
||||
// Resultado
|
||||
std::cout << (success ? "\n** CHECKING FILES COMPLETED.\n" : "\n** CHECKING FILES FAILED.\n") << std::endl;
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -130,15 +125,9 @@ bool Asset::checkFile(const std::string &path) const
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
||||
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
||||
std::cout << "Checking file: ";
|
||||
std::cout.width(longest_name_ + 2);
|
||||
std::cout.fill('.');
|
||||
std::cout << file_name;
|
||||
std::cout << (success ? " [OK]" : " [ERROR]") << std::endl;
|
||||
#endif
|
||||
if (!success)
|
||||
printWithDots("Checking file : ", file_name, (success ? " [ OK ]" : " [ ERROR ]"));
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -1,78 +1,98 @@
|
||||
#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 <algorithm> // for clamp, max
|
||||
#include "asset.h" // for Asset
|
||||
#include "moving_sprite.h" // for MovingSprite
|
||||
#include "param.h" // for param
|
||||
#include "resource.h" // for Resource
|
||||
#include "screen.h"
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Background::Background(SDL_Renderer *renderer)
|
||||
: renderer_(renderer),
|
||||
buildings_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_buildings.png"))),
|
||||
top_clouds_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds1.png"))),
|
||||
bottom_clouds_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds2.png"))),
|
||||
grass_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_grass.png"))),
|
||||
gradients_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_sky_colors.png")))
|
||||
Background::Background()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
|
||||
buildings_texture_(Resource::get()->getTexture("game_buildings.png")),
|
||||
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")),
|
||||
bottom_clouds_texture_(Resource::get()->getTexture("game_clouds2.png")),
|
||||
grass_texture_(Resource::get()->getTexture("game_grass.png")),
|
||||
gradients_texture_(Resource::get()->getTexture("game_sky_colors.png")),
|
||||
|
||||
gradient_number_(0),
|
||||
alpha_(0),
|
||||
clouds_speed_(0),
|
||||
transition_(0),
|
||||
counter_(0),
|
||||
rect_({0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2}),
|
||||
src_rect_({0, 0, 320, 240}),
|
||||
dst_rect_({0, 0, 320, 240}),
|
||||
base_(rect_.h),
|
||||
color_({param.background.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b}),
|
||||
alpha_color_text_(param.background.attenuate_alpha),
|
||||
alpha_color_text_temp_(param.background.attenuate_alpha)
|
||||
|
||||
{
|
||||
// Inicializa variables
|
||||
gradient_number_ = 0;
|
||||
alpha_ = 0;
|
||||
clouds_speed_ = 0;
|
||||
transition_ = 0;
|
||||
counter_ = 0;
|
||||
|
||||
rect_ = {0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2};
|
||||
src_rect_ = {0, 0, 320, 240};
|
||||
dst_rect_ = {0, 0, 320, 240};
|
||||
|
||||
base_ = rect_.h;
|
||||
color_ = {param.background.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b};
|
||||
alpha_color_text_ = alpha_color_text_temp_ = param.background.attenuate_alpha;
|
||||
|
||||
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
|
||||
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
|
||||
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
|
||||
gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h};
|
||||
|
||||
const int top_clouds_texture_height = top_clouds_texture_->getHeight() / 4;
|
||||
const int bottom_clouds_texture_height = bottom_clouds_texture_->getHeight() / 4;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
top_clouds_rect_[i] = {0, i * top_clouds_texture_height, top_clouds_texture_->getWidth(), top_clouds_texture_height};
|
||||
bottom_clouds_rect_[i] = {0, i * bottom_clouds_texture_height, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_height};
|
||||
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
|
||||
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
|
||||
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
|
||||
gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h};
|
||||
|
||||
const int top_clouds_texture_height = top_clouds_texture_->getHeight() / 4;
|
||||
const int bottom_clouds_texture_height = bottom_clouds_texture_->getHeight() / 4;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
top_clouds_rect_[i] = {0, i * top_clouds_texture_height, top_clouds_texture_->getWidth(), top_clouds_texture_height};
|
||||
bottom_clouds_rect_[i] = {0, i * bottom_clouds_texture_height, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_height};
|
||||
}
|
||||
}
|
||||
|
||||
// Crea los sprites
|
||||
const int top_clouds_y = base_ - 165;
|
||||
const int bottom_clouds_y = base_ - 101;
|
||||
constexpr float top_clouds_speed = 0.1f;
|
||||
constexpr float bottom_clouds_speed = 0.05f;
|
||||
top_clouds_sprite_a_ = std::make_unique<MovingSprite>(0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_);
|
||||
top_clouds_sprite_b_ = std::make_unique<MovingSprite>(rect_.w, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_);
|
||||
{
|
||||
const int top_clouds_y = base_ - 165;
|
||||
const int bottom_clouds_y = base_ - 101;
|
||||
|
||||
bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_);
|
||||
bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_);
|
||||
top_clouds_sprite_a_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_Rect){0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight()});
|
||||
top_clouds_sprite_b_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_Rect){rect_.w, top_clouds_y, rect_.w, top_clouds_texture_->getHeight()});
|
||||
|
||||
buildings_sprite_ = std::make_unique<Sprite>(0, 0, buildings_texture_->getWidth(), buildings_texture_->getHeight(), buildings_texture_);
|
||||
gradient_sprite_ = std::make_unique<Sprite>(0, 0, rect_.w, rect_.h, gradients_texture_);
|
||||
grass_sprite_ = std::make_unique<Sprite>(0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2, grass_texture_);
|
||||
bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_Rect){0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()});
|
||||
bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_Rect){rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()});
|
||||
|
||||
buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_, 0, 0, buildings_texture_->getWidth(), buildings_texture_->getHeight());
|
||||
gradient_sprite_ = std::make_unique<Sprite>(gradients_texture_, 0, 0, rect_.w, rect_.h);
|
||||
grass_sprite_ = std::make_unique<Sprite>(grass_texture_, 0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2);
|
||||
}
|
||||
|
||||
// Inicializa objetos
|
||||
top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||
top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||
bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||
buildings_sprite_->setPosY(base_ - buildings_sprite_->getHeight());
|
||||
grass_sprite_->setPosY(base_ - grass_sprite_->getHeight());
|
||||
{
|
||||
constexpr float top_clouds_speed = 0.1f;
|
||||
constexpr float bottom_clouds_speed = 0.05f;
|
||||
|
||||
top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||
top_clouds_sprite_a_->setVelX(-top_clouds_speed);
|
||||
|
||||
top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||
top_clouds_sprite_b_->setVelX(-top_clouds_speed);
|
||||
|
||||
bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||
bottom_clouds_sprite_a_->setVelX(-bottom_clouds_speed);
|
||||
|
||||
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||
bottom_clouds_sprite_b_->setVelX(-bottom_clouds_speed);
|
||||
|
||||
buildings_sprite_->setY(base_ - buildings_sprite_->getHeight());
|
||||
grass_sprite_->setY(base_ - grass_sprite_->getHeight());
|
||||
}
|
||||
|
||||
// Crea la textura para componer el fondo
|
||||
canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||
canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||
SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Crea la textura para atenuar el fondo
|
||||
color_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||
color_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||
SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND);
|
||||
setColor(color_);
|
||||
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_);
|
||||
@@ -101,20 +121,21 @@ void Background::update()
|
||||
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
|
||||
|
||||
// Incrementa el contador
|
||||
counter_++;
|
||||
++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 +144,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 +238,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 +284,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_;
|
||||
}
|
||||
|
||||
@@ -299,10 +315,10 @@ void Background::updateClouds()
|
||||
bottom_clouds_sprite_b_->setVelX(clouds_speed_ / 2);
|
||||
|
||||
// Mueve las nubes
|
||||
top_clouds_sprite_a_->move();
|
||||
top_clouds_sprite_b_->move();
|
||||
bottom_clouds_sprite_a_->move();
|
||||
bottom_clouds_sprite_b_->move();
|
||||
top_clouds_sprite_a_->update();
|
||||
top_clouds_sprite_b_->update();
|
||||
bottom_clouds_sprite_a_->update();
|
||||
bottom_clouds_sprite_b_->update();
|
||||
|
||||
// Calcula el offset de las nubes
|
||||
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth())
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#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
|
||||
#include "moving_sprite.h"
|
||||
#include "sprite.h"
|
||||
#include "texture.h"
|
||||
#include <memory>
|
||||
class MovingSprite;
|
||||
class Sprite;
|
||||
class Texture;
|
||||
|
||||
/*
|
||||
Esta clase es la encargada de dibujar el fondo que aparece durante la sección
|
||||
@@ -107,7 +107,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit Background(SDL_Renderer *renderer);
|
||||
Background();
|
||||
|
||||
// Destructor
|
||||
~Background();
|
||||
|
||||
@@ -1,18 +1,31 @@
|
||||
#include "balloon.h"
|
||||
#include <math.h> // for abs
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include <cmath> // for abs
|
||||
#include "animated_sprite.h" // for SpriteAnimated
|
||||
#include "moving_sprite.h" // for MovingSprite
|
||||
#include "param.h" // for param
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, std::vector<std::string> *animation)
|
||||
: kind_(kind), speed_(speed)
|
||||
Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||
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)
|
||||
{
|
||||
sprite_ = std::make_unique<AnimatedSprite>(texture, "", animation);
|
||||
|
||||
enabled_ = true;
|
||||
|
||||
switch (kind_)
|
||||
{
|
||||
@@ -24,7 +37,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
power_ = 1;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
vel_x_ = vel_x;
|
||||
vel_y_ = 0;
|
||||
max_vel_y_ = 3.0f;
|
||||
gravity_ = param.balloon_1.grav;
|
||||
@@ -46,7 +58,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
power_ = 3;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
vel_x_ = vel_x;
|
||||
vel_y_ = 0;
|
||||
max_vel_y_ = 3.0f;
|
||||
gravity_ = param.balloon_2.grav;
|
||||
@@ -68,7 +79,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
power_ = 7;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
vel_x_ = vel_x;
|
||||
vel_y_ = 0;
|
||||
max_vel_y_ = 3.0f;
|
||||
gravity_ = param.balloon_3.grav;
|
||||
@@ -90,7 +100,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
power_ = 15;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
vel_x_ = vel_x;
|
||||
vel_y_ = 0;
|
||||
max_vel_y_ = 3.0f;
|
||||
gravity_ = param.balloon_4.grav;
|
||||
@@ -112,11 +121,10 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
power_ = 1;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
vel_x_ = vel_x;
|
||||
vel_y_ = abs(vel_x) * 2;
|
||||
max_vel_y_ = abs(vel_x) * 2;
|
||||
vel_y_ = fabs(vel_x_ * 2.0f);
|
||||
max_vel_y_ = vel_y_;
|
||||
gravity_ = 0.00f;
|
||||
default_vel_y_ = abs(vel_x) * 2;
|
||||
default_vel_y_ = vel_y_;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
score_ = BALLOON_SCORE_1;
|
||||
@@ -134,11 +142,10 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
power_ = 3;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
vel_x_ = vel_x;
|
||||
vel_y_ = abs(vel_x) * 2;
|
||||
max_vel_y_ = abs(vel_x) * 2;
|
||||
vel_y_ = fabs(vel_x_ * 2.0f);
|
||||
max_vel_y_ = vel_y_;
|
||||
gravity_ = 0.00f;
|
||||
default_vel_y_ = abs(vel_x) * 2;
|
||||
default_vel_y_ = vel_y_;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
score_ = BALLOON_SCORE_2;
|
||||
@@ -156,11 +163,10 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
power_ = 7;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
vel_x_ = vel_x;
|
||||
vel_y_ = abs(vel_x) * 2;
|
||||
max_vel_y_ = abs(vel_x) * 2;
|
||||
vel_y_ = fabs(vel_x_ * 2.0f);
|
||||
max_vel_y_ = vel_y_;
|
||||
gravity_ = 0.00f;
|
||||
default_vel_y_ = abs(vel_x) * 2;
|
||||
default_vel_y_ = vel_y_;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
score_ = BALLOON_SCORE_3;
|
||||
@@ -178,11 +184,10 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
power_ = 15;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
vel_x_ = vel_x;
|
||||
vel_y_ = abs(vel_x) * 2;
|
||||
max_vel_y_ = abs(vel_x) * 2;
|
||||
vel_y_ = fabs(vel_x_ * 2.0f);
|
||||
max_vel_y_ = vel_y_;
|
||||
gravity_ = 0.00f;
|
||||
default_vel_y_ = abs(vel_x) * 2;
|
||||
default_vel_y_ = vel_y_;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
score_ = BALLOON_SCORE_4;
|
||||
@@ -200,7 +205,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
power_ = 0;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
vel_x_ = vel_x;
|
||||
vel_y_ = 0;
|
||||
max_vel_y_ = 3.0f;
|
||||
gravity_ = param.balloon_4.grav;
|
||||
@@ -213,7 +217,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
menace_ = 0;
|
||||
|
||||
// Añade rotación al sprite_
|
||||
sprite_->setRotate(false);
|
||||
sprite_->disableRotate();
|
||||
sprite_->setRotateSpeed(0);
|
||||
vel_x_ > 0.0f ? sprite_->setRotateAmount(2.0) : sprite_->setRotateAmount(-2.0);
|
||||
|
||||
@@ -223,10 +227,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
break;
|
||||
}
|
||||
|
||||
// Posición inicial
|
||||
pos_x_ = x;
|
||||
pos_y_ = y;
|
||||
|
||||
// Valores para el efecto de rebote
|
||||
bouncing_.enabled = false;
|
||||
bouncing_.counter = 0;
|
||||
@@ -238,36 +238,14 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
bouncing_.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
|
||||
bouncing_.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
|
||||
|
||||
// Alto y ancho del sprite_
|
||||
sprite_->setWidth(width_);
|
||||
sprite_->setHeight(height_);
|
||||
|
||||
// Posición X,Y del sprite_
|
||||
sprite_->setPosX((int)pos_x_);
|
||||
sprite_->setPosY((int)pos_y_);
|
||||
// Configura el sprite
|
||||
sprite_->setPos({static_cast<int>(pos_x_), static_cast<int>(pos_y_), width_, height_});
|
||||
|
||||
// Tamaño del circulo de colisión
|
||||
collider_.r = width_ / 2;
|
||||
|
||||
// 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;
|
||||
creation_counter_ = creation_timer;
|
||||
creation_counter_ini_ = creation_timer;
|
||||
|
||||
// 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
|
||||
@@ -323,7 +301,7 @@ void Balloon::render()
|
||||
|
||||
if (kind_ == POWER_BALL && !isBeingCreated())
|
||||
{
|
||||
auto sp = std::make_unique<Sprite>(sprite_->getPos(), sprite_->getTexture());
|
||||
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPosition());
|
||||
sp->setSpriteClip(BALLOON_WIDTH_4, 0, BALLOON_WIDTH_4, BALLOON_WIDTH_4);
|
||||
sp->render();
|
||||
}
|
||||
@@ -413,10 +391,6 @@ void Balloon::move()
|
||||
|
||||
// Aplica la gravedad al objeto sin pasarse de una velocidad máxima
|
||||
vel_y_ += gravity_;
|
||||
|
||||
// Al parecer esta asignación se quedó sin hacer y ahora el juego no funciona
|
||||
// correctamente si se aplica, así que se deja sin efecto
|
||||
// vel_y_ = std::min(vel_y_, max_vel_y_);
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite_
|
||||
@@ -471,13 +445,13 @@ void Balloon::update()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
sprite_->MovingSprite::update();
|
||||
sprite_->update();
|
||||
move();
|
||||
updateAnimation();
|
||||
updateColliders();
|
||||
updateState();
|
||||
updateBounce();
|
||||
counter_++;
|
||||
++counter_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,7 +501,7 @@ void Balloon::updateState()
|
||||
setInvulnerable(false);
|
||||
if (kind_ == POWER_BALL)
|
||||
{
|
||||
sprite_->setRotate(true);
|
||||
sprite_->enableRotate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -537,7 +511,7 @@ void Balloon::updateState()
|
||||
// Si es una powerball deja de rodar
|
||||
if (kind_ == POWER_BALL)
|
||||
{
|
||||
sprite_->setRotate(false);
|
||||
sprite_->disableRotate();
|
||||
}
|
||||
|
||||
// Reduce el contador
|
||||
@@ -553,7 +527,7 @@ void Balloon::updateState()
|
||||
// Si es una powerball vuelve a rodar
|
||||
if (kind_ == POWER_BALL)
|
||||
{
|
||||
sprite_->setRotate(true);
|
||||
sprite_->enableRotate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -586,7 +560,7 @@ void Balloon::updateAnimation()
|
||||
sprite_->setCurrentAnimation(normal_animation);
|
||||
}
|
||||
|
||||
sprite_->animate();
|
||||
sprite_->update();
|
||||
}
|
||||
|
||||
// Comprueba si el globo está habilitado
|
||||
@@ -626,15 +600,15 @@ int Balloon::getHeight() const
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Balloon::setVelY(float vel_y_)
|
||||
void Balloon::setVelY(float vel_y)
|
||||
{
|
||||
this->vel_y_ = vel_y_;
|
||||
vel_y_ = vel_y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Balloon::setSpeed(float speed_)
|
||||
void Balloon::setSpeed(float speed)
|
||||
{
|
||||
this->speed_ = speed_;
|
||||
speed_ = speed;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
|
||||
@@ -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 SpriteAnimated
|
||||
#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;
|
||||
@@ -141,7 +141,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, std::vector<std::string> *animation);
|
||||
Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation);
|
||||
|
||||
// Destructor
|
||||
~Balloon() = default;
|
||||
|
||||
714
source/balloon_formations.cpp
Normal file
@@ -0,0 +1,714 @@
|
||||
#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] = BalloonFormationParams();
|
||||
}
|
||||
}
|
||||
|
||||
constexpr 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];
|
||||
}
|
||||
67
source/balloon_formations.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
constexpr int NUMBER_OF_BALLOON_FORMATIONS = 100;
|
||||
constexpr int MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION = 50;
|
||||
|
||||
// Estructuras
|
||||
struct BalloonFormationParams
|
||||
{
|
||||
int x = 0; // Posición en el eje X donde crear al enemigo
|
||||
int y = 0; // Posición en el eje Y donde crear al enemigo
|
||||
float vel_x = 0.0f; // Velocidad inicial en el eje X
|
||||
int kind = 0; // Tipo de enemigo
|
||||
int creation_counter = 0; // Temporizador para la creación del enemigo
|
||||
|
||||
// Constructor que inicializa todos los campos con valores proporcionados o predeterminados
|
||||
BalloonFormationParams(int x_val = 0, int y_val = 0, float vel_x_val = 0.0f, int kind_val = 0, int creation_counter_val = 0)
|
||||
: x(x_val), y(y_val), vel_x(vel_x_val), kind(kind_val), creation_counter(creation_counter_val) {}
|
||||
};
|
||||
|
||||
struct BalloonFormationUnit // Contiene la información de una formación enemiga
|
||||
{
|
||||
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;
|
||||
@@ -11,16 +11,23 @@ constexpr int BULLET_VELX_LEFT = -2;
|
||||
constexpr int BULLET_VELX_RIGHT = 2;
|
||||
|
||||
// Constructor
|
||||
Bullet::Bullet(int x, int y, BulletType kind_, bool poweredUp, int owner, SDL_Rect *play_area, std::shared_ptr<Texture> texture)
|
||||
: pos_x_(x), pos_y_(y), width_(BULLET_WIDTH), height_(BULLET_HEIGHT), vel_x_(0), vel_y_(BULLET_VELY),
|
||||
kind_(kind_), owner_(owner), play_area_(play_area)
|
||||
Bullet::Bullet(int x, int y, BulletType kind, bool powered_up, int owner, SDL_Rect *play_area, std::shared_ptr<Texture> texture)
|
||||
: sprite_(std::make_unique<Sprite>(texture, SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT})),
|
||||
pos_x_(x),
|
||||
pos_y_(y),
|
||||
width_(BULLET_WIDTH),
|
||||
height_(BULLET_HEIGHT),
|
||||
vel_x_(0),
|
||||
vel_y_(BULLET_VELY),
|
||||
kind_(kind),
|
||||
owner_(owner),
|
||||
play_area_(play_area)
|
||||
{
|
||||
vel_x_ = (kind_ == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind_ == BulletType::RIGHT) ? BULLET_VELX_RIGHT
|
||||
: 0;
|
||||
|
||||
auto sprite_offset = poweredUp ? 3 : 0;
|
||||
auto kind_index = static_cast<int>(kind_);
|
||||
sprite_ = std::make_unique<Sprite>(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture);
|
||||
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());
|
||||
|
||||
collider_.r = width_ / 2;
|
||||
@@ -50,8 +57,8 @@ BulletMoveStatus Bullet::move()
|
||||
return BulletMoveStatus::OUT;
|
||||
}
|
||||
|
||||
sprite_->setPosX(pos_x_);
|
||||
sprite_->setPosY(pos_y_);
|
||||
sprite_->setX(pos_x_);
|
||||
sprite_->setY(pos_y_);
|
||||
shiftColliders();
|
||||
|
||||
return BulletMoveStatus::OK;
|
||||
@@ -59,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
|
||||
@@ -27,18 +27,21 @@ enum class BulletMoveStatus : Uint8
|
||||
class Bullet
|
||||
{
|
||||
private:
|
||||
int pos_x_; // Posición en el eje X
|
||||
int pos_y_; // Posición en el eje Y
|
||||
Uint8 width_; // Ancho del objeto
|
||||
Uint8 height_; // Alto del objeto
|
||||
int vel_x_; // Velocidad en el eje X
|
||||
int vel_y_; // Velocidad en el eje Y
|
||||
BulletType kind_; // Tipo de objeto
|
||||
int owner_; // Identificador del dueño del objeto
|
||||
Circle collider_; // Círculo de colisión del objeto
|
||||
SDL_Rect *play_area_; // Rectángulo con la zona de juego
|
||||
std::unique_ptr<Sprite> sprite_; // Sprite con los gráficos y métodos de pintado
|
||||
|
||||
int pos_x_; // Posición en el eje X
|
||||
int pos_y_; // Posición en el eje Y
|
||||
Uint8 width_; // Ancho del objeto
|
||||
Uint8 height_; // Alto del objeto
|
||||
|
||||
int vel_x_; // Velocidad en el eje X
|
||||
int vel_y_; // Velocidad en el eje Y
|
||||
|
||||
BulletType kind_; // Tipo de objeto
|
||||
int owner_; // Identificador del dueño del objeto
|
||||
Circle collider_; // Círculo de colisión del objeto
|
||||
SDL_Rect *play_area_; // Rectángulo con la zona de juego
|
||||
|
||||
void shiftColliders(); // Alinea el círculo de colisión con el objeto
|
||||
|
||||
public:
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "define_buttons.h"
|
||||
#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, SectionName, options, SectionOptions
|
||||
#include "section.h" // for Name, Options, name, options
|
||||
#include "text.h" // for Text
|
||||
#include "utils.h" // for OptionsController, Options, Param, ParamGame
|
||||
|
||||
@@ -104,7 +106,7 @@ void DefineButtons::checkInput()
|
||||
case SDL_QUIT:
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_NORMAL;
|
||||
section::options = section::Options::QUIT_WITH_KEYBOARD;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -155,7 +157,7 @@ void DefineButtons::incIndexButton()
|
||||
// Guarda los cambios en las opciones
|
||||
saveBindingsToOptions();
|
||||
|
||||
//input_->allActive(index_controller_);
|
||||
// input_->allActive(index_controller_);
|
||||
|
||||
// Reinicia variables
|
||||
index_button_ = 0;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
@@ -46,7 +47,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
DefineButtons(std::unique_ptr<Text> text);
|
||||
explicit DefineButtons(std::unique_ptr<Text> text);
|
||||
|
||||
// Destructor
|
||||
~DefineButtons() = default;
|
||||
|
||||
@@ -5,43 +5,47 @@
|
||||
#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 <cstdlib> // for system
|
||||
#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 "notifier.h" // for Notifier
|
||||
#include "on_screen_help.h" // for OnScreenHelp
|
||||
#include "options.h" // for options, loadOptionsFile, saveO...
|
||||
#include "param.h" // for param, loadParamsFromFile
|
||||
#include "resource.h" //for Resource
|
||||
#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;
|
||||
@@ -52,6 +56,14 @@ Director::Director(int argc, char *argv[])
|
||||
section::name = section::Name::LOGO;
|
||||
#endif
|
||||
|
||||
#ifndef VERBOSE
|
||||
// Deshabilita todos los std::cout
|
||||
std::ostream null_stream(nullptr);
|
||||
orig_buf = std::cout.rdbuf(null_stream.rdbuf());
|
||||
#endif
|
||||
|
||||
std::cout << "Game start" << std::endl;
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
checkProgramArguments(argc, argv);
|
||||
|
||||
@@ -62,11 +74,8 @@ Director::Director(int argc, char *argv[])
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
Asset::init(executable_path_);
|
||||
|
||||
// Si falta algún fichero no inicia el programa
|
||||
if (!setFileList())
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Crea el indice de ficheros
|
||||
setFileList();
|
||||
|
||||
// Carga el fichero de configuración
|
||||
loadOptionsFile(Asset::get()->get("config.txt"));
|
||||
@@ -95,19 +104,18 @@ Director::Director(int argc, char *argv[])
|
||||
// Crea los objetos
|
||||
lang::loadFromFile(getLangFile((lang::Code)options.game.language));
|
||||
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
initInput();
|
||||
|
||||
Screen::init(window_, renderer_);
|
||||
|
||||
Resource::init();
|
||||
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
bindInputs();
|
||||
|
||||
auto notifier_text = std::make_shared<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
Notifier::init(std::string(), notifier_text, Asset::get()->get("notify.wav"));
|
||||
|
||||
OnScreenHelp::init();
|
||||
|
||||
// Carga los sonidos del juego
|
||||
loadSounds();
|
||||
|
||||
// Carga las musicas del juego
|
||||
loadMusics();
|
||||
|
||||
globalInputs::init();
|
||||
}
|
||||
|
||||
@@ -116,25 +124,23 @@ Director::~Director()
|
||||
saveOptionsFile(Asset::get()->get("config.txt"));
|
||||
|
||||
Asset::destroy();
|
||||
Resource::destroy();
|
||||
Input::destroy();
|
||||
Screen::destroy();
|
||||
Notifier::destroy();
|
||||
OnScreenHelp::destroy();
|
||||
|
||||
sounds_.clear();
|
||||
musics_.clear();
|
||||
|
||||
SDL_DestroyRenderer(renderer_);
|
||||
SDL_DestroyWindow(window_);
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
std::cout << "\nBye!" << std::endl;
|
||||
}
|
||||
|
||||
/// Inicializa el objeto input
|
||||
void Director::initInput()
|
||||
// Asigna los botones y teclas al objeto Input
|
||||
void Director::bindInputs()
|
||||
{
|
||||
// Busca si hay mandos conectados
|
||||
Input::get()->discoverGameControllers();
|
||||
|
||||
// Teclado - Movimiento del jugador
|
||||
Input::get()->bindKey(InputType::UP, SDL_SCANCODE_UP);
|
||||
Input::get()->bindKey(InputType::DOWN, SDL_SCANCODE_DOWN);
|
||||
@@ -160,8 +166,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 +194,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 +206,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 +219,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)
|
||||
@@ -242,9 +248,7 @@ bool Director::initSDL()
|
||||
// Inicializa SDL
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
#endif
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
@@ -252,7 +256,6 @@ bool Director::initSDL()
|
||||
// Inicia el generador de numeros aleatorios
|
||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
#ifdef VERBOSE
|
||||
// Muestra información de la pantalla
|
||||
/*std::cout << "\nDisplay modes list:" << std::endl;
|
||||
for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i)
|
||||
@@ -266,30 +269,23 @@ bool Director::initSDL()
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
std::cout << "\nCurrent display mode: " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
||||
std::cout << "Window resolution : " + std::to_string(param.game.width) + "x" + std::to_string(param.game.height) + " x" + std::to_string(options.video.window.size) << std::endl;
|
||||
#endif
|
||||
|
||||
// Establece el filtro de la textura
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: texture filtering not enabled!\n";
|
||||
#endif
|
||||
}
|
||||
#ifndef NO_SHADERS
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: opengl not enabled!\n";
|
||||
#endif // VERBOSE
|
||||
}
|
||||
#endif // NO_SHADERS
|
||||
// Crea la ventana
|
||||
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
||||
if (!window_)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
#endif
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
@@ -298,7 +294,7 @@ bool Director::initSDL()
|
||||
Uint32 flags = 0;
|
||||
if (options.video.v_sync)
|
||||
{
|
||||
flags = flags | SDL_RENDERER_PRESENTVSYNC;
|
||||
flags = SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
#ifndef NO_SHADERS
|
||||
// La aceleración se activa según el define
|
||||
@@ -308,9 +304,7 @@ bool Director::initSDL()
|
||||
|
||||
if (!renderer_)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
#endif
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
@@ -328,19 +322,17 @@ bool Director::initSDL()
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
return success;
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros
|
||||
bool Director::setFileList()
|
||||
void Director::setFileList()
|
||||
{
|
||||
#ifdef MACOS_BUNDLE
|
||||
const std::string prefix = "/../Resources";
|
||||
#else
|
||||
const std::string prefix = "";
|
||||
const std::string prefix;
|
||||
#endif
|
||||
|
||||
// Ficheros de configuración
|
||||
@@ -379,94 +371,127 @@ bool Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/shaders/crtpi.glsl", AssetType::DATA);
|
||||
|
||||
// Texturas
|
||||
Asset::get()->add(prefix + "/data/gfx/controllers/controllers.png", AssetType::BITMAP);
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.ani", AssetType::ANIMATION);
|
||||
{ // Controllers
|
||||
Asset::get()->add(prefix + "/data/gfx/controllers/controllers.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.ani", AssetType::ANIMATION);
|
||||
{ // Balloons
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.ani", AssetType::ANIMATION);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/powerball.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/powerball.ani", AssetType::ANIMATION);
|
||||
{ // Explosions
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.ani", AssetType::ANIMATION);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP);
|
||||
{ // Power Ball
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/powerball.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/balloon/powerball.ani", AssetType::ANIMATION);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_buildings.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_clouds1.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_clouds2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_grass.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_power_meter.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_text.png", AssetType::BITMAP);
|
||||
{ // Bala
|
||||
Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP);
|
||||
{ // Juego
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_buildings.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_clouds1.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_clouds2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_grass.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_power_meter.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/logo/logo_since_1998.png", AssetType::BITMAP);
|
||||
{ // Game Text
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_1000_points.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_2500_points.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_5000_points.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_powerup.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_one_hit.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_clock.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_clock.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.ani", AssetType::ANIMATION);
|
||||
{ // Intro
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_bg_tile.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_coffee.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_crisis.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_arcade_edition.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_dust.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_dust.ani", AssetType::ANIMATION);
|
||||
{ // Logo
|
||||
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/logo/logo_since_1998.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player1.gif", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player1_pal1.gif", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player1_pal2.gif", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player1_pal3.gif", AssetType::PALETTE);
|
||||
{ // Items
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_clock.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_clock.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.ani", AssetType::ANIMATION);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player2.gif", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player2_pal1.gif", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player2_pal2.gif", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player2_pal3.gif", AssetType::PALETTE);
|
||||
{ // Titulo
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_bg_tile.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_coffee.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_crisis.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_arcade_edition.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_dust.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/title/title_dust.ani", AssetType::ANIMATION);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player.ani", AssetType::ANIMATION);
|
||||
{ // Jugador 1
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player1.gif", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player1_one_coffee_palette.pal", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player1_two_coffee_palette.pal", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player1_all_white_palette.pal", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player1_power.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player_power.gif", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player_power_pal.gif", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player_power.ani", AssetType::ANIMATION);
|
||||
{ // Jugador 2
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player2.gif", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player2_one_coffee_palette.pal", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player2_two_coffee_palette.pal", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player2_all_white_palette.pal", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player2_power.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
{ // Animaciones del jugador
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player.ani", AssetType::ANIMATION);
|
||||
Asset::get()->add(prefix + "/data/gfx/player/player_power.ani", AssetType::ANIMATION);
|
||||
}
|
||||
|
||||
// Fuentes de texto
|
||||
Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia.png", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia_big2.png", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/nokia_big2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/nokia.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia2.png", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/nokia2.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia_big2.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_big.png", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_big.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_big.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_pal1.gif", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_palette1.pal", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/font/smb2.txt", AssetType::FONT);
|
||||
|
||||
// Textos
|
||||
@@ -474,25 +499,27 @@ bool Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/lang/en_UK.txt", AssetType::LANG);
|
||||
Asset::get()->add(prefix + "/data/lang/ba_BA.txt", AssetType::LANG);
|
||||
|
||||
return Asset::get()->check();
|
||||
// Si falta algun fichero, sale del programa
|
||||
if (!Asset::get()->check())
|
||||
throw std::runtime_error("Falta algun fichero");
|
||||
}
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
void Director::loadParams(std::string filepath)
|
||||
void Director::loadParams(const std::string &file_path)
|
||||
{
|
||||
loadParamsFromFile(filepath);
|
||||
loadParamsFromFile(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)
|
||||
@@ -503,7 +530,7 @@ void Director::checkProgramArguments(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
void Director::createSystemFolder(std::string folder)
|
||||
void Director::createSystemFolder(const std::string &folder)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
system_folder_ = std::string(getenv("APPDATA")) + "/" + folder;
|
||||
@@ -562,100 +589,57 @@ void Director::createSystemFolder(std::string folder)
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los sonidos del juego
|
||||
void Director::loadSounds()
|
||||
{
|
||||
// Obtiene la lista con las rutas a los ficheros de sonidos
|
||||
std::vector<std::string> list = Asset::get()->getListByType(AssetType::SOUND);
|
||||
sounds_.clear();
|
||||
|
||||
for (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);
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las musicas del juego
|
||||
void Director::loadMusics()
|
||||
{
|
||||
// Obtiene la lista con las rutas a los ficheros musicales
|
||||
std::vector<std::string> list = Asset::get()->getListByType(AssetType::MUSIC);
|
||||
musics_.clear();
|
||||
|
||||
for (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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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>();
|
||||
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>();
|
||||
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);
|
||||
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>();
|
||||
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>();
|
||||
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);
|
||||
game->run();
|
||||
delete game;
|
||||
}
|
||||
|
||||
int Director::run()
|
||||
@@ -702,8 +686,22 @@ int Director::run()
|
||||
}
|
||||
}
|
||||
|
||||
const int returnCode = section::options == section::Options::QUIT_NORMAL ? 0 : 1;
|
||||
return returnCode;
|
||||
#ifdef ARCADE
|
||||
// Comprueba si ha de apagar el sistema
|
||||
if (section::options == section::Options::QUIT_WITH_CONTROLLER)
|
||||
shutdownSystem();
|
||||
#endif
|
||||
|
||||
const auto return_code = (section::options == section::Options::QUIT_WITH_KEYBOARD) ? "with keyboard" : (section::options == section::Options::QUIT_WITH_CONTROLLER) ? "with controller"
|
||||
: "from event";
|
||||
std::cout << "\nGame end " << return_code << std::endl;
|
||||
|
||||
#ifndef VERBOSE
|
||||
// Habilita de nuevo los std::cout
|
||||
std::cout.rdbuf(orig_buf);
|
||||
#endif
|
||||
|
||||
return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
@@ -728,4 +726,22 @@ std::string Director::getLangFile(lang::Code code)
|
||||
}
|
||||
|
||||
return Asset::get()->get("en_UK.txt");
|
||||
}
|
||||
|
||||
// Apaga el sistema
|
||||
void Director::shutdownSystem()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// Apaga el sistema en Windows
|
||||
system("shutdown /s /t 0");
|
||||
#elif __APPLE__
|
||||
// Apaga el sistema en macOS
|
||||
system("sudo shutdown -h now");
|
||||
#elif __linux__
|
||||
// Apaga el sistema en Linux
|
||||
system("shutdown -h now");
|
||||
#else
|
||||
// Sistema operativo no compatible
|
||||
#error "Sistema operativo no soportado"
|
||||
#endif
|
||||
}
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||
#include <string> // for string, basic_string
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "lang.h" // for lang_e
|
||||
#include "utils.h" // for MusicFile, SoundFile
|
||||
namespace lang
|
||||
{
|
||||
enum class Code : int;
|
||||
}
|
||||
struct ResourceMusic;
|
||||
struct ResourceSound;
|
||||
|
||||
// Textos
|
||||
constexpr char WINDOW_CAPTION[] = "Coffee Crisis Arcade Edition";
|
||||
@@ -14,15 +18,14 @@ class Director
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Window *window_; // La ventana donde dibujamos
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Window *window_; // La ventana donde dibujamos
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
std::streambuf *orig_buf; // Puntero al buffer de flujo original para restaurar std::cout
|
||||
|
||||
// Variables
|
||||
std::string executable_path_; // Path del ejecutable
|
||||
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
||||
std::string executable_path_; // Path del ejecutable
|
||||
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
||||
std::string param_file_argument_; // Argumento para gestionar el fichero con los parametros del programa
|
||||
std::vector<SoundFile> sounds_; // Vector con los sonidos
|
||||
std::vector<MusicFile> musics_; // Vector con las musicas
|
||||
|
||||
// Inicializa jail_audio
|
||||
void initJailAudio();
|
||||
@@ -30,26 +33,20 @@ private:
|
||||
// Arranca SDL y crea la ventana
|
||||
bool initSDL();
|
||||
|
||||
// Inicializa el objeto input
|
||||
void initInput();
|
||||
// Asigna los botones y teclas al objeto Input
|
||||
void bindInputs();
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
void loadParams(std::string file_path);
|
||||
void loadParams(const std::string &file_path);
|
||||
|
||||
// Crea el indice de ficheros
|
||||
bool setFileList();
|
||||
|
||||
// Carga los sonidos del juego
|
||||
void loadSounds();
|
||||
|
||||
// Carga las musicas del juego
|
||||
void loadMusics();
|
||||
void setFileList();
|
||||
|
||||
// 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(std::string folder);
|
||||
void createSystemFolder(const std::string &folder);
|
||||
|
||||
// Ejecuta la sección con el logo
|
||||
void runLogo();
|
||||
@@ -75,9 +72,12 @@ private:
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
std::string getLangFile(lang::Code code);
|
||||
|
||||
// Apaga el sistema
|
||||
void shutdownSystem();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Director(int argc, char *argv[]);
|
||||
Director(int argc, const char *argv[]);
|
||||
|
||||
// Destructor
|
||||
~Director();
|
||||
|
||||
@@ -1,720 +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 creationTime = 300;
|
||||
int incX = 0;
|
||||
int incTime = 0;
|
||||
int j = 0;
|
||||
|
||||
// #00 - Dos enemigos BALLOON4 uno a cada extremo
|
||||
j = 0;
|
||||
enemy_formation_[j].number_of_enemies = 2;
|
||||
incX = x4_100;
|
||||
incTime = 0;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x4_0 + (i * incX);
|
||||
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 = creationTime + (incTime * i);
|
||||
}
|
||||
|
||||
// #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro
|
||||
j = 1;
|
||||
enemy_formation_[j].number_of_enemies = 2;
|
||||
incX = param.game.play_area.center_x;
|
||||
incTime = 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 * incX);
|
||||
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 = creationTime + (incTime * 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;
|
||||
incX = BALLOON_WIDTH_2 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_0 + (i * incX);
|
||||
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 = creationTime - (incTime * 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;
|
||||
incX = BALLOON_WIDTH_2 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_100 - (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha
|
||||
j = 4;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
incX = BALLOON_WIDTH_3 * 2;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda
|
||||
j = 5;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
incX = BALLOON_WIDTH_3 * 2;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha
|
||||
j = 6;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
incX = BALLOON_WIDTH_3 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda
|
||||
j = 7;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
incX = BALLOON_WIDTH_3 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha
|
||||
j = 8;
|
||||
enemy_formation_[j].number_of_enemies = 6;
|
||||
incX = BALLOON_WIDTH_1 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_0 + (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda
|
||||
j = 9;
|
||||
enemy_formation_[j].number_of_enemies = 6;
|
||||
incX = BALLOON_WIDTH_1 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_100 - (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #10 - Tres enemigos BALLOON4 seguidos desde la izquierda
|
||||
j = 10;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
incX = BALLOON_WIDTH_4 + 1;
|
||||
incTime = 15;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x4_0 + (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #11 - Tres enemigos BALLOON4 seguidos desde la derecha
|
||||
j = 11;
|
||||
enemy_formation_[j].number_of_enemies = 3;
|
||||
incX = BALLOON_WIDTH_4 + 1;
|
||||
incTime = 15;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x4_100 - (i * incX);
|
||||
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 = creationTime - (incTime * 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;
|
||||
incX = BALLOON_WIDTH_2 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_0 + (i * incX);
|
||||
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 = creationTime - (incTime * 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;
|
||||
incX = BALLOON_WIDTH_2 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_100 - (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados
|
||||
j = 14;
|
||||
enemy_formation_[j].number_of_enemies = 5;
|
||||
incX = BALLOON_WIDTH_3 * 2;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados
|
||||
j = 15;
|
||||
enemy_formation_[j].number_of_enemies = 5;
|
||||
incX = BALLOON_WIDTH_3 * 2;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos
|
||||
j = 16;
|
||||
enemy_formation_[j].number_of_enemies = 5;
|
||||
incX = BALLOON_WIDTH_3 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_0 + (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos
|
||||
j = 17;
|
||||
enemy_formation_[j].number_of_enemies = 5;
|
||||
incX = BALLOON_WIDTH_3 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos
|
||||
j = 18;
|
||||
enemy_formation_[j].number_of_enemies = 12;
|
||||
incX = BALLOON_WIDTH_1 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_0 + (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos
|
||||
j = 19;
|
||||
enemy_formation_[j].number_of_enemies = 12;
|
||||
incX = BALLOON_WIDTH_1 + 1;
|
||||
incTime = 10;
|
||||
for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++)
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x1_100 - (i * incX);
|
||||
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 = creationTime - (incTime * i);
|
||||
}
|
||||
|
||||
// #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos
|
||||
j = 20;
|
||||
enemy_formation_[j].number_of_enemies = 4;
|
||||
incX = BALLOON_WIDTH_4 + 1;
|
||||
incTime = 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 * incX);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x4_100 - ((i - half) * incX);
|
||||
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 = creationTime + (incTime * i);
|
||||
}
|
||||
|
||||
// #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos
|
||||
j = 21;
|
||||
enemy_formation_[j].number_of_enemies = 10;
|
||||
incX = BALLOON_WIDTH_2 + 1;
|
||||
incTime = 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 * incX);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creationTime) - (incTime * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x2_100 - ((i - half) * incX);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creationTime) - (incTime * (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;
|
||||
incX = BALLOON_WIDTH_3 * 2;
|
||||
incTime = 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 * incX);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creationTime) - (incTime * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - ((i - half) * incX);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creationTime) - (incTime * (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;
|
||||
incX = BALLOON_WIDTH_3 + 1;
|
||||
incTime = 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 * incX);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creationTime) - (incTime * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy_formation_[j].init[i].x = x3_100 - ((i - half) * incX);
|
||||
enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||
enemy_formation_[j].init[i].creation_counter = (creationTime) - (incTime * (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;
|
||||
incX = 0;
|
||||
incTime = 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 = (creationTime) + (incTime * 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 = (creationTime) + (incTime * (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;
|
||||
incX = BALLOON_WIDTH_1 + 1;
|
||||
incTime = 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 = (creationTime) - (incTime * 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 = (creationTime) - (incTime * (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;
|
||||
};
|
||||
@@ -15,7 +15,7 @@ void EnterName::init()
|
||||
|
||||
// Inicia la lista de caracteres permitidos
|
||||
character_list_ = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
|
||||
pos_ = 0;
|
||||
position_ = 0;
|
||||
num_characters_ = (int)character_list_.size();
|
||||
|
||||
// Pone la lista de indices para que refleje el nombre
|
||||
@@ -26,26 +26,27 @@ void EnterName::init()
|
||||
}
|
||||
|
||||
// Incrementa la posición
|
||||
void EnterName::incPos()
|
||||
void EnterName::incPosition()
|
||||
{
|
||||
pos_++;
|
||||
pos_ = std::min(pos_, NAME_LENGHT - 1);
|
||||
position_++;
|
||||
position_ = std::min(position_, NAME_LENGHT - 1);
|
||||
checkIfPositionHasBeenUsed();
|
||||
}
|
||||
|
||||
// Decrementa la posición
|
||||
void EnterName::decPos()
|
||||
void EnterName::decPosition()
|
||||
{
|
||||
pos_--;
|
||||
pos_ = std::max(pos_, 0);
|
||||
position_--;
|
||||
position_ = std::max(position_, 0);
|
||||
}
|
||||
|
||||
// Incrementa el índice
|
||||
void EnterName::incIndex()
|
||||
{
|
||||
++character_index_[pos_];
|
||||
if (character_index_[pos_] >= num_characters_)
|
||||
++character_index_[position_];
|
||||
if (character_index_[position_] >= num_characters_)
|
||||
{
|
||||
character_index_[pos_] = 0;
|
||||
character_index_[position_] = 0;
|
||||
}
|
||||
updateName();
|
||||
}
|
||||
@@ -53,15 +54,15 @@ void EnterName::incIndex()
|
||||
// Decrementa el índice
|
||||
void EnterName::decIndex()
|
||||
{
|
||||
--character_index_[pos_];
|
||||
if (character_index_[pos_] < 0)
|
||||
--character_index_[position_];
|
||||
if (character_index_[position_] < 0)
|
||||
{
|
||||
character_index_[pos_] = num_characters_ - 1;
|
||||
character_index_[position_] = num_characters_ - 1;
|
||||
}
|
||||
updateName();
|
||||
}
|
||||
|
||||
// Actualiza la variable
|
||||
// Actualiza el nombre a partir de la lista de índices
|
||||
void EnterName::updateName()
|
||||
{
|
||||
name_.clear();
|
||||
@@ -74,16 +75,18 @@ void EnterName::updateName()
|
||||
// Actualiza la variable
|
||||
void EnterName::updateCharacterIndex()
|
||||
{
|
||||
// Rellena de espacios
|
||||
// Rellena de espacios y marca como no usados
|
||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||
{
|
||||
character_index_[i] = 0;
|
||||
position_has_been_used_[i] = false;
|
||||
}
|
||||
|
||||
// Coloca los índices en funcion de los caracteres que forman el nombre
|
||||
for (int i = 0; i < (int)name_.size(); ++i)
|
||||
{
|
||||
character_index_[i] = findIndex(name_.at(i));
|
||||
position_has_been_used_[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +110,21 @@ std::string EnterName::getName() const
|
||||
}
|
||||
|
||||
// Obtiene la posición que se está editando
|
||||
int EnterName::getPos() const
|
||||
int EnterName::getPosition() const
|
||||
{
|
||||
return pos_;
|
||||
return position_;
|
||||
}
|
||||
|
||||
// Comprueba la posición y copia el caracter si es necesario
|
||||
void EnterName::checkIfPositionHasBeenUsed()
|
||||
{
|
||||
auto used = position_has_been_used_[position_];
|
||||
|
||||
if (!used && position_ > 0)
|
||||
{
|
||||
character_index_[position_] = character_index_[position_ - 1];
|
||||
}
|
||||
|
||||
position_has_been_used_[position_] = true;
|
||||
updateName();
|
||||
}
|
||||
@@ -16,13 +16,14 @@ constexpr int NAME_LENGHT = 8;
|
||||
class EnterName
|
||||
{
|
||||
private:
|
||||
std::string character_list_; // Lista de todos los caracteres permitidos
|
||||
std::string name_; // Nombre introducido
|
||||
int pos_; // Posición a editar del nombre
|
||||
int num_characters_; // Cantidad de caracteres de la lista de caracteres
|
||||
int character_index_[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||
std::string character_list_; // Lista de todos los caracteres permitidos
|
||||
std::string name_; // Nombre introducido
|
||||
int position_; // Posición a editar del nombre
|
||||
int num_characters_; // Cantidad de caracteres de la lista de caracteres
|
||||
int character_index_[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||
bool position_has_been_used_[NAME_LENGHT]; // Indica si en esa posición se ha puesto ya alguna letra. Se utiliza para replicar la letra anterior la primera vez
|
||||
|
||||
// Actualiza la variable
|
||||
// Actualiza el nombre a partir de la lista de índices
|
||||
void updateName();
|
||||
|
||||
// Actualiza la variable
|
||||
@@ -31,6 +32,9 @@ private:
|
||||
// Encuentra el indice de un caracter en "characterList"
|
||||
int findIndex(char character);
|
||||
|
||||
// Comprueba la posición y copia el caracter si es necesario
|
||||
void checkIfPositionHasBeenUsed();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
EnterName();
|
||||
@@ -42,10 +46,10 @@ public:
|
||||
void init();
|
||||
|
||||
// Incrementa la posición
|
||||
void incPos();
|
||||
void incPosition();
|
||||
|
||||
// Decrementa la posición
|
||||
void decPos();
|
||||
void decPosition();
|
||||
|
||||
// Incrementa el índice
|
||||
void incIndex();
|
||||
@@ -57,5 +61,5 @@ public:
|
||||
std::string getName() const;
|
||||
|
||||
// Obtiene la posición que se está editando
|
||||
int getPos() const;
|
||||
int getPosition() const;
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "explosions.h"
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
class Texture;
|
||||
#include <utility> // for move
|
||||
#include "animated_sprite.h" // for SpriteAnimated
|
||||
class Texture; // lines 3-3
|
||||
|
||||
// Constructor
|
||||
Explosions::Explosions()
|
||||
@@ -37,22 +38,17 @@ void Explosions::render()
|
||||
}
|
||||
|
||||
// Añade texturas al objeto
|
||||
void Explosions::addTexture(int size, std::shared_ptr<Texture> texture, std::vector<std::string> *animation)
|
||||
void Explosions::addTexture(int size, std::shared_ptr<Texture> texture, std::vector<std::string> &animation)
|
||||
{
|
||||
ExplosionTexture temp;
|
||||
temp.size = size;
|
||||
temp.texture = texture;
|
||||
temp.animation = animation;
|
||||
textures_.push_back(temp);
|
||||
textures_.emplace_back(ExplosionTexture(size, texture, animation));
|
||||
}
|
||||
|
||||
// Añade una explosión
|
||||
void Explosions::add(int x, int y, int size)
|
||||
{
|
||||
const int index = getIndexBySize(size);
|
||||
auto sprite = std::make_unique<AnimatedSprite>(textures_[index].texture, "", textures_[index].animation);
|
||||
sprite->setPos(x, y);
|
||||
explosions_.push_back(std::move(sprite));
|
||||
const auto index = getIndexBySize(size);
|
||||
explosions_.emplace_back(std::make_unique<AnimatedSprite>(textures_[index].texture, textures_[index].animation));
|
||||
explosions_.back()->setPos(x, y);
|
||||
}
|
||||
|
||||
// Vacia el vector de elementos finalizados
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "animated_sprite.h"
|
||||
#include <memory>
|
||||
#include "texture.h"
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
struct ExplosionTexture
|
||||
{
|
||||
std::shared_ptr<Texture> texture; // Textura para la explosión
|
||||
std::vector<std::string> *animation; // Animación para la textura
|
||||
int size; // Tamaño de la explosión
|
||||
int size; // Tamaño de la explosión
|
||||
std::shared_ptr<Texture> texture; // Textura para la explosión
|
||||
std::vector<std::string> animation; // Animación para la textura
|
||||
|
||||
// Constructor
|
||||
ExplosionTexture(int sz, std::shared_ptr<Texture> tex, std::vector<std::string> anim)
|
||||
: size(sz), texture(tex), animation(anim) {}
|
||||
};
|
||||
|
||||
// Clase explosions
|
||||
@@ -41,7 +45,7 @@ public:
|
||||
void render();
|
||||
|
||||
// Añade texturas al objeto
|
||||
void addTexture(int size, std::shared_ptr<Texture> texture, std::vector<std::string> *animation);
|
||||
void addTexture(int size, std::shared_ptr<Texture> texture, std::vector<std::string> &animation);
|
||||
|
||||
// Añade una explosión
|
||||
void add(int x, int y, int size);
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for min, max
|
||||
#include "param.h" // for param
|
||||
#include "screen.h"
|
||||
#include "utils.h" // for Param, ParamGame, ParamFade
|
||||
|
||||
// Constructor
|
||||
Fade::Fade(SDL_Renderer *renderer_)
|
||||
: renderer_(renderer_)
|
||||
Fade::Fade()
|
||||
: renderer_(Screen::get()->getRenderer())
|
||||
{
|
||||
// Crea la textura donde dibujar el fade
|
||||
backbuffer_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
|
||||
@@ -54,7 +54,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Fade(SDL_Renderer *renderer);
|
||||
Fade();
|
||||
|
||||
// Destructor
|
||||
~Fade();
|
||||
|
||||
1608
source/game.cpp
287
source/game.h
@@ -1,31 +1,30 @@
|
||||
#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
|
||||
enum class ItemType;
|
||||
|
||||
// Modo demo
|
||||
constexpr bool GAME_MODE_DEMO_OFF = false;
|
||||
@@ -33,26 +32,6 @@ constexpr bool GAME_MODE_DEMO_ON = true;
|
||||
|
||||
// Cantidad de elementos a escribir en los ficheros de datos
|
||||
constexpr int TOTAL_SCORE_DATA = 3;
|
||||
constexpr int TOTAL_DEMO_DATA = 2000;
|
||||
|
||||
// Contadores
|
||||
constexpr int STAGE_COUNTER = 200;
|
||||
constexpr int HELP_COUNTER = 1000;
|
||||
constexpr int GAME_COMPLETED_START_FADE = 500;
|
||||
constexpr int GAME_COMPLETED_END = 700;
|
||||
constexpr int GAME_OVER_COUNTER = 350;
|
||||
|
||||
// Porcentaje de aparición de los objetos
|
||||
constexpr int ITEM_POINTS_1_DISK_ODDS = 10;
|
||||
constexpr int ITEM_POINTS_2_GAVINA_ODDS = 6;
|
||||
constexpr int ITEM_POINTS_3_PACMAR_ODDS = 3;
|
||||
constexpr int ITEM_CLOCK_ODDS = 5;
|
||||
constexpr int ITEM_COFFEE_ODDS = 5;
|
||||
constexpr int ITEM_POWER_BALL_ODDS = 0;
|
||||
constexpr int ITEM_COFFEE_MACHINE_ODDS = 4;
|
||||
|
||||
// Valores para las variables asociadas a los objetos
|
||||
constexpr int TIME_STOPPED_COUNTER = 300;
|
||||
|
||||
/*
|
||||
Esta clase gestiona un estado del programa. Se encarga de toda la parte en la
|
||||
@@ -84,6 +63,7 @@ constexpr int TIME_STOPPED_COUNTER = 300;
|
||||
class Game
|
||||
{
|
||||
private:
|
||||
// Estructuras
|
||||
struct Helper
|
||||
{
|
||||
bool need_coffee; // Indica si se necesitan cafes
|
||||
@@ -98,14 +78,25 @@ private:
|
||||
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
|
||||
};
|
||||
|
||||
struct Demo
|
||||
{
|
||||
bool enabled; // Indica si está activo el modo demo
|
||||
bool recording; // Indica si está activado el modo para grabar la demo
|
||||
int counter; // Contador para el modo demo
|
||||
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
|
||||
DemoKeys data_file[2][TOTAL_DEMO_DATA]; // Vector con diferentes sets de datos con los movimientos para la demo
|
||||
};
|
||||
// Constantes
|
||||
|
||||
// Contadores
|
||||
static constexpr int STAGE_COUNTER_ = 200;
|
||||
static constexpr int HELP_COUNTER_ = 1000;
|
||||
static constexpr int GAME_COMPLETED_START_FADE_ = 500;
|
||||
static constexpr int GAME_COMPLETED_END_ = 700;
|
||||
static constexpr int GAME_OVER_COUNTER_ = 350;
|
||||
static constexpr int TIME_STOPPED_COUNTER_ = 300;
|
||||
static constexpr int TICKS_SPEED_ = 15;
|
||||
|
||||
// Porcentaje de aparición de los objetos
|
||||
static constexpr int ITEM_POINTS_1_DISK_ODDS_ = 10;
|
||||
static constexpr int ITEM_POINTS_2_GAVINA_ODDS_ = 6;
|
||||
static constexpr int ITEM_POINTS_3_PACMAR_ODDS_ = 3;
|
||||
static constexpr int ITEM_CLOCK_ODDS_ = 5;
|
||||
static constexpr int ITEM_COFFEE_ODDS_ = 5;
|
||||
static constexpr int ITEM_POWER_BALL_ODDS_ = 0;
|
||||
static constexpr int ITEM_COFFEE_MACHINE_ODDS_ = 4;
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
@@ -114,32 +105,30 @@ 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
|
||||
|
||||
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
|
||||
std::vector<std::shared_ptr<Balloon>> balloons_; // Vector con los globos
|
||||
std::vector<std::unique_ptr<Bullet>> bullets_; // Vector con las balas
|
||||
std::vector<std::unique_ptr<Item>> items_; // Vector con los items
|
||||
std::vector<SmartSprite *> smart_sprites_; // Vector con los smartsprites
|
||||
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
|
||||
std::vector<std::shared_ptr<Balloon>> balloons_; // Vector con los globos
|
||||
std::vector<std::unique_ptr<Bullet>> bullets_; // Vector con las balas
|
||||
std::vector<std::unique_ptr<Item>> items_; // Vector con los items
|
||||
std::vector<std::unique_ptr<SmartSprite>> smart_sprites_; // Vector con los smartsprites
|
||||
|
||||
std::shared_ptr<Texture> bullet_texture_; // Textura para las balas
|
||||
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
|
||||
std::vector<std::shared_ptr<Texture>> balloon_textures_; // Vector con las texturas de los globos
|
||||
std::vector<std::shared_ptr<Texture>> explosions_textures_; // Vector con las texturas de las explosiones
|
||||
std::vector<std::shared_ptr<Texture>> player1_textures_; // Vector con las texturas del jugador
|
||||
std::vector<std::shared_ptr<Texture>> player2_textures_; // Vector con las texturas del jugador
|
||||
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores;
|
||||
|
||||
std::shared_ptr<Texture> game_text_texture_; // Textura para los sprites con textos
|
||||
std::vector<std::shared_ptr<Texture>> game_text_textures_; // Vector con las texturas para los sprites con textos
|
||||
|
||||
std::vector<std::vector<std::string> *> item_animations_; // Vector con las animaciones de los items
|
||||
std::vector<std::vector<std::string> *> player_animations_; // Vector con las animaciones del jugador
|
||||
std::vector<std::vector<std::string> *> balloon_animations_; // Vector con las animaciones de los globos
|
||||
std::vector<std::vector<std::string> *> explosions_animations_; // Vector con las animaciones de las explosiones
|
||||
std::vector<std::vector<std::string>> item_animations_; // Vector con las animaciones de los items
|
||||
std::vector<std::vector<std::string>> player_animations_; // Vector con las animaciones del jugador
|
||||
std::vector<std::vector<std::string>> balloon_animations_; // Vector con las animaciones de los globos
|
||||
std::vector<std::vector<std::string>> explosions_animations_; // Vector con las animaciones de las explosiones
|
||||
|
||||
std::unique_ptr<Text> text_; // Fuente para los textos del juego
|
||||
std::unique_ptr<Text> text_big_; // Fuente de texto grande
|
||||
@@ -148,62 +137,39 @@ private:
|
||||
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
|
||||
std::shared_ptr<SmartSprite> p1000_sprite_; // Sprite con el texto 1.000
|
||||
std::shared_ptr<SmartSprite> p2500_sprite_; // Sprite con el texto 2.500
|
||||
std::shared_ptr<SmartSprite> p5000_sprite_; // Sprite con el texto 5.000
|
||||
|
||||
JA_Sound_t *balloon_sound_; // Sonido para la explosión del globo
|
||||
JA_Sound_t *bullet_sound_; // Sonido para los disparos
|
||||
JA_Sound_t *player_collision_sound_; // Sonido para la colisión del jugador con un enemigo
|
||||
JA_Sound_t *hi_score_sound_; // Sonido para cuando se alcanza la máxima puntuación
|
||||
JA_Sound_t *item_drop_sound_; // Sonido para cuando se genera un item
|
||||
JA_Sound_t *item_pick_up_sound_; // Sonido para cuando se recoge un item
|
||||
JA_Sound_t *coffee_out_sound_; // Sonido para cuando el jugador pierde el café al recibir un impacto
|
||||
JA_Sound_t *stage_change_sound_; // Sonido para cuando se cambia de fase
|
||||
JA_Sound_t *bubble1_sound_; // Sonido para cuando el jugador muere
|
||||
JA_Sound_t *bubble2_sound_; // Sonido para cuando el jugador muere
|
||||
JA_Sound_t *bubble3_sound_; // Sonido para cuando el jugador muere
|
||||
JA_Sound_t *bubble4_sound_; // Sonido para cuando el jugador muere
|
||||
JA_Sound_t *clock_sound_; // Sonido para cuando se detiene el tiempo con el item reloj
|
||||
JA_Sound_t *power_ball_sound_; // Sonido para cuando se explota una Power Ball
|
||||
JA_Sound_t *coffee_machine_sound_; // Sonido para cuando la máquina de café toca el suelo
|
||||
|
||||
JA_Music_t *music_; // Musica de fondo
|
||||
|
||||
// Variables
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||
bool hi_score_achieved_; // Indica si se ha superado la puntuación máxima
|
||||
HiScoreEntry hi_score_; // Máxima puntuación y nombre de quien la ostenta
|
||||
int current_stage_; // Indica la fase actual
|
||||
int stage_bitmap_counter_; // Contador para el tiempo visible del texto de Stage
|
||||
float stage_bitmap_path_[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
|
||||
float get_ready_bitmap_path_[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
|
||||
int game_over_counter_; // Contador para el estado de fin de partida
|
||||
int menace_current_; // Nivel de amenaza actual
|
||||
int menace_threshold_; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
||||
bool time_stopped_; // Indica si el tiempo está detenido
|
||||
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
|
||||
float enemy_speed_; // Velocidad a la que se mueven los enemigos
|
||||
float default_enemy_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
|
||||
bool coffee_machine_enabled_; // Indica si hay una máquina de café en el terreno de juego
|
||||
bool game_completed_; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
||||
int game_completed_counter_; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
||||
GameDifficulty difficulty_; // Dificultad del juego
|
||||
float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad
|
||||
Color difficulty_color_; // Color asociado a la dificultad
|
||||
int last_stage_reached_; // Contiene el número de la última pantalla que se ha alcanzado
|
||||
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
|
||||
int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases
|
||||
bool paused_; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade)
|
||||
int current_power_; // Poder actual almacenado para completar la fase
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
bool hi_score_achieved_; // Indica si se ha superado la puntuación máxima
|
||||
HiScoreEntry hi_score_; // Máxima puntuación y nombre de quien la ostenta
|
||||
int current_stage_; // Indica la fase actual
|
||||
int stage_bitmap_counter_; // Contador para el tiempo visible del texto de Stage
|
||||
float stage_bitmap_path_[STAGE_COUNTER_]; // Vector con los puntos Y por donde se desplaza el texto
|
||||
float get_ready_bitmap_path_[STAGE_COUNTER_]; // Vector con los puntos X por donde se desplaza el texto
|
||||
int game_over_counter_; // Contador para el estado de fin de partida
|
||||
int menace_current_; // Nivel de amenaza actual
|
||||
int menace_threshold_; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
||||
bool time_stopped_; // Indica si el tiempo está detenido
|
||||
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_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_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
|
||||
bool coffee_machine_enabled_; // Indica si hay una máquina de café en el terreno de juego
|
||||
bool game_completed_; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
||||
int game_completed_counter_; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
||||
GameDifficulty difficulty_; // Dificultad del juego
|
||||
float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad
|
||||
Color difficulty_color_; // Color asociado a la dificultad
|
||||
int last_stage_reached_; // Contiene el número de la última pantalla que se ha alcanzado
|
||||
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
|
||||
int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases
|
||||
bool paused_; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade)
|
||||
int current_power_; // Poder actual almacenado para completar la fase
|
||||
#ifdef DEBUG
|
||||
bool auto_pop_balloons_; // Si es true, incrementa automaticamente los globos explotados
|
||||
#endif
|
||||
@@ -226,14 +192,8 @@ private:
|
||||
// Libera los recursos previamente cargados
|
||||
void unloadMedia();
|
||||
|
||||
// Carga el fichero de datos para la demo
|
||||
bool loadDemoFile(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);
|
||||
#endif
|
||||
// Crea una formación de enemigos
|
||||
void deployEnemyFormation();
|
||||
void deployBalloonFormation();
|
||||
|
||||
// Aumenta el poder de la fase
|
||||
void increaseStageCurrentPower(int power);
|
||||
@@ -268,12 +228,6 @@ private:
|
||||
// Establece la velocidad de los globos
|
||||
void setBalloonSpeed(float speed);
|
||||
|
||||
// Incrementa la velocidad de los globos
|
||||
void incBalloonSpeed();
|
||||
|
||||
// Decrementa la velocidad de los globos
|
||||
void decBalloonSpeed();
|
||||
|
||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||
void updateBalloonSpeed();
|
||||
|
||||
@@ -283,9 +237,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();
|
||||
|
||||
@@ -295,9 +246,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();
|
||||
|
||||
@@ -329,28 +277,28 @@ private:
|
||||
void renderItems();
|
||||
|
||||
// Devuelve un item en función del azar
|
||||
int dropItem();
|
||||
ItemType dropItem();
|
||||
|
||||
// Crea un objeto item
|
||||
void createItem(int kind, float x, float y);
|
||||
void createItem(ItemType type, float x, float y);
|
||||
|
||||
// Vacia el vector de items
|
||||
void freeItems();
|
||||
|
||||
// Crea un objeto SmartSprite
|
||||
void createItemScoreSprite(int x, int y, std::shared_ptr<SmartSprite> sprite);
|
||||
// Crea un objeto SpriteSmart
|
||||
void createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture);
|
||||
|
||||
// Vacia el vector de smartsprites
|
||||
void freeSmartSprites();
|
||||
void freeSpriteSmarts();
|
||||
|
||||
// Crea un SmartSprite para arrojar el item café al recibir un impacto
|
||||
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
|
||||
void throwCoffee(int x, int y);
|
||||
|
||||
// Actualiza los SmartSprites
|
||||
void updateSmartSprites();
|
||||
// Actualiza los SpriteSmarts
|
||||
void updateSpriteSmarts();
|
||||
|
||||
// Pinta los SmartSprites activos
|
||||
void renderSmartSprites();
|
||||
// Pinta los SpriteSmarts activos
|
||||
void renderSpriteSmarts();
|
||||
|
||||
// Acciones a realizar cuando el jugador muere
|
||||
void killPlayer(std::shared_ptr<Player> &player);
|
||||
@@ -374,7 +322,7 @@ private:
|
||||
void incTimeStoppedCounter(int value);
|
||||
|
||||
// Actualiza la variable EnemyDeployCounter
|
||||
void updateEnemyDeployCounter();
|
||||
void updateBalloonDeployCounter();
|
||||
|
||||
// Actualiza y comprueba el valor de la variable
|
||||
void updateTimeStoppedCounter();
|
||||
@@ -385,9 +333,6 @@ private:
|
||||
// Actualiza el fondo
|
||||
void updateBackground();
|
||||
|
||||
// Gestiona la entrada durante el juego
|
||||
void checkInput();
|
||||
|
||||
// Pinta diferentes mensajes en la pantalla
|
||||
void renderMessages();
|
||||
|
||||
@@ -421,9 +366,6 @@ private:
|
||||
// Comprueba si todos los jugadores han terminado de jugar
|
||||
bool allPlayersAreNotPlaying();
|
||||
|
||||
// Carga las animaciones
|
||||
void loadAnimations(std::string file_path, std::vector<std::string> *buffer);
|
||||
|
||||
// Elimina todos los objetos contenidos en vectores
|
||||
void deleteAllVectorObjects();
|
||||
|
||||
@@ -443,7 +385,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);
|
||||
@@ -457,9 +399,40 @@ private:
|
||||
// Obtiene un controlador a partir del "id" del jugador
|
||||
int getController(int playerId);
|
||||
|
||||
// Gestiona la entrada durante el juego
|
||||
void checkInput();
|
||||
|
||||
// Verifica si alguno de los controladores ha solicitado una pausa y actualiza el estado de pausa del juego.
|
||||
void checkPauseInput();
|
||||
|
||||
// Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.
|
||||
void handleDemoMode();
|
||||
|
||||
// Procesa las entradas para un jugador específico durante el modo demo.
|
||||
// Incluye movimientos (izquierda, derecha, sin movimiento) y disparos automáticos.
|
||||
void handleDemoPlayerInput(const std::shared_ptr<Player> &player, int index);
|
||||
|
||||
// Maneja el disparo de un jugador, incluyendo la creación de balas y la gestión del tiempo de espera entre disparos.
|
||||
void handleFireInput(const std::shared_ptr<Player> &player, BulletType bulletType);
|
||||
|
||||
// Gestiona las entradas de todos los jugadores en el modo normal (fuera del modo demo).
|
||||
void handlePlayersInput();
|
||||
|
||||
// Maneja las entradas de movimiento y disparo para un jugador en modo normal.
|
||||
void handleNormalPlayerInput(const std::shared_ptr<Player> &player);
|
||||
|
||||
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
|
||||
void handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex);
|
||||
|
||||
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
|
||||
void handlePlayerContinue(const std::shared_ptr<Player> &player);
|
||||
|
||||
// Procesa las entradas para la introducción del nombre del jugador.
|
||||
void handleNameInput(const std::shared_ptr<Player> &player);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Game(int playerID, int current_stage, bool demo, JA_Music_t *music);
|
||||
Game(int playerID, int current_stage, bool demo);
|
||||
|
||||
// Destructor
|
||||
~Game();
|
||||
|
||||
@@ -1,47 +1,40 @@
|
||||
#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 "animated_sprite.h" // for SpriteAnimated
|
||||
#include "asset.h" // for Asset
|
||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound
|
||||
#include "jail_audio.h" // JA_PlaySound
|
||||
#include "param.h" // for param
|
||||
#include "resource.h" // for Resource
|
||||
#include "screen.h" // for Screen
|
||||
#include "smart_sprite.h" // for SmartSprite
|
||||
#include "smart_sprite.h" // for SpriteSmart
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for Param, ParamGame, ParamTitle
|
||||
|
||||
// Constructor
|
||||
GameLogo::GameLogo(int x, int y)
|
||||
: x_(x), y_(y)
|
||||
: dust_texture_(Resource::get()->getTexture("title_dust.png")),
|
||||
coffee_texture_(Resource::get()->getTexture("title_coffee.png")),
|
||||
crisis_texture_(Resource::get()->getTexture("title_crisis.png")),
|
||||
arcade_edition_texture_(Resource::get()->getTexture("title_arcade_edition.png")),
|
||||
|
||||
dust_left_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Resource::get()->getAnimation("title_dust.ani"))),
|
||||
dust_right_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Resource::get()->getAnimation("title_dust.ani"))),
|
||||
|
||||
coffee_sprite_(std::make_unique<SmartSprite>(coffee_texture_)),
|
||||
crisis_sprite_(std::make_unique<SmartSprite>(crisis_texture_)),
|
||||
|
||||
arcade_edition_sprite_(std::make_unique<Sprite>(arcade_edition_texture_, (param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight())),
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
GameLogo::~GameLogo()
|
||||
{
|
||||
JA_DeleteSound(crash_sound_);
|
||||
}
|
||||
|
||||
// Inicializa las variables
|
||||
void GameLogo::init()
|
||||
{
|
||||
@@ -125,7 +118,9 @@ void GameLogo::render()
|
||||
// Actualiza la lógica de la clase
|
||||
void GameLogo::update()
|
||||
{
|
||||
if (status_ == Status::MOVING)
|
||||
switch (status_)
|
||||
{
|
||||
case Status::MOVING:
|
||||
{
|
||||
coffee_sprite_->update();
|
||||
crisis_sprite_->update();
|
||||
@@ -136,11 +131,13 @@ void GameLogo::update()
|
||||
status_ = Status::SHAKING;
|
||||
|
||||
// Reproduce el efecto sonoro
|
||||
JA_PlaySound(crash_sound_);
|
||||
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
else if (status_ == Status::SHAKING)
|
||||
case Status::SHAKING:
|
||||
{
|
||||
// Agita el logo
|
||||
if (shake_.remaining > 0)
|
||||
@@ -167,12 +164,20 @@ void GameLogo::update()
|
||||
|
||||
dust_right_sprite_->update();
|
||||
dust_left_sprite_->update();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
else if (status_ == Status::FINISHED)
|
||||
case Status::FINISHED:
|
||||
{
|
||||
dust_right_sprite_->update();
|
||||
dust_left_sprite_->update();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <memory>
|
||||
#include "texture.h"
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
#include "animated_sprite.h"
|
||||
#include "smart_sprite.h"
|
||||
#include "sprite.h"
|
||||
|
||||
struct JA_Sound_t;
|
||||
class Sprite;
|
||||
class Texture;
|
||||
struct JA_Sound_t; // lines 10-10
|
||||
|
||||
// Clase GameLogo
|
||||
class GameLogo
|
||||
{
|
||||
private:
|
||||
// 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> 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_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
|
||||
std::unique_ptr<SmartSprite> crisis_sprite_; // Sprite con la palabra "CRISIS" para la pantalla de titulo
|
||||
|
||||
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition"
|
||||
|
||||
JA_Sound_t *crash_sound_; // Sonido con el impacto del título
|
||||
|
||||
// Variables
|
||||
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
|
||||
{
|
||||
@@ -49,7 +27,28 @@ private:
|
||||
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
|
||||
};
|
||||
|
||||
// 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> 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_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
|
||||
std::unique_ptr<SmartSprite> crisis_sprite_; // Sprite con la palabra "CRISIS" para la pantalla de titulo
|
||||
|
||||
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition"
|
||||
|
||||
// Variables
|
||||
int x_; // Posición donde dibujar el logo
|
||||
int y_; // Posición donde dibujar el logo
|
||||
|
||||
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();
|
||||
@@ -62,7 +61,7 @@ public:
|
||||
GameLogo(int x, int y);
|
||||
|
||||
// Destructor
|
||||
~GameLogo();
|
||||
~GameLogo() = default;
|
||||
|
||||
// Pinta la clase en pantalla
|
||||
void render();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "input.h" // for Input, inputs_e, INPUT_DO_NOT_ALLOW_REPEAT
|
||||
#include "jail_audio.h" // for JA_EnableMusic, JA_EnableSound
|
||||
#include "lang.h" // for getText
|
||||
#include "notifier.h" // for Notifier
|
||||
#include "options.h" // for options
|
||||
#include "on_screen_help.h"
|
||||
#include "screen.h" // for Screen
|
||||
@@ -28,14 +29,21 @@ namespace globalInputs
|
||||
// Termina
|
||||
void quit(section::Options code)
|
||||
{
|
||||
if (Screen::get()->notificationsAreActive())
|
||||
const std::string exit_code = "QUIT";
|
||||
auto code_found = stringInVector(Notifier::get()->getCodes(), exit_code);
|
||||
if (code_found)
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = code;
|
||||
}
|
||||
else
|
||||
{
|
||||
Screen::get()->showNotification(lang::getText(94));
|
||||
#ifdef ARCADE
|
||||
const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
||||
Notifier::get()->showText(lang::getText(index), std::string(), -1, exit_code);
|
||||
#else
|
||||
Notifier::get()->showText(lang::getText(94), std::string(), -1, exit_code);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +51,7 @@ namespace globalInputs
|
||||
void reset()
|
||||
{
|
||||
section::name = section::Name::INIT;
|
||||
Screen::get()->showNotification("Reset");
|
||||
Notifier::get()->showText("Reset");
|
||||
}
|
||||
|
||||
// Activa o desactiva el audio
|
||||
@@ -52,7 +60,7 @@ namespace globalInputs
|
||||
options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled;
|
||||
JA_EnableMusic(options.audio.music.enabled);
|
||||
JA_EnableSound(options.audio.sound.enabled);
|
||||
Screen::get()->showNotification("Audio " + boolToOnOff(options.audio.music.enabled));
|
||||
Notifier::get()->showText("Audio " + boolToOnOff(options.audio.music.enabled));
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
@@ -61,7 +69,7 @@ namespace globalInputs
|
||||
// Comprueba si se sale con el teclado
|
||||
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
quit(section::Options::QUIT_NORMAL);
|
||||
quit(section::Options::QUIT_WITH_KEYBOARD);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,7 +107,7 @@ namespace globalInputs
|
||||
// Comprueba si se sale con el mando
|
||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
quit(section::Options::QUIT_SHUTDOWN);
|
||||
quit(section::Options::QUIT_WITH_CONTROLLER);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,42 +8,36 @@
|
||||
#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 "resource.h" // for Resource
|
||||
#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)
|
||||
: music_(music)
|
||||
HiScoreTable::HiScoreTable()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
fade_(std::make_unique<Fade>()),
|
||||
background_(std::make_unique<Background>()),
|
||||
text_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
counter_(0),
|
||||
ticks_(0),
|
||||
view_area_({0, 0, param.game.width, param.game.height}),
|
||||
fade_mode_(FadeMode::IN)
|
||||
{
|
||||
// Copia punteros
|
||||
renderer_ = Screen::get()->getRenderer();
|
||||
|
||||
// Objetos
|
||||
fade_ = std::make_unique<Fade>(renderer_);
|
||||
background_ = std::make_unique<Background>(renderer_);
|
||||
text_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer_);
|
||||
|
||||
// Crea un backbuffer para el renderizador
|
||||
backbuffer_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa variables
|
||||
// Inicializa el resto de variables
|
||||
section::name = section::Name::HI_SCORE_TABLE;
|
||||
ticks_ = 0;
|
||||
ticks_speed_ = 15;
|
||||
counter_ = 0;
|
||||
counter_end_ = 800;
|
||||
view_area_ = {0, 0, param.game.width, param.game.height};
|
||||
fade_mode_ = FadeMode::IN;
|
||||
|
||||
// Inicializa objetos
|
||||
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
||||
background_->setPos(param.game.game_area.rect);
|
||||
background_->setCloudsSpeed(-0.1f);
|
||||
background_->setGradientNumber(1);
|
||||
@@ -67,7 +62,7 @@ HiScoreTable::~HiScoreTable()
|
||||
void HiScoreTable::update()
|
||||
{
|
||||
// Actualiza las variables
|
||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||
if (SDL_GetTicks() - ticks_ > TICKS_SPEED_)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks_ = SDL_GetTicks();
|
||||
@@ -75,7 +70,7 @@ void HiScoreTable::update()
|
||||
// Mantiene la música sonando
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
JA_PlayMusic(music_);
|
||||
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||
}
|
||||
|
||||
// Actualiza el objeto screen
|
||||
@@ -96,7 +91,7 @@ void HiScoreTable::update()
|
||||
background_->setAlpha(96);
|
||||
}
|
||||
|
||||
if (counter_ == counter_end_)
|
||||
if (counter_ == COUNTER_END_)
|
||||
{
|
||||
fade_->activate();
|
||||
}
|
||||
@@ -129,7 +124,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 + ".";
|
||||
@@ -185,6 +180,7 @@ void HiScoreTable::checkEvents()
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_FROM_EVENT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -255,7 +251,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,14 @@
|
||||
#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
|
||||
|
||||
/*
|
||||
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
|
||||
@@ -27,10 +24,13 @@ struct JA_Music_t;
|
||||
class HiScoreTable
|
||||
{
|
||||
private:
|
||||
// Constantes
|
||||
static constexpr Uint16 COUNTER_END_ = 800; // Valor final para el contador
|
||||
static constexpr Uint32 TICKS_SPEED_ = 15; // Velocidad a la que se repiten los bucles del programa
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
||||
JA_Music_t *music_; // Musica de fondo
|
||||
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
@@ -38,9 +38,7 @@ private:
|
||||
|
||||
// Variables
|
||||
Uint16 counter_; // Contador
|
||||
Uint16 counter_end_; // Valor final para el contador
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||
SDL_Rect view_area_; // Parte de la textura que se muestra en pantalla
|
||||
FadeMode fade_mode_; // Modo de fade a utilizar
|
||||
|
||||
@@ -70,7 +68,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
HiScoreTable(JA_Music_t *music);
|
||||
HiScoreTable();
|
||||
|
||||
// Destructor
|
||||
~HiScoreTable();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -398,11 +396,9 @@ bool Input::discoverGameControllers()
|
||||
|
||||
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
{
|
||||
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
num_joysticks_ = SDL_NumJoysticks();
|
||||
@@ -420,12 +416,9 @@ bool Input::discoverGameControllers()
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
{
|
||||
std::cout << "\nChecking for game controllers...\n";
|
||||
std::cout << num_joysticks_ << " joysticks found, " << num_gamepads_ << " are gamepads\n";
|
||||
}
|
||||
#endif
|
||||
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||
// std::cout << " " << num_joysticks_ << " joysticks found" << std::endl;
|
||||
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
|
||||
|
||||
if (num_gamepads_ > 0)
|
||||
{
|
||||
@@ -434,32 +427,29 @@ 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);
|
||||
#ifdef VERBOSE
|
||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||
{
|
||||
std::cout << name << std::endl;
|
||||
std::cout << "#" << i << ": " << name << std::endl;
|
||||
}
|
||||
#endif
|
||||
controller_names_.push_back(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
{
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
}
|
||||
|
||||
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
@@ -528,7 +518,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 +562,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 +592,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,37 +1,38 @@
|
||||
#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 "resource.h" // for Resource
|
||||
#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 "tiled_bg.h" // for TiledBG, TILED_MODE_STATIC
|
||||
#include "utils.h" // for Param, ParamGame, Color, shdw_txt_color
|
||||
struct JA_Music_t; // lines 22-22
|
||||
|
||||
// Constructor
|
||||
Instructions::Instructions(JA_Music_t *music)
|
||||
: music_(music)
|
||||
Instructions::Instructions()
|
||||
{
|
||||
// Copia los punteros
|
||||
renderer_ = Screen::get()->getRenderer();
|
||||
|
||||
// Crea objetos
|
||||
text_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer_);
|
||||
tiled_bg_ = std::make_unique<Tiledbg>(Asset::get()->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_STATIC);
|
||||
fade_ = std::make_unique<Fade>(renderer_);
|
||||
text_ = std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"));
|
||||
tiled_bg_ = std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC);
|
||||
fade_ = std::make_unique<Fade>();
|
||||
|
||||
// Crea un backbuffer para el renderizador
|
||||
backbuffer_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
@@ -79,26 +80,17 @@ Instructions::~Instructions()
|
||||
void Instructions::iniSprites()
|
||||
{
|
||||
// Inicializa las texturas
|
||||
auto item1 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_points1_disk.png"));
|
||||
item_textures_.push_back(item1);
|
||||
|
||||
auto item2 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_points2_gavina.png"));
|
||||
item_textures_.push_back(item2);
|
||||
|
||||
auto item3 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_points3_pacmar.png"));
|
||||
item_textures_.push_back(item3);
|
||||
|
||||
auto item4 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_clock.png"));
|
||||
item_textures_.push_back(item4);
|
||||
|
||||
auto item5 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_coffee.png"));
|
||||
item_textures_.push_back(item5);
|
||||
item_textures_.emplace_back(Resource::get()->getTexture("item_points1_disk.png"));
|
||||
item_textures_.emplace_back(Resource::get()->getTexture("item_points2_gavina.png"));
|
||||
item_textures_.emplace_back(Resource::get()->getTexture("item_points3_pacmar.png"));
|
||||
item_textures_.emplace_back(Resource::get()->getTexture("item_clock.png"));
|
||||
item_textures_.emplace_back(Resource::get()->getTexture("item_coffee.png"));
|
||||
|
||||
// Inicializa los sprites
|
||||
for (int i = 0; i < (int)item_textures_.size(); ++i)
|
||||
{
|
||||
auto sprite = std::make_unique<Sprite>(0, 0, param.game.item_size, param.game.item_size, item_textures_[i]);
|
||||
sprite->setPos((SDL_Point){sprite_pos_.x, sprite_pos_.y + ((param.game.item_size + item_space_) * i)});
|
||||
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, param.game.item_size, param.game.item_size);
|
||||
sprite->setPosition((SDL_Point){sprite_pos_.x, sprite_pos_.y + ((param.game.item_size + item_space_) * i)});
|
||||
sprites_.push_back(std::move(sprite));
|
||||
}
|
||||
}
|
||||
@@ -230,7 +222,7 @@ void Instructions::update()
|
||||
|
||||
// Mantiene la música sonando
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
JA_PlayMusic(music_);
|
||||
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
@@ -305,6 +297,7 @@ void Instructions::checkEvents()
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_FROM_EVENT;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <memory> // for unique_ptr, shared_ptr
|
||||
#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;
|
||||
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
|
||||
@@ -34,11 +33,10 @@ private:
|
||||
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
|
||||
std::vector<std::unique_ptr<Sprite>> sprites_; // Vector con los sprites de los items
|
||||
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::unique_ptr<Tiledbg> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
JA_Music_t *music_; // Musica de fondo
|
||||
SDL_Texture *texture_; // Textura fija con el texto
|
||||
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
||||
|
||||
@@ -80,7 +78,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Instructions(JA_Music_t *music);
|
||||
Instructions();
|
||||
|
||||
// Destructor
|
||||
~Instructions();
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
#include "intro.h"
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#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 <string> // for basic_string
|
||||
#include <utility> // for move
|
||||
#include "asset.h" // for Asset
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
#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 "resource.h" // for Resource
|
||||
#include "screen.h" // for Screen
|
||||
#include "section.h" // for name, SectionName, options, SectionOptions
|
||||
#include "smart_sprite.h" // for SmartSprite
|
||||
#include "section.h" // for Name, name, Options, options
|
||||
#include "smart_sprite.h" // for SpriteSmart
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for ParamGame, Param, Zone, BLOCK
|
||||
#include "utils.h" // for Param, ParamGame, Zone, BLOCK, Color
|
||||
#include "writer.h" // for Writer
|
||||
struct JA_Music_t;
|
||||
struct JA_Music_t; // lines 19-19
|
||||
|
||||
// Constructor
|
||||
Intro::Intro(JA_Music_t *music)
|
||||
: music_(music)
|
||||
Intro::Intro()
|
||||
{
|
||||
// Copia los punteros
|
||||
auto renderer = Screen::get()->getRenderer();
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("intro.png"));
|
||||
text_ = std::make_shared<Text>(Asset::get()->get("nokia.png"), Asset::get()->get("nokia.txt"), renderer);
|
||||
texture_ = Resource::get()->getTexture("intro.png");
|
||||
text_ = std::make_shared<Text>(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt"));
|
||||
|
||||
// Inicializa variables
|
||||
section::name = section::Name::INTRO;
|
||||
@@ -173,6 +170,7 @@ void Intro::checkEvents()
|
||||
case SDL_QUIT:
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_FROM_EVENT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -408,12 +406,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();
|
||||
}
|
||||
@@ -425,7 +423,7 @@ void Intro::render()
|
||||
// Bucle principal
|
||||
void Intro::run()
|
||||
{
|
||||
JA_PlayMusic(music_, 0);
|
||||
JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0);
|
||||
|
||||
while (section::name == section::Name::INTRO)
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||
#include <memory> // for unique_ptr, shared_ptr
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
#include "smart_sprite.h"
|
||||
#include "texture.h"
|
||||
#include "text.h"
|
||||
#include "writer.h"
|
||||
struct JA_Music_t;
|
||||
#include "smart_sprite.h" // for SpriteSmart
|
||||
#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
|
||||
@@ -29,7 +28,6 @@ private:
|
||||
// Variables
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint8 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||
JA_Music_t *music_; // Musica para la intro
|
||||
int scene_; // Indica que escena está activa
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
@@ -52,7 +50,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Intro(JA_Music_t *music);
|
||||
Intro();
|
||||
|
||||
// Destructor
|
||||
~Intro() = default;
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
#include "item.h"
|
||||
#include <stdlib.h> // for rand
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "animated_sprite.h" // for SpriteAnimated
|
||||
#include "param.h" // for param
|
||||
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)
|
||||
Item::Item(ItemType type, float x, float y, SDL_Rect *play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||
accel_x_(0.0f),
|
||||
floor_collision_(false),
|
||||
type_(type),
|
||||
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)
|
||||
if (type == ItemType::COFFEE_MACHINE)
|
||||
{
|
||||
width_ = 28;
|
||||
height_ = 37;
|
||||
@@ -105,7 +104,7 @@ void Item::move()
|
||||
}
|
||||
|
||||
// Si se sale por arriba rebota (excepto la maquina de café)
|
||||
if ((pos_y_ < param.game.play_area.rect.y) && !(kind_ == ITEM_COFFEE_MACHINE))
|
||||
if ((pos_y_ < param.game.play_area.rect.y) && !(type_ == ItemType::COFFEE_MACHINE))
|
||||
{
|
||||
// Corrige
|
||||
pos_y_ = param.game.play_area.rect.y;
|
||||
@@ -123,7 +122,7 @@ void Item::move()
|
||||
accel_x_ = 0;
|
||||
accel_y_ = 0;
|
||||
pos_y_ = play_area_->h - height_;
|
||||
if (kind_ == ITEM_COFFEE_MACHINE)
|
||||
if (type_ == ItemType::COFFEE_MACHINE)
|
||||
{
|
||||
floor_collision_ = true;
|
||||
}
|
||||
@@ -145,7 +144,7 @@ void Item::disable()
|
||||
void Item::update()
|
||||
{
|
||||
move();
|
||||
sprite_->animate();
|
||||
sprite_->update();
|
||||
updateTimeToLive();
|
||||
checkTimeToLive();
|
||||
}
|
||||
@@ -191,9 +190,9 @@ int Item::getHeight()
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int Item::getClass()
|
||||
ItemType Item::getType()
|
||||
{
|
||||
return kind_;
|
||||
return type_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
|
||||
@@ -2,21 +2,24 @@
|
||||
|
||||
#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 <memory>
|
||||
#include "utils.h" // for Circle
|
||||
#include "animated_sprite.h"
|
||||
#include "texture.h"
|
||||
#include "animated_sprite.h" // for SpriteAnimated
|
||||
#include "utils.h" // for Circle
|
||||
class Texture;
|
||||
|
||||
// Tipos de objetos
|
||||
constexpr int ITEM_POINTS_1_DISK = 1;
|
||||
constexpr int ITEM_POINTS_2_GAVINA = 2;
|
||||
constexpr int ITEM_POINTS_3_PACMAR = 3;
|
||||
constexpr int ITEM_CLOCK = 4;
|
||||
constexpr int ITEM_COFFEE = 5;
|
||||
constexpr int ITEM_COFFEE_MACHINE = 6;
|
||||
constexpr int ITEM_NULL = 7;
|
||||
enum class ItemType : int
|
||||
{
|
||||
DISK = 1,
|
||||
GAVINA = 2,
|
||||
PACMAR = 3,
|
||||
CLOCK = 4,
|
||||
COFFEE = 5,
|
||||
COFFEE_MACHINE = 6,
|
||||
NONE = 7,
|
||||
};
|
||||
|
||||
// Clase Item
|
||||
class Item
|
||||
@@ -35,7 +38,7 @@ private:
|
||||
float accel_x_; // Aceleración en el eje X
|
||||
float accel_y_; // Aceleración en el eje Y
|
||||
bool floor_collision_; // Indica si el objeto colisiona con el suelo
|
||||
int kind_; // Especifica el tipo de objeto que es
|
||||
ItemType type_; // Especifica el tipo de objeto que es
|
||||
bool enabled_; // Especifica si el objeto está habilitado
|
||||
Circle collider_; // Circulo de colisión del objeto
|
||||
SDL_Rect *play_area_; // Rectangulo con la zona de juego
|
||||
@@ -55,7 +58,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Item(int kind, float x, float y, SDL_Rect *play_area, std::shared_ptr<Texture> texture, std::vector<std::string> *animation);
|
||||
Item(ItemType type, float x, float y, SDL_Rect *play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation);
|
||||
|
||||
// Destructor
|
||||
~Item() = default;
|
||||
@@ -85,7 +88,7 @@ public:
|
||||
int getHeight();
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int getClass();
|
||||
ItemType getType();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isEnabled();
|
||||
|
||||
@@ -129,7 +129,7 @@ JA_Music_t *JA_LoadMusic(const char* filename) {
|
||||
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop)
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
if (!JA_musicEnabled || !music) return;
|
||||
|
||||
if (current_music != NULL) {
|
||||
current_music->pos = 0;
|
||||
@@ -223,7 +223,7 @@ JA_Sound_t *JA_LoadSound(const char* filename) {
|
||||
|
||||
int JA_PlaySound(JA_Sound_t *sound, const int loop)
|
||||
{
|
||||
if (!JA_soundEnabled) return 0;
|
||||
if (!JA_soundEnabled || !sound) return 0;
|
||||
|
||||
int channel = 0;
|
||||
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
#ifdef JA_USESDLMIXER
|
||||
#include "jail_audio.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct JA_Sound_t {}; // Dummy structs
|
||||
struct JA_Music_t {};
|
||||
|
||||
int JA_freq {48000};
|
||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
||||
Uint8 JA_channels {2};
|
||||
int JA_musicVolume = 128;
|
||||
int JA_soundVolume = 64;
|
||||
bool JA_musicEnabled = true;
|
||||
bool JA_soundEnabled = true;
|
||||
|
||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
||||
JA_freq = freq;
|
||||
JA_format = format;
|
||||
JA_channels = channels;
|
||||
Mix_OpenAudio(JA_freq, JA_format, JA_channels, 1024);
|
||||
}
|
||||
|
||||
void JA_Quit() {
|
||||
Mix_CloseAudio();
|
||||
}
|
||||
|
||||
JA_Music_t *JA_LoadMusic(const char* filename) {
|
||||
return (JA_Music_t*)Mix_LoadMUS(filename);
|
||||
}
|
||||
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop)
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
Mix_PlayMusic((Mix_Music*)music, loop);
|
||||
Mix_VolumeMusic(JA_musicVolume);
|
||||
}
|
||||
|
||||
void JA_PauseMusic()
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
Mix_PauseMusic();
|
||||
}
|
||||
|
||||
void JA_ResumeMusic()
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
Mix_ResumeMusic();
|
||||
}
|
||||
|
||||
void JA_StopMusic()
|
||||
{
|
||||
if (!JA_musicEnabled) return;
|
||||
Mix_HaltMusic();
|
||||
}
|
||||
|
||||
JA_Music_state JA_GetMusicState()
|
||||
{
|
||||
if (!JA_musicEnabled) return JA_MUSIC_DISABLED;
|
||||
|
||||
if (Mix_PausedMusic()) {
|
||||
return JA_MUSIC_PAUSED;
|
||||
} else if (Mix_PlayingMusic()) {
|
||||
return JA_MUSIC_PLAYING;
|
||||
} else {
|
||||
return JA_MUSIC_STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
void JA_DeleteMusic(JA_Music_t *music)
|
||||
{
|
||||
Mix_FreeMusic((Mix_Music*)music);
|
||||
}
|
||||
|
||||
int JA_SetMusicVolume(int volume)
|
||||
{
|
||||
JA_musicVolume = volume;
|
||||
Mix_VolumeMusic(JA_musicVolume);
|
||||
return JA_musicVolume;
|
||||
}
|
||||
|
||||
void JA_EnableMusic(const bool value)
|
||||
{
|
||||
if (Mix_PlayingMusic()) Mix_HaltMusic();
|
||||
JA_musicEnabled = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JA_Sound_t *JA_LoadSound(const char* filename) {
|
||||
JA_Sound_t *sound = (JA_Sound_t*)Mix_LoadWAV(filename);
|
||||
return sound;
|
||||
}
|
||||
|
||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
||||
if (!JA_soundEnabled) return -1;
|
||||
const int channel = Mix_PlayChannel(-1, (Mix_Chunk*)sound, loop);
|
||||
Mix_Volume(-1, JA_soundVolume);
|
||||
return channel;
|
||||
}
|
||||
|
||||
void JA_DeleteSound(JA_Sound_t *sound)
|
||||
{
|
||||
Mix_FreeChunk((Mix_Chunk*)sound);
|
||||
}
|
||||
|
||||
void JA_PauseChannel(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return;
|
||||
Mix_Pause(channel);
|
||||
}
|
||||
|
||||
void JA_ResumeChannel(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return;
|
||||
Mix_Resume(channel);
|
||||
}
|
||||
|
||||
void JA_StopChannel(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return;
|
||||
Mix_HaltChannel(channel);
|
||||
}
|
||||
|
||||
JA_Channel_state JA_GetChannelState(const int channel)
|
||||
{
|
||||
if (!JA_soundEnabled) return JA_SOUND_DISABLED;
|
||||
|
||||
if (Mix_Paused(channel)) {
|
||||
return JA_CHANNEL_PAUSED;
|
||||
} else if (Mix_Playing(channel)) {
|
||||
return JA_CHANNEL_PLAYING;
|
||||
} else {
|
||||
return JA_CHANNEL_FREE;
|
||||
}
|
||||
}
|
||||
|
||||
int JA_SetSoundVolume(int volume)
|
||||
{
|
||||
JA_musicVolume = volume;
|
||||
Mix_Volume(-1, JA_musicVolume);
|
||||
return JA_musicVolume;
|
||||
}
|
||||
|
||||
void JA_EnableSound(const bool value)
|
||||
{
|
||||
Mix_HaltChannel(-1);
|
||||
JA_soundEnabled = value;
|
||||
}
|
||||
|
||||
|
||||
int JA_SetVolume(int volume)
|
||||
{
|
||||
JA_SetSoundVolume(volume);
|
||||
return JA_SetMusicVolume(volume);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,28 +1,26 @@
|
||||
#include "logo.h"
|
||||
#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 <string> // for basic_string
|
||||
#include <utility> // for move
|
||||
#include "asset.h" // for Asset
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_StopMusic
|
||||
#include "param.h" // for param
|
||||
#include "resource.h" // for Resource
|
||||
#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 "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Logo::Logo()
|
||||
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
|
||||
since_sprite_(std::make_unique<Sprite>(since_texture_)),
|
||||
jail_texture_(Resource::get()->getTexture("logo_jailgames.png"))
|
||||
{
|
||||
// Copia la dirección de los objetos
|
||||
SDL_Renderer *renderer = Screen::get()->getRenderer();
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
jail_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames.png"));
|
||||
since_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_since_1998.png"));
|
||||
since_sprite_ = std::make_unique<Sprite>((param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight(), since_texture_);
|
||||
|
||||
// Inicializa variables
|
||||
counter_ = 0;
|
||||
@@ -30,18 +28,19 @@ Logo::Logo()
|
||||
ticks_ = 0;
|
||||
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
|
||||
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
||||
since_sprite_->setPosY(dest_.y + jail_texture_->getHeight() + 5);
|
||||
since_sprite_->setPosition({(param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight()});
|
||||
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
|
||||
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
||||
since_texture_->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ??
|
||||
|
||||
// Crea los sprites de cada linea
|
||||
for (int i = 0; i < jail_texture_->getHeight(); ++i)
|
||||
{
|
||||
auto temp = std::make_unique<Sprite>(0, i, jail_texture_->getWidth(), 1, jail_texture_);
|
||||
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
|
||||
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
|
||||
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
|
||||
temp->setPosX(posX);
|
||||
temp->setPosY(dest_.y + i);
|
||||
temp->setX(posX);
|
||||
temp->setY(dest_.y + i);
|
||||
jail_sprite_.push_back(std::move(temp));
|
||||
}
|
||||
|
||||
@@ -74,6 +73,7 @@ void Logo::checkEvents()
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_FROM_EVENT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -114,22 +114,22 @@ void Logo::updateJAILGAMES()
|
||||
{
|
||||
for (int i = 0; i < (int)jail_sprite_.size(); ++i)
|
||||
{
|
||||
if (jail_sprite_[i]->getPosX() != dest_.x)
|
||||
if (jail_sprite_[i]->getX() != dest_.x)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
jail_sprite_[i]->incPosX(-SPEED);
|
||||
if (jail_sprite_[i]->getPosX() < dest_.x)
|
||||
jail_sprite_[i]->incX(-SPEED);
|
||||
if (jail_sprite_[i]->getX() < dest_.x)
|
||||
{
|
||||
jail_sprite_[i]->setPosX(dest_.x);
|
||||
jail_sprite_[i]->setX(dest_.x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
jail_sprite_[i]->incPosX(SPEED);
|
||||
if (jail_sprite_[i]->getPosX() > dest_.x)
|
||||
jail_sprite_[i]->incX(SPEED);
|
||||
if (jail_sprite_[i]->getX() > dest_.x)
|
||||
{
|
||||
jail_sprite_[i]->setPosX(dest_.x);
|
||||
jail_sprite_[i]->setX(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,15 @@ 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;
|
||||
// Crea el objeto Director
|
||||
auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv));
|
||||
|
||||
// Crea el objeto Director
|
||||
Director *director = new Director(argc, argv);
|
||||
|
||||
// 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;
|
||||
|
||||
return exit;
|
||||
// Bucle principal
|
||||
return director->run();
|
||||
}
|
||||
|
||||
@@ -50,26 +50,24 @@ 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;
|
||||
#endif
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << file_name.c_str() << std::endl;
|
||||
for (int i = 0; i < (int)table_->size(); ++i)
|
||||
{
|
||||
int nameSize = 0;
|
||||
@@ -86,7 +84,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 +111,10 @@ 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)
|
||||
{
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
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)
|
||||
@@ -130,17 +128,13 @@ bool ManageHiScoreTable::saveToFile(std::string file_path)
|
||||
SDL_RWwrite(file, table_->at(i).name.c_str(), nameSize, 1);
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Writing file: " << fileName.c_str() << std::endl;
|
||||
#endif
|
||||
std::cout << "Writing file: " << file_name.c_str() << std::endl;
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Error: Unable to save " << fileName.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||
#endif
|
||||
std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
ManageHiScoreTable(std::vector<HiScoreEntry> *table);
|
||||
explicit ManageHiScoreTable(std::vector<HiScoreEntry> *table);
|
||||
|
||||
// Destructor
|
||||
~ManageHiScoreTable() = default;
|
||||
@@ -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);
|
||||
};
|
||||
@@ -2,41 +2,44 @@
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float vx, float vy, float ax, float ay, std::shared_ptr<Texture> texture)
|
||||
: Sprite((int)x, (int)y, w, h, texture),
|
||||
x_(x),
|
||||
y_(y),
|
||||
vx_(vx),
|
||||
vy_(vy),
|
||||
ax_(ax),
|
||||
ay_(ay)
|
||||
{
|
||||
// Establece el zoom W,H del sprite
|
||||
zoom_w_ = 1;
|
||||
zoom_h_ = 1;
|
||||
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip)
|
||||
: Sprite(texture, pos),
|
||||
x_(pos.x),
|
||||
y_(pos.y),
|
||||
vx_(0.0f),
|
||||
vy_(0.0f),
|
||||
ax_(0.0f),
|
||||
ay_(0.0f),
|
||||
rotate_(rotate),
|
||||
zoom_w_(zoom_w),
|
||||
zoom_h_(zoom_h),
|
||||
flip_(flip) {}
|
||||
|
||||
// Establece los valores de rotacion
|
||||
rotate_.enabled = false;
|
||||
rotate_.speed = 0;
|
||||
rotate_.angle = 0.0f;
|
||||
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, SDL_Rect pos)
|
||||
: Sprite(texture, pos),
|
||||
x_(pos.x),
|
||||
y_(pos.y),
|
||||
vx_(0.0f),
|
||||
vy_(0.0f),
|
||||
ax_(0.0f),
|
||||
ay_(0.0f),
|
||||
rotate_(Rotate()),
|
||||
zoom_w_(1.0f),
|
||||
zoom_h_(1.0f),
|
||||
flip_(SDL_FLIP_NONE) {}
|
||||
|
||||
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture)
|
||||
: Sprite(texture)
|
||||
{
|
||||
clear();
|
||||
};
|
||||
: Sprite(texture),
|
||||
x_(0.0f),
|
||||
y_(0.0f),
|
||||
vx_(0.0f),
|
||||
vy_(0.0f),
|
||||
ax_(0.0f),
|
||||
ay_(0.0f),
|
||||
rotate_(Rotate()),
|
||||
zoom_w_(1.0f),
|
||||
zoom_h_(1.0f),
|
||||
flip_(SDL_FLIP_NONE) { Sprite::clear(); }
|
||||
|
||||
// Reinicia todas las variables
|
||||
void MovingSprite::clear()
|
||||
@@ -50,21 +53,14 @@ void MovingSprite::clear()
|
||||
ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
||||
ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
rotate_ = Rotate(); // Inicializa la estructura
|
||||
|
||||
zoom_w_ = 1.0f; // Zoom aplicado a la anchura
|
||||
zoom_h_ = 1.0f; // Zoom aplicado a la altura
|
||||
|
||||
rotate_.enabled = false; // Indica si ha de rotar
|
||||
rotate_.speed = 0; // Velocidad de giro
|
||||
rotate_.angle = 0.0f; // Angulo para dibujarlo
|
||||
rotate_.amount = 0.0f; // Cantidad de grados a girar en cada iteración
|
||||
rotate_.center = nullptr; // Centro de rotación
|
||||
|
||||
counter_ = 0; // Contador interno
|
||||
|
||||
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||
|
||||
setPos((SDL_Rect){0, 0, 0, 0});
|
||||
setSpriteClip((SDL_Rect){0, 0, 0, 0});
|
||||
Sprite::clear();
|
||||
}
|
||||
|
||||
// Mueve el sprite
|
||||
@@ -75,12 +71,140 @@ void MovingSprite::move()
|
||||
|
||||
vx_ += ax_;
|
||||
vy_ += ay_;
|
||||
|
||||
pos_.x = static_cast<int>(x_);
|
||||
pos_.y = static_cast<int>(y_);
|
||||
}
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
void MovingSprite::update()
|
||||
{
|
||||
move();
|
||||
rotate();
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void MovingSprite::render()
|
||||
{
|
||||
texture_->render((int)x_, (int)y_, &sprite_clip_, zoom_w_, zoom_h_, (double)rotate_.angle, rotate_.center, flip_);
|
||||
texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomW() const
|
||||
{
|
||||
return zoom_w_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomH() const
|
||||
{
|
||||
return zoom_h_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
double MovingSprite::getAngle() const
|
||||
{
|
||||
return rotate_.angle;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomW(float value)
|
||||
{
|
||||
zoom_w_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomH(float value)
|
||||
{
|
||||
zoom_h_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAngle(double value)
|
||||
{
|
||||
rotate_.angle = value;
|
||||
}
|
||||
|
||||
// Incrementa el valor del ángulo
|
||||
void MovingSprite::updateAngle()
|
||||
{
|
||||
rotate_.angle += rotate_.amount;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool MovingSprite::isRotating() const
|
||||
{
|
||||
return rotate_.enabled;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int MovingSprite::getRotateSpeed() const
|
||||
{
|
||||
return rotate_.speed;
|
||||
}
|
||||
|
||||
// Establece la rotacion
|
||||
void MovingSprite::rotate()
|
||||
{
|
||||
if (rotate_.enabled)
|
||||
{
|
||||
++rotate_.counter;
|
||||
if (rotate_.counter % rotate_.speed == 0)
|
||||
{
|
||||
updateAngle();
|
||||
rotate_.counter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::enableRotate()
|
||||
{
|
||||
rotate_.enabled = true;
|
||||
rotate_.counter = 0;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::disableRotate()
|
||||
{
|
||||
rotate_.enabled = false;
|
||||
rotate_.counter = 0;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateSpeed(int value)
|
||||
{
|
||||
rotate_.speed = std::max(1, value);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateAmount(double value)
|
||||
{
|
||||
rotate_.amount = value;
|
||||
}
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void MovingSprite::switchRotate()
|
||||
{
|
||||
rotate_.amount *= -1;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setFlip(SDL_RendererFlip flip)
|
||||
{
|
||||
flip_ = flip;
|
||||
}
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void MovingSprite::flip()
|
||||
{
|
||||
flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip MovingSprite::getFlip()
|
||||
{
|
||||
return flip_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
@@ -119,29 +243,11 @@ float MovingSprite::getAccelY() const
|
||||
return ay_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomW() const
|
||||
{
|
||||
return zoom_w_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomH() const
|
||||
{
|
||||
return zoom_h_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getAngle() const
|
||||
{
|
||||
return rotate_.angle;
|
||||
}
|
||||
|
||||
// Establece la posición y_ el tamaño del objeto
|
||||
void MovingSprite::setPos(SDL_Rect rect)
|
||||
{
|
||||
x_ = (float)rect.x;
|
||||
y_ = (float)rect.y;
|
||||
x_ = static_cast<float>(rect.x);
|
||||
y_ = static_cast<float>(rect.y);
|
||||
|
||||
pos_ = rect;
|
||||
}
|
||||
@@ -152,22 +258,22 @@ void MovingSprite::setPos(float x, float y)
|
||||
x_ = x;
|
||||
y_ = y;
|
||||
|
||||
pos_.x = (int)x;
|
||||
pos_.y = (int)y;
|
||||
pos_.x = static_cast<int>(x_);
|
||||
pos_.y = static_cast<int>(y_);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosX(float value)
|
||||
{
|
||||
x_ = value;
|
||||
pos_.x = (int)x_;
|
||||
pos_.x = static_cast<int>(x_);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosY(float value)
|
||||
{
|
||||
y_ = value;
|
||||
pos_.y = (int)y_;
|
||||
pos_.y = static_cast<int>(y_);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
@@ -192,121 +298,4 @@ void MovingSprite::setAccelX(float value)
|
||||
void MovingSprite::setAccelY(float value)
|
||||
{
|
||||
ay_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomW(float value)
|
||||
{
|
||||
zoom_w_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomH(float value)
|
||||
{
|
||||
zoom_h_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAngle(double value)
|
||||
{
|
||||
rotate_.angle = value;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void MovingSprite::incAngle(double value)
|
||||
{
|
||||
rotate_.angle += value;
|
||||
}
|
||||
|
||||
// Decrementa el valor de la variable
|
||||
void MovingSprite::decAngle(double value)
|
||||
{
|
||||
rotate_.angle -= value;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool MovingSprite::getRotate() const
|
||||
{
|
||||
return rotate_.enabled;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 MovingSprite::getRotateSpeed() const
|
||||
{
|
||||
return rotate_.speed;
|
||||
}
|
||||
|
||||
// Establece la rotacion
|
||||
void MovingSprite::rotate()
|
||||
{
|
||||
if (rotate_.enabled)
|
||||
{
|
||||
if (counter_ % rotate_.speed == 0)
|
||||
{
|
||||
incAngle(rotate_.amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotate(bool value)
|
||||
{
|
||||
rotate_.enabled = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateSpeed(int value)
|
||||
{
|
||||
rotate_.speed = (value < 1) ? 1 : value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateAmount(double value)
|
||||
{
|
||||
rotate_.amount = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::disableRotate()
|
||||
{
|
||||
rotate_.enabled = false;
|
||||
rotate_.angle = 0.0f;
|
||||
}
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
void MovingSprite::update()
|
||||
{
|
||||
move();
|
||||
rotate();
|
||||
++counter_ %= 60000;
|
||||
}
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void MovingSprite::switchRotate()
|
||||
{
|
||||
rotate_.amount *= -1;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setFlip(SDL_RendererFlip flip)
|
||||
{
|
||||
flip_ = flip;
|
||||
}
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void MovingSprite::flip()
|
||||
{
|
||||
flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip MovingSprite::getFlip()
|
||||
{
|
||||
return flip_;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect MovingSprite::getPos() const
|
||||
{
|
||||
return (SDL_Rect){(int)x_, (int)y_, pos_.w, pos_.h};
|
||||
}
|
||||
@@ -3,23 +3,27 @@
|
||||
#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 <memory> // for shared_ptr
|
||||
#include "sprite.h" // for Sprite
|
||||
class Texture;
|
||||
|
||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||
// Clase MovingSprite. Añade movimiento y efectos de rotación, zoom y flip al sprite
|
||||
class MovingSprite : public Sprite
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
struct Rotate
|
||||
{
|
||||
bool enabled; // Indica si ha de rotar
|
||||
int counter; // Contador
|
||||
int speed; // Velocidad de giro
|
||||
float angle; // Angulo para dibujarlo
|
||||
float amount; // Cantidad de grados a girar en cada iteración
|
||||
double angle; // Angulo para dibujarlo
|
||||
float amount; // Cantidad de grados a girar en cada iteración
|
||||
SDL_Point *center; // Centro de rotación
|
||||
|
||||
Rotate() : enabled(false), counter(0), speed(0), angle(0.0), amount(0.0f), center(nullptr) {}
|
||||
};
|
||||
|
||||
protected:
|
||||
float x_; // Posición en el eje X
|
||||
float y_; // Posición en el eje Y
|
||||
|
||||
@@ -29,17 +33,13 @@ protected:
|
||||
float ax_; // Aceleración en el eje X. Variación de la velocidad
|
||||
float ay_; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
float zoom_w_; // Zoom aplicado a la anchura
|
||||
float zoom_h_; // Zoom aplicado a la altura
|
||||
|
||||
int counter_; // Contador interno
|
||||
Rotate rotate_; // Variables usada para controlar la rotación del sprite
|
||||
float zoom_w_; // Zoom aplicado a la anchura
|
||||
float zoom_h_; // Zoom aplicado a la altura
|
||||
SDL_RendererFlip flip_; // Indica como se voltea el sprite
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
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);
|
||||
// Incrementa el valor del ángulo
|
||||
void updateAngle();
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
@@ -47,54 +47,46 @@ public:
|
||||
// Rota el sprite
|
||||
void rotate();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, MovingSprite::Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip);
|
||||
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos);
|
||||
explicit MovingSprite(std::shared_ptr<Texture> texture);
|
||||
|
||||
// Destructor
|
||||
~MovingSprite() = default;
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
virtual void update();
|
||||
|
||||
// Reinicia todas las variables
|
||||
void clear();
|
||||
// Reinicia todas las variables a cero
|
||||
void clear() override;
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render() override;
|
||||
|
||||
// Obten el valor de la variable
|
||||
// Obtiene la variable
|
||||
float getPosX() const;
|
||||
float getPosY() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getVelX() const;
|
||||
float getVelY() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAccelX() const;
|
||||
float getAccelY() const;
|
||||
|
||||
// Establece la variable
|
||||
void setVelX(float value);
|
||||
void setVelY(float value);
|
||||
void setAccelX(float value);
|
||||
void setAccelY(float value);
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getZoomW() const;
|
||||
float getZoomH() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAngle() const;
|
||||
bool getRotate() const;
|
||||
Uint16 getRotateSpeed() const;
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPos(SDL_Rect rect) override;
|
||||
void setPos(float x, float y);
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getPos() const override;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float value);
|
||||
void setPosY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelX(float value);
|
||||
void setVelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelX(float value);
|
||||
void setAccelY(float value);
|
||||
bool isRotating() const;
|
||||
double getAngle() const;
|
||||
int getRotateSpeed() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomW(float value);
|
||||
@@ -102,17 +94,15 @@ public:
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double vaue);
|
||||
void incAngle(double value);
|
||||
void decAngle(double value);
|
||||
|
||||
// Activa o desactiva el efecto derotación
|
||||
void enableRotate();
|
||||
void disableRotate();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotate(bool value);
|
||||
void setRotateSpeed(int value);
|
||||
void setRotateAmount(double value);
|
||||
|
||||
// Quita el efecto de rotación y deja el sprite en su angulo inicial.
|
||||
void disableRotate();
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void switchRotate();
|
||||
|
||||
@@ -125,5 +115,15 @@ public:
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip getFlip();
|
||||
|
||||
// Establece la posición y_ el tamaño del objeto
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de las variables
|
||||
void setPos(float x, float y);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(float value);
|
||||
};
|
||||
344
source/notifier.cpp
Normal file
@@ -0,0 +1,344 @@
|
||||
#include "notifier.h"
|
||||
#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 "resource.h" // for Resource
|
||||
#include "screen.h" // for Screen
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Notifier *Notifier::notifier_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
void Notifier::init(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file)
|
||||
{
|
||||
Notifier::notifier_ = new Notifier(icon_file, text, sound_file);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
void Notifier::destroy()
|
||||
{
|
||||
delete Notifier::notifier_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
Notifier *Notifier::get()
|
||||
{
|
||||
return Notifier::notifier_;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Notifier::Notifier(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file)
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
text_(text),
|
||||
bg_color_(param.notification.color),
|
||||
wait_time_(150),
|
||||
stack_(false),
|
||||
sound_(JA_LoadSound(sound_file.c_str()))
|
||||
{
|
||||
// Inicializa variables
|
||||
has_icons_ = !icon_file.empty();
|
||||
|
||||
// Crea objetos
|
||||
icon_texture_ = has_icons_ ? std::make_unique<Texture>(renderer_, icon_file) : nullptr;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Notifier::~Notifier()
|
||||
{
|
||||
// Libera la memoria de los objetos
|
||||
JA_DeleteSound(sound_);
|
||||
|
||||
notifications_.clear();
|
||||
}
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void Notifier::render()
|
||||
{
|
||||
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
|
||||
{
|
||||
notifications_[i].sprite->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void Notifier::update()
|
||||
{
|
||||
for (int i = 0; i < (int)notifications_.size(); ++i)
|
||||
{
|
||||
// Si la notificación anterior está "saliendo", no hagas nada
|
||||
if (i > 0)
|
||||
{
|
||||
if (notifications_[i - 1].status == NotificationStatus::RISING)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
notifications_[i].counter++;
|
||||
|
||||
// Hace sonar la notificación en el primer frame
|
||||
if (notifications_[i].counter == 1)
|
||||
{
|
||||
if (param.notification.sound)
|
||||
{
|
||||
if (notifications_[i].status == NotificationStatus::RISING)
|
||||
{ // Reproduce el sonido de la notificación
|
||||
JA_PlaySound(sound_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los estados
|
||||
if (notifications_[i].status == NotificationStatus::RISING)
|
||||
{
|
||||
const float step = ((float)notifications_[i].counter / notifications_[i].travel_dist);
|
||||
const int alpha = 255 * step;
|
||||
|
||||
if (param.notification.pos_v == NotifyPosition::TOP)
|
||||
{
|
||||
notifications_[i].rect.y++;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifications_[i].rect.y--;
|
||||
}
|
||||
notifications_[i].texture->setAlpha(alpha);
|
||||
|
||||
if (notifications_[i].rect.y == notifications_[i].y)
|
||||
{
|
||||
notifications_[i].status = NotificationStatus::STAY;
|
||||
notifications_[i].texture->setAlpha(255);
|
||||
notifications_[i].counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (notifications_[i].status == NotificationStatus::STAY)
|
||||
{
|
||||
if (notifications_[i].counter == wait_time_)
|
||||
{
|
||||
notifications_[i].status = NotificationStatus::VANISHING;
|
||||
notifications_[i].counter = 0;
|
||||
}
|
||||
}
|
||||
else if (notifications_[i].status == NotificationStatus::VANISHING)
|
||||
{
|
||||
|
||||
const float step = (notifications_[i].counter / (float)notifications_[i].travel_dist);
|
||||
const int alpha = 255 * (1 - step);
|
||||
|
||||
if (param.notification.pos_v == NotifyPosition::TOP)
|
||||
{
|
||||
notifications_[i].rect.y--;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifications_[i].rect.y++;
|
||||
}
|
||||
notifications_[i].texture->setAlpha(alpha);
|
||||
|
||||
if (notifications_[i].rect.y == notifications_[i].y - notifications_[i].travel_dist)
|
||||
{
|
||||
notifications_[i].status = NotificationStatus::FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
notifications_[i].sprite->setPosition(notifications_[i].rect);
|
||||
}
|
||||
|
||||
clearFinishedNotifications();
|
||||
}
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void Notifier::clearFinishedNotifications()
|
||||
{
|
||||
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (notifications_[i].status == NotificationStatus::FINISHED)
|
||||
{
|
||||
notifications_.erase(notifications_.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Notifier::showText(std::string text1, std::string text2, int icon, std::string code)
|
||||
{
|
||||
// Cuenta el número de textos a mostrar
|
||||
const int num_texts = !text1.empty() + !text2.empty();
|
||||
|
||||
// Si no hay texto, acaba
|
||||
if (num_texts == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Si solo hay un texto, lo coloca en la primera variable
|
||||
if (num_texts == 1)
|
||||
{
|
||||
text1 += text2;
|
||||
text2.clear();
|
||||
}
|
||||
|
||||
// Si las notificaciones no se apilan, elimina las anteriores
|
||||
if (!stack_)
|
||||
{
|
||||
clearNotifications();
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
constexpr auto icon_size = 16;
|
||||
constexpr auto padding_out = 1;
|
||||
const auto padding_in_h = text_->getCharacterSize();
|
||||
const auto padding_in_v = text_->getCharacterSize() / 2;
|
||||
const auto icon_space = icon >= 0 ? icon_size + padding_in_h : 0;
|
||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||
const auto width = text_->lenght(txt) + (padding_in_h * 2) + icon_space;
|
||||
const auto height = (text_->getCharacterSize() * num_texts) + (padding_in_v * 2);
|
||||
const auto shape = NotificationShape::SQUARED;
|
||||
|
||||
// Posición horizontal
|
||||
auto desp_h = 0;
|
||||
if (param.notification.pos_h == NotifyPosition::LEFT)
|
||||
{
|
||||
desp_h = padding_out;
|
||||
}
|
||||
else if (param.notification.pos_h == NotifyPosition::MIDDLE)
|
||||
{
|
||||
desp_h = ((param.game.width / 2) - (width / 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
desp_h = param.game.width - width - padding_out;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
const int desp_v = (param.notification.pos_v == NotifyPosition::TOP) ? padding_out : (param.game.height - height - padding_out);
|
||||
|
||||
// Offset
|
||||
const auto travel_dist = height + padding_out;
|
||||
auto offset = 0;
|
||||
if (param.notification.pos_v == NotifyPosition::TOP)
|
||||
{
|
||||
offset = (int)notifications_.size() > 0 ? notifications_.back().y + travel_dist : desp_v;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = (int)notifications_.size() > 0 ? notifications_.back().y - travel_dist : desp_v;
|
||||
}
|
||||
|
||||
// Crea la notificacion
|
||||
Notification n;
|
||||
|
||||
// Inicializa variables
|
||||
n.code = code;
|
||||
n.y = offset;
|
||||
n.travel_dist = travel_dist;
|
||||
n.counter = 0;
|
||||
n.status = NotificationStatus::RISING;
|
||||
n.text1 = text1;
|
||||
n.text2 = text2;
|
||||
n.shape = shape;
|
||||
auto y_pos = offset + (param.notification.pos_v == NotifyPosition::TOP ? -travel_dist : travel_dist);
|
||||
n.rect = {desp_h, y_pos, width, height};
|
||||
|
||||
// Crea la textura
|
||||
n.texture = std::make_shared<Texture>(renderer_);
|
||||
n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Prepara para dibujar en la textura
|
||||
n.texture->setAsRenderTarget(renderer_);
|
||||
|
||||
// Dibuja el fondo de la notificación
|
||||
SDL_SetRenderDrawColor(renderer_, bg_color_.r, bg_color_.g, bg_color_.b, 255);
|
||||
SDL_Rect rect;
|
||||
if (shape == NotificationShape::ROUNDED)
|
||||
{
|
||||
rect = {4, 0, width - (4 * 2), height};
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
|
||||
rect = {4 / 2, 1, width - 4, height - 2};
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
|
||||
rect = {1, 4 / 2, width - 2, height - 4};
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
|
||||
rect = {0, 4, width, height - (4 * 2)};
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
}
|
||||
|
||||
else if (shape == NotificationShape::SQUARED)
|
||||
{
|
||||
SDL_RenderClear(renderer_);
|
||||
}
|
||||
|
||||
// Dibuja el icono de la notificación
|
||||
if (has_icons_ && icon >= 0 && num_texts == 2)
|
||||
{
|
||||
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_Rect){0, 0, icon_size, icon_size});
|
||||
sp->setPosition({padding_in_h, padding_in_v, icon_size, icon_size});
|
||||
sp->setSpriteClip({icon_size * (icon % 10), icon_size * (icon / 10), icon_size, icon_size});
|
||||
sp->render();
|
||||
}
|
||||
|
||||
// Escribe el texto de la notificación
|
||||
Color color = {255, 255, 255};
|
||||
if (num_texts == 2)
|
||||
{ // Dos lineas de texto
|
||||
text_->writeColored(padding_in_h + icon_space, padding_in_v, text1, color);
|
||||
text_->writeColored(padding_in_h + icon_space, padding_in_v + text_->getCharacterSize() + 1, text2, color);
|
||||
}
|
||||
else
|
||||
{ // Una linea de texto
|
||||
text_->writeColored(padding_in_h + icon_space, padding_in_v, text1, color);
|
||||
}
|
||||
|
||||
// Deja de dibujar en la textura
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
|
||||
// Crea el sprite de la notificación
|
||||
n.sprite = std::make_shared<Sprite>(n.texture, n.rect);
|
||||
|
||||
// Deja la notificación invisible
|
||||
n.texture->setAlpha(0);
|
||||
|
||||
// Añade la notificación a la lista
|
||||
notifications_.push_back(n);
|
||||
}
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool Notifier::isActive()
|
||||
{
|
||||
if ((int)notifications_.size() > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Finaliza y elimnina todas las notificaciones activas
|
||||
void Notifier::clearNotifications()
|
||||
{
|
||||
for (int i = 0; i < (int)notifications_.size(); ++i)
|
||||
{
|
||||
notifications_[i].status = NotificationStatus::FINISHED;
|
||||
}
|
||||
|
||||
clearFinishedNotifications();
|
||||
}
|
||||
|
||||
// Obtiene los códigos de las notificaciones
|
||||
std::vector<std::string> Notifier::getCodes()
|
||||
{
|
||||
std::vector<std::string> codes;
|
||||
for (int i = 0; i < (int)notifications_.size(); ++i)
|
||||
{
|
||||
codes.push_back(notifications_[i].code);
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
121
source/notifier.h
Normal file
@@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
#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 Notifier
|
||||
{
|
||||
private:
|
||||
// [SINGLETON] Objeto notifier privado para Don Melitón
|
||||
static Notifier *notifier_;
|
||||
|
||||
enum class NotificationStatus
|
||||
{
|
||||
RISING,
|
||||
STAY,
|
||||
VANISHING,
|
||||
FINISHED,
|
||||
};
|
||||
|
||||
enum class NotificationPosition
|
||||
{
|
||||
UPPER_LEFT,
|
||||
UPPER_CENTER,
|
||||
UPPER_RIGHT,
|
||||
MIDDLE_LEFT,
|
||||
MIDDLE_RIGHT,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_CENTER,
|
||||
BOTTOM_RIGHT,
|
||||
};
|
||||
|
||||
enum class NotificationShape
|
||||
{
|
||||
ROUNDED,
|
||||
SQUARED,
|
||||
};
|
||||
|
||||
struct Notification
|
||||
{
|
||||
std::shared_ptr<Texture> texture;
|
||||
std::shared_ptr<Sprite> sprite;
|
||||
std::string text1;
|
||||
std::string text2;
|
||||
int counter;
|
||||
NotificationStatus status;
|
||||
NotificationPosition position;
|
||||
NotificationShape shape;
|
||||
SDL_Rect rect;
|
||||
int y;
|
||||
int travel_dist;
|
||||
std::string code; // Permite asignar un código a la notificación
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
|
||||
std::shared_ptr<Texture> icon_texture_; // Textura para los iconos de las notificaciones
|
||||
std::shared_ptr<Text> text_; // Objeto para dibujar texto
|
||||
|
||||
// Variables
|
||||
Color bg_color_; // Color de fondo de las notificaciones
|
||||
int wait_time_; // Tiempo que se ve la notificación
|
||||
std::vector<Notification> notifications_; // La lista de notificaciones activas
|
||||
bool stack_; // Indica si las notificaciones se apilan
|
||||
bool has_icons_; // 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();
|
||||
|
||||
// Finaliza y elimnina todas las notificaciones activas
|
||||
void clearNotifications();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera
|
||||
|
||||
// Constructor
|
||||
Notifier(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file);
|
||||
|
||||
// Destructor
|
||||
~Notifier();
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto notifier con esta función estática
|
||||
static void init(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto notifier con esta función estática
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto notifier y podemos trabajar con él
|
||||
static Notifier *get();
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void render();
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void update();
|
||||
|
||||
/**
|
||||
* @brief Muestra una notificación de texto por pantalla.
|
||||
*
|
||||
* @param text1 Primer texto opcional para mostrar (valor predeterminado: cadena vacía).
|
||||
* @param text2 Segundo texto opcional para mostrar (valor predeterminado: cadena vacía).
|
||||
* @param icon Icono opcional para mostrar (valor predeterminado: -1).
|
||||
* @param code Permite asignar un código a la notificación (valor predeterminado: cadena vacía).
|
||||
*/
|
||||
void showText(std::string text1 = std::string(), std::string text2 = std::string(), int icon = -1, std::string code = std::string());
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool isActive();
|
||||
|
||||
// Obtiene los códigos de las notificaciones
|
||||
std::vector<std::string> getCodes();
|
||||
};
|
||||
@@ -1,312 +0,0 @@
|
||||
#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
|
||||
|
||||
// Constructor
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile)
|
||||
: renderer(renderer)
|
||||
{
|
||||
// Inicializa variables
|
||||
bgColor = param.notification.color;
|
||||
waitTime = 150;
|
||||
stack = false;
|
||||
hasIcons = iconFile == "" ? false : true;
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Notify::~Notify()
|
||||
{
|
||||
// Libera la memoria de los objetos
|
||||
JA_DeleteSound(sound);
|
||||
|
||||
notifications.clear();
|
||||
}
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void Notify::render()
|
||||
{
|
||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||
{
|
||||
notifications[i].sprite->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void Notify::update()
|
||||
{
|
||||
for (int i = 0; i < (int)notifications.size(); ++i)
|
||||
{
|
||||
// Si la notificación anterior está "saliendo", no hagas nada
|
||||
if (i > 0)
|
||||
{
|
||||
if (notifications[i - 1].status == NotificationStatus::RISING)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
notifications[i].counter++;
|
||||
|
||||
// Hace sonar la notificación en el primer frame
|
||||
if (notifications[i].counter == 1)
|
||||
{
|
||||
if (param.notification.sound)
|
||||
{
|
||||
if (notifications[i].status == NotificationStatus::RISING)
|
||||
{ // Reproduce el sonido de la notificación
|
||||
JA_PlaySound(sound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los estados
|
||||
if (notifications[i].status == NotificationStatus::RISING)
|
||||
{
|
||||
const float step = ((float)notifications[i].counter / notifications[i].travelDist);
|
||||
const int alpha = 255 * step;
|
||||
|
||||
if (param.notification.pos_v == NotifyPosition::TOP)
|
||||
{
|
||||
notifications[i].rect.y++;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifications[i].rect.y--;
|
||||
}
|
||||
notifications[i].texture->setAlpha(alpha);
|
||||
|
||||
if (notifications[i].rect.y == notifications[i].y)
|
||||
{
|
||||
notifications[i].status = NotificationStatus::STAY;
|
||||
notifications[i].texture->setAlpha(255);
|
||||
notifications[i].counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (notifications[i].status == NotificationStatus::STAY)
|
||||
{
|
||||
if (notifications[i].counter == waitTime)
|
||||
{
|
||||
notifications[i].status = NotificationStatus::VANISHING;
|
||||
notifications[i].counter = 0;
|
||||
}
|
||||
}
|
||||
else if (notifications[i].status == NotificationStatus::VANISHING)
|
||||
{
|
||||
|
||||
const float step = (notifications[i].counter / (float)notifications[i].travelDist);
|
||||
const int alpha = 255 * (1 - step);
|
||||
|
||||
if (param.notification.pos_v == NotifyPosition::TOP)
|
||||
{
|
||||
notifications[i].rect.y--;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifications[i].rect.y++;
|
||||
}
|
||||
notifications[i].texture->setAlpha(alpha);
|
||||
|
||||
if (notifications[i].rect.y == notifications[i].y - notifications[i].travelDist)
|
||||
{
|
||||
notifications[i].status = NotificationStatus::FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
notifications[i].sprite->setPos(notifications[i].rect);
|
||||
}
|
||||
|
||||
clearFinishedNotifications();
|
||||
}
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void Notify::clearFinishedNotifications()
|
||||
{
|
||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (notifications[i].status == NotificationStatus::FINISHED)
|
||||
{
|
||||
notifications.erase(notifications.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
{
|
||||
// Cuenta el número de textos a mostrar
|
||||
const int numTexts = (text1 != "") + (text2 != "");
|
||||
|
||||
// Si no hay texto, acaba
|
||||
if (numTexts == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Si solo hay un texto, lo coloca en la primera variable
|
||||
else if (numTexts == 1)
|
||||
{
|
||||
text1 = text1 + text2;
|
||||
text2 = "";
|
||||
}
|
||||
|
||||
// Si las notificaciones no se apilan, elimina las anteriores
|
||||
if (!stack)
|
||||
{
|
||||
clearNotifications();
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
constexpr auto iconSize = 16;
|
||||
constexpr auto paddingOut = 1;
|
||||
const auto paddingIn = text->getCharacterSize() / 2;
|
||||
const auto iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
|
||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||
const auto width = text->lenght(txt) + (paddingIn * 2) + iconSpace;
|
||||
const auto height = (text->getCharacterSize() * numTexts) + (paddingIn * 2);
|
||||
const auto shape = NotificationShape::SQUARED;
|
||||
|
||||
// Posición horizontal
|
||||
auto despH = 0;
|
||||
if (param.notification.pos_h == NotifyPosition::LEFT)
|
||||
{
|
||||
despH = paddingOut;
|
||||
}
|
||||
else if (param.notification.pos_h == NotifyPosition::MIDDLE)
|
||||
{
|
||||
despH = ((param.game.width / 2) - (width / 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
despH = param.game.width - width - paddingOut;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
const int despV = (param.notification.pos_v == NotifyPosition::TOP) ? paddingOut : (param.game.height - height - paddingOut);
|
||||
|
||||
// Offset
|
||||
const auto travelDist = height + paddingOut;
|
||||
auto offset = 0;
|
||||
if (param.notification.pos_v == NotifyPosition::TOP)
|
||||
{
|
||||
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = (int)notifications.size() > 0 ? notifications.back().y - travelDist : despV;
|
||||
}
|
||||
|
||||
// Crea la notificacion
|
||||
Notification n;
|
||||
|
||||
// Inicializa variables
|
||||
n.y = offset;
|
||||
n.travelDist = travelDist;
|
||||
n.counter = 0;
|
||||
n.status = NotificationStatus::RISING;
|
||||
n.text1 = text1;
|
||||
n.text2 = text2;
|
||||
n.shape = shape;
|
||||
auto yPos = offset + (param.notification.pos_v == NotifyPosition::TOP ? -travelDist : travelDist);
|
||||
n.rect = {despH, yPos, width, height};
|
||||
|
||||
// Crea la textura
|
||||
n.texture = std::make_shared<Texture>(renderer);
|
||||
n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Prepara para dibujar en la textura
|
||||
n.texture->setAsRenderTarget(renderer);
|
||||
|
||||
// Dibuja el fondo de la notificación
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_Rect rect;
|
||||
if (shape == NotificationShape::ROUNDED)
|
||||
{
|
||||
rect = {4, 0, width - (4 * 2), height};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
rect = {4 / 2, 1, width - 4, height - 2};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
rect = {1, 4 / 2, width - 2, height - 4};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
rect = {0, 4, width, height - (4 * 2)};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
|
||||
else if (shape == NotificationShape::SQUARED)
|
||||
{
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
// Dibuja el icono de la notificación
|
||||
if (hasIcons && icon >= 0 && numTexts == 2)
|
||||
{
|
||||
auto sp = std::make_unique<Sprite>((SDL_Rect){0, 0, iconSize, iconSize}, iconTexture);
|
||||
sp->setPos({paddingIn, paddingIn, iconSize, iconSize});
|
||||
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
|
||||
sp->render();
|
||||
}
|
||||
|
||||
// Escribe el texto de la notificación
|
||||
Color color = {255, 255, 255};
|
||||
if (numTexts == 2)
|
||||
{ // Dos lineas de texto
|
||||
text->writeColored(paddingIn + iconSpace, paddingIn, text1, color);
|
||||
text->writeColored(paddingIn + iconSpace, paddingIn + text->getCharacterSize() + 1, text2, color);
|
||||
}
|
||||
else
|
||||
{ // Una linea de texto
|
||||
text->writeColored(paddingIn + iconSpace, paddingIn, text1, color);
|
||||
}
|
||||
|
||||
// Deja de dibujar en la textura
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
// Crea el sprite de la notificación
|
||||
n.sprite = std::make_shared<Sprite>(n.rect, n.texture);
|
||||
|
||||
// Deja la notificación invisible
|
||||
n.texture->setAlpha(0);
|
||||
|
||||
// Añade la notificación a la lista
|
||||
notifications.push_back(n);
|
||||
}
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool Notify::active()
|
||||
{
|
||||
if ((int)notifications.size() > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Finaliza y elimnina todas las notificaciones activas
|
||||
void Notify::clearNotifications()
|
||||
{
|
||||
for (int i = 0; i < (int)notifications.size(); ++i)
|
||||
{
|
||||
notifications[i].status = NotificationStatus::FINISHED;
|
||||
}
|
||||
|
||||
clearFinishedNotifications();
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
#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;
|
||||
|
||||
class Notify
|
||||
{
|
||||
private:
|
||||
enum class NotificationStatus
|
||||
{
|
||||
RISING,
|
||||
STAY,
|
||||
VANISHING,
|
||||
FINISHED,
|
||||
};
|
||||
|
||||
enum class NotificationPosition
|
||||
{
|
||||
UPPER_LEFT,
|
||||
UPPER_CENTER,
|
||||
UPPER_RIGHT,
|
||||
MIDDLE_LEFT,
|
||||
MIDDLE_RIGHT,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_CENTER,
|
||||
BOTTOM_RIGHT,
|
||||
};
|
||||
|
||||
enum class NotificationShape
|
||||
{
|
||||
ROUNDED,
|
||||
SQUARED,
|
||||
};
|
||||
|
||||
struct Notification
|
||||
{
|
||||
std::shared_ptr<Texture> texture;
|
||||
std::shared_ptr<Sprite> sprite;
|
||||
std::string text1;
|
||||
std::string text2;
|
||||
int counter;
|
||||
NotificationStatus status;
|
||||
NotificationPosition position;
|
||||
NotificationShape shape;
|
||||
SDL_Rect rect;
|
||||
int y;
|
||||
int travelDist;
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
|
||||
std::shared_ptr<Texture> iconTexture; // Textura para los iconos de las notificaciones
|
||||
std::unique_ptr<Text> text; // Objeto para dibujar texto
|
||||
|
||||
// Variables
|
||||
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
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void clearFinishedNotifications();
|
||||
|
||||
// Finaliza y elimnina todas las notificaciones activas
|
||||
void clearNotifications();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile);
|
||||
|
||||
// Destructor
|
||||
~Notify();
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void render();
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void update();
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void showText(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool active();
|
||||
};
|
||||
@@ -1,16 +1,16 @@
|
||||
#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 <memory> // for make_unique, make_shared, unique_ptr
|
||||
#include "asset.h" // for Asset
|
||||
#include "lang.h" // for getText
|
||||
#include "param.h" // for param
|
||||
#include "resource.h" // for Resource
|
||||
#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 "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;
|
||||
@@ -96,13 +96,13 @@ void OnScreenHelp::fillTexture()
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
|
||||
|
||||
// Crea el objeto para el texto
|
||||
auto text = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer());
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
|
||||
// Crea la textura con los gráficos
|
||||
auto controllersTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("controllers.png"));
|
||||
auto controllersTexture = Resource::get()->getTexture("controllers.png");
|
||||
|
||||
// Crea el sprite para dibujar los gráficos
|
||||
auto sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, 16, 16}, controllersTexture);
|
||||
auto sprite = std::make_unique<Sprite>(controllersTexture, (SDL_Rect){0, 0, 16, 16});
|
||||
|
||||
// Borra la textura
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
||||
@@ -171,7 +171,7 @@ void OnScreenHelp::toggleState()
|
||||
// Calcula la longitud en pixels del texto más largo
|
||||
auto OnScreenHelp::getLargestStringSize() -> int const
|
||||
{
|
||||
auto text = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer());
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
auto size = 0;
|
||||
|
||||
for (int i = 107; i <= 113; ++i)
|
||||
@@ -187,7 +187,7 @@ auto OnScreenHelp::getLargestStringSize() -> int const
|
||||
void OnScreenHelp::renderButton(Sprite *sprite, Text *text, const SDL_Rect &buttonClip, const SDL_Rect &buttonPos, int textId)
|
||||
{
|
||||
sprite->setSpriteClip(buttonClip);
|
||||
sprite->setPos(buttonPos);
|
||||
sprite->setPosition(buttonPos);
|
||||
sprite->render();
|
||||
text->write(buttonPos.x + DESP.x, buttonPos.y + DESP.y, lang::getText(textId));
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
@@ -93,9 +93,7 @@ bool loadOptionsFile(std::string file_path)
|
||||
if (file.good())
|
||||
{
|
||||
// Procesa el fichero linea a linea
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Reading file: " << file_name << std::endl;
|
||||
#endif
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
@@ -107,10 +105,8 @@ bool loadOptionsFile(std::string file_path)
|
||||
// Procesa las dos subcadenas
|
||||
if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: file " << file_name << std::endl;
|
||||
std::cout << "Unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
#endif
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
@@ -155,15 +151,11 @@ bool saveOptionsFile(std::string file_path)
|
||||
|
||||
if (!file.good())
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << file_name << " can't be opened" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Writing file: " << file_name << std::endl;
|
||||
#endif
|
||||
|
||||
// Opciones de video
|
||||
const auto value_video_mode_winow = std::to_string(static_cast<int>(ScreenVideoMode::WINDOW));
|
||||
@@ -240,10 +232,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 +381,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("#"))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
140
source/param.cpp
@@ -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,110 +55,62 @@ 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(const std::string &file_path)
|
||||
{
|
||||
// Pone valores por defecto a las variables
|
||||
// Inicializa los parámetros con valores por defecto
|
||||
initParam();
|
||||
|
||||
// Variables para manejar el fichero
|
||||
std::ifstream file(filePath);
|
||||
std::string line;
|
||||
std::string param1;
|
||||
std::string param2;
|
||||
|
||||
// Si el fichero se puede abrir
|
||||
if (file.good())
|
||||
// Abre el archivo
|
||||
std::ifstream file(file_path);
|
||||
if (!file.is_open())
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << filename << std::endl;
|
||||
#endif
|
||||
// Procesa cada linea del fichero
|
||||
while (std::getline(file, line))
|
||||
std::cerr << "Error: No se pudo abrir el archivo " << file_path << std::endl;
|
||||
throw std::runtime_error("No se pudo abrir el archivo: " + file_path);
|
||||
}
|
||||
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << file_name << std::endl;
|
||||
|
||||
std::string line, param1, param2;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Elimina comentarios
|
||||
auto comment_pos = line.find('#');
|
||||
if (comment_pos != std::string::npos)
|
||||
{
|
||||
// Reinicia variables
|
||||
param1 = "";
|
||||
param2 = "";
|
||||
|
||||
// Elimina los comentarios
|
||||
line = line.substr(0, line.find("#"));
|
||||
|
||||
// Ignora los espacios en blanco
|
||||
int pos = 0;
|
||||
while (pos < (int)line.size() && (int)line[pos] <= 32)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
|
||||
// Si no ha llegado al final de la linea, es que hay algo escrito (no es una linea vacía)
|
||||
if (pos < (int)line.size())
|
||||
{
|
||||
// Elimina el espacio en blanco
|
||||
line = line.substr(pos, std::string::npos);
|
||||
|
||||
// Se queda con todo lo que no sean espacios en blanco
|
||||
pos = 1;
|
||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
|
||||
// Si llega al final de la linea, falta la segunda palabra
|
||||
if (pos < (int)line.size())
|
||||
{
|
||||
// Se queda con la primera palabra
|
||||
param1 = line.substr(0, pos);
|
||||
|
||||
// Y recorta la linea
|
||||
line = line.substr(pos, std::string::npos);
|
||||
|
||||
// Ignora los espacios en blanco
|
||||
pos = 0;
|
||||
while (pos <= (int)line.size() && (int)line[pos] <= 32)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
|
||||
// Si llega al final de la linea, falta la segunda palabra
|
||||
if (pos < (int)line.size())
|
||||
{
|
||||
// Elimina el espacio en blanco
|
||||
line = line.substr(pos, std::string::npos);
|
||||
|
||||
// Ignora los espacios en blanco
|
||||
pos = 1;
|
||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
// Se queda con la segunda palabra
|
||||
param2 = line.substr(0, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setParams(param1, param2);
|
||||
line.resize(comment_pos);
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
// Usa un stream para separar palabras
|
||||
std::istringstream iss(line);
|
||||
if (iss >> param1 >> param2)
|
||||
{
|
||||
setParams(param1, param2);
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
else
|
||||
std::cout << "Failed to load file: " << filePath << std::endl;
|
||||
#endif
|
||||
|
||||
// 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")
|
||||
@@ -193,6 +148,11 @@ bool setParams(std::string var, std::string value)
|
||||
param.game.play_area.rect.h = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.enter_name_seconds")
|
||||
{
|
||||
param.game.enter_name_seconds = std::stoi(value);
|
||||
}
|
||||
|
||||
// FADE
|
||||
else if (var == "fade.num_squares_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);
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for max, min
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "animated_sprite.h" // for SpriteAnimated
|
||||
#include "input.h" // for inputs_e
|
||||
#include "param.h" // for param
|
||||
#include "texture.h" // for Texture
|
||||
@@ -11,31 +11,30 @@
|
||||
#include "options.h"
|
||||
|
||||
// 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::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations)
|
||||
: 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();
|
||||
}
|
||||
@@ -56,7 +55,9 @@ void Player::init()
|
||||
coffees_ = 0;
|
||||
input_ = true;
|
||||
continue_ticks_ = 0;
|
||||
continue_counter_ = 20;
|
||||
continue_counter_ = 10;
|
||||
enter_name_ticks_ = 0;
|
||||
enter_name_counter_ = param.game.enter_name_seconds;
|
||||
width_ = 30;
|
||||
height_ = 30;
|
||||
collider_.r = 9;
|
||||
@@ -69,6 +70,7 @@ void Player::init()
|
||||
cooldown_ = 10;
|
||||
|
||||
// Establece la posición del sprite
|
||||
player_sprite_->clear();
|
||||
player_sprite_->setPosX(pos_x_);
|
||||
player_sprite_->setPosY(pos_y_);
|
||||
|
||||
@@ -150,11 +152,11 @@ void Player::setInputEnteringName(InputType input)
|
||||
switch (input)
|
||||
{
|
||||
case InputType::LEFT:
|
||||
enter_name_->decPos();
|
||||
enter_name_->decPosition();
|
||||
break;
|
||||
|
||||
case InputType::RIGHT:
|
||||
enter_name_->incPos();
|
||||
enter_name_->incPosition();
|
||||
break;
|
||||
|
||||
case InputType::UP:
|
||||
@@ -237,21 +239,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
|
||||
@@ -286,10 +280,10 @@ void Player::setAnimation()
|
||||
}
|
||||
|
||||
// Actualiza las animaciones de los sprites
|
||||
player_sprite_->animate();
|
||||
player_sprite_->update();
|
||||
|
||||
// powerSprite->setFlip(flip_walk);
|
||||
power_sprite_->animate();
|
||||
power_sprite_->update();
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
@@ -353,9 +347,10 @@ void Player::update()
|
||||
setAnimation();
|
||||
shiftColliders();
|
||||
updateCooldown();
|
||||
updatePowerUpCounter();
|
||||
updatePowerUp();
|
||||
updateInvulnerable();
|
||||
updateContinueCounter();
|
||||
updateEnterNameCounter();
|
||||
updateScoreboard();
|
||||
}
|
||||
|
||||
@@ -583,7 +578,7 @@ void Player::updateInvulnerable()
|
||||
{
|
||||
if (invulnerable_counter_ > 0)
|
||||
{
|
||||
invulnerable_counter_--;
|
||||
--invulnerable_counter_;
|
||||
invulnerable_counter_ % 8 > 3 ? player_sprite_->getTexture()->setPalette(coffees_) : player_sprite_->getTexture()->setPalette(3);
|
||||
}
|
||||
else
|
||||
@@ -620,15 +615,12 @@ void Player::setPowerUpCounter(int value)
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updatePowerUpCounter()
|
||||
void Player::updatePowerUp()
|
||||
{
|
||||
if ((power_up_counter_ > 0) && (power_up_))
|
||||
if (power_up_)
|
||||
{
|
||||
power_up_counter_--;
|
||||
}
|
||||
else
|
||||
{
|
||||
power_up_ = false;
|
||||
--power_up_counter_;
|
||||
power_up_ = power_up_counter_ > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,7 +686,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]);
|
||||
@@ -720,6 +712,20 @@ void Player::updateContinueCounter()
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el contador de entrar nombre
|
||||
void Player::updateEnterNameCounter()
|
||||
{
|
||||
if (status_playing_ == PlayerStatus::ENTERING_NAME)
|
||||
{
|
||||
constexpr Uint32 ticks_speed = 1000;
|
||||
|
||||
if (SDL_GetTicks() - enter_name_ticks_ > ticks_speed)
|
||||
{
|
||||
decEnterNameCounter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Le asigna un panel en el marcador al jugador
|
||||
void Player::setScoreBoardPanel(int panel)
|
||||
{
|
||||
@@ -736,21 +742,33 @@ int Player::getScoreBoardPanel() const
|
||||
void Player::decContinueCounter()
|
||||
{
|
||||
continue_ticks_ = SDL_GetTicks();
|
||||
continue_counter_--;
|
||||
--continue_counter_;
|
||||
if (continue_counter_ < 0)
|
||||
{
|
||||
setStatusPlaying(PlayerStatus::GAME_OVER);
|
||||
}
|
||||
}
|
||||
|
||||
// Decrementa el contador de entrar nombre
|
||||
void Player::decEnterNameCounter()
|
||||
{
|
||||
enter_name_ticks_ = SDL_GetTicks();
|
||||
--enter_name_counter_;
|
||||
if (enter_name_counter_ < 0)
|
||||
{
|
||||
enter_name_counter_ = param.game.enter_name_seconds;
|
||||
setStatusPlaying(PlayerStatus::CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
@@ -772,7 +790,7 @@ int Player::getRecordNamePos() const
|
||||
{
|
||||
if (enter_name_)
|
||||
{
|
||||
return enter_name_->getPos();
|
||||
return enter_name_->getPosition();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
|
||||
#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 <memory> // for unique_ptr, shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "animated_sprite.h" // for SpriteAnimated
|
||||
#include "smart_sprite.h" // for SpriteAnimated
|
||||
#include "enter_name.h" // for EnterName
|
||||
#include "utils.h" // for Circle
|
||||
#include "texture.h" // lines 12-12
|
||||
enum class ScoreboardMode;
|
||||
class Texture;
|
||||
enum class InputType : int;
|
||||
enum class ScoreboardMode; // lines 12-12
|
||||
|
||||
// Estados del jugador
|
||||
enum class PlayerStatus
|
||||
@@ -47,7 +49,7 @@ private:
|
||||
SDL_Rect *play_area_; // Rectangulo con la zona de juego
|
||||
|
||||
// Variables
|
||||
int id_; // Numero de identificación para el jugador
|
||||
int id_; // Numero de identificación para el jugador. Player1 = 1, Player2 = 2
|
||||
float pos_x_; // Posicion en el eje X
|
||||
int pos_y_; // Posicion en el eje Y
|
||||
float default_pos_x_; // Posición inicial para el jugador
|
||||
@@ -76,9 +78,11 @@ private:
|
||||
Uint32 continue_ticks_; // Variable para poder cambiar el contador de continue en función del tiempo
|
||||
int scoreboard_panel_; // Panel del marcador asociado al jugador
|
||||
std::string name_; // Nombre del jugador
|
||||
std::string record_name_; // Nombre del jugador para l atabla de mejores puntuaciones
|
||||
std::string record_name_; // Nombre del jugador para la tabla de mejores puntuaciones
|
||||
int controller_index_; // Indice del array de mandos que utilizará para moverse
|
||||
bool demo_; // Para que el jugador sepa si está en el modo demostración
|
||||
int enter_name_counter_; // Contador para poner nombre
|
||||
Uint32 enter_name_ticks_; // Variable para poder cambiar el contador de poner nombre en función del tiempo
|
||||
|
||||
// Actualiza el circulo de colisión a la posición del jugador
|
||||
void shiftColliders();
|
||||
@@ -89,6 +93,12 @@ private:
|
||||
// Actualiza el contador de continue
|
||||
void updateContinueCounter();
|
||||
|
||||
// Actualiza el contador de entrar nombre
|
||||
void updateEnterNameCounter();
|
||||
|
||||
// Decrementa el contador de entrar nombre
|
||||
void decEnterNameCounter();
|
||||
|
||||
// Indica si el jugador se puede dibujar
|
||||
bool isRenderable() const;
|
||||
|
||||
@@ -103,7 +113,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
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(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations);
|
||||
|
||||
// Destructor
|
||||
~Player() = default;
|
||||
@@ -118,7 +128,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);
|
||||
@@ -235,7 +245,7 @@ public:
|
||||
void setPowerUpCounter(int value);
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updatePowerUpCounter();
|
||||
void updatePowerUp();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool hasExtraHit() const;
|
||||
@@ -271,10 +281,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;
|
||||
|
||||
256
source/resource.cpp
Normal file
@@ -0,0 +1,256 @@
|
||||
#include <iostream>
|
||||
#include "resource.h"
|
||||
#include "asset.h"
|
||||
#include "screen.h"
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Resource *Resource::resource_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
void Resource::init()
|
||||
{
|
||||
Resource::resource_ = new Resource();
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
void Resource::destroy()
|
||||
{
|
||||
delete Resource::resource_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
Resource *Resource::get()
|
||||
{
|
||||
return Resource::resource_;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Resource::Resource()
|
||||
{
|
||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||
loadSounds();
|
||||
loadMusics();
|
||||
loadTextures();
|
||||
loadTextFiles();
|
||||
loadAnimations();
|
||||
loadDemoData();
|
||||
addPalettes();
|
||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Resource::~Resource()
|
||||
{
|
||||
sounds_.clear();
|
||||
musics_.clear();
|
||||
textures_.clear();
|
||||
text_files_.clear();
|
||||
animations_.clear();
|
||||
}
|
||||
|
||||
// Obtiene el sonido a partir de un nombre
|
||||
JA_Sound_t *Resource::getSound(const std::string &name)
|
||||
{
|
||||
for (const auto &s : sounds_)
|
||||
{
|
||||
if (s.name == name)
|
||||
{
|
||||
return s.sound;
|
||||
}
|
||||
}
|
||||
std::cerr << "Error: Sonido no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("Sonido no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la música a partir de un nombre
|
||||
JA_Music_t *Resource::getMusic(const std::string &name)
|
||||
{
|
||||
for (const auto &m : musics_)
|
||||
{
|
||||
if (m.name == name)
|
||||
{
|
||||
return m.music;
|
||||
}
|
||||
}
|
||||
std::cerr << "Error: Música no encontrada " << name << std::endl;
|
||||
throw std::runtime_error("Música no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la textura a partir de un nombre
|
||||
std::shared_ptr<Texture> Resource::getTexture(const std::string &name)
|
||||
{
|
||||
for (const auto &t : textures_)
|
||||
{
|
||||
if (t.name == name)
|
||||
{
|
||||
return t.texture;
|
||||
}
|
||||
}
|
||||
std::cerr << "Error: Imagen no encontrada " << name << std::endl;
|
||||
throw std::runtime_error("Imagen no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el fichero de texto a partir de un nombre
|
||||
std::shared_ptr<TextFile> Resource::getTextFile(const std::string &name)
|
||||
{
|
||||
for (const auto &t : text_files_)
|
||||
{
|
||||
if (t.name == name)
|
||||
{
|
||||
return t.text_file;
|
||||
}
|
||||
}
|
||||
std::cerr << "Error: TextFile no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("TextFile no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
Animations &Resource::getAnimation(const std::string &name)
|
||||
{
|
||||
for (auto &a : animations_)
|
||||
{
|
||||
if (a.name == name)
|
||||
{
|
||||
return a.animation;
|
||||
}
|
||||
}
|
||||
std::cerr << "Error: Animación no encontrada " << name << std::endl;
|
||||
throw std::runtime_error("Animación no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
|
||||
DemoData &Resource::getDemoData(int index)
|
||||
{
|
||||
return demos_.at(index);
|
||||
}
|
||||
|
||||
// Carga los sonidos
|
||||
void Resource::loadSounds()
|
||||
{
|
||||
std::cout << "\n>> SOUND FILES" << std::endl;
|
||||
|
||||
// Obtiene la lista con las rutas a los ficheros de sonidos
|
||||
auto list = Asset::get()->getListByType(AssetType::SOUND);
|
||||
sounds_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
// Encuentra el último índice de '/'
|
||||
auto last_index = l.find_last_of('/') + 1;
|
||||
|
||||
// Obtiene la subcadena desde el último '/'
|
||||
auto name = l.substr(last_index);
|
||||
|
||||
sounds_.emplace_back(ResourceSound(name, JA_LoadSound(l.c_str())));
|
||||
printWithDots("Sound : ", name, "[ LOADED ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las musicas
|
||||
void Resource::loadMusics()
|
||||
{
|
||||
std::cout << "\n>> MUSIC FILES" << std::endl;
|
||||
|
||||
// Obtiene la lista con las rutas a los ficheros musicales
|
||||
auto list = Asset::get()->getListByType(AssetType::MUSIC);
|
||||
musics_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
// Encuentra el último índice de '/'
|
||||
auto last_index = l.find_last_of('/') + 1;
|
||||
|
||||
// Obtiene la subcadena desde el último '/'
|
||||
auto name = l.substr(last_index);
|
||||
|
||||
musics_.emplace_back(ResourceMusic(name, JA_LoadMusic(l.c_str())));
|
||||
printWithDots("Music : ", name, "[ LOADED ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las texturas
|
||||
void Resource::loadTextures()
|
||||
{
|
||||
std::cout << "\n>> TEXTURES" << std::endl;
|
||||
|
||||
// Obtiene la lista con las rutas a los ficheros png
|
||||
auto list = Asset::get()->getListByType(AssetType::BITMAP);
|
||||
textures_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
// Encuentra el último índice de '/'
|
||||
auto last_index = l.find_last_of('/') + 1;
|
||||
|
||||
// Obtiene la subcadena desde el último '/'
|
||||
auto name = l.substr(last_index);
|
||||
|
||||
textures_.emplace_back(ResourceTexture(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l)));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los ficheros de texto
|
||||
void Resource::loadTextFiles()
|
||||
{
|
||||
std::cout << "\n>> TEXT FILES" << std::endl;
|
||||
// Obtiene la lista con las rutas a los ficheros png
|
||||
auto list = Asset::get()->getListByType(AssetType::FONT);
|
||||
text_files_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
// Encuentra el último índice de '/'
|
||||
auto last_index = l.find_last_of('/') + 1;
|
||||
|
||||
// Obtiene la subcadena desde el último '/'
|
||||
auto name = l.substr(last_index);
|
||||
|
||||
text_files_.emplace_back(ResourceTextFile(name, loadTextFile(l)));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las animaciones
|
||||
void Resource::loadAnimations()
|
||||
{
|
||||
std::cout << "\n>> ANIMATIONS" << std::endl;
|
||||
// Obtiene la lista con las rutas a los ficheros ani
|
||||
auto list = Asset::get()->getListByType(AssetType::ANIMATION);
|
||||
animations_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
// Encuentra el último índice de '/'
|
||||
auto last_index = l.find_last_of('/') + 1;
|
||||
|
||||
// Obtiene la subcadena desde el último '/'
|
||||
auto name = l.substr(last_index);
|
||||
|
||||
animations_.emplace_back(ResourceAnimation(name, loadAnimationsFromFile(l)));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los datos para el modo demostración
|
||||
void Resource::loadDemoData()
|
||||
{
|
||||
std::cout << "\n>> DEMO_FILES" << std::endl;
|
||||
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get("demo1.bin")));
|
||||
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get("demo2.bin")));
|
||||
}
|
||||
|
||||
// Añade paletas a las texturas
|
||||
void Resource::addPalettes()
|
||||
{
|
||||
// Jugador 1
|
||||
std::cout << "\n>> PALETTES" << std::endl;
|
||||
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_one_coffee_palette.pal"));
|
||||
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_two_coffee_palette.pal"));
|
||||
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_all_white_palette.pal"));
|
||||
|
||||
// Jugador 2
|
||||
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_one_coffee_palette.pal"));
|
||||
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_two_coffee_palette.pal"));
|
||||
getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_all_white_palette.pal"));
|
||||
|
||||
// Fuentes
|
||||
getTexture("smb2.gif")->addPaletteFromFile(Asset::get()->get("smb2_palette1.pal"));
|
||||
}
|
||||
137
source/resource.h
Normal file
@@ -0,0 +1,137 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "jail_audio.h"
|
||||
#include "texture.h"
|
||||
#include "text.h"
|
||||
#include "utils.h"
|
||||
#include "animated_sprite.h"
|
||||
|
||||
// Estructura para almacenar ficheros de sonido y su nombre
|
||||
struct ResourceSound
|
||||
{
|
||||
std::string name; // Nombre del sonido
|
||||
JA_Sound_t *sound; // Objeto con el sonido
|
||||
|
||||
// Constructor
|
||||
ResourceSound(const std::string &name, JA_Sound_t *sound)
|
||||
: name(name), sound(sound) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros musicales y su nombre
|
||||
struct ResourceMusic
|
||||
{
|
||||
std::string name; // Nombre de la musica
|
||||
JA_Music_t *music; // Objeto con la música
|
||||
|
||||
// Constructor
|
||||
ResourceMusic(const std::string &name, JA_Music_t *music)
|
||||
: name(name), music(music) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar objetos Texture y su nombre
|
||||
struct ResourceTexture
|
||||
{
|
||||
std::string name; // Nombre de la textura
|
||||
std::shared_ptr<Texture> texture; // Objeto con la textura
|
||||
|
||||
// Constructor
|
||||
ResourceTexture(const std::string &name, std::shared_ptr<Texture> texture)
|
||||
: name(name), texture(texture) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros TextFile y su nombre
|
||||
struct ResourceTextFile
|
||||
{
|
||||
std::string name; // Nombre del fichero
|
||||
std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto
|
||||
|
||||
// Constructor
|
||||
ResourceTextFile(const std::string &name, std::shared_ptr<TextFile> text_file)
|
||||
: name(name), text_file(text_file) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros animaciones y su nombre
|
||||
struct ResourceAnimation
|
||||
{
|
||||
std::string name; // Nombre del fichero
|
||||
Animations animation; // Objeto con las animaciones
|
||||
|
||||
// Constructor
|
||||
ResourceAnimation(const std::string &name, Animations animation)
|
||||
: name(name), animation(animation) {}
|
||||
};
|
||||
|
||||
class Resource
|
||||
{
|
||||
private:
|
||||
// [SINGLETON] Objeto resource privado para Don Melitón
|
||||
static Resource *resource_;
|
||||
|
||||
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
||||
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||
std::vector<ResourceTexture> textures_; // Vector con las musicas
|
||||
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
||||
std::vector<DemoData> demos_; // Vector con los ficheros de datos para el modo demostración
|
||||
|
||||
// Carga los sonidos
|
||||
void loadSounds();
|
||||
|
||||
// Carga las musicas
|
||||
void loadMusics();
|
||||
|
||||
// Carga las texturas
|
||||
void loadTextures();
|
||||
|
||||
// Carga los ficheros de texto
|
||||
void loadTextFiles();
|
||||
|
||||
// Carga las animaciones
|
||||
void loadAnimations();
|
||||
|
||||
// Carga los datos para el modo demostración
|
||||
void loadDemoData();
|
||||
|
||||
// Añade paletas a las texturas
|
||||
void addPalettes();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||
|
||||
// Constructor
|
||||
Resource();
|
||||
|
||||
// Destructor
|
||||
~Resource();
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto resource con esta función estática
|
||||
static void init();
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto resource con esta función estática
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él
|
||||
static Resource *get();
|
||||
|
||||
// Obtiene el sonido a partir de un nombre
|
||||
JA_Sound_t *getSound(const std::string &name);
|
||||
|
||||
// Obtiene la música a partir de un nombre
|
||||
JA_Music_t *getMusic(const std::string &name);
|
||||
|
||||
// Obtiene la textura a partir de un nombre
|
||||
std::shared_ptr<Texture> getTexture(const std::string &name);
|
||||
|
||||
// Obtiene el fichero de texto a partir de un nombre
|
||||
std::shared_ptr<TextFile> getTextFile(const std::string &name);
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
Animations &getAnimation(const std::string &name);
|
||||
|
||||
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
|
||||
DemoData &getDemoData(int index);
|
||||
};
|
||||
@@ -5,8 +5,10 @@
|
||||
#include <math.h> // for roundf
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include "asset.h" // for Asset
|
||||
#include "lang.h" // for getText
|
||||
#include "asset.h" // for Asset
|
||||
#include "lang.h" // for getText
|
||||
#include "resource.h" // for Resource
|
||||
#include "screen.h"
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
@@ -15,9 +17,9 @@
|
||||
Scoreboard *Scoreboard::scoreboard_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto score_board con esta función estática
|
||||
void Scoreboard::init(SDL_Renderer *renderer)
|
||||
void Scoreboard::init()
|
||||
{
|
||||
Scoreboard::scoreboard_ = new Scoreboard(renderer);
|
||||
Scoreboard::scoreboard_ = new Scoreboard();
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto score_board con esta función estática
|
||||
@@ -33,43 +35,40 @@ Scoreboard *Scoreboard::get()
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
||||
: renderer_(renderer)
|
||||
{
|
||||
// Inicializa punteros
|
||||
game_power_meter_texture_ = nullptr;
|
||||
power_meter_sprite_ = nullptr;
|
||||
text_scoreboard_ = nullptr;
|
||||
Scoreboard::Scoreboard()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
|
||||
game_power_meter_texture_(Resource::get()->getTexture("game_power_meter.png")),
|
||||
power_meter_sprite_(std::make_unique<Sprite>(game_power_meter_texture_)),
|
||||
text_scoreboard_(std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"))),
|
||||
|
||||
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 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_->setPosition({slot4_2_.x - 20, slot4_2_.y, 40, 7});
|
||||
|
||||
// Crea la textura de fondo
|
||||
background_ = nullptr;
|
||||
@@ -109,7 +108,7 @@ std::string Scoreboard::updateScoreText(int num)
|
||||
// Actualiza el contador
|
||||
void Scoreboard::updateCounter()
|
||||
{
|
||||
if (SDL_GetTicks() - ticks_ > SCOREBOARD_TICK_SPEED)
|
||||
if (SDL_GetTicks() - ticks_ > SCOREBOARD_TICK_SPEED_)
|
||||
{
|
||||
ticks_ = SDL_GetTicks();
|
||||
counter_++;
|
||||
@@ -130,13 +129,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 +183,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 +322,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 +330,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;
|
||||
}
|
||||
@@ -421,8 +420,8 @@ void Scoreboard::recalculateAnchors()
|
||||
// Recoloca los sprites
|
||||
if (power_meter_sprite_)
|
||||
{
|
||||
power_meter_sprite_->setPosX(slot4_2_.x - 20);
|
||||
power_meter_sprite_->setPosY(slot4_2_.y);
|
||||
power_meter_sprite_->setX(slot4_2_.x - 20);
|
||||
power_meter_sprite_->setY(slot4_2_.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,20 +3,19 @@
|
||||
#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 <memory> // for unique_ptr, shared_ptr
|
||||
#include <string> // for 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
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
|
||||
// Defines
|
||||
constexpr int SCOREBOARD_LEFT_PANEL = 0;
|
||||
constexpr int SCOREBOARD_CENTER_PANEL = 1;
|
||||
constexpr int SCOREBOARD_RIGHT_PANEL = 2;
|
||||
constexpr int SCOREBOARD_MAX_PANELS = 3;
|
||||
constexpr int SCOREBOARD_TICK_SPEED = 100;
|
||||
|
||||
// Enums
|
||||
enum class ScoreboardMode : int
|
||||
@@ -42,6 +41,9 @@ struct Panel
|
||||
class Scoreboard
|
||||
{
|
||||
private:
|
||||
// Constantes
|
||||
static constexpr int SCOREBOARD_TICK_SPEED_ = 100;
|
||||
|
||||
// [SINGLETON] Objeto scoreboard privado para Don Melitón
|
||||
static Scoreboard *scoreboard_;
|
||||
|
||||
@@ -50,9 +52,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,14 +105,14 @@ private:
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados
|
||||
|
||||
// Constructor
|
||||
Scoreboard(SDL_Renderer *renderer);
|
||||
Scoreboard();
|
||||
|
||||
// Destructor
|
||||
~Scoreboard();
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto scoreboard con esta función estática
|
||||
static void init(SDL_Renderer *renderer);
|
||||
static void init();
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto scoreboard con esta función estática
|
||||
static void destroy();
|
||||
@@ -125,10 +127,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 +154,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);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "dbgtxt.h" // for dbg_print
|
||||
#include "global_inputs.h" // for servicePressedCounter
|
||||
#include "input.h" // for Input, inputs_e, INPUT_DO_NOT_ALLOW_REPEAT
|
||||
#include "notify.h" // for Notify
|
||||
#include "notifier.h" // for Notify
|
||||
#include "on_screen_help.h" // for OnScreenHelp
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
@@ -44,12 +44,26 @@ Screen *Screen::get()
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
: window_(window), renderer_(renderer)
|
||||
: window_(window),
|
||||
renderer_(renderer),
|
||||
|
||||
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 +76,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);
|
||||
|
||||
@@ -131,7 +126,7 @@ void Screen::blit()
|
||||
displayInfo();
|
||||
|
||||
// Muestra las notificaciones
|
||||
notify_->render();
|
||||
Notifier::get()->render();
|
||||
|
||||
#ifdef NO_SHADERS
|
||||
// Vuelve a dejar el renderizador en modo normal
|
||||
@@ -183,9 +178,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)
|
||||
@@ -203,8 +199,9 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
#endif
|
||||
// Modifica el tamaño de la ventana
|
||||
SDL_Point pos = getNewPosition();
|
||||
SDL_SetWindowSize(window_, param.game.width * options.video.window.size, param.game.height * options.video.window.size);
|
||||
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
SDL_SetWindowPosition(window_, pos.x, pos.y);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -283,7 +280,7 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||
void Screen::update()
|
||||
{
|
||||
updateShakeEffect();
|
||||
notify_->update();
|
||||
Notifier::get()->update();
|
||||
updateFPS();
|
||||
OnScreenHelp::get()->update();
|
||||
}
|
||||
@@ -297,7 +294,7 @@ void Screen::checkInput()
|
||||
{
|
||||
switchVideoMode();
|
||||
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
||||
showNotification(mode + " mode");
|
||||
Notifier::get()->showText(mode + " mode");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -306,7 +303,7 @@ void Screen::checkInput()
|
||||
{
|
||||
decWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
showNotification("Window size x" + size);
|
||||
Notifier::get()->showText("Window size x" + size);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -315,7 +312,7 @@ void Screen::checkInput()
|
||||
{
|
||||
incWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
showNotification("Window size x" + size);
|
||||
Notifier::get()->showText("Window size x" + size);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -445,7 +442,7 @@ void Screen::switchShaders()
|
||||
options.video.shaders = !options.video.shaders;
|
||||
setVideoMode(options.video.mode);
|
||||
const std::string value = options.video.shaders ? "on" : "off";
|
||||
showNotification("Shaders " + value);
|
||||
Notifier::get()->showText("Shaders " + value);
|
||||
}
|
||||
|
||||
// Atenua la pantalla
|
||||
@@ -454,12 +451,6 @@ void Screen::attenuate(bool value)
|
||||
attenuate_effect_ = value;
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
||||
{
|
||||
notify_->showText(text1, text2, icon);
|
||||
}
|
||||
|
||||
// Obtiene el puntero al renderizador
|
||||
SDL_Renderer *Screen::getRenderer()
|
||||
{
|
||||
@@ -493,8 +484,38 @@ void Screen::displayInfo()
|
||||
}
|
||||
}
|
||||
|
||||
// Indica si hay alguna notificación activa en pantalla
|
||||
bool Screen::notificationsAreActive() const
|
||||
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
||||
SDL_Point Screen::getNewPosition()
|
||||
{
|
||||
return notify_->active();
|
||||
// Obtiene la posición actual de la ventana
|
||||
SDL_Point current_position;
|
||||
SDL_GetWindowPosition(window_, ¤t_position.x, ¤t_position.y);
|
||||
|
||||
// Obtiene las dimensiones actuales de la ventana
|
||||
int current_width, current_height;
|
||||
SDL_GetWindowSize(window_, ¤t_width, ¤t_height);
|
||||
|
||||
// Obtiene las dimesiones que tendrá la ventana
|
||||
const int new_width = param.game.width * options.video.window.size;
|
||||
const int new_height = param.game.height * options.video.window.size;
|
||||
|
||||
// Obtiene el centro de la ventana actual
|
||||
SDL_Point center;
|
||||
center.x = current_position.x + current_width / 2;
|
||||
center.y = current_position.y + current_height / 2;
|
||||
|
||||
// Calcula la nueva posición a partir del centro y las nuevas diemsiones
|
||||
SDL_Point new_pos;
|
||||
new_pos.x = center.x - new_width / 2;
|
||||
new_pos.y = center.y - new_height / 2;
|
||||
|
||||
// Obtiene las dimensiones del escritorio
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
|
||||
// Evita que la ventana quede fuera del escritorio
|
||||
new_pos.x = std::clamp(new_pos.x, 30, DM.w - new_width);
|
||||
new_pos.y = std::clamp(new_pos.y, 30, DM.h - new_height);
|
||||
|
||||
return new_pos;
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <string> // for basic_string, string
|
||||
#include "utils.h" // for Color
|
||||
#include <memory>
|
||||
class Notify;
|
||||
|
||||
enum class ScreenFilter : int
|
||||
{
|
||||
@@ -29,11 +28,10 @@ private:
|
||||
static Screen *screen_;
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Window *window_; // Ventana de la aplicación
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
std::unique_ptr<Notify> notify_; // Pinta notificaciones en pantalla
|
||||
SDL_Texture *game_canvas_; // Textura donde se dibuja todo antes de volcarse al renderizador
|
||||
SDL_Texture *shader_canvas_; // Textura para pasarle al shader desde gameCanvas
|
||||
SDL_Window *window_; // Ventana de la aplicación
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Texture *game_canvas_; // Textura donde se dibuja todo antes de volcarse al renderizador
|
||||
SDL_Texture *shader_canvas_; // Textura para pasarle al shader desde gameCanvas
|
||||
|
||||
// Variables
|
||||
SDL_Rect src_rect_; // Coordenadas de donde va a pillar la textura del juego para dibujarla
|
||||
@@ -85,6 +83,9 @@ private:
|
||||
// Muestra información por pantalla
|
||||
void displayInfo();
|
||||
|
||||
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
||||
SDL_Point getNewPosition();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera
|
||||
|
||||
// Constructor
|
||||
@@ -151,12 +152,6 @@ public:
|
||||
// Atenua la pantalla
|
||||
void attenuate(bool value);
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||
|
||||
// Indica si hay alguna notificación activa en pantalla
|
||||
bool notificationsAreActive() const;
|
||||
|
||||
// Obtiene el puntero al renderizador
|
||||
SDL_Renderer *getRenderer();
|
||||
};
|
||||
@@ -23,9 +23,10 @@ namespace section
|
||||
GAME_PLAY_2P = 1,
|
||||
TITLE_1 = 2,
|
||||
TITLE_2 = 3,
|
||||
QUIT_NORMAL = 4,
|
||||
QUIT_SHUTDOWN = 5,
|
||||
NONE = 6,
|
||||
QUIT_WITH_KEYBOARD = 4,
|
||||
QUIT_WITH_CONTROLLER = 5,
|
||||
QUIT_FROM_EVENT = 6,
|
||||
NONE = 7,
|
||||
};
|
||||
|
||||
extern Name name;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "smart_sprite.h"
|
||||
#include "moving_sprite.h" // for MovingSprite
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
@@ -14,8 +13,7 @@ void SmartSprite::init()
|
||||
{
|
||||
finished_counter_ = 0;
|
||||
on_destination_ = false;
|
||||
dest_x_ = 0;
|
||||
dest_y_ = 0;
|
||||
dest_x_ = dest_y_ = 0;
|
||||
finished_ = false;
|
||||
enabled_ = false;
|
||||
}
|
||||
@@ -127,7 +125,7 @@ void SmartSprite::checkMove()
|
||||
void SmartSprite::checkFinished()
|
||||
{
|
||||
// Comprueba si ha llegado a su destino
|
||||
on_destination_ = (getPosX() == dest_x_ && getPosY() == dest_y_) ? true : false;
|
||||
on_destination_ = (getPosX() == dest_x_ && getPosY() == dest_y_);
|
||||
|
||||
if (on_destination_)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "texture.h"
|
||||
#include <memory>
|
||||
#include <memory> // for shared_ptr
|
||||
#include "animated_sprite.h" // for SpriteAnimated
|
||||
class Texture;
|
||||
|
||||
// Clase SmartSprite
|
||||
// Clase SpriteSmart
|
||||
class SmartSprite : public AnimatedSprite
|
||||
{
|
||||
private:
|
||||
@@ -16,12 +16,12 @@ private:
|
||||
bool finished_; // Indica si ya ha terminado
|
||||
bool enabled_; // Indica si el objeto está habilitado
|
||||
|
||||
// Comprueba el movimiento
|
||||
void checkMove();
|
||||
|
||||
// Comprueba si ha terminado
|
||||
void checkFinished();
|
||||
|
||||
// Comprueba el movimiento
|
||||
void checkMove();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit SmartSprite(std::shared_ptr<Texture> texture);
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
#include "sprite.h"
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(int x, int y, int w, int h, std::shared_ptr<Texture> texture)
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture, int x, int y, int w, int h)
|
||||
: texture_(texture),
|
||||
pos_((SDL_Rect){x, y, w, h}),
|
||||
sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
Sprite::Sprite(SDL_Rect rect, std::shared_ptr<Texture> texture)
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture, SDL_Rect rect)
|
||||
: texture_(texture),
|
||||
pos_(rect),
|
||||
sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture)
|
||||
: texture_(texture) {}
|
||||
: texture_(texture),
|
||||
pos_({0, 0, texture_->getWidth(), texture_->getHeight()}),
|
||||
sprite_clip_(pos_) {}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render()
|
||||
@@ -21,13 +23,13 @@ void Sprite::render()
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosX() const
|
||||
int Sprite::getX() const
|
||||
{
|
||||
return pos_.x;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosY() const
|
||||
int Sprite::getY() const
|
||||
{
|
||||
return pos_.y;
|
||||
}
|
||||
@@ -45,33 +47,33 @@ int Sprite::getHeight() const
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPos(int x, int y)
|
||||
void Sprite::setPosition(int x, int y)
|
||||
{
|
||||
pos_.x = x;
|
||||
pos_.y = y;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPos(SDL_Point p)
|
||||
void Sprite::setPosition(SDL_Point p)
|
||||
{
|
||||
pos_.x = p.x;
|
||||
pos_.y = p.y;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPos(SDL_Rect r)
|
||||
void Sprite::setPosition(SDL_Rect r)
|
||||
{
|
||||
pos_ = r;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosX(int x)
|
||||
void Sprite::setX(int x)
|
||||
{
|
||||
pos_.x = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosY(int y)
|
||||
void Sprite::setY(int y)
|
||||
{
|
||||
pos_.y = y;
|
||||
}
|
||||
@@ -119,19 +121,26 @@ void Sprite::setTexture(std::shared_ptr<Texture> texture)
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect Sprite::getPos() const
|
||||
SDL_Rect Sprite::getPosition() const
|
||||
{
|
||||
return pos_;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incPosX(int value)
|
||||
void Sprite::incX(int value)
|
||||
{
|
||||
pos_.x += value;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incPosY(int value)
|
||||
void Sprite::incY(int value)
|
||||
{
|
||||
pos_.y += value;
|
||||
}
|
||||
|
||||
// Reinicia las variables a cero
|
||||
void Sprite::clear()
|
||||
{
|
||||
pos_ = {0, 0, 0, 0};
|
||||
sprite_clip_ = {0, 0, 0, 0};
|
||||
}
|
||||
@@ -15,9 +15,9 @@ protected:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit Sprite(int x = 0, int y = 0, int w = 0, int h = 0, std::shared_ptr<Texture> texture = nullptr);
|
||||
explicit Sprite(SDL_Rect rect, std::shared_ptr<Texture> texture = nullptr);
|
||||
explicit Sprite(std::shared_ptr<Texture> texture = nullptr);
|
||||
Sprite(std::shared_ptr<Texture>, int x, int y, int w, int h);
|
||||
Sprite(std::shared_ptr<Texture>, SDL_Rect rect);
|
||||
explicit Sprite(std::shared_ptr<Texture>);
|
||||
|
||||
// Destructor
|
||||
~Sprite() = default;
|
||||
@@ -25,29 +25,32 @@ public:
|
||||
// Muestra el sprite por pantalla
|
||||
virtual void render();
|
||||
|
||||
// Reinicia las variables a cero
|
||||
virtual void clear();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosX() const;
|
||||
int getPosY() const;
|
||||
int getX() const;
|
||||
int getY() const;
|
||||
int getWidth() const;
|
||||
int getHeight() const;
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
virtual SDL_Rect getPos() const;
|
||||
|
||||
SDL_Rect getPosition() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(int x);
|
||||
void setPosY(int y);
|
||||
void setX(int x);
|
||||
void setY(int y);
|
||||
void setWidth(int w);
|
||||
void setHeight(int h);
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPos(int x, int y);
|
||||
void setPos(SDL_Point p);
|
||||
virtual void setPos(SDL_Rect r);
|
||||
void setPosition(int x, int y);
|
||||
void setPosition(SDL_Point p);
|
||||
void setPosition(SDL_Rect r);
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incPosX(int value);
|
||||
void incPosY(int value);
|
||||
void incX(int value);
|
||||
void incY(int value);
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect getSpriteClip() const;
|
||||
|
||||
119
source/text.cpp
@@ -1,23 +1,25 @@
|
||||
#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 "resource.h" // for Resource
|
||||
#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)
|
||||
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
||||
{
|
||||
TextFile tf;
|
||||
auto tf = std::make_shared<TextFile>();
|
||||
|
||||
// Inicializa a cero el vector con las coordenadas
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
tf.offset[i].x = 0;
|
||||
tf.offset[i].y = 0;
|
||||
tf.offset[i].w = 0;
|
||||
tf.box_width = 0;
|
||||
tf.box_height = 0;
|
||||
tf->offset[i].x = 0;
|
||||
tf->offset[i].y = 0;
|
||||
tf->offset[i].w = 0;
|
||||
tf->box_width = 0;
|
||||
tf->box_height = 0;
|
||||
}
|
||||
|
||||
// Abre el fichero para leer los valores
|
||||
@@ -31,11 +33,11 @@ TextFile LoadTextFile(std::string file_path)
|
||||
// Lee los dos primeros valores del fichero
|
||||
std::getline(file, buffer);
|
||||
std::getline(file, buffer);
|
||||
tf.box_width = std::stoi(buffer);
|
||||
tf->box_width = std::stoi(buffer);
|
||||
|
||||
std::getline(file, buffer);
|
||||
std::getline(file, buffer);
|
||||
tf.box_height = std::stoi(buffer);
|
||||
tf->box_height = std::stoi(buffer);
|
||||
|
||||
// lee el resto de datos del fichero
|
||||
auto index = 32;
|
||||
@@ -45,7 +47,7 @@ TextFile LoadTextFile(std::string file_path)
|
||||
// Almacena solo las lineas impares
|
||||
if (line_read % 2 == 1)
|
||||
{
|
||||
tf.offset[index++].w = std::stoi(buffer);
|
||||
tf->offset[index++].w = std::stoi(buffer);
|
||||
}
|
||||
|
||||
// Limpia el buffer
|
||||
@@ -53,80 +55,53 @@ TextFile LoadTextFile(std::string file_path)
|
||||
line_read++;
|
||||
};
|
||||
|
||||
// Cierra el fichero
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Text loaded: " << file_name.c_str() << std::endl;
|
||||
#endif
|
||||
// Cierra el fichero
|
||||
printWithDots("Text File : ", file_name, "[ LOADED ]");
|
||||
file.close();
|
||||
}
|
||||
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
||||
#endif
|
||||
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||
}
|
||||
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
for (int i = 32; i < 128; ++i)
|
||||
{
|
||||
tf.offset[i].x = ((i - 32) % 15) * tf.box_width;
|
||||
tf.offset[i].y = ((i - 32) / 15) * tf.box_height;
|
||||
tf->offset[i].x = ((i - 32) % 15) * tf->box_width;
|
||||
tf->offset[i].y = ((i - 32) / 15) * tf->box_height;
|
||||
}
|
||||
|
||||
return tf;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Text::Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer)
|
||||
Text::Text(std::shared_ptr<Texture> texture, const std::string &text_file)
|
||||
{
|
||||
// Carga los offsets desde el fichero
|
||||
auto tf = LoadTextFile(text_file);
|
||||
auto tf = loadTextFile(text_file);
|
||||
|
||||
// Inicializa variables desde la estructura
|
||||
box_height_ = tf.box_height;
|
||||
box_width_ = tf.box_width;
|
||||
box_height_ = tf->box_height;
|
||||
box_width_ = tf->box_width;
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset_[i].x = tf.offset[i].x;
|
||||
offset_[i].y = tf.offset[i].y;
|
||||
offset_[i].w = tf.offset[i].w;
|
||||
offset_[i].x = tf->offset[i].x;
|
||||
offset_[i].y = tf->offset[i].y;
|
||||
offset_[i].w = tf->offset[i].w;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
texture_ = std::make_shared<Texture>(renderer, bitmap_file);
|
||||
sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture_);
|
||||
sprite_ = std::make_unique<Sprite>(texture, (SDL_Rect){0, 0, box_width_, box_height_});
|
||||
|
||||
// Inicializa variables
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Text::Text(std::string text_file, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
// Carga los offsets desde el fichero
|
||||
auto tf = LoadTextFile(text_file);
|
||||
|
||||
// Inicializa variables desde la estructura
|
||||
box_height_ = tf.box_height;
|
||||
box_width_ = tf.box_width;
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset_[i].x = tf.offset[i].x;
|
||||
offset_[i].y = tf.offset[i].y;
|
||||
offset_[i].w = tf.offset[i].w;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture);
|
||||
|
||||
// Inicializa variables
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Text::Text(TextFile *text_file, std::shared_ptr<Texture> texture)
|
||||
Text::Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file)
|
||||
{
|
||||
// Inicializa variables desde la estructura
|
||||
box_height_ = text_file->box_height;
|
||||
@@ -139,14 +114,14 @@ Text::Text(TextFile *text_file, std::shared_ptr<Texture> texture)
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture);
|
||||
sprite_ = std::make_unique<Sprite>(texture, (SDL_Rect){0, 0, box_width_, box_height_});
|
||||
|
||||
// Inicializa variables
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
@@ -155,21 +130,21 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
lenght = text.length();
|
||||
}
|
||||
|
||||
sprite_->setPosY(y);
|
||||
sprite_->setY(y);
|
||||
const auto width = sprite_->getWidth();
|
||||
const auto height = sprite_->getHeight();
|
||||
for (int i = 0; i < lenght; ++i)
|
||||
{
|
||||
const auto index = static_cast<int>(text[i]);
|
||||
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height);
|
||||
sprite_->setPosX(x + shift);
|
||||
sprite_->setX(x + shift);
|
||||
sprite_->render();
|
||||
shift += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning);
|
||||
}
|
||||
}
|
||||
|
||||
// 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 +152,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 +161,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 +210,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;
|
||||
|
||||
@@ -264,16 +239,4 @@ void Text::reLoadTexture()
|
||||
void Text::setFixedWidth(bool value)
|
||||
{
|
||||
fixed_width_ = value;
|
||||
}
|
||||
|
||||
// Carga una paleta de colores para el texto
|
||||
void Text::addPalette(std::string path)
|
||||
{
|
||||
texture_->addPalette(path);
|
||||
}
|
||||
|
||||
// Establece una paleta de colores para el texto
|
||||
void Text::setPalette(int index)
|
||||
{
|
||||
texture_->setPalette(index);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -26,48 +26,46 @@ struct TextFile
|
||||
};
|
||||
|
||||
// Llena una estructuta TextFile desde un fichero
|
||||
TextFile LoadTextFile(std::string file);
|
||||
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path);
|
||||
|
||||
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
||||
class Text
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::unique_ptr<Sprite> sprite_; // Objeto con los graficos para el texto
|
||||
std::shared_ptr<Texture> texture_; // Textura con los bitmaps del texto
|
||||
std::unique_ptr<Sprite> sprite_; // Objeto con los graficos para el 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(TextFile *text_file, std::shared_ptr<Texture> texture);
|
||||
Text(std::shared_ptr<Texture> texture, const std::string &text_file);
|
||||
Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file);
|
||||
|
||||
// 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;
|
||||
@@ -77,10 +75,4 @@ public:
|
||||
|
||||
// Establece si se usa un tamaño fijo de letra
|
||||
void setFixedWidth(bool value);
|
||||
|
||||
// Carga una paleta de colores para el texto
|
||||
void addPalette(std::string path);
|
||||
|
||||
// Establece una paleta de colores para el texto
|
||||
void setPalette(int index);
|
||||
};
|
||||