From 8bbafc4d100325c58bb7c6d69358cee4536ebe0d Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 30 Jun 2025 12:36:00 -0400 Subject: [PATCH] Raycaster now keeps track of the square we are aimed but _does not_ know what is there, that's the job of other things like MainUI. Closes #50. --- constants.hpp | 1 + gui/main_ui.cpp | 6 ++---- raycaster.cpp | 16 ++++++++++------ raycaster.hpp | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/constants.hpp b/constants.hpp index d78c94e..aff596c 100644 --- a/constants.hpp +++ b/constants.hpp @@ -14,6 +14,7 @@ constexpr const int RAY_VIEW_X=(SCREEN_WIDTH - RAY_VIEW_WIDTH); constexpr const int RAY_VIEW_Y=0; constexpr const int GLOW_LIMIT=220; constexpr const int LIGHT_MULTIPLIER=2.5; +constexpr const float AIMED_AT_BRIGHTNESS=0.2f; constexpr const int BOSS_VIEW_WIDTH=1080; constexpr const int BOSS_VIEW_HEIGHT=SCREEN_HEIGHT; diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 96c5800..36a80a5 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -31,10 +31,8 @@ namespace gui { } DinkyECS::Entity MainUI::camera_aim() { - auto aimed_at = $rayview.aimed_at(); - - if($level.collision->occupied(aimed_at)) { - return $level.collision->get(aimed_at); + if($level.collision->occupied($rayview.aiming_at)) { + return $level.collision->get($rayview.aiming_at); } else { return 0; } diff --git a/raycaster.cpp b/raycaster.cpp index 860b2a4..a3a7884 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -204,7 +204,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { apply_sprite_effect(effect, sprite_width, sprite_height); } else { effect = $brightness; - level += (aiming_at == rec.second) * 0.1; + level += (aiming_at == sprite_pos.location) * AIMED_AT_BRIGHTNESS; effect->setUniform("darkness", level); } @@ -475,6 +475,8 @@ bool Raycaster::play_rotate() { $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) }; + return $camera.t >= 1.0; } @@ -482,19 +484,21 @@ 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) }; + return $camera.t >= 1.0; } 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) }; } -Point Raycaster::aimed_at() { - return { - size_t($pos_x + $dir_x), - size_t($pos_y + $dir_y) - }; +bool Raycaster::is_target(DinkyECS::Entity entity) { + (void)entity; + return false; } Point Raycaster::camera_target() { diff --git a/raycaster.hpp b/raycaster.hpp index b7d132a..9c82023 100644 --- a/raycaster.hpp +++ b/raycaster.hpp @@ -26,7 +26,7 @@ struct Raycaster { double $plane_y = 0.66; sf::Texture $view_texture; sf::Sprite $view_sprite; - DinkyECS::Entity aiming_at = 0; + Point aiming_at{0,0}; CameraLOL $camera; std::unique_ptr $pixels = nullptr; @@ -72,6 +72,6 @@ struct Raycaster { bool play_move(); void abort_plan(); - Point aimed_at(); + bool is_target(DinkyECS::Entity entity); Point camera_target(); };