14 static list_t
*listLayer
;
16 static bool_t isLayerInit
= FALSE
;
18 bool_t
layer_is_inicialized()
24 * Initialize global list of the layers
28 listLayer
= list_new();
33 * Add image to queue for rendering
34 * *img - image to be rendered
35 * x,y - coordinates where to draw the image
36 * w,h - width and height of rendered part of image
37 * px,py - coordinates of upper left corner of rendered part of image
38 * layer - on which layer to draw
39 * [0] - under Tuxanek; [1] same as Tuxanek; [2] over Tuxanek
41 void addLayer(image_t
*img
, int x
, int y
, int px
, int py
, int w
, int h
, int player
)
51 new = malloc(sizeof(layer_t
));
61 new_value
= player
* WINDOW_SIZE_Y
+ y
+ h
;
63 /* here we are sure, that we want to insert it somewhere else than the begining */
64 for (i
= 0; i
< listLayer
->count
; i
++) {
65 actual
= list_get(listLayer
, i
);
67 actual_value
= actual
->layer
* WINDOW_SIZE_Y
+ actual
->y
+ actual
->h
;
69 if (actual_value
> new_value
) {
70 list_ins(listLayer
, i
, new);
75 list_add(listLayer
, new);
79 * Draws all items onto the screen according to the layer and coordinate Y+H
80 * After drawing frees the list
87 for (i
= 0; i
< listLayer
->count
; i
++) {
88 this = (layer_t
*) listLayer
->list
[i
];
90 image_draw(this->image
, this->x
, this->y
, this->px
, this->py
, this->w
, this->h
);
93 /*printf("listLayer->count = %d\n", listLayer->count);*/
95 list_destroy_item(listLayer
, free
);
96 listLayer
= list_new();
99 void layer_draw_center(int x
, int y
)
102 int screen_x
, screen_y
;
106 arena_get_center_screen(&screen_x
, &screen_y
, x
, y
, WINDOW_SIZE_X
, WINDOW_SIZE_Y
);
108 for (i
= 0; i
< listLayer
->count
; i
++) {
109 this = (layer_t
*) listLayer
->list
[i
];
111 if (this->x
+ this->w
< screen_x
||
112 this->x
> screen_x
+ WINDOW_SIZE_X
||
113 this->y
+ this->h
< screen_y
||
114 this->y
> screen_y
+ WINDOW_SIZE_Y
) {
119 image_draw(this->image
, this->x
- screen_x
, this->y
- screen_y
,
120 this->px
, this->py
, this->w
, this->h
);
122 /*printf("%d %d\n", this->x - screen_x, this->y - screen_y);*/
125 /*printf("count = %d\n", count);*/
127 list_destroy_item(listLayer
, free
);
128 listLayer
= list_new();
131 void layer_draw_slpit(int local_x
, int local_y
, int x
, int y
, int w
, int h
)
137 for (i
= 0; i
< listLayer
->count
; i
++) {
138 this = (layer_t
*) listLayer
->list
[i
];
140 if (this->x
+ this->w
< x
|| this->x
> x
+ w
||
141 this->y
+ this->h
< y
|| this->y
> y
+ h
) {
147 if (local_x
+ (this->x
- x
) < local_x
) {
150 z
= local_x
- (local_x
+ (this->x
- x
));
157 if (local_x
+ (this->x
- x
) + this->w
> local_x
+ w
) {
158 this->w
-= (local_x
+ (this->x
- x
) + this->w
) - (local_x
+ w
);
161 if (local_y
+ (this->y
- y
) < local_y
) {
164 z
= local_y
- (local_y
+ (this->y
- y
));
171 if (local_y
+ (this->y
- y
) + this->h
> local_y
+ h
) {
172 this->h
-= (local_y
+ (this->y
- y
) + this->h
) - (local_y
+ h
);
175 image_draw(this->image
, local_x
+ (this->x
- x
), local_y
+ (this->y
- y
),
176 this->px
, this->py
, this->w
, this->h
);
178 /*printf("%d %d\n", this->x - screen_x, this->y - screen_y);*/
181 /*printf("count = %d\n", count);*/
183 list_destroy_item(listLayer
, free
);
184 listLayer
= list_new();
189 list_destroy_item(listLayer
, free
);
190 listLayer
= list_new();
194 * Delete list of layers from memory
198 list_destroy_item(listLayer
, free
);