diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 18d5822..57e7c76 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -59,7 +59,7 @@ namespace gui { if($rayview->play_move()) { $needs_render = false; return std::make_optional( - $rayview->camera_target(), + $rayview->camera_at, $rayview->aiming_at); } else { $needs_render = true; diff --git a/raycaster.cpp b/raycaster.cpp index 9f7c13c..76db2de 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -66,6 +66,10 @@ Raycaster::Raycaster(int width, int height) : $view_sprite.setPosition({0, 0}); $pixels = make_unique($width * $height); $view_texture.setSmooth(false); + + $camera.target_x = $pos_x; + $camera.target_y = $pos_y; + update_camera_aiming(); } void Raycaster::set_position(int x, int y) { @@ -83,8 +87,7 @@ void Raycaster::position_camera(float player_x, float player_y) { $plane_x = 0; $plane_y = 0.66; - // BUG: make this a function? - aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) }; + update_camera_aiming(); } void Raycaster::draw_pixel_buffer() { @@ -474,8 +477,7 @@ bool Raycaster::play_rotate() { $dir_y = std::lerp($dir_y, $camera.target_dir_y, $camera.t); $plane_x = std::lerp($plane_x, $camera.target_plane_x, $camera.t); $plane_y = std::lerp($plane_y, $camera.target_plane_y, $camera.t); - - aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) }; + update_camera_aiming(); return $camera.t >= 1.0; } @@ -484,8 +486,7 @@ bool Raycaster::play_move() { $camera.t += $camera.move_speed; $pos_x = std::lerp($pos_x, $camera.target_x, $camera.t); $pos_y = std::lerp($pos_y, $camera.target_y, $camera.t); - - aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) }; + update_camera_aiming(); return $camera.t >= 1.0; } @@ -493,7 +494,7 @@ bool Raycaster::play_move() { void Raycaster::abort_plan() { $camera.target_x = $pos_x; $camera.target_y = $pos_y; - aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) }; + update_camera_aiming(); } bool Raycaster::is_target(DinkyECS::Entity entity) { @@ -501,8 +502,7 @@ bool Raycaster::is_target(DinkyECS::Entity entity) { return false; } -Point Raycaster::camera_target() { - return { - size_t($camera.target_x), - size_t($camera.target_y)}; +void Raycaster::update_camera_aiming() { + aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) }; + camera_at = { size_t($camera.target_x), size_t($camera.target_y) }; } diff --git a/raycaster.hpp b/raycaster.hpp index b9e7bff..1ab5a62 100644 --- a/raycaster.hpp +++ b/raycaster.hpp @@ -27,6 +27,7 @@ struct Raycaster { sf::Texture $view_texture; sf::Sprite $view_sprite; Point aiming_at{0,0}; + Point camera_at{0,0}; CameraLOL $camera; std::unique_ptr $pixels = nullptr; @@ -74,5 +75,5 @@ struct Raycaster { void abort_plan(); bool is_target(DinkyECS::Entity entity); - Point camera_target(); + void update_camera_aiming(); }; diff --git a/systems.cpp b/systems.cpp index 9f2cdbe..ac8d7b1 100644 --- a/systems.cpp +++ b/systems.cpp @@ -270,7 +270,6 @@ void System::combat(int attack_id) { battle.set_all("enemy_found", true); battle.set_all("in_combat", true); battle.plan(); - battle.dump(); } while(auto act = battle.next()) {