Files
AbadFentLaRonda/abad.cpp

56 lines
1.5 KiB
C++

#include <SDL2/SDL.h>
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *win = SDL_CreateWindow("ABAD", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_Renderer *ren = SDL_CreateRenderer(win, -1, 0);
SDL_RenderSetLogicalSize(ren, 64, 36);
SDL_ShowCursor(SDL_DISABLE);
SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, SDL_LoadBMP("abad.bmp"));
SDL_Rect src = {0,0,20,35};
SDL_Rect dst = {0,2,20,35};
int frames[4] = {0, 1, 0, 2};
int current_frame = 0;
int x = -5;
Uint32 time = SDL_GetTicks();
int reset = 0;
Uint32 elapsed = SDL_GetTicks();
FILE *f = fopen("reset.txt", "r");
fscanf(f, "%i", &reset);
fclose(f);
SDL_Event e;
bool should_exit = false;
while (!should_exit)
{
while (SDL_PollEvent(&e))
{
if (e.type==SDL_QUIT || (e.type==SDL_KEYDOWN && e.key.keysym.scancode==SDL_SCANCODE_ESCAPE)) { should_exit=true; break; }
}
if (SDL_GetTicks()-time>=125)
{
src.x = frames[current_frame]*20; current_frame=(current_frame+1)%4;
dst.x = x * 4; x++;
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
SDL_RenderClear(ren);
SDL_RenderCopy(ren, tex, &src, &dst);
SDL_RenderPresent(ren);
time = SDL_GetTicks();
}
if (SDL_GetTicks()-elapsed >= reset*1000)
{
x = -5;
elapsed = SDL_GetTicks();
}
}
SDL_Quit();
return 0;
}