1 /*-------------------------------------------------------
3 --------------------------------------------------------
4 Copyright (c) 2002, Kronoman
5 En memoria de mi querido padre
7 --------------------------------------------------------
8 Engine de humo (para edificios en llamas)
9 usando una lista enlazada muy sencilla
10 --------------------------------------------------------*/
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... */
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
)
72 EMISOR_HUMO
**tmp_p
= &prt1er_emisor
;
73 EMISOR_HUMO
*tmp
= NULL
;
79 /* DEBUG: aqui agrego particulas de humo */
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),
87 makecol(255,rand()%255,0),
89 ftofix(rand_ex(0, 10) / 100.0));
91 // agregar un 'humo' hacia la derecha y arriba
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)),
101 itofix(rand_ex(3,10)),
102 ftofix(rand_ex(0, 25) / 100.0));
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;
116 /* murio, eliminar!!! */
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
;
134 EMISOR_HUMO
*next
= 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
,
155 int col
, fixed r
, fixed ri
)
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... */
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
;
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
);
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;
219 /* la particula murio, eliminar!!! */
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!)
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);
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
);
257 { circlefill(bmp
, fixtoi(tmp
->x
)-x
, fixtoi(tmp
->y
)-y
, fixtoi(tmp
->r
), tmp
->col
);}
259 tmp
= tmp
->next
; /* proximo... */
265 /* Esta funcion se debe llamar cuando no se precise mas el humo
266 Libera la RAM usada y reinicia la lista
270 HUMO
*tmp
= prt_1er_humo
;
274 HUMO
*next
= tmp
->next
;