Have a way to detect the best rotation but it's still off a bit. Seems to choose wrong in simple situations. Look in System::shortest_rotate.

This commit is contained in:
Zed A. Shaw 2025-09-01 01:37:03 -04:00
parent f98cc543f6
commit d822cb3438
6 changed files with 32 additions and 48 deletions

View file

@ -17,6 +17,7 @@
#include "shaders.hpp"
#include "inventory.hpp"
#include "game_level.hpp"
#include "gui/fsm_events.hpp"
using std::string;
using namespace fmt;
@ -648,3 +649,14 @@ bool System::use_item(const string& slot_name) {
return false;
}
}
gui::Event System::shortest_rotate(Point player_at, Point aiming_at, Point turn_to) {
dbc::check(aiming_at != turn_to, "you're already pointing there.");
dbc::check(player_at != turn_to, "you can't turn on yourself");
Point facing{player_at.x - aiming_at.x, player_at.y - aiming_at.y};
Point target{player_at.x - turn_to.x, player_at.y - turn_to.y};
Point mag{size_t(abs(int(facing.x - target.x))), size_t(abs(int(facing.y - target.y)))};
return mag.x <= mag.y ? gui::Event::ROTATE_LEFT : gui::Event::ROTATE_RIGHT;
}