Completada la classe PathSprite

This commit is contained in:
2024-10-27 22:28:44 +01:00
parent d054e188b6
commit 1dd96cfaff
6 changed files with 257 additions and 16 deletions

View File

@@ -27,6 +27,7 @@
#include "manage_hiscore_table.h" // para ManageHiScoreTable
#include "notifier.h" // para Notifier
#include "param.h" // para param
#include "path_sprite.h" // para PathSprite
#include "player.h" // para Player, PlayerStatus
#include "resource.h" // para Resource
#include "scoreboard.h" // para Scoreboard, ScoreboardMode, SCOREB...
@@ -917,8 +918,24 @@ void Game::createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture)
smart_sprites_.back()->setFinishedCounter(100);
}
// Crea un objeto PathSprite
void Game::createPathSprite(SDL_Point start, SDL_Point end, std::shared_ptr<Texture> texture)
{
path_sprites_.emplace_back(std::make_unique<PathSprite>(texture));
const auto w = texture->getWidth();
const auto h = texture->getHeight();
// Inicializa
path_sprites_.back()->setWidth(w);
path_sprites_.back()->setHeight(h);
path_sprites_.back()->setSpriteClip({0, 0, w, h});
path_sprites_.back()->addVerticalPath(start, end, 50, 10);
path_sprites_.back()->enable();
}
// Vacia el vector de smartsprites
void Game::freeSpriteSmarts()
void Game::freeSmartSprites()
{
if (!smart_sprites_.empty())
for (int i = smart_sprites_.size() - 1; i >= 0; --i)
@@ -926,6 +943,15 @@ void Game::freeSpriteSmarts()
smart_sprites_.erase(smart_sprites_.begin() + i);
}
// Vacia el vector de pathsprites
void Game::freePathSprites()
{
if (!path_sprites_.empty())
for (int i = path_sprites_.size() - 1; i >= 0; --i)
if (path_sprites_[i]->hasFinished())
path_sprites_.erase(path_sprites_.begin() + i);
}
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
void Game::throwCoffee(int x, int y)
{
@@ -949,18 +975,32 @@ void Game::throwCoffee(int x, int y)
smart_sprites_.back()->setRotateAmount(90.0);
}
// Actualiza los SpriteSmarts
void Game::updateSpriteSmarts()
// Actualiza los SmartSprites
void Game::updateSmartSprites()
{
for (auto &ss : smart_sprites_)
ss->update();
for (auto &sprite : smart_sprites_)
sprite->update();
}
// Pinta los SpriteSmarts activos
void Game::renderSpriteSmarts()
// Pinta los SmartSprites activos
void Game::renderSmartSprites()
{
for (auto &ss : smart_sprites_)
ss->render();
for (auto &sprite : smart_sprites_)
sprite->render();
}
// Actualiza los PathSprites
void Game::updatePathSprites()
{
for (auto &sprite : path_sprites_)
sprite->update();
}
// Pinta los PathSprites activos
void Game::renderPathSprites()
{
for (auto &sprite : path_sprites_)
sprite->render();
}
// Acciones a realizar cuando el jugador muere
@@ -1122,7 +1162,10 @@ void Game::update()
updateGameOver();
// Actualiza los SpriteSmarts
updateSpriteSmarts();
updateSmartSprites();
// Actualiza los PathSmarts
updatePathSprites();
// Actualiza los contadores de estado y efectos
updateTimeStopped();
@@ -1150,7 +1193,8 @@ void Game::update()
freeBullets();
freeBalloons();
freeItems();
freeSpriteSmarts();
freeSmartSprites();
freePathSprites();
}
// Comprueba si la música ha de estar sonando
@@ -1197,7 +1241,8 @@ void Game::fillCanvas()
// Dibuja los objetos
background_->render();
renderItems();
renderSpriteSmarts();
renderSmartSprites();
renderPathSprites();
explosions_->render();
renderBalloons();
renderBullets();
@@ -1506,7 +1551,7 @@ void Game::checkEvents()
}
#ifdef DEBUG
else if (event.type == SDL_KEYDOWN)
else if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
{
switch (event.key.keysym.sym)
{
@@ -1531,6 +1576,15 @@ void Game::checkEvents()
createItem(ItemType::CLOCK, players_.at(0)->getPosX(), players_.at(0)->getPosY() - 40);
break;
}
case SDLK_5: // Crea un PathSprite
{
const auto x = players_.at(0)->getPosX();
const SDL_Point start = {x, 200};
const SDL_Point end = {x, 170};
createPathSprite(start, end, game_text_textures_.at(3));
path_sprites_.back()->addVerticalPath({x,170}, {x,0}, 100, 1);
break;
}
default:
break;
}