@ -407,47 +407,6 @@ void System::plan_motion(World& world, Position move_to) {
motion . dy = move_to . location . y - player_position . location . y ;
}
void System : : draw_map ( GameLevel & level , Matrix & grid , EntityGrid & entity_map , int compass_dir ) {
( void ) compass_dir ;
World & world = * level . world ;
Map & map = * level . map ;
size_t view_x = matrix : : width ( grid ) - 1 ;
size_t view_y = matrix : : height ( grid ) - 1 ;
entity_map . clear ( ) ;
auto player_pos = world . get < Position > ( level . player ) . location ;
Point cam_orig = map . center_camera ( player_pos , view_x , view_y ) ;
auto & tiles = map . tiles ( ) ;
auto & tile_set = textures : : get_map_tile_set ( ) ;
/* I'm doing double tid->wchar_t conversion here, maybe just
* render the tids into the grid then let someone else do this . */
// first fill it with the map cells
for ( shiterator : : each_cell_t it { grid } ; it . next ( ) ; ) {
size_t tile_y = size_t ( it . y ) + cam_orig . y ;
size_t tile_x = size_t ( it . x ) + cam_orig . x ;
if ( matrix : : inbounds ( tiles , tile_x , tile_y ) ) {
size_t tid = tiles [ tile_y ] [ tile_x ] ;
grid [ it . y ] [ it . x ] = tile_set [ tid ] ;
} else {
grid [ it . y ] [ it . x ] = L ' ' ;
}
}
// then get the enemy/item/device tiles and fill those in
world . query < Position , Tile > ( [ & ] ( auto , auto & pos , auto & entity_glyph ) {
// BUG: don't I have a within bounds macro somewhere?
if ( pos . location . x > = cam_orig . x & & pos . location . x < = cam_orig . x + view_x
& & pos . location . y > = cam_orig . y & & pos . location . y < = cam_orig . y + view_y )
{
Point view_pos = map . map_to_camera ( pos . location , cam_orig ) ;
entity_map . insert_or_assign ( view_pos , entity_glyph . display ) ;
}
} ) ;
}
void System : : player_status ( GameLevel & level ) {
auto & combat = level . world - > get < Combat > ( level . player ) ;
@ -567,7 +526,49 @@ bool System::inventory_occupied(GameLevel& level, Entity container_id, const std
}
void System : : render_map ( Matrix & tiles , EntityGrid & entity_map , sf : : RenderTexture & render ) {
void System : : draw_map ( GameLevel & level , Matrix & grid , EntityGrid & entity_map ) {
World & world = * level . world ;
Map & map = * level . map ;
size_t view_x = matrix : : width ( grid ) - 1 ;
size_t view_y = matrix : : height ( grid ) - 1 ;
entity_map . clear ( ) ;
auto player_pos = world . get < Position > ( level . player ) . location ;
Point cam_orig = map . center_camera ( player_pos , view_x , view_y ) ;
auto & tiles = map . tiles ( ) ;
auto & tile_set = textures : : get_map_tile_set ( ) ;
/* I'm doing double tid->wchar_t conversion here, maybe just
* render the tids into the grid then let someone else do this . */
// first fill it with the map cells
for ( shiterator : : each_cell_t it { grid } ; it . next ( ) ; ) {
size_t tile_y = size_t ( it . y ) + cam_orig . y ;
size_t tile_x = size_t ( it . x ) + cam_orig . x ;
if ( matrix : : inbounds ( tiles , tile_x , tile_y ) ) {
size_t tid = tiles [ tile_y ] [ tile_x ] ;
grid [ it . y ] [ it . x ] = tile_set [ tid ] ;
} else {
grid [ it . y ] [ it . x ] = L ' ' ;
}
}
// then get the enemy/item/device tiles and fill those in
world . query < Position , Tile > ( [ & ] ( auto , auto & pos , auto & entity_glyph ) {
// BUG: don't I have a within bounds macro somewhere?
if ( pos . location . x > = cam_orig . x & & pos . location . x < = cam_orig . x + view_x
& & pos . location . y > = cam_orig . y & & pos . location . y < = cam_orig . y + view_y )
{
Point view_pos = map . map_to_camera ( pos . location , cam_orig ) ;
entity_map . insert_or_assign ( view_pos , entity_glyph . display ) ;
}
} ) ;
}
void System : : render_map ( Matrix & tiles , EntityGrid & entity_map , sf : : RenderTexture & render , int compass_dir , wchar_t player_display ) {
sf : : Vector2i size { MAP_TILE_DIM , MAP_TILE_DIM } ;
unsigned int width = matrix : : width ( tiles ) ;
unsigned int height = matrix : : height ( tiles ) ;
@ -591,7 +592,19 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture
for ( auto [ point , display ] : entity_map ) {
auto & sprite = textures : : get_map_sprite ( display ) ;
sprite . setPosition ( { float ( point . x * size . x ) , float ( point . y * size . y ) } ) ;
if ( display = = player_display ) {
sf : : Vector2f size = sprite . getLocalBounds ( ) . size ;
sf : : Vector2f center { size . x / 2 , size . y / 2 } ;
float degrees = ( ( ( compass_dir * 45 ) + 270 ) % 360 ) ;
sprite . setOrigin ( center ) ;
sprite . setRotation ( sf : : degrees ( degrees ) ) ;
sprite . setPosition ( { float ( point . x * size . x ) + center . x , float ( point . y * size . y ) + center . y } ) ;
} else {
sprite . setPosition ( { float ( point . x * size . x ) , float ( point . y * size . y ) } ) ;
}
render . draw ( sprite ) ;
}