Skip to content

Commit

Permalink
before update and inf finished move fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed May 10, 2024
1 parent 8bec7ff commit 4f7495c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/Avatar/Avatar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Avatar : public Moving,
virtual void Start(glm::vec2 spawnlocationcell);
void noOrderUpdate();
void spawnedUpdate();
void finishedmovingUpdate();
void moveUpdate();
void deadUpdate();
void attackUpdate();
Expand Down
8 changes: 8 additions & 0 deletions src/Avatar/Avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void Avatar::moveUpdate() {
m_CurrentDir = m_MovePath.front();
m_MovePath.pop_front();
} else {
finishedmovingUpdate();
m_CurrentDir = MoveDirection::IDLE;
m_AvatarOrder = AvatarOrderType::NO_ORDER;
}
Expand Down Expand Up @@ -122,3 +123,10 @@ void Avatar::DEBUG_printCurrentMoveDirection(MoveDirection Dir) {
}
}
}

void Avatar::finishedmovingUpdate() {
Moving::moveToCellCorner(AvatarStandingCorner::CENTER);
m_Transform.translation = getCurrentLocation();

Draw();
}
20 changes: 17 additions & 3 deletions src/Avatar/Moving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,31 @@ void Moving::moveToNextCell() {
}

bool Moving::ifArrivedAtNextCell() {
if (m_PrevCell != getCurrentCell()) {
return true;
if (m_CurrentDir == MoveDirection::DOWN_RIGHT ||
m_CurrentDir == MoveDirection::DOWN_LEFT ||
m_CurrentDir == MoveDirection::UP_RIGHT ||
m_CurrentDir == MoveDirection::DOWN_RIGHT) {
if (m_PrevCell.x != getCurrentCell().x &&
m_PrevCell.y != getCurrentCell().y) {
return true;
} else {
return false;
}
} else {
return false;
if (m_PrevCell != getCurrentCell()) {
return true;
} else {
return false;
}
}
}
void Moving::moveToCellCorner(AvatarStandingCorner corner) {
float quaterHeight = CELL_SIZE.y / 4;
float quaterWidth = CELL_SIZE.x / 4;
switch (corner) {
case (AvatarStandingCorner::CENTER):
m_CurrentLocation = MapUtil::CellCoordToGlobal(
MapUtil::GlobalCoordToCellCoord(m_CurrentLocation));
break;
case (AvatarStandingCorner::UPPER_LEFT):
m_CurrentLocation = {m_CurrentLocation.x - quaterWidth,
Expand Down

0 comments on commit 4f7495c

Please sign in to comment.