Files
letnik3koncni-prap/src/game/agame/trash.cpp
2026-05-13 07:58:59 +02:00

40 lines
1.5 KiB
C++

#include <game/agame/trash.hpp>
#include <game/agame/player.hpp>
#include <object/components/boxcollider.hpp>
#include <algorithm>
namespace Game::AGame {
void Trash::start() {
mZIndex = 20;
addComponent<Object::Components::BoxCollider>();
}
void Trash::update(float deltaTime) {
(void)deltaTime;
/*if (mSeaOnly) {
const float landBoundaryX = GameManager::getSharedData<float>("terrainLandBoundaryX");
const float margin = 25.f;
const float halfWidth = getTexture() ? getTexture()->getWidth() * mTransform.adjustedScaleX() / 2.f : 0.f;
if (mTransform.x - halfWidth < landBoundaryX + margin) {
mTransform.x = landBoundaryX + margin + halfWidth;
}
}*/
// Naključno premikanje
mTransform.x += static_cast<float>(Utils::getUtils().rirng32(-50, 50)) * deltaTime;
mTransform.y += static_cast<float>(Utils::getUtils().rirng32(-50, 50)) * deltaTime;
//return;
}
void Trash::onCollisionEnter(Object::Entity* other) {
auto* player = dynamic_cast<Player*>(other);
if (!player || !player->isShipMode()) {
return;
}
GameManager::setSharedData("trashActiveCount", std::max(0, GameManager::getSharedData<int>("trashActiveCount") - 1));
GameManager::setSharedData("gameScore", GameManager::getSharedData<int>("gameScore") + 25);
GameManager::destroyEntity(this);
}
}