From c5648c6959e9ab63406ab3907ae189da6fbead0e Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Fri, 20 Mar 2026 02:09:25 -0500 Subject: removed init.c and moved init-multi.c to init.c --- lib/global_objects.c | 72 -------------------------------------------------- lib/init-multi.c | 74 ---------------------------------------------------- lib/init-multi.h | 15 ----------- lib/init.c | 17 ++++++++---- lib/init.h | 2 +- lib/vectorlib.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 85 insertions(+), 167 deletions(-) delete mode 100644 lib/global_objects.c delete mode 100755 lib/init-multi.c delete mode 100755 lib/init-multi.h mode change 100755 => 100644 lib/init.c mode change 100755 => 100644 lib/init.h create mode 100644 lib/vectorlib.c (limited to 'lib') diff --git a/lib/global_objects.c b/lib/global_objects.c deleted file mode 100644 index 2e3f2fd..0000000 --- a/lib/global_objects.c +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef global_objects -#define global_objects - -#include -#include - -#define flaot float - -typedef struct { - float x; - float y; -} Point; - -void point_add(Point *A, Point *B){ - A->x = A->x + B->x; - A->y = A->y + B->y; -} - -void point_sub(Point *A, Point *B){ - A->x = A->x - B->x; - A->y = A->y - B->y; -} - -void point_mul(Point *A, Point *B){ - A->x = A->x * B->x; - 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))); -} - -void point_set_mag(Point *point, float mag){ - flaot getmag = magnitude(point->x, point->y); - flaot rx = (point->x / getmag) * mag; - flaot ry = (point->y / getmag) * mag; - - point->x = rx; - 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; -} - -float constrain(float val, float min, float max){ - if(val > max) val=max; - else if(val < min) val=min; - return val; -} - -#endif diff --git a/lib/init-multi.c b/lib/init-multi.c deleted file mode 100755 index 734835c..0000000 --- a/lib/init-multi.c +++ /dev/null @@ -1,74 +0,0 @@ -#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=600; - int starth=600; - - 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_INER obj_storage[obj_n]; - - STUFFS stuff = { - startw, - starth, - false, - 0, - 0, - (OBJECT){}, - }; - - init_stuffs(startw,starth,obj_storage,&stuff); - - - for (int i = 0; i < obj_n; i++) - stuff.obj.objs[i] = &obj_storage[i]; - - SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); - - 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 deleted file mode 100755 index 72bb366..0000000 --- a/lib/init-multi.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef inithell -#define inithell - -#include -#include - -typedef struct{ - int width; - int height; - bool mousedown; - int mx; - int my; - OBJECT obj; -} STUFFS; -#endif diff --git a/lib/init.c b/lib/init.c old mode 100755 new mode 100644 index 6adb878..5e32a4b --- a/lib/init.c +++ b/lib/init.c @@ -11,8 +11,8 @@ 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; + int startw=600; + int starth=600; SDL_Window *window = SDL_CreateWindow(PROJECT_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, startw, starth, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); if (!window) { @@ -23,9 +23,8 @@ int main(int argc, char *argv[]) printf("Failed to create renderer: %s\n", SDL_GetError()); } - srand(time(NULL)); - OBJECT obj = init_stuffs(startw,starth); + OBJECT_INER obj_storage[obj_n]; STUFFS stuff = { startw, @@ -33,9 +32,17 @@ int main(int argc, char *argv[]) false, 0, 0, - &obj, + (OBJECT){}, }; + init_stuffs(startw,starth,obj_storage,&stuff); + + + for (int i = 0; i < obj_n; i++) + stuff.obj.objs[i] = &obj_storage[i]; + + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); + bool quit = false; SDL_Event e; while (!quit) { diff --git a/lib/init.h b/lib/init.h old mode 100755 new mode 100644 index a4d9736..72bb366 --- a/lib/init.h +++ b/lib/init.h @@ -10,6 +10,6 @@ typedef struct{ bool mousedown; int mx; int my; - OBJECT *obj; + OBJECT obj; } STUFFS; #endif diff --git a/lib/vectorlib.c b/lib/vectorlib.c new file mode 100644 index 0000000..2e3f2fd --- /dev/null +++ b/lib/vectorlib.c @@ -0,0 +1,72 @@ +#ifndef global_objects +#define global_objects + +#include +#include + +#define flaot float + +typedef struct { + float x; + float y; +} Point; + +void point_add(Point *A, Point *B){ + A->x = A->x + B->x; + A->y = A->y + B->y; +} + +void point_sub(Point *A, Point *B){ + A->x = A->x - B->x; + A->y = A->y - B->y; +} + +void point_mul(Point *A, Point *B){ + A->x = A->x * B->x; + 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))); +} + +void point_set_mag(Point *point, float mag){ + flaot getmag = magnitude(point->x, point->y); + flaot rx = (point->x / getmag) * mag; + flaot ry = (point->y / getmag) * mag; + + point->x = rx; + 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; +} + +float constrain(float val, float min, float max){ + if(val > max) val=max; + else if(val < min) val=min; + return val; +} + +#endif -- cgit v1.3