|
|
|
@ -66,6 +66,10 @@ Raycaster::Raycaster(int width, int height) : |
|
|
|
|
$view_sprite.setPosition({0, 0}); |
|
|
|
|
$pixels = make_unique<RGBA[]>($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) }; |
|
|
|
|
} |
|
|
|
|