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.

master
Zed A. Shaw 22 hours ago
parent 0d79ce35b3
commit 8bbafc4d10
  1. 1
      constants.hpp
  2. 6
      gui/main_ui.cpp
  3. 16
      raycaster.cpp
  4. 4
      raycaster.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 RAY_VIEW_Y=0;
constexpr const int GLOW_LIMIT=220; constexpr const int GLOW_LIMIT=220;
constexpr const int LIGHT_MULTIPLIER=2.5; 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_WIDTH=1080;
constexpr const int BOSS_VIEW_HEIGHT=SCREEN_HEIGHT; constexpr const int BOSS_VIEW_HEIGHT=SCREEN_HEIGHT;

@ -31,10 +31,8 @@ namespace gui {
} }
DinkyECS::Entity MainUI::camera_aim() { DinkyECS::Entity MainUI::camera_aim() {
auto aimed_at = $rayview.aimed_at(); if($level.collision->occupied($rayview.aiming_at)) {
return $level.collision->get($rayview.aiming_at);
if($level.collision->occupied(aimed_at)) {
return $level.collision->get(aimed_at);
} else { } else {
return 0; return 0;
} }

@ -204,7 +204,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
apply_sprite_effect(effect, sprite_width, sprite_height); apply_sprite_effect(effect, sprite_width, sprite_height);
} else { } else {
effect = $brightness; effect = $brightness;
level += (aiming_at == rec.second) * 0.1; level += (aiming_at == sprite_pos.location) * AIMED_AT_BRIGHTNESS;
effect->setUniform("darkness", level); 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_x = std::lerp($plane_x, $camera.target_plane_x, $camera.t);
$plane_y = std::lerp($plane_y, $camera.target_plane_y, $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; return $camera.t >= 1.0;
} }
@ -482,19 +484,21 @@ bool Raycaster::play_move() {
$camera.t += $camera.move_speed; $camera.t += $camera.move_speed;
$pos_x = std::lerp($pos_x, $camera.target_x, $camera.t); $pos_x = std::lerp($pos_x, $camera.target_x, $camera.t);
$pos_y = std::lerp($pos_y, $camera.target_y, $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; return $camera.t >= 1.0;
} }
void Raycaster::abort_plan() { void Raycaster::abort_plan() {
$camera.target_x = $pos_x; $camera.target_x = $pos_x;
$camera.target_y = $pos_y; $camera.target_y = $pos_y;
aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) };
} }
Point Raycaster::aimed_at() { bool Raycaster::is_target(DinkyECS::Entity entity) {
return { (void)entity;
size_t($pos_x + $dir_x), return false;
size_t($pos_y + $dir_y)
};
} }
Point Raycaster::camera_target() { Point Raycaster::camera_target() {

@ -26,7 +26,7 @@ struct Raycaster {
double $plane_y = 0.66; double $plane_y = 0.66;
sf::Texture $view_texture; sf::Texture $view_texture;
sf::Sprite $view_sprite; sf::Sprite $view_sprite;
DinkyECS::Entity aiming_at = 0; Point aiming_at{0,0};
CameraLOL $camera; CameraLOL $camera;
std::unique_ptr<RGBA[]> $pixels = nullptr; std::unique_ptr<RGBA[]> $pixels = nullptr;
@ -72,6 +72,6 @@ struct Raycaster {
bool play_move(); bool play_move();
void abort_plan(); void abort_plan();
Point aimed_at(); bool is_target(DinkyECS::Entity entity);
Point camera_target(); Point camera_target();
}; };

Loading…
Cancel
Save