xlib_playground

Xlib playground for experiments.
Log | Files | Refs

main.h (2258B)


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