|
|
@ -62,6 +62,10 @@ void Raycaster::position_camera(float player_x, float player_y) { |
|
|
|
// x and y start position
|
|
|
|
// x and y start position
|
|
|
|
$pos_x = player_x; |
|
|
|
$pos_x = player_x; |
|
|
|
$pos_y = player_y; |
|
|
|
$pos_y = player_y; |
|
|
|
|
|
|
|
$dir_x = 1; |
|
|
|
|
|
|
|
$dir_y = 0; |
|
|
|
|
|
|
|
$plane_x = 0; |
|
|
|
|
|
|
|
$plane_y = 0.66; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Raycaster::draw_pixel_buffer() { |
|
|
|
void Raycaster::draw_pixel_buffer() { |
|
|
@ -81,8 +85,8 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { |
|
|
|
for(auto& rec : sprite_order) { |
|
|
|
for(auto& rec : sprite_order) { |
|
|
|
if(!$sprites.contains(rec.second)) continue; |
|
|
|
if(!$sprites.contains(rec.second)) continue; |
|
|
|
|
|
|
|
|
|
|
|
// BUG: eventually this needs to go away too
|
|
|
|
auto& sprite_texture = $sprites.at(rec.second); |
|
|
|
auto& sf_sprite = $sprites.at(rec.second).sprite; |
|
|
|
auto& sf_sprite = sprite_texture.sprite; |
|
|
|
auto sprite_pos = $level.world->get<components::Position>(rec.second); |
|
|
|
auto sprite_pos = $level.world->get<components::Position>(rec.second); |
|
|
|
|
|
|
|
|
|
|
|
double sprite_x = double(sprite_pos.location.x) - $pos_x + 0.5; |
|
|
|
double sprite_x = double(sprite_pos.location.x) - $pos_x + 0.5; |
|
|
@ -100,11 +104,12 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { |
|
|
|
// calculate the height of the sprite on screen
|
|
|
|
// calculate the height of the sprite on screen
|
|
|
|
//using "transform_y" instead of the real distance prevents fisheye
|
|
|
|
//using "transform_y" instead of the real distance prevents fisheye
|
|
|
|
int sprite_height = abs(int($height / transform_y)); |
|
|
|
int sprite_height = abs(int($height / transform_y)); |
|
|
|
|
|
|
|
if(sprite_height == 0) continue; |
|
|
|
|
|
|
|
|
|
|
|
// calculate width the the sprite
|
|
|
|
// calculate width the the sprite
|
|
|
|
// same as height of sprite, given that it's square
|
|
|
|
// same as height of sprite, given that it's square
|
|
|
|
int sprite_width = abs(int($height / transform_y)); |
|
|
|
int sprite_width = abs(int($height / transform_y)); |
|
|
|
// CUT
|
|
|
|
if(sprite_width == 0) continue; |
|
|
|
|
|
|
|
|
|
|
|
int draw_start_x = -sprite_width / 2 + sprite_screen_x; |
|
|
|
int draw_start_x = -sprite_width / 2 + sprite_screen_x; |
|
|
|
if(draw_start_x < 0) draw_start_x = 0; |
|
|
|
if(draw_start_x < 0) draw_start_x = 0; |
|
|
@ -369,12 +374,11 @@ void Raycaster::update_sprite(DinkyECS::Entity ent, components::Sprite& sprite) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Raycaster::update_level(GameLevel level) { |
|
|
|
void Raycaster::update_level(GameLevel level) { |
|
|
|
$level = level; |
|
|
|
$sprites.clear(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$level = level; |
|
|
|
auto& tiles = $level.map->tiles(); |
|
|
|
auto& tiles = $level.map->tiles(); |
|
|
|
$map = textures::convert_char_to_texture(tiles.$tile_ids); |
|
|
|
$map = textures::convert_char_to_texture(tiles.$tile_ids); |
|
|
|
$dir_x = 1; // reset dir vector
|
|
|
|
|
|
|
|
$dir_y = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$level.world->query<components::Sprite>([&](const auto ent, auto& sprite) { |
|
|
|
$level.world->query<components::Sprite>([&](const auto ent, auto& sprite) { |
|
|
|
// player doesn't need a sprite
|
|
|
|
// player doesn't need a sprite
|
|
|
|