-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.h
106 lines (89 loc) · 3.58 KB
/
item.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**********************************************************************
* item.h - item (ball) declaration
*
* Copyright 1993, David Nedde
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is granted
* provided that the above copyright notice appears in all copies.
* It is provided "as is" without express or implied warranty.
**********************************************************************/
#ifndef __ITEM_H__
#define __ITEM_H__
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include "misc.h"
#include "intf.h"
#define MAX_COLORS 256
#ifndef ELASTICITY
#define ELASTICITY 90 /* Default */
#endif
/* Static data shared for all items */
typedef struct {
int width;
int height;
int half_width; /* Precalculated for copying pixmap offset */
int half_height;
double elasticity;
Bool ball_collide;
Bool perpetual;
Bool visible;
char * rgb_txt;
char * rgb_txt2;
Display * display;
Window window;
Pixel background;
GC gc;
Pixmap pixmaps[MAX_COLORS]; /* Holds all item drawings */
int num_colors; /* Holds number of colors/pixmaps used */
int curr_pixmap; /* Holds pixmap index to use for next item*/
} item_static_struct_type, *item_static_type;
typedef struct {
item_static_type static_data;
Display *display;
Window window;
intf x,y; /* Location of items center */
intf y_vel; /* vel < 0 means dropping, > 0 means climbing */
intf x_vel; /* vel < 0 means to left, > 0 means to right */
int rebounded; /* Used to determine if item collision */
/* had already been calculated for this item */
Bool shown; /* True if items image is visible */
Pixmap pixmap; /* Pixel map to use for drawing item */
} item_struct_type, *item_type;
item_type item__create(/* display, window, x, y, x_vel, y_vel*/);
void item__init(/*display, window, background*/);
Bool item__initted(/**/);
void item__destroy(/* item*/);
void item__draw(/* item*/);
void item__undraw(/* item, x, y*/);
void item__redraw(/* item*/);
void item__erase(/* item*/);
void item__redraw(/* item*/);
void item__move_pos(/* item, x, y*/);
void item__randomize(/* item, min_x_vel, max_x_vel, min_y_vel, max_y_vel*/);
void item__move(/* item, room, items*/);
void item__rebound_item(/* moved_item, fixed_item*/);
void item__set_elasticity_cb(/*w, datap_ptr, call_data*/);
int item__get_width(/**/);
int item__get_height(/**/);
void item__perpetual_mcb(/*w, item, call_data, extra*/);
void item__collide_mcb(/*w, item, call_data, extra*/);
void item__set_perpetual(/* set */);
void item__set_ball_collide(/* set*/);
void item__set_visible(/*visible*/);;
#ifdef DEBUG
void item__print(/* item */);
#endif
/* Inline functions */
#define item__set_x_vel( item, vel) ((item)->x_vel = int2intf(vel))
#define item__set_y_vel( item, vel) ((item)->y_vel = int2intf(vel))
#define item__get_x_vel( item) (intf2int((item)->x_vel))
#define item__get_y_vel( item) (intf2int((item)->y_vel))
#define item__get_x( item) (intf2int((item)->x))
#define item__get_y( item) (intf2int((item)->y))
#define item__erase( item) (item__undraw( (item), (item)->x, (item)->y))
#define item__stopped(item, room) \
(item->y_vel == 0) && \
(ABS(item->y) >= room__get_floor(room) - room__get_gravity(room)) && \
(item->x_vel == 0)
#endif