Skip to content

Commit

Permalink
Merge pull request #66 from jonylu7/fix-inf
Browse files Browse the repository at this point in the history
Fix inf
  • Loading branch information
jonylu7 authored May 10, 2024
2 parents 95cdf7d + 621ebe0 commit c058b6e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions include/Map/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MapClass : public Core::Drawable {
void InitGrid();

private:
const glm::vec2 m_MapTransShift = {10, -10};
std::vector<std::shared_ptr<Util::ImageArray>> m_Images;
std::unordered_map<std::string, std::vector<glm::vec2>> m_Tiles;
unsigned int m_MapWdith = 0;
Expand Down
11 changes: 6 additions & 5 deletions include/Map/Tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,20 @@ class TileClass {
}

void removeAvatar(std::shared_ptr<Avatar> avatar) {
for (auto i : m_Avatars) {
if (i == avatar) {
std::remove(m_Avatars.begin(), m_Avatars.end(), i);
for (int i = 0; i < m_Avatars.size(); i++) {
if (m_Avatars[i] == avatar) {
auto it = m_Avatars.begin() + i;
m_Avatars.erase(it);
i--;

if (m_Avatars.size() < 4) {
setWalkable(true);
}
if (m_Avatars.size() == 0) {
setBuildable(true);
}
return;
}
}
LOG_DEBUG("Remove Avatar Failed");
}

void removeStructure() {
Expand Down
3 changes: 2 additions & 1 deletion src/Avatar/Avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ void Avatar::spawnedUpdate() {
void Avatar::moveUpdate() {

if (ifArrivedAtNextCell()) {
if (m_MovePath.size() >= 1) {
m_PrevCell = getCurrentCell();
if (!m_MovePath.empty()) {
m_CurrentDir = m_MovePath.front();
m_MovePath.pop_front();
} else {
Expand Down
15 changes: 8 additions & 7 deletions src/Map/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@ std::shared_ptr<TileClass> MapClass::getTileByCellPosition(glm::vec2 position) {

if (position.x > m_MapWdith - 1 || position.y > m_MapHeight - 1 ||
position.x < 0 || position.y < 0) {
LOG_DEBUG("False Position Getting");
return std::make_shared<TileClass>(UnitType::null, 0, 0, 0, "");
std::cerr << "False Position Getting" << position.x << position.y
<< std::endl;
return nullptr;
}
return m_Map[position.x][position.y];
}

void MapClass::Draw(const Util::Transform &trans, const float zindex) {
auto maptrans = trans;
maptrans.translation.x += m_MapTransShift.x;
maptrans.translation.y += m_MapTransShift.y;

Util::Transform mapTrans;

mapTrans.translation = m_MapPosition;
for (auto i : m_Images) {
i->DrawUsingCamera(mapTrans, 1);
i->DrawUsingCamera(maptrans, zindex);
}
m_Grid.DrawUsingCamera(mapTrans, zindex);
m_Grid.DrawUsingCamera(trans, zindex - 0.2);
}

void MapClass::Init(std::vector<std::vector<std::shared_ptr<TileClass>>> map,
Expand Down
2 changes: 1 addition & 1 deletion src/Mechanics/AvatarNavigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ bool AvatarNavigator::canResumeWalkingStraight(glm::vec2 currentcell,
glm::vec2 destinationcell) {
std::vector<MoveDirection> path;
auto arrived = findStraightPath(currentcell, destinationcell, &path);
if (arrived || !path.empty()) {
if (arrived) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Scene/MapScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ void MapScene::Update() {
Util::Transform trans;
trans.scale = {1, 1};
trans.translation = {0, 0};
m_Map->Draw(trans, 0);
m_Map->Draw(trans, -0.1);
}

0 comments on commit c058b6e

Please sign in to comment.