Level traversal works better now, compass is accurate, and direction is maintained when you traverse.
This commit is contained in:
parent
b75a2b8c31
commit
14c7f660de
11 changed files with 35 additions and 16 deletions
|
@ -283,6 +283,7 @@ namespace gui {
|
|||
event(Event::ATTACK);
|
||||
break;
|
||||
case KEY::P:
|
||||
sound::mute(false);
|
||||
$main_ui.debug();
|
||||
break;
|
||||
default:
|
||||
|
|
1
main.cpp
1
main.cpp
|
@ -5,6 +5,7 @@
|
|||
int main() {
|
||||
textures::init();
|
||||
sound::init();
|
||||
sound::mute(true);
|
||||
gui::FSM main;
|
||||
main.event(gui::Event::STARTED);
|
||||
|
||||
|
|
15
main_ui.cpp
15
main_ui.cpp
|
@ -69,9 +69,12 @@ namespace gui {
|
|||
}
|
||||
|
||||
void MainUI::init() {
|
||||
auto& player_position = $level.world->get<Position>($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<Position>($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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
4
map.cpp
4
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;
|
||||
|
|
2
map.hpp
2
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);
|
||||
|
|
|
@ -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<components::Position>(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<components::Sprite>([&](const auto ent, auto& sprite) {
|
||||
// player doesn't need a sprite
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace textures {
|
|||
auto sprite = make_shared<sf::Sprite>(*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"]);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
namespace textures {
|
||||
|
||||
struct SpriteTexture {
|
||||
std::string name;
|
||||
std::shared_ptr<sf::Sprite> sprite = nullptr;
|
||||
std::shared_ptr<sf::Texture> texture = nullptr;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue