diff options
Diffstat (limited to 'src/all.c')
-rw-r--r-- | src/all.c | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -134,6 +134,7 @@ static DrawList *render(State *state, UI *ui, Arena *a) { .h = cellHeight, .fill = {255, 0, 0, 63}, .border = {255, 0, 0, 255}, + .image = 1, }; drawList->els[drawList->len++] = (DrawElement) { @@ -213,6 +214,16 @@ static void update(Game *game, uint64_t now, Arena a) { #include <SDL3/SDL.h> +typedef struct { + int width, height; + Color colors[16]; + const char *pixels; +} Image; + +#include "../build/images.c" + +SDL_Texture *textures[sizeof(images) / sizeof(images[0])]; + int main(int argc, char **argv) { (void) argc; (void) argv; @@ -249,6 +260,23 @@ int main(int argc, char **argv) { SDL_Renderer *r = SDL_CreateRendererWithProperties(renderProps); SDL_DestroyProperties(renderProps); SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_BLEND); + + for (int j = 1; j < (int) (sizeof(images) / sizeof(images[0])); j++) { + textures[j] = SDL_CreateTexture( + r, + SDL_PIXELFORMAT_ABGR8888, + SDL_TEXTUREACCESS_STATIC, + images[j].width, + images[j].height + ); + SDL_SetTextureScaleMode(textures[j], SDL_SCALEMODE_NEAREST); + Arena scratch = a; + Color *pixels = new(&scratch, images[j].width * images[j].height, Color); + for (int i = 0; i < images[j].width * images[j].height; i++) { + pixels[i] = images[j].colors[(int) images[j].pixels[i]]; + } + SDL_UpdateTexture(textures[j], NULL, pixels, images[j].width * 4); + } for (;;) { uint64_t now = SDL_GetTicks(); @@ -284,6 +312,7 @@ int main(int argc, char **argv) { DrawList *drawList = render(&game->state, &game->ui, &scratch); SDL_SetRenderDrawColor(r, 0, 0, 0, 255); SDL_RenderFillRect(r, NULL); + for (int i = 0; i < drawList->len; i++) { SDL_FRect rect = { .x = (float) drawList->els[i].x, @@ -309,6 +338,10 @@ int main(int argc, char **argv) { drawList->els[i].border.a ); SDL_RenderRect(r, &rect); + + if (drawList->els[i].image != 0) { + SDL_RenderTexture(r, textures[drawList->els[i].image], NULL, &rect); + } } update(game, now, a); @@ -331,7 +364,10 @@ void game_init(void) { perm.end = heap + MEM_SIZE; game = new(&perm, 1, Game); - game->state.grid[0] = 1; + xmemcpy(&game->state.grid, &levels[0].grid, sizeof(game->state.grid)); + game->state.goalx = levels[0].goalx; + game->state.goaly = levels[0].goaly; + game->state.playing = 0; } __attribute((export_name("game_render"))) |