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
114 lines
2.3 KiB
C
114 lines
2.3 KiB
C
#define SDL_MAIN_USE_CALLBACKS
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_main.h>
|
|
#include "stb_image.h"
|
|
|
|
#include "dat.h"
|
|
#include "fns.h"
|
|
|
|
void
|
|
SDL_AppQuit(void *as, SDL_AppResult res)
|
|
{
|
|
State *st;
|
|
|
|
st = as;
|
|
if (st) {
|
|
babble("put samply to bed!!");
|
|
put_samply_to_bed(st->sam);
|
|
babble("free state...");
|
|
SDL_free(st);
|
|
}
|
|
|
|
babble("bye!");
|
|
return;
|
|
}
|
|
|
|
SDL_AppResult
|
|
SDL_AppEvent(void *as, SDL_Event *ev)
|
|
{
|
|
switch (ev->type) {
|
|
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
|
babble("mouse button down event");
|
|
if (ev->button.button == SDL_BUTTON_RIGHT) {
|
|
babble("right-click quit requested");
|
|
return SDL_APP_SUCCESS;
|
|
}
|
|
break;
|
|
case SDL_EVENT_QUIT:
|
|
babble("quit requested");
|
|
return SDL_APP_SUCCESS;
|
|
break; /* unreachable; here for visual symmetry */
|
|
}
|
|
|
|
return SDL_APP_CONTINUE;
|
|
}
|
|
|
|
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);
|
|
|
|
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;
|
|
}
|
|
|
|
SDL_AppResult
|
|
SDL_AppInit(void **as, int argc, char **argv)
|
|
{
|
|
State *st;
|
|
|
|
babble("init sdl...");
|
|
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
|
fuck("sdl init fail: %s", SDL_GetError());
|
|
return SDL_APP_FAILURE;
|
|
}
|
|
|
|
babble("alloc state...");
|
|
st = SDL_calloc(1, sizeof(State));
|
|
if (!st) {
|
|
fuck("mem alloc fail: %s", SDL_GetError());
|
|
return SDL_APP_FAILURE;
|
|
}
|
|
*as = st;
|
|
|
|
SDL_SetHint(SDL_HINT_X11_FORCE_OVERRIDE_REDIRECT, "1");
|
|
|
|
st->lastframe = SDL_GetTicks();
|
|
|
|
babble("create win+render...");
|
|
if (!SDL_CreateWindowAndRenderer("slutpet", 320, 320,
|
|
SDL_WINDOW_TRANSPARENT | SDL_WINDOW_BORDERLESS
|
|
| SDL_WINDOW_NOT_FOCUSABLE
|
|
| SDL_WINDOW_ALWAYS_ON_TOP,
|
|
&st->win, &st->ren)) {
|
|
fuck("win creation fail: %s", SDL_GetError());
|
|
return SDL_APP_FAILURE;
|
|
}
|
|
|
|
babble("create samply!!...");
|
|
st->sam = wake_samply_up(st->ren);
|
|
if (!st->sam) {
|
|
fuck("samply said no. too bad!");
|
|
return SDL_APP_FAILURE;
|
|
}
|
|
|
|
babble("hi!!");
|
|
babble("program startup took %llums!", SDL_GetTicks());
|
|
return SDL_APP_CONTINUE;
|
|
}
|