@ -49,10 +49,10 @@ sf::Color GUI::color(Value val) {
}
}
GUI : : GUI ( ) : $ game_map ( GAME_MAP_X , GAME_MAP_Y ) ,
GUI : : GUI ( ) : $ game_map ( GAME_MAP_X , GAME_MAP_Y ) ,
$ canvas ( GAME_MAP _X * 2 , GAME_MAP _Y * 4 ) ,
$ canvas ( VIEW_PORT _X * 2 , VIEW_PORT _Y * 4 ) ,
$ window ( sf : : VideoMode ( VIDEO_X , VIDEO_Y ) , " Roguish " ) ,
$ window ( sf : : VideoMode ( VIDEO_X , VIDEO_Y ) , " Roguish " ) ,
$ screen ( SCREEN_X , SCREEN_Y ) ,
$ screen ( SCREEN_X , SCREEN_Y ) ,
$ map_screen ( GAME_MAP_X , GAME_MAP _Y)
$ map_screen ( VIEW_PORT_X , VIEW_PORT _Y)
{
{
int res = $ hit_buf . loadFromFile ( " ./assets/hit.wav " ) ;
int res = $ hit_buf . loadFromFile ( " ./assets/hit.wav " ) ;
dbc : : check ( res , " failed to load hit.wav " ) ;
dbc : : check ( res , " failed to load hit.wav " ) ;
@ -77,27 +77,7 @@ void GUI::create_renderer() {
auto player = $ world . get < Player > ( ) ;
auto player = $ world . get < Player > ( ) ;
$ map_view = Renderer ( [ & , player ] {
$ map_view = Renderer ( [ & , player ] {
const auto & player_position = $ world . component < Position > ( player . entity ) ;
System : : draw_map ( $ world , $ game_map , $ canvas , VIEW_PORT_X , VIEW_PORT_Y ) ;
Matrix & walls = $ game_map . walls ( ) ;
$ game_map . set_target ( player_position . location ) ;
$ game_map . make_paths ( ) ;
Matrix & paths = $ game_map . paths ( ) ;
for ( size_t x = 0 ; x < walls [ 0 ] . size ( ) ; + + x ) {
for ( size_t y = 0 ; y < walls . size ( ) ; + + y ) {
string tile = walls [ y ] [ x ] = = 1 ? WALL_TILE : format ( " {} " , paths [ y ] [ x ] ) ;
if ( tile = = WALL_TILE ) {
$ canvas . DrawText ( x * 2 , y * 4 , tile ) ;
} else if ( $ show_paths ) {
//int pnum = paths[y][x];
$ canvas . DrawText ( x * 2 , y * 4 , tile ) ;
} else {
$ canvas . DrawText ( x * 2 , y * 4 , FLOOR_TILE ) ;
}
}
}
System : : draw_entities ( $ world , $ canvas ) ;
return canvas ( $ canvas ) ;
return canvas ( $ canvas ) ;
} ) ;
} ) ;
@ -118,13 +98,15 @@ void GUI::create_renderer() {
void GUI : : handle_events ( ) {
void GUI : : handle_events ( ) {
sf : : Event event ;
sf : : Event event ;
auto player = $ world . get < Player > ( ) ;
auto & player_motion = $ world . component < Motion > ( player . entity ) ;
while ( $ window . pollEvent ( event ) ) {
while ( $ window . pollEvent ( event ) ) {
if ( event . type = = sf : : Event : : Closed ) {
if ( event . type = = sf : : Event : : Closed ) {
$ window . close ( ) ;
$ window . close ( ) ;
} else if ( event . type = = sf : : Event : : KeyPressed ) {
} else if ( event . type = = sf : : Event : : KeyPressed ) {
auto player = $ world . get < Player > ( ) ;
auto & player_motion = $ world . component < Motion > ( player . entity ) ;
auto & player_position = $ world . component < Position > ( player . entity ) ;
if ( sf : : Keyboard : : isKeyPressed ( sf : : Keyboard : : Left ) ) {
if ( sf : : Keyboard : : isKeyPressed ( sf : : Keyboard : : Left ) ) {
player_motion . dx = - 1 ;
player_motion . dx = - 1 ;
} else if ( sf : : Keyboard : : isKeyPressed ( sf : : Keyboard : : Right ) ) {
} else if ( sf : : Keyboard : : isKeyPressed ( sf : : Keyboard : : Right ) ) {
@ -135,6 +117,8 @@ void GUI::handle_events() {
player_motion . dy = 1 ;
player_motion . dy = 1 ;
}
}
$ game_map . set_target ( player_position . location ) ;
$ game_map . make_paths ( ) ;
// COMPOSE system? You create a bunch of callbacks and then combine them into
// COMPOSE system? You create a bunch of callbacks and then combine them into
// a single run over the data?
// a single run over the data?
System : : enemy_pathing ( $ world , $ game_map , player ) ;
System : : enemy_pathing ( $ world , $ game_map , player ) ;