From e06ab8f76be21b866207a708f1336a5c1a53f149 Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Sun, 8 Feb 2026 20:01:32 -0600 Subject: gfx and 2-2 and multi objects --- lib/global_objects.c | 25 ++++++++++++++++++ lib/init-multi.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/init-multi.h | 15 +++++++++++ lib/init.c | 8 +++++- lib/init.h | 2 ++ 5 files changed, 120 insertions(+), 1 deletion(-) create mode 100755 lib/init-multi.c create mode 100755 lib/init-multi.h (limited to 'lib') diff --git a/lib/global_objects.c b/lib/global_objects.c index 74abb86..fe56c0b 100644 --- a/lib/global_objects.c +++ b/lib/global_objects.c @@ -2,6 +2,7 @@ #define global_objects #include +#include #define flaot float @@ -25,6 +26,11 @@ void point_mul(Point *A, Point *B){ A->y = A->y * B->y; } +void point_div(Point *A, Point *B){ + A->x = A->x / B->x; + A->y = A->y / B->y; +} + float magnitude(flaot x, flaot y) { return sqrt((pow(x,2) + pow(y,2))); } @@ -38,4 +44,23 @@ void point_set_mag(Point *point, float mag){ point->y = ry; } +void point_limit(Point *point, float mag){ + flaot getmag = magnitude(point->x, point->y); + flaot rx, ry; + if (getmag > mag){ + rx = (point->x / getmag) * mag; + ry = (point->y / getmag) * mag; + } else { + rx = point->x; + ry = point->y; + } + + point->x = rx; + point->y = ry; +} + +float RandomFloat(float min, float max){ + return ((max - min) * ((float)rand() / (double)RAND_MAX)) + min; +} + #endif diff --git a/lib/init-multi.c b/lib/init-multi.c new file mode 100755 index 0000000..054ef9e --- /dev/null +++ b/lib/init-multi.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +#include +#include + +int main(int argc, char *argv[]) +{ + if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) + SDL_Log("SDL fails to initialize! %s\n", SDL_GetError()); + + int startw=400; + int starth=400; + + SDL_Window *window = SDL_CreateWindow(PROJECT_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, startw, starth, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); + if (!window) { + printf("Failed to create window: %s\n", SDL_GetError()); + } + SDL_Renderer *renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_SOFTWARE); + if (!renderer) { + printf("Failed to create renderer: %s\n", SDL_GetError()); + } + + + srand(time(NULL)); + OBJECT obj_storage[obj_n]; + + init_stuffs(startw,starth,obj_storage); + + STUFFS stuff = { + startw, + starth, + false, + 0, + 0, + }; + + for (int i = 0; i < obj_n; i++) + stuff.obj[i] = &obj_storage[i]; + + bool quit = false; + SDL_Event e; + while (!quit) { + while (SDL_PollEvent(&e)) { + if (e.type == SDL_QUIT) { + quit = true; + } + else if(e.type == SDL_MOUSEBUTTONDOWN){ + if(e.button.button==SDL_BUTTON_LEFT){ + stuff.mousedown=true; + } else if(e.button.button==SDL_BUTTON_RIGHT){ + } + } else if(e.type==SDL_MOUSEBUTTONUP){ + stuff.mousedown=false; + } + stuff.mx=e.button.x; + stuff.my=e.button.y; + } + draw(renderer,window,&stuff); + SDL_Delay(10); + } + + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_Quit(); + + return 0; +} diff --git a/lib/init-multi.h b/lib/init-multi.h new file mode 100755 index 0000000..34376e1 --- /dev/null +++ b/lib/init-multi.h @@ -0,0 +1,15 @@ +#ifndef inithell +#define inithell + +#include +#include + +typedef struct{ + int width; + int height; + bool mousedown; + int mx; + int my; + OBJECT *obj[obj_n]; +} STUFFS; +#endif diff --git a/lib/init.c b/lib/init.c index 3880c6d..6adb878 100755 --- a/lib/init.c +++ b/lib/init.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -23,12 +24,15 @@ int main(int argc, char *argv[]) } + srand(time(NULL)); OBJECT obj = init_stuffs(startw,starth); STUFFS stuff = { startw, starth, false, + 0, + 0, &obj, }; @@ -47,9 +51,11 @@ int main(int argc, char *argv[]) } else if(e.type==SDL_MOUSEBUTTONUP){ stuff.mousedown=false; } + stuff.mx=e.button.x; + stuff.my=e.button.y; } draw(renderer,window,&stuff); - SDL_Delay(30); + SDL_Delay(10); } SDL_DestroyRenderer(renderer); diff --git a/lib/init.h b/lib/init.h index e957476..a4d9736 100755 --- a/lib/init.h +++ b/lib/init.h @@ -8,6 +8,8 @@ typedef struct{ int width; int height; bool mousedown; + int mx; + int my; OBJECT *obj; } STUFFS; #endif -- cgit v1.3