Player's aim is now updated constantly as they move, just need to solve #57 to complete it. Closes #9.

This commit is contained in:
Zed A. Shaw 2025-07-05 11:18:26 -04:00
parent 584c4e9f67
commit a26f0b0c0a
7 changed files with 48 additions and 27 deletions

View file

@ -101,14 +101,18 @@ namespace gui {
}
}
void FSM::ROTATING(Event ) {
if($main_ui.play_rotate()) {
void FSM::ROTATING(Event) {
if(auto aim = $main_ui.play_rotate()) {
auto& player_pos = System::player_position($level);
player_pos.aiming_at = *aim;
state(State::IDLE);
}
}
void FSM::COMBAT_ROTATE(Event ) {
if($main_ui.play_rotate()) {
void FSM::COMBAT_ROTATE(Event) {
if(auto aim = $main_ui.play_rotate()) {
auto& player_pos = System::player_position($level);
player_pos.aiming_at = *aim;
state(State::IN_COMBAT);
}
}
@ -132,6 +136,12 @@ namespace gui {
void FSM::IDLE(Event ev, std::any data) {
using enum Event;
auto& player_pos = System::player_position($level);
fmt::println("AIMING AT: {},{}; POS: {},{}",
player_pos.aiming_at.x, player_pos.aiming_at.y,
player_pos.location.x, player_pos.location.y);
sound::stop("walk");
switch(ev) {

View file

@ -45,27 +45,26 @@ namespace gui {
$overlay_ui.render($window);
}
void MainUI::health_low() {
$overlay_ui.show_sprite("middle", "blood_splatter");
}
lel::Cell MainUI::overlay_cell(const std::string& name) {
return $overlay_ui.$gui.cell_for(name);
}
bool MainUI::play_rotate() {
bool done = $rayview.play_rotate();
$needs_render = !done;
return done;
std::optional<Point> MainUI::play_rotate() {
if($rayview.play_rotate()) {
$needs_render = false;
return std::make_optional<Point>($rayview.aiming_at);
} else {
$needs_render = true;
return std::nullopt;
}
}
std::optional<Point> MainUI::play_move() {
std::optional<components::Position> MainUI::play_move() {
if($rayview.play_move()) {
$needs_render = false;
return std::make_optional<Point>(
$rayview.camera_target());
return std::make_optional<Position>(
$rayview.camera_target(),
$rayview.aiming_at);
} else {
$needs_render = true;
return std::nullopt;
@ -104,6 +103,9 @@ namespace gui {
$rayview.update_level($level);
$rayview.position_camera(player.x + 0.5, player.y + 0.5);
// BUG #57: I think this is in the wrong direction?
player_position.aiming_at = $rayview.aiming_at;
$compass_dir = 0;
$overlay_ui.update_level(level);

View file

@ -28,8 +28,8 @@ namespace gui {
void render_debug();
void plan_rotate(int dir, float amount);
bool play_rotate();
std::optional<Point> play_move();
std::optional<Point> play_rotate();
std::optional<components::Position> play_move();
Point plan_move(int dir, bool strafe);
void abort_plan();
void update_level(GameLevel level);
@ -40,7 +40,6 @@ namespace gui {
void dirty();
lel::Cell overlay_cell(const std::string& name);
void health_low();
void dead_entity(DinkyECS::Entity entity);
};
}