1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include <stdbool.h>
#include <vectorlib.c>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#define PROJECT_NAME "vectors-rand vec"
#define obj_n 1
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_INER *obj){
obj->pos.x = (float)w/2;
obj->pos.y = (float)h/2;
}
void init_stuffs(int w, int h, OBJECT_INER *objs, STUFFS *stuff){
constructor(w,h,&objs[0]);
}
void update(STUFFS *stuff){
Point rand_point = {RandomFloat(-1, 1),RandomFloat(-1, 1)};
point_set_mag(&rand_point, 1);
float random_mul = RandomFloat(50, 100);
point_mul(&rand_point,&(Point){.x = random_mul, .y = random_mul});
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.objs[0]->pos.x,stuff->obj.objs[0]->pos.y);
}
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);
SDL_RenderPresent(renderer);
}
#include <init.c>
|