Compare commits
3 commits
d65a270aab
...
aa95148fc9
Author | SHA1 | Date | |
---|---|---|---|
|
aa95148fc9 | ||
|
304282f5fe | ||
|
6a826d4b37 |
4 changed files with 29 additions and 8 deletions
1
dat.h
1
dat.h
|
@ -21,6 +21,7 @@ struct Image {
|
|||
struct State {
|
||||
SDL_Window *win;
|
||||
SDL_Renderer *ren;
|
||||
Uint64 lastframe;
|
||||
|
||||
Samply *sam;
|
||||
};
|
||||
|
|
9
readme
9
readme
|
@ -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
|
||||
|
|
9
samply.c
9
samply.c
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
16
slutpet.c
16
slutpet.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue