diff --git a/raycaster.cpp b/raycaster.cpp index 7cbfa3d..860b2a4 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -97,9 +97,6 @@ void Raycaster::apply_sprite_effect(shared_ptr effect, float width, void Raycaster::sprite_casting(sf::RenderTarget &target) { - constexpr const int texture_width = TEXTURE_WIDTH; - constexpr const int texture_height = TEXTURE_HEIGHT; - constexpr const int half_height = TEXTURE_HEIGHT / 2; auto& lights = $level.lights->lighting(); // sort sprites from far to close @@ -110,6 +107,11 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { if(!$sprites.contains(rec.second)) continue; auto& sprite_texture = $sprites.at(rec.second); + + int texture_width = (float)sprite_texture.frame_size.x; + int texture_height =(float)sprite_texture.frame_size.y; + int half_height = texture_height / 2; + auto& sf_sprite = sprite_texture.sprite; auto sprite_pos = $level.world->get(rec.second); @@ -175,7 +177,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { int d = y * texture_height - $height * half_height + sprite_height * half_height; int tex_y = ((d * texture_height) / sprite_height) / texture_height; - sf::Vector2f origin{texture_width / 2, texture_height / 2}; + sf::Vector2f origin{texture_width / 2.0f, texture_height / 2.0f}; sf::Vector2f scale{sprite_scale_w, sprite_scale_h}; sf::Vector2f position{x + origin.x * scale.x, y + origin.y * scale.y}; sf::IntRect in_texture{ {tex_x, tex_y}, {tex_render_width, texture_height}}; @@ -323,8 +325,9 @@ void Raycaster::cast_rays() { } void Raycaster::draw_ceiling_floor() { - constexpr static const int texture_width = TEXTURE_WIDTH; - constexpr static const int texture_height = TEXTURE_HEIGHT; + constexpr const int texture_width = TEXTURE_WIDTH; + constexpr const int texture_height = TEXTURE_HEIGHT; + auto &lights = $level.lights->lighting(); size_t surface_i = 0; const RGBA *floor_texture = textures::get_surface(surface_i);