FINALLY fix that stupid bug. The cause was two-fold: I was giving every 'enemy' a sprite, but that automatically included the player in the list of enemies, which meant that I was rendering the player's sprite while moving. Then in the sprite casting loop I was rendering things at 0.
This commit is contained in:
parent
25ad9b51f8
commit
a19bc47904
4 changed files with 12 additions and 6 deletions
|
@ -67,6 +67,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
|||
|
||||
// sort sprites from far to close
|
||||
auto sprite_order = $level.collision->distance_sorted({(size_t)$posX, (size_t)$posY});
|
||||
|
||||
// after sorting the sprites, do the projection
|
||||
for(auto& rec : sprite_order) {
|
||||
if(!$sprites.contains(rec.second)) continue;
|
||||
|
@ -332,9 +333,13 @@ void Raycaster::set_level(GameLevel level) {
|
|||
$level = level;
|
||||
auto& tiles = $level.map->tiles();
|
||||
auto world = $level.world;
|
||||
auto& player = world->get_the<components::Player>();
|
||||
$map = $textures.convert_char_to_texture(tiles.$tile_ids);
|
||||
|
||||
world->query<components::Position>([&](const auto ent, auto &pos) {
|
||||
// player doesn't need a sprite
|
||||
if(player.entity == ent) return;
|
||||
|
||||
if(world->has<components::Combat>(ent)) {
|
||||
fmt::println("enemy: {}, pos={},{}", ent, pos.location.x, pos.location.y);
|
||||
auto sprite_txt = $textures.sprite_textures.at("evil_eye");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue