diff --git a/gui_fsm.cpp b/gui_fsm.cpp index d2cc9dc..811fa73 100644 --- a/gui_fsm.cpp +++ b/gui_fsm.cpp @@ -283,6 +283,7 @@ namespace gui { event(Event::ATTACK); break; case KEY::P: + sound::mute(false); $main_ui.debug(); break; default: diff --git a/main.cpp b/main.cpp index 42ca456..08623bd 100644 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,7 @@ int main() { textures::init(); sound::init(); + sound::mute(true); gui::FSM main; main.event(gui::Event::STARTED); diff --git a/main_ui.cpp b/main_ui.cpp index c395a21..fe50d54 100644 --- a/main_ui.cpp +++ b/main_ui.cpp @@ -69,9 +69,12 @@ namespace gui { } void MainUI::init() { + auto& player_position = $level.world->get($level.player); + auto player = player_position.location; + $rayview.init_shaders(); $rayview.set_position(RAY_VIEW_X, RAY_VIEW_Y); - $rayview.position_camera($player.x + 0.5, $player.y + 0.5); + $rayview.position_camera(player.x + 0.5, player.y + 0.5); $overlay_ui.show_label("top", $compass[$compass_dir]); @@ -88,8 +91,6 @@ namespace gui { $show_level = true; } - - void MainUI::draw() { auto start = $stats.time_start(); @@ -159,9 +160,13 @@ namespace gui { void MainUI::update_level(GameLevel level) { $level = level; auto& player_position = $level.world->get($level.player); - $player = player_position.location; + auto player = player_position.location; + $rayview.update_level($level); - $rayview.position_camera($player.x + 0.5, $player.y + 0.5); + $rayview.position_camera(player.x + 0.5, player.y + 0.5); + + $compass_dir = 0; + $overlay_ui.update_label("top", $compass[$compass_dir]); dirty(); } diff --git a/main_ui.hpp b/main_ui.hpp index 184e034..ba8bc77 100644 --- a/main_ui.hpp +++ b/main_ui.hpp @@ -18,7 +18,6 @@ namespace gui { }; bool $show_level = false; bool $needs_render = true; - Point $player{0,0}; Stats $stats; sf::Clock $clock; sf::RenderWindow& $window; diff --git a/map.cpp b/map.cpp index 080d7f9..77ddf6c 100644 --- a/map.cpp +++ b/map.cpp @@ -117,7 +117,7 @@ Point Map::center_camera(const Point &around, size_t view_x, size_t view_y) { * drunkenly gradually reaching the player, and dodging * in and out. */ -bool Map::neighbors(Point &out, bool random) { +bool Map::neighbors(Point &out, bool random, int direction) { Matrix &paths = $paths.$paths; bool zero_found = false; @@ -145,7 +145,7 @@ bool Map::neighbors(Point &out, bool random) { if(!inmap(dir.x, dir.y)) continue; //skip unpathable stuff int weight = cur - paths[dir.y][dir.x]; - if(weight == 1) { + if(weight == direction) { // no matter what we follow direct paths out = dir; return true; diff --git a/map.hpp b/map.hpp index e835f8d..87349fc 100644 --- a/map.hpp +++ b/map.hpp @@ -52,7 +52,7 @@ public: bool iswall(size_t x, size_t y); bool can_move(Point move_to); // BUG: this isn't really neighbors anymore. Maybe move? Walk? - bool neighbors(Point &out, bool random=false); + bool neighbors(Point &out, bool random=false, int direction=1); void make_paths(); void set_target(const Point &at, int value=0); diff --git a/raycaster.cpp b/raycaster.cpp index 9f3d4e0..6b72f4d 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -62,6 +62,10 @@ void Raycaster::position_camera(float player_x, float player_y) { // x and y start position $pos_x = player_x; $pos_y = player_y; + $dir_x = 1; + $dir_y = 0; + $plane_x = 0; + $plane_y = 0.66; } void Raycaster::draw_pixel_buffer() { @@ -81,8 +85,8 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { for(auto& rec : sprite_order) { if(!$sprites.contains(rec.second)) continue; - // BUG: eventually this needs to go away too - auto& sf_sprite = $sprites.at(rec.second).sprite; + auto& sprite_texture = $sprites.at(rec.second); + auto& sf_sprite = sprite_texture.sprite; auto sprite_pos = $level.world->get(rec.second); 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 //using "transform_y" instead of the real distance prevents fisheye int sprite_height = abs(int($height / transform_y)); + if(sprite_height == 0) continue; // calculate width the the sprite // same as height of sprite, given that it's square int sprite_width = abs(int($height / transform_y)); - // CUT + if(sprite_width == 0) continue; int draw_start_x = -sprite_width / 2 + sprite_screen_x; 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) { - $level = level; + $sprites.clear(); + $level = level; auto& tiles = $level.map->tiles(); $map = textures::convert_char_to_texture(tiles.$tile_ids); - $dir_x = 1; // reset dir vector - $dir_y = 0; $level.world->query([&](const auto ent, auto& sprite) { // player doesn't need a sprite diff --git a/sound.cpp b/sound.cpp index f3b381a..185e306 100644 --- a/sound.cpp +++ b/sound.cpp @@ -6,6 +6,7 @@ namespace sound { static SoundManager SMGR; static bool initialized = false; + static bool muted = false; using namespace fmt; using std::make_shared; @@ -38,6 +39,8 @@ namespace sound { void play(const std::string name) { dbc::check(initialized, "You need to call sound::init() first"); + if(muted) return; + if(SMGR.sounds.contains(name)) { // get the sound from the sound map auto pair = SMGR.sounds.at(name); @@ -60,4 +63,8 @@ namespace sound { name)); } } + + void mute(bool setting) { + muted = setting; + } } diff --git a/sound.hpp b/sound.hpp index 720a5cc..a20727a 100644 --- a/sound.hpp +++ b/sound.hpp @@ -19,4 +19,5 @@ namespace sound { void load(const std::string name, const std::string path); void play(const std::string name); void play_at(const std::string name, float x, float y, float z); + void mute(bool setting); } diff --git a/textures.cpp b/textures.cpp index 8eb8314..52fd84d 100644 --- a/textures.cpp +++ b/textures.cpp @@ -23,7 +23,7 @@ namespace textures { auto sprite = make_shared(*texture); string name = el.key(); - TMGR.sprite_textures[name] = {sprite, texture}; + TMGR.sprite_textures.try_emplace(name, name, sprite, texture); } TMGR.floor = load_image(assets["sprites"]["floor"]); diff --git a/textures.hpp b/textures.hpp index 7c2fdb0..129ff1c 100644 --- a/textures.hpp +++ b/textures.hpp @@ -10,6 +10,7 @@ namespace textures { struct SpriteTexture { + std::string name; std::shared_ptr sprite = nullptr; std::shared_ptr texture = nullptr; };