Include and link physfs properly.
[tuxanci.git] / src / client / layer.c
blob22c037dc5debb3f4cdf47e94e00f484a3af39af5
1 #include <stdlib.h>
2 #include <assert.h>
4 #include "main.h"
5 #include "list.h"
6 #include "tux.h"
8 #include "interface.h"
9 #include "layer.h"
10 #include "image.h"
12 #include "world.h"
14 static list_t *listLayer;
16 static bool_t isLayerInit = FALSE;
18 bool_t layer_is_inicialized()
20 return isLayerInit;
24 * Initialize global list of the layers
26 void layer_init()
28 listLayer = list_new();
29 isLayerInit = TRUE;
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)
43 layer_t *new;
44 layer_t *actual;
45 int actual_value;
46 int new_value;
47 int i;
49 assert(img != NULL);
51 new = malloc(sizeof(layer_t));
52 new->x = x;
53 new->y = y;
54 new->w = w;
55 new->h = h;
56 new->px = px;
57 new->py = py;
58 new->layer = player;
59 new->image = img;
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);
71 return;
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
82 void layer_draw_all()
84 layer_t *this;
85 int i;
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)
101 layer_t *this;
102 int screen_x, screen_y;
103 int i;
104 /*int count = 0;*/
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) {
115 continue;
117 /*count++;*/
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)
133 layer_t *this;
134 int i;
135 /*int count = 0;*/
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) {
142 continue;
145 /*count++;*/
147 if (local_x + (this->x - x) < local_x) {
148 int z;
150 z = local_x - (local_x + (this->x - x));
152 this->x += z;
153 this->px += z;
154 this->w -= z;
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) {
162 int z;
164 z = local_y - (local_y + (this->y - y));
166 this->y += z;
167 this->py += z;
168 this->h -= z;
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();
187 void layer_flush()
189 list_destroy_item(listLayer, free);
190 listLayer = list_new();
194 * Delete list of layers from memory
196 void layer_quit()
198 list_destroy_item(listLayer, free);
199 isLayerInit = FALSE;