object.h (1461B)
1 // include list.h before this file 2 3 enum object_shape { 4 SRECTANGLE, 5 STRIANGLE, 6 SCIRCLE, 7 }; 8 9 enum object_type { 10 TPLAYER, 11 TBLOCK, 12 TENEMY, 13 TFLAG, 14 NUM_OBJ_TYPE, 15 }; 16 17 typedef struct Point { 18 float x; 19 float y; 20 } Point; 21 22 typedef struct Rectangle { // origin is top left corner 23 int w, h; 24 } Rectangle; 25 26 typedef struct Triangle { 27 Point v2; 28 Point v3; 29 } Triangle; 30 31 typedef struct Circle { // origin is center 32 float r; 33 } Circle; 34 35 union Body { 36 Circle circle; 37 Triangle triangle; 38 Rectangle rectangle; 39 }; 40 41 typedef struct Object { 42 enum object_type type; 43 enum object_shape shape; 44 uint32_t color; 45 Point pp; 46 Point p; 47 Point v; 48 Point a; 49 union Body body; 50 int m; 51 int on_floor; 52 void (*next_tick)(struct Object *, long); 53 } Object; 54 55 extern void (* col_func[NUM_OBJ_TYPE][NUM_OBJ_TYPE])(Object *, Object *); 56 57 int object_dist(Object *, Object *); 58 void ohandle_collision(Object *, Object *); 59 int test_collision(Object *, Object *); // 1 if collide, 0 if not 60 void o_next_tick(Object *o, long); 61 void handle_collision_mf(Object *, Object *); 62 Object *create_object(enum object_type, uint32_t, 63 float, float, float, float, float, float, 64 int, int, int, 65 void (*)(Object *, long)); 66 void free_object(Object *); 67 int get_obj_count(void); 68 int get_lld_count(void); 69 int is_on_floor(Object *, Object *); 70 int is_on_floor_before(Object *, Object *); 71 void oprint(Object *); 72 73 void lhandle_collision(List *);