From fcb13db79e3fa84f4ace6a6647182617ff5d9d63 Mon Sep 17 00:00:00 2001 From: David Husicka Date: Tue, 14 Dec 2021 17:47:10 +0100 Subject: [PATCH] tile texture matching --- src/gui.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui.c b/src/gui.c index c240b65..75d9cbb 100644 --- a/src/gui.c +++ b/src/gui.c @@ -48,7 +48,7 @@ void gui_init() { // load up textures tile_texture = texture_from_png("res/tile.png"); - tile_textures[0] = tile_textures; + tile_textures[0] = tile_texture; tile_textures[1] = texture_from_png("res/2.png"); tile_textures[3] = texture_from_png("res/4.png"); tile_textures[4] = texture_from_png("res/8.png"); @@ -98,7 +98,15 @@ void gui_loop(Game *game) { tile_rect.x = i * 175; for (int j = 0; j < game->field_size_y; j++) { tile_rect.y = j * 175; - SDL_RenderCopy( window_renderer, tile_texture, NULL, &tile_rect); + + // get texture index from value + for (int k = 0; k < 13; k++) { + if (!(game->field[i][j] >> k)) { + SDL_RenderCopy( window_renderer, tile_textures[k], NULL, &tile_rect); + break; + } + } + // SDL_RenderCopy( window_renderer, tile_texture, NULL, &tile_rect); } } SDL_RenderPresent(window_renderer);