Remove static label from game functions
[kraptor.git] / src / humo.c
blob3bb35822a94368e318fde31ec92935e7a636233e
1 /*-------------------------------------------------------
2 humo.c
3 --------------------------------------------------------
4 Copyright (c) 2002, Kronoman
5 En memoria de mi querido padre
6 Enero - 2003
7 --------------------------------------------------------
8 Engine de humo (para edificios en llamas)
9 usando una lista enlazada muy sencilla
10 --------------------------------------------------------*/
12 #ifndef HUMO_C
13 #define HUMO_C
15 #include <stdio.h>
16 #include <allegro.h>
18 #include "humo.h"
19 #include "azar.h"
21 /* DEBUG - estas variables son especificas a Kraptor */
22 #include "global.h" // para saber el nivel de detalle unicamente...
24 BITMAP *humo_spr = NULL; // sprite de representacion del humo...
26 /* --- globales internas --- */
28 static HUMO *prt_1er_humo = NULL; /* puntero al comienzo de la lista */
29 static EMISOR_HUMO *prt1er_emisor = NULL; /* lista de emisores de humo */
31 //========================================================================
32 // Funciones de los emisores de humo,
33 // son zonas de 40x40 que emiten humo por un determinado espacio de tiempo
36 /* Esta funcion agrega un nuevo emisor de humo
37 Devuelve puntero al emisor creado.
38 Si vida <= 0, NO se crea...
40 EMISOR_HUMO *agrega_emisor_humo(fixed x, fixed y, int vida )
42 EMISOR_HUMO *nueva = NULL;
44 if (vida <= 0) return NULL; /* ni pierdo el tiempo... */
46 if (nivel_detalle < 2) return NULL; // nivel de detalle minimo, no hacer nada
48 nueva = (EMISOR_HUMO *)malloc(sizeof(EMISOR_HUMO));
49 nueva->next = prt1er_emisor;
50 prt1er_emisor = nueva;
52 if (nueva != NULL) /* si el malloc funciono, seteo los datos... */
54 nueva->x = x;
55 nueva->y = y;
56 nueva->vida = vida;
59 return nueva;
63 Esta funcion actualiza la logica (mueve) los emisores de humo
64 En realidad, los emisores de humo agregan particulas, pero no se mueven...
65 tambien los elimina si vida < 0 o si estan fuera de pantalla
66 Pasar en x, y la posicion de scroll en pantalla
67 en w, h el ancho y alto de la pantalla
69 void mover_emisor_humo(int x, int y, int w, int h)
71 int i;
72 EMISOR_HUMO **tmp_p = &prt1er_emisor;
73 EMISOR_HUMO *tmp = NULL;
75 while (*tmp_p) {
77 tmp = *tmp_p;
79 /* DEBUG: aqui agrego particulas de humo */
80 // fueguito...
81 if (rand()%100 < 80)
82 agrega_humo( fixadd(tmp->x, itofix(rand_ex(-5,5))) ,
83 fixadd(tmp->y, itofix(rand_ex(-5,5))) ,
84 ftofix(rand_ex(-150,150) / 100.0),
85 ftofix(rand_ex(-150,150) / 100.0),
86 rand_ex(5, 15),
87 makecol(255,rand()%255,0),
88 itofix(rand_ex(2,6)),
89 ftofix(rand_ex(0, 10) / 100.0));
91 // agregar un 'humo' hacia la derecha y arriba
92 if (rand()%100 < 95)
94 i = rand_ex(0,96); // gris oscuro
95 agrega_humo( fixadd(tmp->x, itofix(rand_ex(-5,5))),
96 fixadd(tmp->y, itofix(rand_ex(-5,5))),
97 ftofix(rand_ex(10,200) / 100.0),
98 ftofix(-1.0 * (rand_ex(50,300) / 100.0)),
99 rand_ex(10, 50),
100 makecol(i,i,i),
101 itofix(rand_ex(3,10)),
102 ftofix(rand_ex(0, 25) / 100.0));
105 tmp->vida--;
107 /* verificar si estan fuera de pantalla (da 40 pixeles de margen para
108 permitir que salga totalmente de pantalla) */
109 // NOTA: no los elimino por arriba, sino los edificos aparecen 'apagados'
110 // if (tmp->y < itofix(y-80)) tmp->vida = -1;
111 if (tmp->y > itofix(y+h+80)) tmp->vida = -1;
112 if (tmp->x < itofix(x-80)) tmp->vida = -1;
113 if (tmp->x > itofix(x+w+80)) tmp->vida = -1;
115 if (tmp->vida < 0) {
116 /* murio, eliminar!!! */
117 *tmp_p = tmp->next;
118 free(tmp);
119 } else {
120 tmp_p = &tmp->next; /* siguiente por favor! */
125 /* Esta funcion se debe llamar cuando no se precise
126 mas la lista de emisores de humo
127 Libera la RAM usada y reinicia la lista
129 void liberar_emisores_humo() {
130 EMISOR_HUMO *tmp = prt1er_emisor;
131 prt1er_emisor = NULL;
133 while (tmp) {
134 EMISOR_HUMO *next = tmp->next;
135 free(tmp);
136 tmp = next;
141 //========================================================================
143 // ---------------------- FUNCIONES DE PARTICULAS DE HUMO EN SI ----------
145 //========================================================================
147 /* Esta funcion agrega humo a la lista enlazada [al principio].
148 Devuelve puntero a la particula recien creada.
149 Los parametros son los parametros de la particula
150 Si vida <= 0, NO se crea la particula... (return derecho...)
152 HUMO *agrega_humo( fixed x, fixed y,
153 fixed dx, fixed dy,
154 int vida,
155 int col, fixed r, fixed ri)
157 HUMO *nueva = NULL;
159 if (vida <= 0) return NULL; /* ni pierdo el tiempo... */
161 if (nivel_detalle < 2) return NULL; // nivel de detalle minimo, no hacer nada
163 nueva =malloc(sizeof(HUMO));
164 nueva->next = prt_1er_humo;
165 prt_1er_humo = nueva;
167 if (nueva != NULL) /* si el malloc funciono, seteo los datos... */
169 nueva->x = x;
170 nueva->y = y;
171 nueva->dx = dx;
172 nueva->dy = dy;
173 nueva->vida = vida;
174 nueva->col = col;
175 nueva->r = r;
176 nueva->ri = ri;
179 return nueva;
183 Esta funcion actualiza la logica (mueve) el humo
184 tambien las elimina si vida < 0 o si estan fuera de pantalla
185 Pasar en x, y la posicion de scroll en pantalla
186 en w, h el ancho y alto de la pantalla
188 void mover_humo(int x, int y, int w, int h)
190 HUMO **tmp_p = &prt_1er_humo;
191 HUMO *tmp = NULL;
193 while (*tmp_p) {
195 tmp = *tmp_p;
197 /* aqui muevo la particula */
198 tmp->x = fixadd(tmp->x, tmp->dx);
200 // efecto 'sacudida' para simular el humo...
201 tmp->x = fixadd(tmp->x, ftofix( rand_ex(-200, 200 ) / 100.0 ) );
203 tmp->y = fixadd(tmp->y, tmp->dy);
204 tmp->vida--;
206 // aumentar el radio
207 tmp->r = fixadd(tmp->r, tmp->ri);
208 if (fixtoi(tmp->r) < 1) tmp->vida = -1;
211 /* DEBUG: verificar si estan fuera de pantalla (da 15 pixeles de margen para
212 permitir que la particula salga totalmente de pantalla) */
213 if (tmp->y < itofix(y-15)) tmp->vida = -1;
214 if (tmp->y > itofix(y+h+15)) tmp->vida = -1;
215 if (tmp->x < itofix(x-15)) tmp->vida = -1;
216 if (tmp->x > itofix(x+w+15)) tmp->vida = -1;
218 if (tmp->vida < 0) {
219 /* la particula murio, eliminar!!! */
220 *tmp_p = tmp->next;
221 free(tmp);
222 } else {
223 tmp_p = &tmp->next; /* siguiente por favor! */
229 Esta funcion dibuja el humo en el bitmap bmp
230 Las dibuja desplazadas x,y
232 void dibujar_humo(BITMAP *bmp, int x, int y)
234 HUMO *tmp = prt_1er_humo;
235 BITMAP *tbmp = NULL; // bitmap temporal para el dibujado de sprites escalados
237 if (nivel_detalle > 5)
238 drawing_mode(DRAW_MODE_TRANS, NULL, 0,0); // usar transparencias (queda joya!)
240 while (tmp) {
241 /* dibujar */
243 // si el nivel de detalle es maximo, usara sprites transparentes
244 // escalados, lo cual es *muy* lento!
245 if (nivel_detalle >= 10 && fixtoi(tmp->r) > 5 && humo_spr != NULL)
247 tbmp = create_bitmap(fixtoi(tmp->r)*2,fixtoi(tmp->r)*2);
248 if (tbmp != NULL)
250 stretch_blit(humo_spr, tbmp, 0, 0, humo_spr->w, humo_spr->h,0,0,tbmp->w, tbmp->h);
251 draw_trans_sprite(bmp, tbmp, fixtoi(tmp->x)-x-(tbmp->w/2), fixtoi(tmp->y)-y-(tbmp->h/2));
252 destroy_bitmap(tbmp);
253 tbmp = NULL;
256 else
257 { circlefill(bmp, fixtoi(tmp->x)-x, fixtoi(tmp->y)-y, fixtoi(tmp->r), tmp->col);}
259 tmp = tmp->next; /* proximo... */
262 solid_mode();
265 /* Esta funcion se debe llamar cuando no se precise mas el humo
266 Libera la RAM usada y reinicia la lista
268 void liberar_humo()
270 HUMO *tmp = prt_1er_humo;
271 prt_1er_humo = NULL;
273 while (tmp) {
274 HUMO *next = tmp->next;
275 free(tmp);
276 tmp = next;
281 #endif