aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoriceyrazor <iceyrazor@mailfence.com>2026-02-08 04:07:36 -0600
committericeyrazor <iceyrazor@mailfence.com>2026-02-08 04:07:36 -0600
commit82f4a3b8acfd5677762fd8cb00922fd32c102fef (patch)
treeaa9fa91ee341edc4d54e7b960301d1bfa3d7c0c3 /lib
a janky init
Diffstat (limited to 'lib')
-rw-r--r--lib/global_objects.c55
-rwxr-xr-xlib/init.c61
-rwxr-xr-xlib/init.h13
3 files changed, 129 insertions, 0 deletions
diff --git a/lib/global_objects.c b/lib/global_objects.c
new file mode 100644
index 0000000..e6f8de5
--- /dev/null
+++ b/lib/global_objects.c
@@ -0,0 +1,55 @@
+#ifndef global_objects
+#define global_objects
+
+#include <math.h>
+
+#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;
+}
+
+/*
+fn set_mag(x: &f64,y: &f64, mag: &f64) -> Vec<f64>{
+ let getmag: f64 = magnitude(*x, *y);
+ let rx = (*x / getmag) * mag;
+ let ry = (*y / getmag) * mag;
+
+ return vec![rx,ry]
+}
+
+fn magnitude(x: f64,y: f64) -> f64 {
+ ((x).powi(2) + (y).powi(2)).sqrt()
+}
+*/
+
+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;
+}
+
+#endif
diff --git a/lib/init.c b/lib/init.c
new file mode 100755
index 0000000..6c4f314
--- /dev/null
+++ b/lib/init.c
@@ -0,0 +1,61 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include "init.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());
+ }
+
+
+ OBJECT obj = init_stuffs(startw,starth);
+
+ STUFFS stuff = {
+ startw,
+ starth,
+ false,
+ &obj,
+ };
+
+ 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;
+ }
+ }
+ draw(renderer,window,&stuff);
+ SDL_Delay(30);
+ }
+
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ SDL_Quit();
+
+ return 0;
+}
diff --git a/lib/init.h b/lib/init.h
new file mode 100755
index 0000000..e957476
--- /dev/null
+++ b/lib/init.h
@@ -0,0 +1,13 @@
+#ifndef inithell
+#define inithell
+
+#include <stdio.h>
+#include <stdbool.h>
+
+typedef struct{
+ int width;
+ int height;
+ bool mousedown;
+ OBJECT *obj;
+} STUFFS;
+#endif