aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoriceyrazor <iceyrazor@mailfence.com>2026-02-08 20:01:32 -0600
committericeyrazor <iceyrazor@mailfence.com>2026-02-08 20:01:32 -0600
commite06ab8f76be21b866207a708f1336a5c1a53f149 (patch)
treebb0e53dd6b0fd3906ab53e0b292e56c735a7cbec /lib
parentce57691f9631e5a08a82221634898b5ce58b7a5e (diff)
gfx and 2-2 and multi objects
Diffstat (limited to 'lib')
-rw-r--r--lib/global_objects.c25
-rwxr-xr-xlib/init-multi.c71
-rwxr-xr-xlib/init-multi.h15
-rwxr-xr-xlib/init.c8
-rwxr-xr-xlib/init.h2
5 files changed, 120 insertions, 1 deletions
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 <math.h>
+#include <stdlib.h>
#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 <stdio.h>
+#include <stdbool.h>
+#include <time.h>
+#include <init-multi.h>
+
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_video.h>
+
+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 <stdio.h>
+#include <stdbool.h>
+
+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 <stdio.h>
#include <stdbool.h>
+#include <time.h>
#include <init.h>
#include <SDL2/SDL.h>
@@ -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