#include #include "dat.h" #include "fns.h" int samply_step(State *st) { Uint64 ms; int x, y; if (SDL_GetWindowPosition(st->win, &x, &y) == false) { shit("window pos query fail: %s", SDL_GetError()); goto render_it; } ms = SDL_GetTicks(); if ((ms / 100) % 2) { babble("anim walka"); st->sam->tx = st->sam->walka; } else { babble("anim walkb"); st->sam->tx = st->sam->walkb; } x++; babble("bounds %d %d %d %d", st->bounds.x, st->bounds.y, st->bounds.w, st->bounds.h); babble("img %d %d %d %d", x, y, st->sam->tx->w, st->sam->tx->h); // if (in_bounds(st->sam->tx, x, y, &st->bounds) == false) { if (st->bounds.w - st->sam->tx->w < x) { st->sam->tx = st->sam->idle; x = st->bounds.w - st->sam->tx->w; babble("*bonk*"); } if (SDL_SetWindowPosition(st->win, x, y) == false) shit("window pos set fail: %s", SDL_GetError()); render_it: if (SDL_RenderTexture(st->ren, st->sam->tx->tex, 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(State *st) { 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(st->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(st->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(st->ren, "samply/Samply_Walk2.png"); if (!sam->walkb) { fuck("samply would rather stay in bed. too bad!"); put_samply_to_bed(sam); return NULL; } sam->tx = sam->idle; return sam; }