diff options
author | Paul Duncan <pabs@pablotron.org> | 2019-01-14 03:49:02 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2019-01-14 03:49:02 -0500 |
commit | 065795330a7e0c254fdb755498c7724fba45ea5d (patch) | |
tree | 837131daeb67683dc1d562f97dbff1600c3e94a2 /src | |
parent | c711fdb3e9e3862ba26d2e05393b2bbacc7f012b (diff) | |
download | sok-065795330a7e0c254fdb755498c7724fba45ea5d.tar.bz2 sok-065795330a7e0c254fdb755498c7724fba45ea5d.zip |
remove level zero, add border, sync to vblank, add spaces around text, misc cleanups
Diffstat (limited to 'src')
-rw-r--r-- | src/sdl/draw.c | 38 | ||||
-rw-r--r-- | src/sdl/main.c | 38 | ||||
-rw-r--r-- | src/text/levels.c | 8 |
3 files changed, 60 insertions, 24 deletions
diff --git a/src/sdl/draw.c b/src/sdl/draw.c index 6616ce7..630ecd1 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -64,6 +64,32 @@ draw_cell( } } +static void +draw_border( + draw_ctx_t * const draw_ctx, + const sok_pos_t level_size +) { + const size_t cell_size = get_cell_size(draw_ctx); + + // calc rect + const SDL_Rect rect = { + draw_ctx->render_ofs_x - cell_size / 8, + draw_ctx->render_ofs_y - cell_size / 8, + level_size.x * cell_size + cell_size / 4, + level_size.y * cell_size + cell_size / 4, + }; + + // set color + if (SDL_SetRenderDrawColor(draw_ctx->renderer, 0, 0, 0, 0xFF)) { + die("SDL_SetRenderDrawColor(): %s", SDL_GetError()); + } + + // fill border rect + if (SDL_RenderFillRect(draw_ctx->renderer, &rect)) { + die("SDL_RenderFillRect(): %s", SDL_GetError()); + } +} + static bool draw_sprites_on_size( const sok_ctx_t * const ctx, @@ -73,6 +99,8 @@ draw_sprites_on_size( on_size(ctx, level_size, data); draw_ctx_t * const draw_ctx = data; + draw_border(draw_ctx, level_size); + // draw floor for (size_t y = 0; y < level_size.y; y++) { for (size_t x = 0; x < level_size.x; x++) { @@ -296,14 +324,14 @@ draw_text( } static void -draw_level_text( +draw_title_text( draw_ctx_t * const draw_ctx ) { // build text char buf[256]; snprintf( buf, sizeof(buf), - "%s: %s (#%zu)", + " %s: %s (#%zu) ", draw_ctx->level->pack, draw_ctx->level->name, *draw_ctx->level_num @@ -336,7 +364,7 @@ draw_moves_text( char buf[256]; snprintf( buf, sizeof(buf), - "Moves: %zu%s", + " Moves: %zu%s ", draw_ctx->ctx->num_moves, sok_ctx_is_done(draw_ctx->ctx) ? " (Won!)" : "" ); @@ -370,7 +398,7 @@ draw_help_text( char buf[256]; snprintf( buf, sizeof(buf), - "%sU: Undo" DELIM "R: Reset" DELIM "S: Solve" DELIM "Q: Quit", + " %sU: Undo" DELIM "R: Reset" DELIM "S: Solve" DELIM "Q: Quit ", sok_ctx_is_done(draw_ctx->ctx) ? "Space: Next Level" DELIM : "" ); @@ -440,7 +468,7 @@ draw( sok_ctx_walk(draw_ctx->ctx, &DRAW_CBS, draw_ctx); // render text - draw_level_text(draw_ctx); + draw_title_text(draw_ctx); draw_moves_text(draw_ctx); draw_help_text(draw_ctx); diff --git a/src/sdl/main.c b/src/sdl/main.c index 5eca49c..fb0f2e0 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -109,18 +109,13 @@ set_level( die("Couldn't load level %zu", level_num); } - // build title - char buf[1024]; - snprintf( - buf, sizeof(buf), - "Sokoban: %s: %s (#%zu)", + // log level title + SDL_Log( + "Loaded level \"%s: %s\" (#%zu)", draw_ctx->level->pack, draw_ctx->level->name, level_num ); - - // set window title - SDL_SetWindowTitle(win, buf); } int main(int argc, char *argv[]) { @@ -159,13 +154,30 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } - // create window and renderer - SDL_Window *win; - SDL_Renderer *renderer; - if (SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &win, &renderer)) { - die("SDL_CreateWindowAndRenderer(): %s", SDL_GetError()); + // create window + SDL_Window *win = SDL_CreateWindow( + "Sokoban", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + 800, + 600, + SDL_WINDOW_RESIZABLE + ); + + // check for error + if (!win) { + die("SDL_CreateWindow(): %s", SDL_GetError()); } + // create renderer + SDL_Renderer *renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + if (!renderer) { + die("SDl_CreateRenderer(): %s", SDL_GetError()); + } + + // set window title + SDL_SetWindowTitle(win, "Sokoban"); + log_renderer_info(renderer); // init draw context diff --git a/src/text/levels.c b/src/text/levels.c index 4db92c8..4971604 100644 --- a/src/text/levels.c +++ b/src/text/levels.c @@ -7,12 +7,8 @@ static const level_t LEVELS[] = {{ - .pack = "Tutorials", - .name = "Hello World!", - .data = "5#|#@$.#|5#", -}, { - .pack = "Tutorials", - .name = "Plus", + .pack = "Introduction", + .name = "Welcome to Sokoban", .data = "7#|3#.3#|3#$3#|#.$@$.#|3#$3#|3#.3#|7#", }, { .pack = "Microban", |