From 4b18b218617d38a91a14171b14265d39a8023857 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Wed, 5 Feb 2025 20:26:09 -0500 Subject: [PATCH] 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. --- assets/config.json | 4 ++-- gui.cpp | 16 ++++++++++------ raycaster.cpp | 17 ++++++++++++----- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/assets/config.json b/assets/config.json index a99e293..cefe86d 100644 --- a/assets/config.json +++ b/assets/config.json @@ -15,7 +15,7 @@ }, "worldgen": { "enemy_probability": 20, - "empty_room_probability": 50, - "device_probability": 0 + "empty_room_probability": 10, + "device_probability": 10 } } diff --git a/gui.cpp b/gui.cpp index 739a8f8..6490d87 100644 --- a/gui.cpp +++ b/gui.cpp @@ -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(); + auto& player = level.world->get_the(); auto& player_position = level.world->get(player.entity); - player_position.location.x = size_t($camera.targetX); - player_position.location.y = size_t($camera.targetY); + auto& motion = level.world->get(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"); } diff --git a/raycaster.cpp b/raycaster.cpp index 89a03ae..06a77cf 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -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([&](const auto ent, auto& combat, auto &pos) { - fmt::println("entity: {}, hp: {}, pos={},{}", ent, combat.hp, pos.location.x, pos.location.y); - - auto sprite_txt = $textures.sprite_textures.at("evil_eye"); - $sprites.try_emplace(ent, sprite_txt); + world->query([&](const auto ent, auto &pos) { + if(world->has(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); + } }); }