55 lines
1.5 KiB
C++
55 lines
1.5 KiB
C++
#include "pch.h"
|
|
#include "Building.h"
|
|
|
|
#include <iostream>
|
|
#include <utility>
|
|
|
|
#include "colors.h"
|
|
#include "GameManager.h"
|
|
#include "Player.h"
|
|
#include "utils.h"
|
|
Building::Building(const std::string& filePath, const Vector2f& position, const Rectf& boundingBox, TextureManager* pTextureManager): m_Position(position),
|
|
m_BoundingBox(boundingBox) {
|
|
m_Texture = pTextureManager->GetTexture(filePath);
|
|
m_Size = Vector2f(m_Texture->GetWidth(), m_Texture->GetHeight());
|
|
}
|
|
void Building::Draw() const {
|
|
utils::SetColor(Colors::WHITE);
|
|
m_Texture->Draw(m_Position);
|
|
// utils::SetColor(Colors::GREEN);
|
|
// Rectf temp = m_BoundingBox;
|
|
// temp.left += m_Position.x;
|
|
// temp.bottom += m_Position.y;
|
|
// utils::DrawRect(temp);
|
|
}
|
|
void Building::Update(float dt, const Rectf& objectBoundingBox) {
|
|
if (IsObjectInHitbox(objectBoundingBox)) {
|
|
Player* player = GameManager::GetInstance().GetPlayer();
|
|
float speed = player->GetVelocity().Length();
|
|
if (speed < 100.0f) {
|
|
if (!m_IsPlayerInHitbox) {
|
|
m_IsPlayerInHitbox = true;
|
|
if (m_OnEnterHitbox != nullptr) {
|
|
m_OnEnterHitbox();
|
|
}
|
|
else {
|
|
std::cout << "No function set for onEnterHitbox" << std::endl;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
else {
|
|
m_IsPlayerInHitbox = false;
|
|
}
|
|
}
|
|
void Building::SetOnEnterHitbox(std::function<void()> onEnterHitbox) {
|
|
m_OnEnterHitbox = std::move(onEnterHitbox);
|
|
}
|
|
bool Building::IsObjectInHitbox(const Rectf& objectBoundingBox) const {
|
|
Rectf temp = m_BoundingBox;
|
|
temp.left += m_Position.x;
|
|
temp.bottom += m_Position.y;
|
|
return utils::IsRectInRect(objectBoundingBox, temp);
|
|
}
|