Movement is more correct now since it uses the System::motion to do it for the player, which will always keep all the things updated. I also put placeholder barrels for all the non-combatant entities in the map. Finally, it still has the backup bug and now won't close when you close the window.

master
Zed A. Shaw 10 months ago
parent 14128ab10f
commit 4b18b21861
  1. 4
      assets/config.json
  2. 16
      gui.cpp
  3. 13
      raycaster.cpp

@ -15,7 +15,7 @@
},
"worldgen": {
"enemy_probability": 20,
"empty_room_probability": 50,
"device_probability": 0
"empty_room_probability": 10,
"device_probability": 10
}
}

@ -44,12 +44,14 @@ namespace gui {
void FSM::MOVING(Event ) {
if($camera.play_move($rayview)) {
// really annoying but we have to figure out the motion factor then run the systems
auto &level = $levels.current();
auto player = level.world->get_the<Player>();
auto& player = level.world->get_the<Player>();
auto& player_position = level.world->get<Position>(player.entity);
player_position.location.x = size_t($camera.targetX);
player_position.location.y = size_t($camera.targetY);
auto& motion = level.world->get<Motion>(player.entity);
Point move_to{size_t($camera.targetX), size_t($camera.targetY)};
motion.dx = move_to.x - player_position.location.x;
motion.dy = move_to.y - player_position.location.y;
run_systems();
@ -90,11 +92,13 @@ namespace gui {
case FU::ROTATE_LEFT:
$camera.plan_rotate($rayview, 1);
state(State::ROTATING);
break;
return; // get out early since can always rotate
break; // need this?
case FU::ROTATE_RIGHT:
$camera.plan_rotate($rayview, -1);
state(State::ROTATING);
break;
return; // get out early since can always rotate
break; // need this?
default:
dbc::sentinel("unhandled event in IDLE");
}

@ -76,6 +76,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
double spriteX = double(sprite_pos.location.x) - $posX + 0.5;
double spriteY = double(sprite_pos.location.y) - $posY + 0.5;
//transform sprite with the inverse camera matrix
// [ $planeX $dirX ] -1 [ $dirY -$dirX ]
// [ ] = 1/($planeX*$dirY-$dirX*$planeY) * [ ]
@ -330,12 +331,18 @@ void Raycaster::draw(sf::RenderTarget& target) {
void Raycaster::set_level(GameLevel level) {
$level = level;
auto& tiles = $level.map->tiles();
auto world = $level.world;
$map = $textures.convert_char_to_texture(tiles.$tile_ids);
$level.world->query<components::Combat, components::Position>([&](const auto ent, auto& combat, auto &pos) {
fmt::println("entity: {}, hp: {}, pos={},{}", ent, combat.hp, pos.location.x, pos.location.y);
world->query<components::Position>([&](const auto ent, auto &pos) {
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");
$sprites.try_emplace(ent, sprite_txt);
} else {
fmt::println("item or device: {}, pos={},{}", ent, pos.location.x, pos.location.y);
auto sprite_txt = $textures.sprite_textures.at("barrel");
$sprites.try_emplace(ent, sprite_txt);
}
});
}