Compare commits

..

3 commits

Author SHA1 Message Date
cat
aa95148fc9 AAAAA IT ANIMATES
i will probably handle animation with an Animation struct
containing an array of frames, with options to set intervals
and whether it loops or reverts to another state after
the animation is done
2025-05-26 15:39:16 +10:00
cat
304282f5fe file info to readme 2025-05-26 15:28:08 +10:00
cat
6a826d4b37 square window size (samply imgs are square) 2025-05-26 15:11:05 +10:00
4 changed files with 29 additions and 8 deletions

1
dat.h
View file

@ -21,6 +21,7 @@ struct Image {
struct State {
SDL_Window *win;
SDL_Renderer *ren;
Uint64 lastframe;
Samply *sam;
};

9
readme
View file

@ -8,3 +8,12 @@ i want people to be able to create their own pets without having to
figure out how to recompile.
run it with `SDL_LOGGING=app=debug ./slutpet` for verbose logging
file layout:
dat.h - data structure header
fns.h - functions and macros header
slutpet.c - sdl init and close
img.c - loading images
samply.c - pet Samply

View file

@ -13,10 +13,9 @@ put_samply_to_bed(Samply *sam)
free_image(sam->walka);
babble("free samply walk b!!");
free_image(sam->walkb);
babble("good night, samply!!");
SDL_free(sam);
}
babble("good night, samply!!");
SDL_free(sam);
}
Samply *
@ -34,7 +33,7 @@ wake_samply_up(SDL_Renderer *ren)
babble("stand samply up!!");
sam->idle = load_image(ren, "samply/Samply.png");
if (!sam->idle) {
fuck("samply would rather stay in bed. too bad! %s", SDL_GetError());
fuck("samply would rather stay in bed. too bad!");
put_samply_to_bed(sam);
return NULL;
}
@ -42,7 +41,7 @@ wake_samply_up(SDL_Renderer *ren)
babble("samply walk! part 1!!");
sam->walka = load_image(ren, "samply/Samply_Walk1.png");
if (!sam->walka) {
fuck("samply would rather stay in bed. too bad! %s", SDL_GetError());
fuck("samply would rather stay in bed. too bad!");
put_samply_to_bed(sam);
return NULL;
}
@ -50,7 +49,7 @@ wake_samply_up(SDL_Renderer *ren)
babble("samply walk! part 2!!");
sam->walkb = load_image(ren, "samply/Samply_Walk2.png");
if (!sam->walkb) {
fuck("samply would rather stay in bed. too bad! %s", SDL_GetError());
fuck("samply would rather stay in bed. too bad!");
put_samply_to_bed(sam);
return NULL;
}

View file

@ -47,15 +47,24 @@ SDL_AppResult
SDL_AppIterate(void *as)
{
State *st = as;
SDL_Texture *tx;
Uint64 ms;
SDL_SetRenderDrawColor(st->ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
SDL_RenderClear(st->ren);
if (SDL_RenderTexture(st->ren, st->sam->idle->tex, NULL, NULL) == false) {
ms = SDL_GetTicks();
if ((ms / 100) % 2)
tx = st->sam->walka->tex;
else
tx = st->sam->walkb->tex;
if (SDL_RenderTexture(st->ren, tx, NULL, NULL) == false) {
fuck("rendertexture fail: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
SDL_RenderPresent(st->ren);
st->lastframe = SDL_GetTicks();
return SDL_APP_CONTINUE;
}
@ -80,8 +89,10 @@ SDL_AppInit(void **as, int argc, char **argv)
SDL_SetHint(SDL_HINT_X11_FORCE_OVERRIDE_REDIRECT, "1");
st->lastframe = SDL_GetTicks();
babble("create win+render...");
if (!SDL_CreateWindowAndRenderer("slutpet", 320, 240,
if (!SDL_CreateWindowAndRenderer("slutpet", 320, 320,
SDL_WINDOW_TRANSPARENT | SDL_WINDOW_BORDERLESS
| SDL_WINDOW_NOT_FOCUSABLE
| SDL_WINDOW_ALWAYS_ON_TOP,
@ -98,5 +109,6 @@ SDL_AppInit(void **as, int argc, char **argv)
}
babble("hi!!");
babble("program startup took %llums!", SDL_GetTicks());
return SDL_APP_CONTINUE;
}