mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-17 01:11:47 +01:00
Remove Point2f, replace with Vector2f
This commit is contained in:
@@ -18,8 +18,8 @@ WorldGridManager::~WorldGridManager() {
|
||||
}
|
||||
surroundingTiles WorldGridManager::GetSurroundingTiles(const WorldTile* world_tile) {
|
||||
surroundingTiles tiles;
|
||||
Point2f pos = world_tile->GetPosition();
|
||||
Point2f gridCoords = this->GetIndexFromPosition(pos);
|
||||
Vector2f pos = world_tile->GetPosition();
|
||||
Vector2f gridCoords = this->GetIndexFromPosition(pos);
|
||||
int x = gridCoords.x;
|
||||
//TODO: Stupid fix, fix this
|
||||
int y = gridCoords.y - 1;
|
||||
@@ -38,10 +38,10 @@ surroundingTiles WorldGridManager::GetSurroundingTiles(const WorldTile* world_ti
|
||||
return tiles;
|
||||
|
||||
}
|
||||
Point2f WorldGridManager::GetIndexFromPosition(Point2f position) {
|
||||
Vector2f WorldGridManager::GetIndexFromPosition(Vector2f position) {
|
||||
int x = int(position.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
||||
int y = int(-position.y / TILE_HEIGHT);
|
||||
return Point2f{ float(x), float(y) };
|
||||
return Vector2f{ float(x), float(y) };
|
||||
}
|
||||
WorldTile * WorldGridManager::GetTileAtIndex(const int x, const int y) const {
|
||||
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
||||
@@ -50,7 +50,7 @@ WorldTile * WorldGridManager::GetTileAtIndex(const int x, const int y) const {
|
||||
}
|
||||
return m_worldTiles[x][y];
|
||||
}
|
||||
WorldTile * WorldGridManager::GetTileAtWorldPos(const Point2f& pos) const {
|
||||
WorldTile * WorldGridManager::GetTileAtWorldPos(const Vector2f& pos) const {
|
||||
int x = int(pos.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
||||
int y = int(-pos.y / TILE_HEIGHT);
|
||||
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
||||
|
||||
@@ -48,12 +48,12 @@ public:
|
||||
WorldGridManager();
|
||||
~WorldGridManager();
|
||||
surroundingTiles GetSurroundingTiles(const WorldTile* world_tile);
|
||||
Point2f GetIndexFromPosition(Point2f position);
|
||||
Vector2f GetIndexFromPosition(Vector2f position);
|
||||
|
||||
WorldGridManager(const WorldGridManager& other) = default;
|
||||
|
||||
WorldTile * GetTileAtIndex(const int x, const int y) const;
|
||||
WorldTile * GetTileAtWorldPos(const Point2f& pos) const;
|
||||
WorldTile * GetTileAtWorldPos(const Vector2f& pos) const;
|
||||
|
||||
void SetTileAtIndex(const int x, const int y, WorldTile* tile);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "WorldGridManager.h"
|
||||
|
||||
|
||||
WorldTile::WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager) : m_Position { position }, m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } {
|
||||
WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager) : m_Position { position }, m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } {
|
||||
// const std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png";
|
||||
// m_pTexture = new Texture(dirtPath);
|
||||
m_pTexture = pTextureManager->GetTexture(groundTileType->getPath());
|
||||
@@ -140,12 +140,12 @@ void WorldTile::Draw() {
|
||||
// GroundTileTypes type = tile->GetTileType()->getType();
|
||||
// if(type == Tiles::AIR->getType()) {
|
||||
// utils::SetColor(Colors::BLACK);
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Point2f{50,50}});
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Vector2f{50,50}});
|
||||
// continue;
|
||||
// }
|
||||
// if(type != Tiles::AIR->getType()) {
|
||||
// utils::SetColor(Colors::YELLOW);
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Point2f{50,50}});
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Vector2f{50,50}});
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -176,7 +176,7 @@ void WorldTile::Draw() {
|
||||
// if(topLeftType != Tiles::AIR) {
|
||||
// m_pTopLeftTexture->Draw(m_Position);
|
||||
// utils::SetColor(Colors::YELLOW);
|
||||
// utils::FillRect(Rectf{topLeft->GetPosition(), Point2f{50,50}});
|
||||
// utils::FillRect(Rectf{topLeft->GetPosition(), Vector2f{50,50}});
|
||||
// }
|
||||
//
|
||||
// WorldTile* topRight = m_SurroundingTiles.GetTile(TileDirection::TopRight);
|
||||
@@ -187,9 +187,9 @@ void WorldTile::Draw() {
|
||||
//
|
||||
}
|
||||
void WorldTile::Update(Camera* camera) {
|
||||
Point2f CurrentIndex = m_pGridManager->GetIndexFromPosition(m_Position);
|
||||
Vector2f CurrentIndex = m_pGridManager->GetIndexFromPosition(m_Position);
|
||||
m_SurroundingTiles = m_pGridManager->GetSurroundingTiles(this);
|
||||
Point2f mousePos = camera->TransformMouse(Point2f{utils::GetMousePos().x, 500 - utils::GetMousePos().y});
|
||||
Vector2f mousePos = camera->TransformMouse(Vector2f{utils::GetMousePos().x, 500 - utils::GetMousePos().y});
|
||||
m_Hightlight = utils::IsPointInRect(mousePos, Rectf{GetCollisionRect().pos, GetCollisionRect().size});
|
||||
if(CurrentIndex.x == 1 && CurrentIndex.y == 1) {
|
||||
// std::cout << "Hey" << std::endl;
|
||||
|
||||
@@ -95,21 +95,21 @@ class WorldTile
|
||||
{
|
||||
public:
|
||||
WorldTile() = default;
|
||||
WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager);
|
||||
WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager);
|
||||
~WorldTile();
|
||||
|
||||
void Draw();
|
||||
void Update(Camera* camera); //TODO: no use
|
||||
|
||||
Point2f GetPosition() const {
|
||||
Vector2f GetPosition() const {
|
||||
return m_Position;
|
||||
}
|
||||
void SetPosition(const Point2f& position) {
|
||||
void SetPosition(const Vector2f& position) {
|
||||
m_Position = position;
|
||||
}
|
||||
|
||||
Point2f GetSize() const {
|
||||
return Point2f { 50, 50 };
|
||||
Vector2f GetSize() const {
|
||||
return Vector2f { 50, 50 };
|
||||
}
|
||||
|
||||
GroundTileType * GetTileType() const {
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
bool m_Hightlight { false };
|
||||
|
||||
private:
|
||||
Point2f m_Position;
|
||||
Vector2f m_Position;
|
||||
GroundTileType* m_GroundTileType;
|
||||
|
||||
Texture* m_pTexture;
|
||||
|
||||
Reference in New Issue
Block a user