This commit is contained in:
win7he 2026-06-10 18:02:37 +00:00
commit f89d6cf1f2
14 changed files with 158 additions and 0 deletions

1
compile.sh Executable file
View file

@ -0,0 +1 @@
gcc main.c -o pofrc -l SDL2 -l SDL2_image -lm -g

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 937 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

BIN
data/images/tiles/anvil.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
data/images/tiles/bomb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
data/images/tiles/fire.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
data/images/tiles/ice.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
data/images/tiles/luck.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

157
main.c Normal file
View file

@ -0,0 +1,157 @@
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
// 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;
}