Skip to content

Commit

Permalink
cast: face direction the cast was in
Browse files Browse the repository at this point in the history
  • Loading branch information
city41 committed Nov 30, 2018
1 parent f7c562b commit 0ef7832
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ void Player::updateScanning(uint8_t frame) {
castCount = 0;

State::gameState.baitCounts[static_cast<int8_t>(currentBait)] -= 1;
dir = determineDirection(x, y, cursorX, cursorY, dir);

currentUpdate = &Player::updateCast;
currentRender = &Player::renderCast;
Expand Down Expand Up @@ -845,20 +846,26 @@ void Player::onGetWorm(Worm& worm) {
}

Direction Player::determineDirection(int16_t px, int16_t py, int16_t x, int16_t y, Direction prevDir) {

if (px == x && py == y) {
return prevDir;
}

if (px == x) {
if (py > y) {
return UP;
int16_t diffX = x - px;
int16_t diffY = y - py;

if (abs(diffX) > abs(diffY)) {
if (diffX < 0) {
return LEFT;
} else {
return RIGHT;
}
return DOWN;
} else {
if (px > x) {
return LEFT;
if (diffY < 0) {
return UP;
} else {
return DOWN;
}
return RIGHT;
}
}

Expand Down

0 comments on commit 0ef7832

Please sign in to comment.