- First commit (tampoc crec que hi hagen molts més XD)

This commit is contained in:
2024-07-26 09:36:57 +02:00
commit a534d61f0c
5 changed files with 69 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
abad
abad.exe
.vscode/*

9
Makefile Normal file
View File

@@ -0,0 +1,9 @@
windows:
@echo off
g++ abad.cpp -lmingw32 -lSDL2main -lSDL2 -mwindows -o abad.exe
macos:
clang++ abad.cpp -std=c++11 -lSDL2 -o abad
linux:
g++ abad.cpp -lSDL2 -o abad

BIN
abad.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

56
abad.cpp Normal file
View File

@@ -0,0 +1,56 @@
#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;
}

1
reset.txt Normal file
View File

@@ -0,0 +1 @@
10