commit f89d6cf1f224172878457c4da8113115ecbf59a9 Author: win7he Date: Wed Jun 10 18:02:37 2026 +0000 update diff --git a/compile.sh b/compile.sh new file mode 100755 index 0000000..11ec882 --- /dev/null +++ b/compile.sh @@ -0,0 +1 @@ +gcc main.c -o pofrc -l SDL2 -l SDL2_image -lm -g \ No newline at end of file diff --git a/data/images/placeholder/placeholder.png b/data/images/placeholder/placeholder.png new file mode 100644 index 0000000..c178ea8 Binary files /dev/null and b/data/images/placeholder/placeholder.png differ diff --git a/data/images/placeholder/placeholder2.png b/data/images/placeholder/placeholder2.png new file mode 100644 index 0000000..a0873ca Binary files /dev/null and b/data/images/placeholder/placeholder2.png differ diff --git a/data/images/sprites/funnyguy.png b/data/images/sprites/funnyguy.png new file mode 100644 index 0000000..7d048f8 Binary files /dev/null and b/data/images/sprites/funnyguy.png differ diff --git a/data/images/sprites/funnyguy.png.kra b/data/images/sprites/funnyguy.png.kra new file mode 100644 index 0000000..7dd3ccb Binary files /dev/null and b/data/images/sprites/funnyguy.png.kra differ diff --git a/data/images/tiles/anvil.png b/data/images/tiles/anvil.png new file mode 100644 index 0000000..7364372 Binary files /dev/null and b/data/images/tiles/anvil.png differ diff --git a/data/images/tiles/bomb.png b/data/images/tiles/bomb.png new file mode 100644 index 0000000..a120067 Binary files /dev/null and b/data/images/tiles/bomb.png differ diff --git a/data/images/tiles/elimin.png b/data/images/tiles/elimin.png new file mode 100644 index 0000000..9ee0bf5 Binary files /dev/null and b/data/images/tiles/elimin.png differ diff --git a/data/images/tiles/fire.png b/data/images/tiles/fire.png new file mode 100644 index 0000000..f49f765 Binary files /dev/null and b/data/images/tiles/fire.png differ diff --git a/data/images/tiles/ice.png b/data/images/tiles/ice.png new file mode 100644 index 0000000..f380e39 Binary files /dev/null and b/data/images/tiles/ice.png differ diff --git a/data/images/tiles/luck.png b/data/images/tiles/luck.png new file mode 100644 index 0000000..d27b815 Binary files /dev/null and b/data/images/tiles/luck.png differ diff --git a/data/images/tiles/neutrl.png b/data/images/tiles/neutrl.png new file mode 100644 index 0000000..2250b3a Binary files /dev/null and b/data/images/tiles/neutrl.png differ diff --git a/data/images/tiles/spring.png b/data/images/tiles/spring.png new file mode 100644 index 0000000..81fefdd Binary files /dev/null and b/data/images/tiles/spring.png differ diff --git a/main.c b/main.c new file mode 100644 index 0000000..2cecbf2 --- /dev/null +++ b/main.c @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#include +#include + +// Function for loading an image to SDL_Texture +static SDL_Texture *loadImage(SDL_Renderer *renderer, const char *path) +{ + SDL_Surface *img = IMG_Load(path); + if (img == NULL) + { + printf("no workie\n"); + return NULL; + } + SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, img); + SDL_FreeSurface(img); + if (texture == NULL) + { + printf("texture nule\n"); + return NULL; + } + return texture; +} + +long currentMillis(void) { + struct timespec ts; + long n = 0; + + clock_gettime(CLOCK_MONOTONIC, &ts); + + n += ts.tv_nsec / 1000 / 1000; + n += ts.tv_sec * 1000; + + return n; +} + +SDL_Point getsize(SDL_Texture *texture) { + SDL_Point size; + SDL_QueryTexture(texture, NULL, NULL, &size.x, &size.y); + return size; +} + +SDL_Rect rectang(int x, int y, int w, int h) { + SDL_Rect out; + out.x = x; + out.y = y; + out.w = w; + out.h = h; + return out; +} + +long timerval(long start){ + return currentMillis() - start; +} + +void randt(char *tiletypes){ + char i; + srand((int) currentMillis()); + for (i=0;i<12;i++){ + tiletypes[i]=(rand()%7)+1; + } +} + +int threadFunction( void* data ) +{ + while (1) { + randt((char *) data); + SDL_Delay(1000); + } +} + +int main() +{ + pthread_t tchthr; + long timerstart; + double timer; + timerstart = currentMillis(); + if (SDL_Init(SDL_INIT_EVERYTHING) != 0) + { + fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError()); + return 1; + } + SDL_Window *window = SDL_CreateWindow("plate o fate or smth", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0); + if (window == NULL) + { + fprintf(stderr, "SDL_CreateWindow Error: %s\n", SDL_GetError()); + return 1; + } + SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0); + if (renderer == NULL) + { + fprintf(stderr, "SDL_CreateRenderer Error: %s\n", SDL_GetError()); + return 1; + } + // Better scaling quality + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); + + + int SDL_PollEvent(SDL_Event * event); + int w, h; + char i; + char tiletypes[12] = {0}; + + SDL_Texture *imageTexture[10]; + SDL_Point isize[11]; + imageTexture[0] = loadImage(renderer, "data/images/placeholder/placeholder.png"); + imageTexture[1] = loadImage(renderer, "data/images/placeholder/placeholder2.png"); + imageTexture[2] = loadImage(renderer, "data/images/tiles/neutrl.png"); + imageTexture[3] = loadImage(renderer, "data/images/tiles/spring.png"); + imageTexture[4] = loadImage(renderer, "data/images/tiles/ice.png"); + imageTexture[5] = loadImage(renderer, "data/images/tiles/elimin.png"); + imageTexture[6] = loadImage(renderer, "data/images/tiles/fire.png"); + imageTexture[7] = loadImage(renderer, "data/images/tiles/bomb.png"); + imageTexture[8] = loadImage(renderer, "data/images/tiles/luck.png"); + imageTexture[9] = loadImage(renderer, "data/images/tiles/anvil.png"); + imageTexture[10] = loadImage(renderer, "data/images/sprites/funnyguy.png"); + for (i=0;i<11;i++){ + isize[i] = getsize(imageTexture[i]); + } + + SDL_GetRendererOutputSize(renderer, &w, &h); + SDL_Rect dest[14]; + dest[0] = rectang(0, 0, w, h); + + for (i=0;i<12;i++){ + dest[i+1] = rectang(50+135*(i%4), 40+400/3*(i/4), 135, 400/3); + } + + + SDL_Event event; + SDL_Thread* threadID = SDL_CreateThread( threadFunction, "thread test", (void*)tiletypes ); + while (1) + { + + while (SDL_PollEvent(&event)) { + if(event.type == SDL_QUIT){ + SDL_Quit(); + printf("\n"); + return 0; + } + } + timer = (double) timerval(timerstart); + dest[13] = rectang(50, 50, 50, 75); + SDL_GetRendererOutputSize(renderer, &w, &h); + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, imageTexture[0], NULL, &dest[0]); // background + for (i=0;i<12;i++){ + SDL_RenderCopy(renderer, imageTexture[2+tiletypes[i]], NULL, &dest[i+1]); // tiles + } + SDL_RenderCopy(renderer, imageTexture[10], NULL, &dest[13]); // funny guy + + SDL_RenderPresent(renderer); + } + return 0; +}