Skip to content

Commit

Permalink
select cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Apr 19, 2024
1 parent 1de873b commit 93b42a9
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions include/Mechanics/GameObjectManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,27 @@ class GameObjectManager {

// get cursor position
*end = Util::Input::GetCursorPosition();
}

// select objects
auto startcell = MapUtil::GlobalCoordToCellCoord(
MapUtil::ScreenToGlobalCoord(*start));
auto endcell =
MapUtil::GlobalCoordToCellCoord(MapUtil::ScreenToGlobalCoord(*end));

int max_x_cell = std::max(startcell.x, endcell.x);
int max_y_cell = std::max(startcell.y, endcell.y);
int min_x_cell = std::min(startcell.x, endcell.x);
int min_y_cell = std::min(startcell.y, endcell.y);

for (int i = min_y_cell; i <= max_y_cell; i++) {
for (int j = min_x_cell; j <= max_x_cell; j++) {
auto objects = m_Map->getTileByCellPosition(glm::vec2(i, j))
->getSelectableObjects();
for (auto i : objects) {
if (i->getSelected() == false) {
i->setSelected(true);
lastSeletctedObjects.push_back(i);

// select objects
auto startcell = MapUtil::GlobalCoordToCellCoord(
MapUtil::ScreenToGlobalCoord(*start));
auto endcell = MapUtil::GlobalCoordToCellCoord(
MapUtil::ScreenToGlobalCoord(*end));

int max_x_cell = std::max(startcell.x, endcell.x);
int max_y_cell = std::max(startcell.y, endcell.y);
int min_x_cell = std::min(startcell.x, endcell.x);
int min_y_cell = std::min(startcell.y, endcell.y);

for (int i = min_y_cell; i <= max_y_cell; i++) {
for (int j = min_x_cell; j <= max_x_cell; j++) {
auto objects = m_Map->getTileByCellPosition(glm::vec2(j, i))
->getSelectableObjects();
for (auto i : objects) {
if (i->getSelected() == false) {
i->setSelected(true);
lastSeletctedObjects.push_back(i);
}
}
}
}
Expand Down

0 comments on commit 93b42a9

Please sign in to comment.