El game_text ara gasta PathSprites en lloc d'SmartSprites
fix: la paleta dels jugadors no s'iniciava correctament
This commit is contained in:
@@ -651,25 +651,29 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
||||
case ItemType::DISK:
|
||||
{
|
||||
player->addScore(1000);
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[0]->getWidth() / 2), player->getPosY(), game_text_textures_[0]);
|
||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[0]->getWidth()) / 2;
|
||||
createPathSprite(x, game_text_textures_[0]);
|
||||
break;
|
||||
}
|
||||
case ItemType::GAVINA:
|
||||
{
|
||||
player->addScore(2500);
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[1]->getWidth() / 2), player->getPosY(), game_text_textures_[1]);
|
||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[1]->getWidth()) / 2;
|
||||
createPathSprite(x, game_text_textures_[1]);
|
||||
break;
|
||||
}
|
||||
case ItemType::PACMAR:
|
||||
{
|
||||
player->addScore(5000);
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[2]->getWidth() / 2), player->getPosY(), game_text_textures_[2]);
|
||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[2]->getWidth()) / 2;
|
||||
createPathSprite(x, game_text_textures_[2]);
|
||||
break;
|
||||
}
|
||||
case ItemType::CLOCK:
|
||||
{
|
||||
enableTimeStopItem();
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[5]->getWidth() / 2), player->getPosY(), game_text_textures_[5]);
|
||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[5]->getWidth()) / 2;
|
||||
createPathSprite(x, game_text_textures_[5]);
|
||||
break;
|
||||
}
|
||||
case ItemType::COFFEE:
|
||||
@@ -677,12 +681,14 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
||||
if (player->getCoffees() == 2)
|
||||
{
|
||||
player->addScore(5000);
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[2]->getWidth() / 2), player->getPosY(), game_text_textures_[2]);
|
||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[2]->getWidth()) / 2;
|
||||
createPathSprite(x, game_text_textures_[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
player->giveExtraHit();
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[4]->getWidth() / 2), player->getPosY(), game_text_textures_[4]);
|
||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[4]->getWidth()) / 2;
|
||||
createPathSprite(x, game_text_textures_[4]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -690,7 +696,8 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
||||
{
|
||||
player->setPowerUp();
|
||||
coffee_machine_enabled_ = false;
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (game_text_textures_[3]->getWidth() / 2), player->getPosY(), game_text_textures_[3]);
|
||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_[3]->getWidth()) / 2;
|
||||
createPathSprite(x, game_text_textures_[3]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -889,42 +896,27 @@ void Game::freeItems()
|
||||
items_.erase(items_.begin() + i);
|
||||
}
|
||||
|
||||
// Crea un objeto SpriteSmart para mostrar la puntuación al coger un objeto
|
||||
void Game::createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
smart_sprites_.emplace_back(std::make_unique<SmartSprite>(texture));
|
||||
|
||||
const auto w = texture->getWidth();
|
||||
const auto h = texture->getHeight();
|
||||
|
||||
// Ajusta para que no se dibuje fuera de pantalla
|
||||
x = std::clamp(x, 0, param.game.play_area.rect.w - w);
|
||||
|
||||
// Inicializa
|
||||
smart_sprites_.back()->setPos({0, 0, w, h});
|
||||
smart_sprites_.back()->setSpriteClip({0, 0, w, h});
|
||||
smart_sprites_.back()->setPosX(x);
|
||||
smart_sprites_.back()->setPosY(param.game.play_area.rect.h - h);
|
||||
smart_sprites_.back()->setDestX(x);
|
||||
smart_sprites_.back()->setDestY(y - 35);
|
||||
smart_sprites_.back()->setVelY(-0.5f);
|
||||
smart_sprites_.back()->setAccelY(-0.1f);
|
||||
smart_sprites_.back()->setEnabled(true);
|
||||
smart_sprites_.back()->setFinishedCounter(100);
|
||||
}
|
||||
|
||||
// Crea un objeto PathSprite
|
||||
void Game::createPathSprite(std::shared_ptr<Texture> texture)
|
||||
void Game::createPathSprite(int x, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
path_sprites_.emplace_back(std::make_unique<PathSprite>(texture));
|
||||
|
||||
const auto w = texture->getWidth();
|
||||
const auto h = texture->getHeight();
|
||||
|
||||
const int y0 = param.game.play_area.rect.h - h;
|
||||
const int y1 = 160;
|
||||
const int y2 = -h;
|
||||
|
||||
// Ajusta para que no se dibuje fuera de pantalla
|
||||
x = std::clamp(x, 2, param.game.play_area.rect.w - w - 2);
|
||||
|
||||
// Inicializa
|
||||
path_sprites_.back()->setWidth(w);
|
||||
path_sprites_.back()->setHeight(h);
|
||||
path_sprites_.back()->setSpriteClip({0, 0, w, h});
|
||||
path_sprites_.back()->addPath(y0, y1, PathType::VERTICAL, x, 100, easeOutQuint, 0);
|
||||
path_sprites_.back()->addPath(y1, y2, PathType::VERTICAL, x, 80, easeInQuint, 0);
|
||||
path_sprites_.back()->enable();
|
||||
}
|
||||
|
||||
@@ -1572,10 +1564,8 @@ void Game::checkEvents()
|
||||
}
|
||||
case SDLK_5: // Crea un PathSprite
|
||||
{
|
||||
const auto x = players_.at(0)->getPosX();
|
||||
createPathSprite(game_text_textures_.at(3));
|
||||
path_sprites_.back()->addPath(220, 160, PathType::VERTICAL, x, 100, easeOutQuint, 0);
|
||||
path_sprites_.back()->addPath(160, -21, PathType::VERTICAL, x, 80, easeInQuint, 0);
|
||||
const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2;
|
||||
createPathSprite(x, game_text_textures_.at(3));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user