slutpet/samply.c
2025-05-28 16:45:15 +10:00

76 lines
1.5 KiB
C

#include <SDL3/SDL.h>
#include "dat.h"
#include "fns.h"
int
samply_step(State *st)
{
Uint64 ms;
SDL_Texture *tx;
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 -1;
}
}
void
put_samply_to_bed(Samply *sam)
{
if (sam) {
babble("free samply idle!!");
free_image(sam->idle);
babble("free samply walk a!!");
free_image(sam->walka);
babble("free samply walk b!!");
free_image(sam->walkb);
babble("good night, samply!!");
SDL_free(sam);
}
}
Samply *
wake_samply_up(SDL_Renderer *ren)
{
Samply *sam;
babble("wake up, samply!!");
sam = SDL_calloc(1, sizeof(Samply));
if (!sam) {
fuck("samply would rather stay in bed. too bad! %s", SDL_GetError());
return NULL;
}
babble("stand samply up!!");
sam->idle = load_image(ren, "samply/Samply.png");
if (!sam->idle) {
fuck("samply would rather stay in bed. too bad!");
put_samply_to_bed(sam);
return NULL;
}
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!");
put_samply_to_bed(sam);
return NULL;
}
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!");
put_samply_to_bed(sam);
return NULL;
}
return sam;
}