main.h (2157B)
1 /* 2 * util.c 3 */ 4 enum object_shape { 5 SRECTANGLE, 6 STRIANGLE, 7 SCIRCLE, 8 }; 9 10 struct Point { 11 float x; 12 float y; 13 }; 14 15 struct Rectangle { // origin is top left corner 16 int w, h; 17 }; 18 19 struct Triangle { 20 struct Point v2; 21 struct Point v3; 22 }; 23 24 struct Circle { // origin is center 25 float r; 26 }; 27 28 union Body { 29 struct Circle circle; 30 struct Triangle triangle; 31 struct Rectangle rectangle; 32 }; 33 34 struct Object { 35 enum object_shape shape; 36 struct Point pp; 37 struct Point p; 38 struct Point v; 39 struct Point a; 40 union Body body; 41 int m; 42 }; 43 44 struct OH { 45 struct OL *first; 46 }; 47 48 /* 49 * linked list which starts with OH and 50 * terminates with ->next == NULL 51 */ 52 struct OL { 53 struct Object *o; 54 struct OL *next; 55 }; 56 struct OH *create_ol(void); 57 void free_ol(struct OH *); 58 void free_obj_and_ol(struct OH *); 59 void append_ol(struct OH *, struct Object *); 60 void swap_ol(struct OL *, struct OL *); 61 void sort_ol(struct OH *, struct Object *); 62 int object_dist(struct Object *, struct Object *); 63 64 struct rect { 65 struct Point pp; 66 struct Point p; 67 struct Point v; 68 struct Point a; 69 int w, h; 70 int m; 71 }; 72 73 struct circle { 74 struct Point pp; 75 struct Point p; 76 struct Point v; 77 struct Point a; 78 int r; 79 int m; 80 }; 81 82 int test_collision(struct Object *, struct Object *); // 1 if collide, 0 if not 83 void next_tick(struct Object *o, long); 84 void handle_collision_mf(struct Object *, struct Object *); 85 int object_is_falling(struct Object *o, struct Object *fb, int num_f); 86 struct Object *create_object(float, float, float, float, float, float, 87 int, int, int); 88 int is_on_floor_before(struct Object *, struct Object *); 89 /* 90 * x.c 91 */ 92 enum event_type { 93 XKEYPRESS, 94 XKEYRELEASE, 95 XEXPOSE, 96 XWINDEL, 97 NOEVENT, 98 }; 99 100 int x_setup_window(int, int, unsigned int, unsigned int, unsigned long, char *); 101 void x_clear_area(void); 102 void x_draw_string(unsigned long color, int x, int y, const char *str, int length); 103 void x_draw_rectangle(unsigned long color, int x, int y, 104 unsigned int w, unsigned int h); 105 void x_flush(void); 106 void x_clean_up(void); 107 int x_next_event(char *c); 108 int x_pending(void); 109 void x_get_win_wh(int *, int *);