aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriceyrazor <iceyrazor@mailfence.com>2026-03-20 02:09:25 -0500
committericeyrazor <iceyrazor@mailfence.com>2026-03-20 02:09:25 -0500
commitc5648c6959e9ab63406ab3907ae189da6fbead0e (patch)
tree2003e86c41ad0eedd5fd8af49cc025ceaf703c74
parentd52cdf58241e476f64be98d2d8b1b03825d7edfd (diff)
removed init.c and moved init-multi.c to init.c
-rwxr-xr-xbuild.sh8
-rwxr-xr-xlib/init-multi.c74
-rwxr-xr-xlib/init-multi.h15
-rw-r--r--[-rwxr-xr-x]lib/init.c17
-rw-r--r--[-rwxr-xr-x]lib/init.h2
-rw-r--r--lib/vectorlib.c (renamed from lib/global_objects.c)0
-rw-r--r--[-rwxr-xr-x]src/1-1-walker.c28
-rw-r--r--[-rwxr-xr-x]src/1-2-vec-math.c30
-rw-r--r--[-rwxr-xr-x]src/1-3-rand-vec.c28
-rw-r--r--[-rwxr-xr-x]src/1-5-unit-vec.c22
-rw-r--r--[-rwxr-xr-x]src/1-6-mover.c40
-rw-r--r--[-rwxr-xr-x]src/2-1-gravity-wind.c68
-rw-r--r--[-rwxr-xr-x]src/2-2-mass-accel.c10
-rw-r--r--[-rwxr-xr-x]src/2-3-friction.c6
-rw-r--r--[-rwxr-xr-x]src/2-4-drag.c6
-rw-r--r--[-rwxr-xr-x]src/2-5-grav-attraction.c10
16 files changed, 131 insertions, 233 deletions
diff --git a/build.sh b/build.sh
index 2c3d3b9..e32a8cb 100755
--- a/build.sh
+++ b/build.sh
@@ -13,15 +13,15 @@ done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
-if [[ "$1" ]]; then
- echo making src/$1
+if [ "$1" ]; then
+ echo "making src/$1"
file="src/$1"
clang -o bin/$(basename $file | sed 's/.c$//') $file $LIB `sdl2-config --cflags --libs` -lm $DEBUG
else
for file in src/*; do
if [ -f "$file" ]; then
- if [[ "$file" != ".clangd" ]]; then
- echo making $file
+ if [ "$file" != ".clangd" ]; then
+ echo "making $file"
clang -o bin/$(basename $file | sed 's/.c$//') $file $LIB `sdl2-config --cflags --libs` -lm $DEBUG
fi
fi
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 <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=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 <stdio.h>
-#include <stdbool.h>
-
-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
index 6adb878..5e32a4b 100755..100644
--- 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
index a4d9736..72bb366 100755..100644
--- 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/global_objects.c b/lib/vectorlib.c
index 2e3f2fd..2e3f2fd 100644
--- a/lib/global_objects.c
+++ b/lib/vectorlib.c
diff --git a/src/1-1-walker.c b/src/1-1-walker.c
index ba8f696..5b3d0e1 100755..100644
--- a/src/1-1-walker.c
+++ b/src/1-1-walker.c
@@ -5,32 +5,34 @@
#include <SDL2/SDL_video.h>
#define PROJECT_NAME "vectors-walker"
+#define obj_n 1
-typedef struct {
+typedef struct OBJECT_INER {
float x;
float y;
+} OBJECT_INER;
+
+typedef struct OBJECT {
+ OBJECT_INER *objs[obj_n];
} OBJECT;
#include <init.h>
-void constructor(int w, int h, OBJECT *obj){
+void constructor(int w, int h, OBJECT_INER *obj){
obj->x = (float)w/2;
obj->y = (float)h/2;
}
-OBJECT init_stuffs(int w, int h){
- OBJECT obj;
- constructor(w,h,&obj);
-
- return obj;
+void init_stuffs(int w, int h, OBJECT_INER *objs, STUFFS *stuff){
+ constructor(w,h,&objs[0]);
}
-void update(OBJECT *obj){
+void update(OBJECT_INER *obj){
obj->x = obj->x + (rand() % 2 - 0.5);
obj->y = obj->y + (rand() % 2 - 0.5);
}
-void show(SDL_Renderer* renderer,OBJECT *obj){
+void show(SDL_Renderer* renderer,OBJECT_INER *obj){
SDL_SetRenderDrawColor(renderer,150,50,255,255);
SDL_RenderDrawPoint(renderer,obj->x,obj->y);
}
@@ -39,15 +41,11 @@ void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
//SDL_SetRenderDrawColor(renderer,0,0,0,255);
//SDL_RenderClear(renderer);
- update(stuff->obj);
- show(renderer,stuff->obj);
+ update(stuff->obj.objs[0]);
+ show(renderer,stuff->obj.objs[0]);
SDL_RenderPresent(renderer);
//SDL_UpdateWindowSurface(window);
}
-void mousePressed(STUFFS *stuff){
-
-}
-
#include <init.c>
diff --git a/src/1-2-vec-math.c b/src/1-2-vec-math.c
index 201bbc0..b4e2c1e 100755..100644
--- a/src/1-2-vec-math.c
+++ b/src/1-2-vec-math.c
@@ -1,37 +1,39 @@
#include <stdbool.h>
-#include <global_objects.c>
+#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#define PROJECT_NAME "vectors-vec math"
+#define obj_n 1
-typedef struct {
+typedef struct OBJECT_INER {
Point pos;
Point vel;
+} OBJECT_INER;
+
+typedef struct OBJECT {
+ OBJECT_INER *objs[obj_n];
} OBJECT;
#include <init.h>
-void constructor(int w, int h, OBJECT *obj){
+void constructor(int w, int h, OBJECT_INER *obj){
obj->pos.x = (float)w/2;
obj->pos.y = (float)h/2;
obj->vel.x = 1;
obj->vel.y = -1;
}
-OBJECT init_stuffs(int w, int h){
- OBJECT obj;
- constructor(w,h,&obj);
-
- return obj;
+void init_stuffs(int w, int h, OBJECT_INER *objs, STUFFS *stuff){
+ constructor(w,h,&objs[0]);
}
-void update(OBJECT *obj){
+void update(OBJECT_INER *obj){
point_add(&obj->pos, &obj->vel);
}
-void show(SDL_Renderer* renderer,OBJECT *obj){
+void show(SDL_Renderer* renderer,OBJECT_INER *obj){
SDL_SetRenderDrawColor(renderer,150,50,255,255);
SDL_RenderFillRect(renderer,&(SDL_Rect){.x = obj->pos.x - 5, .y=obj->pos.y - 5, .w = 10, .h = 10});
}
@@ -40,14 +42,10 @@ void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
SDL_SetRenderDrawColor(renderer,0,0,0,255);
SDL_RenderClear(renderer);
- update(stuff->obj);
- show(renderer,stuff->obj);
+ update(stuff->obj.objs[0]);
+ show(renderer,stuff->obj.objs[0]);
SDL_RenderPresent(renderer);
}
-void mousePressed(STUFFS *stuff){
-
-}
-
#include <init.c>
diff --git a/src/1-3-rand-vec.c b/src/1-3-rand-vec.c
index a5289d5..992a81a 100755..100644
--- a/src/1-3-rand-vec.c
+++ b/src/1-3-rand-vec.c
@@ -1,27 +1,29 @@
#include <stdbool.h>
-#include <global_objects.c>
+#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#define PROJECT_NAME "vectors-rand vec"
+#define obj_n 1
-typedef struct {
+typedef struct OBJECT_INER {
Point pos;
+} OBJECT_INER;
+
+typedef struct OBJECT {
+ OBJECT_INER *objs[obj_n];
} OBJECT;
#include <init.h>
-void constructor(int w, int h, OBJECT *obj){
+void constructor(int w, int h, OBJECT_INER *obj){
obj->pos.x = (float)w/2;
obj->pos.y = (float)h/2;
}
-OBJECT init_stuffs(int w, int h){
- OBJECT obj;
- constructor(w,h,&obj);
-
- return obj;
+void init_stuffs(int w, int h, OBJECT_INER *objs, STUFFS *stuff){
+ constructor(w,h,&objs[0]);
}
void update(STUFFS *stuff){
@@ -31,14 +33,14 @@ void update(STUFFS *stuff){
float random_mul = RandomFloat(50, 100);
point_mul(&rand_point,&(Point){.x = random_mul, .y = random_mul});
- stuff->obj->pos.x = rand_point.x + (float)stuff->width / 2;;
- stuff->obj->pos.y = rand_point.y + (float)stuff->height / 2;
+ stuff->obj.objs[0]->pos.x = rand_point.x + (float)stuff->width / 2;;
+ stuff->obj.objs[0]->pos.y = rand_point.y + (float)stuff->height / 2;
}
void show(SDL_Renderer* renderer,STUFFS *stuff){
SDL_SetRenderDrawColor(renderer,150,50,255,255);
//SDL_RenderFillRect(renderer,&(SDL_Rect){.x = obj->pos.x - 5, .y=obj->pos.y - 5, .w = 10, .h = 10});
- SDL_RenderDrawLine(renderer,stuff->width/2,stuff->height/2,stuff->obj->pos.x,stuff->obj->pos.y);
+ SDL_RenderDrawLine(renderer,stuff->width/2,stuff->height/2,stuff->obj.objs[0]->pos.x,stuff->obj.objs[0]->pos.y);
}
void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
@@ -51,8 +53,4 @@ void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
SDL_RenderPresent(renderer);
}
-void mousePressed(STUFFS *stuff){
-
-}
-
#include <init.c>
diff --git a/src/1-5-unit-vec.c b/src/1-5-unit-vec.c
index b888b13..1f3acbb 100755..100644
--- a/src/1-5-unit-vec.c
+++ b/src/1-5-unit-vec.c
@@ -1,27 +1,29 @@
#include <stdbool.h>
-#include <global_objects.c>
+#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#define PROJECT_NAME "vectors-unit vec"
+#define obj_n 1
typedef struct {
Point pos;
+} OBJECT_INER;
+
+typedef struct OBJECT {
+ OBJECT_INER *objs[obj_n];
} OBJECT;
#include <init.h>
-void constructor(int w, int h, OBJECT *obj){
+void constructor(int w, int h, OBJECT_INER *obj){
obj->pos.x = (float)w/2;
obj->pos.y = (float)h/2;
}
-OBJECT init_stuffs(int w, int h){
- OBJECT obj;
- constructor(w,h,&obj);
-
- return obj;
+void init_stuffs(int w, int h, OBJECT_INER *objs, STUFFS *stuff){
+ constructor(w,h,&objs[0]);
}
void normalize(Point *p){
@@ -32,7 +34,7 @@ void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
SDL_SetRenderDrawColor(renderer,0,0,0,255);
SDL_RenderClear(renderer);
- Point pos = { 200,200 };
+ Point pos = { 300,300 };
Point mouse = {stuff->mx, stuff->my};
Point v = {
@@ -55,8 +57,4 @@ void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
SDL_RenderPresent(renderer);
}
-void mousePressed(STUFFS *stuff){
-
-}
-
#include <init.c>
diff --git a/src/1-6-mover.c b/src/1-6-mover.c
index d4535d5..a59fa91 100755..100644
--- a/src/1-6-mover.c
+++ b/src/1-6-mover.c
@@ -1,22 +1,27 @@
#include <stdlib.h>
#include <stdbool.h>
-#include <global_objects.c>
+#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#include <time.h>
#define PROJECT_NAME "vectors-mover"
+#define obj_n 1
typedef struct {
Point pos;
Point vel;
Point acc;
+} OBJECT_INER;
+
+typedef struct OBJECT {
+ OBJECT_INER *objs[obj_n];
} OBJECT;
#include <init.h>
-void constructor(int w, int h, OBJECT *obj){
+void constructor(int w, int h, OBJECT_INER *obj){
obj->pos.x = (float)w/2;
obj->pos.y = (float)h/2;
obj->vel.x = RandomFloat(-1, 1);
@@ -27,12 +32,9 @@ void constructor(int w, int h, OBJECT *obj){
point_set_mag(&obj->acc, 0.01);
}
-OBJECT init_stuffs(int w, int h){
+void init_stuffs(int w, int h, OBJECT_INER *objs, STUFFS *stuff){
srand(time(NULL));
- OBJECT obj;
- constructor(w,h,&obj);
-
- return obj;
+ constructor(w,h,&objs[0]);
}
Point vec_sub(Point A, Point B){
@@ -40,41 +42,37 @@ Point vec_sub(Point A, Point B){
return A;
}
-void update(STUFFS *stuff){
+void update(STUFFS *stuff, OBJECT_INER *obj){
Point mouse = {
stuff->mx,
stuff->my,
};
- stuff->obj->acc = vec_sub(mouse, stuff->obj->pos);
- point_set_mag(&stuff->obj->acc, 1);
+ obj->acc = vec_sub(mouse, obj->pos);
+ point_set_mag(&obj->acc, 1);
//stuff->obj->acc.x = RandomFloat(-1, 1);
//stuff->obj->acc.y = RandomFloat(-1, 1);
- point_add(&stuff->obj->vel,&stuff->obj->acc);
- point_limit(&stuff->obj->vel, 5);
+ point_add(&obj->vel,&obj->acc);
+ point_limit(&obj->vel, 5);
- point_add(&stuff->obj->pos, &stuff->obj->vel);
+ point_add(&obj->pos, &obj->vel);
}
-void show(SDL_Renderer* renderer,STUFFS *stuff){
+void show(SDL_Renderer* renderer,OBJECT_INER *obj){
SDL_SetRenderDrawColor(renderer,150,50,255,255);
- SDL_RenderFillRect(renderer,&(SDL_Rect){.x = stuff->obj->pos.x - 5, .y=stuff->obj->pos.y - 5, .w = 10, .h = 10});
+ SDL_RenderFillRect(renderer,&(SDL_Rect){.x = obj->pos.x - 5, .y=obj->pos.y - 5, .w = 10, .h = 10});
}
void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
SDL_SetRenderDrawColor(renderer,0,0,0,255);
SDL_RenderClear(renderer);
- update(stuff);
- show(renderer,stuff);
+ update(stuff, stuff->obj.objs[0]);
+ show(renderer,stuff->obj.objs[0]);
SDL_RenderPresent(renderer);
}
-void mousePressed(STUFFS *stuff){
-
-}
-
#include <init.c>
diff --git a/src/2-1-gravity-wind.c b/src/2-1-gravity-wind.c
index a5a2bb2..8e3be27 100755..100644
--- a/src/2-1-gravity-wind.c
+++ b/src/2-1-gravity-wind.c
@@ -1,23 +1,28 @@
#include <stdlib.h>
#include <stdbool.h>
-#include <global_objects.c>
+#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#include <time.h>
#define PROJECT_NAME "vectors-gravity wind"
+#define obj_n 1
typedef struct {
Point pos;
Point vel;
Point acc;
float r;
+} OBJECT_INER;
+
+typedef struct OBJECT {
+ OBJECT_INER *objs[obj_n];
} OBJECT;
#include <init.h>
-void constructor(int w, int h, OBJECT *obj){
+void constructor(int w, int h, OBJECT_INER *obj){
obj->pos.x = (float)w/2;
obj->pos.y = (float)h/2;
obj->vel = (Point){0,0};
@@ -25,12 +30,9 @@ void constructor(int w, int h, OBJECT *obj){
obj->r = 40;
}
-OBJECT init_stuffs(int w, int h){
+void init_stuffs(int w, int h, OBJECT_INER *objs, STUFFS *stuff){
srand(time(NULL));
- OBJECT obj;
- constructor(w,h,&obj);
-
- return obj;
+ constructor(w,h,&objs[0]);
}
Point vec_sub(Point A, Point B){
@@ -38,42 +40,42 @@ Point vec_sub(Point A, Point B){
return A;
}
-void applyForce(OBJECT *obj, Point force){
+void applyForce(OBJECT_INER *obj, Point force){
point_add(&obj->acc, &force);
}
-void edges(STUFFS *stuff) {
- if (stuff->obj->pos.y >= stuff->height - stuff->obj->r / 2){
- stuff->obj->pos.y = stuff->height - stuff->obj->r / 2;
- stuff->obj->vel.y = stuff->obj->vel.y * -1;
+void edges(STUFFS *stuff, OBJECT_INER *obj) {
+ if (obj->pos.y >= stuff->height - obj->r / 2){
+ obj->pos.y = stuff->height - obj->r / 2;
+ obj->vel.y = obj->vel.y * -1;
}
- if (stuff->obj->pos.x >= stuff->width - stuff->obj->r / 2){
- stuff->obj->pos.x = stuff->width - stuff->obj->r / 2;
- stuff->obj->vel.x = stuff->obj->vel.x * -1;
- } else if (stuff->obj->pos.x <= stuff->obj->r / 2){
- stuff->obj->pos.x = stuff->obj->r / 2;
- stuff->obj->vel.x = stuff->obj->vel.x * -1;
+ if (obj->pos.x >= stuff->width - obj->r / 2){
+ obj->pos.x = stuff->width - obj->r / 2;
+ obj->vel.x = obj->vel.x * -1;
+ } else if (obj->pos.x <= obj->r / 2){
+ obj->pos.x = obj->r / 2;
+ obj->vel.x = obj->vel.x * -1;
}
}
-void update(STUFFS *stuff){
+void update(STUFFS *stuff, OBJECT_INER *obj){
//Point mouse = {
// stuff->mx,
// stuff->my,
//};
- //stuff->obj->acc = vec_sub(mouse, stuff->obj->pos);
- //point_set_mag(&stuff->obj->acc, 0.1);
+ //obj->acc = vec_sub(mouse, obj->pos);
+ //point_set_mag(&obj->acc, 0.1);
- point_add(&stuff->obj->vel,&stuff->obj->acc);
- point_add(&stuff->obj->pos, &stuff->obj->vel);
- stuff->obj->acc = (Point){0,0};
+ point_add(&obj->vel,&obj->acc);
+ point_add(&obj->pos, &obj->vel);
+ obj->acc = (Point){0,0};
}
-void show(SDL_Renderer* renderer,STUFFS *stuff){
+void show(SDL_Renderer* renderer,OBJECT_INER *obj){
SDL_SetRenderDrawColor(renderer,150,50,255,255);
- SDL_RenderFillRect(renderer,&(SDL_Rect){.x = stuff->obj->pos.x - (stuff->obj->r / 2), .y=stuff->obj->pos.y - (stuff->obj->r / 2), .w = stuff->obj->r, .h = stuff->obj->r});
+ SDL_RenderFillRect(renderer,&(SDL_Rect){.x = obj->pos.x - (obj->r / 2), .y=obj->pos.y - (obj->r / 2), .w = obj->r, .h = obj->r});
}
void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
@@ -82,22 +84,18 @@ void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
if(stuff->mousedown == true){
Point wind = {0.1, 0};
- applyForce(stuff->obj, wind);
+ applyForce(stuff->obj.objs[0], wind);
}
Point gravity = {0, 0.2};
- applyForce(stuff->obj, gravity);
+ applyForce(stuff->obj.objs[0], gravity);
- update(stuff);
- edges(stuff);
- show(renderer,stuff);
+ update(stuff,stuff->obj.objs[0]);
+ edges(stuff,stuff->obj.objs[0]);
+ show(renderer,stuff->obj.objs[0]);
SDL_RenderPresent(renderer);
}
-void mousePressed(STUFFS *stuff){
-
-}
-
#include <init.c>
diff --git a/src/2-2-mass-accel.c b/src/2-2-mass-accel.c
index 48b1784..1281433 100755..100644
--- a/src/2-2-mass-accel.c
+++ b/src/2-2-mass-accel.c
@@ -1,5 +1,5 @@
#include <stdbool.h>
-#include <global_objects.c>
+#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
@@ -20,7 +20,7 @@ typedef struct OBJECT {
OBJECT_INER *objs[obj_n];
} OBJECT;
-#include <init-multi.h>
+#include <init.h>
void constructor(int w, int h, OBJECT_INER *obj, float x, float y, float mass){
obj->pos.x = (float)w/2 + x;
@@ -103,8 +103,4 @@ void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
SDL_RenderPresent(renderer);
}
-void mousePressed(STUFFS *stuff){
-
-}
-
-#include <init-multi.c>
+#include <init.c>
diff --git a/src/2-3-friction.c b/src/2-3-friction.c
index d78fc8e..974b19e 100755..100644
--- a/src/2-3-friction.c
+++ b/src/2-3-friction.c
@@ -1,5 +1,5 @@
#include <stdbool.h>
-#include <global_objects.c>
+#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
@@ -22,7 +22,7 @@ typedef struct OBJECT {
float mu=0.1;
-#include <init-multi.h>
+#include <init.h>
void constructor(int w, int h, OBJECT_INER *obj, float x, float y, float mass){
obj->pos.x = x;
@@ -130,4 +130,4 @@ void mousePressed(STUFFS *stuff){
}
-#include <init-multi.c>
+#include <init.c>
diff --git a/src/2-4-drag.c b/src/2-4-drag.c
index 503af42..1bcbe17 100755..100644
--- a/src/2-4-drag.c
+++ b/src/2-4-drag.c
@@ -1,6 +1,6 @@
#include <SDL2/SDL_render.h>
#include <stdbool.h>
-#include <global_objects.c>
+#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
@@ -23,7 +23,7 @@ typedef struct OBJECT {
float DragC = 0.2;
-#include <init-multi.h>
+#include <init.h>
void constructor(int w, int h, OBJECT_INER *obj, float x, float y, float mass){
obj->pos.x = x;
@@ -132,7 +132,7 @@ void mousePressed(STUFFS *stuff){
}
-#include <init-multi.c>
+#include <init.c>
/* Exercises
diff --git a/src/2-5-grav-attraction.c b/src/2-5-grav-attraction.c
index 89ee28a..e4e0313 100755..100644
--- a/src/2-5-grav-attraction.c
+++ b/src/2-5-grav-attraction.c
@@ -1,6 +1,6 @@
#include <SDL2/SDL_render.h>
#include <stdbool.h>
-#include <global_objects.c>
+#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
@@ -28,7 +28,7 @@ typedef struct OBJECT {
OBJECT_INER *objs[obj_n];
} OBJECT;
-#include <init-multi.h>
+#include <init.h>
void constructor(int w, int h, OBJECT_INER *obj, float x, float y, float mass){
obj->pos.x = x;
@@ -107,8 +107,4 @@ void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
SDL_RenderPresent(renderer);
}
-void mousePressed(STUFFS *stuff){
-
-}
-
-#include <init-multi.c>
+#include <init.c>