2 Editor de la matriz de enemigos para Kraptor
3 NOTA: si se ejecuta con krapmain.dat presente en el mismo directorio, _MUESTRA_ los enemigos
4 con sprites, en vez de usar los numeros. [cool!]
7 En memoria de mi querido padre
10 BARRA = situar valor seleccionado
11 FLECHAS = mover cursor
12 + y - del keypad: alterar valor en +1
13 1 y 2 : alterar valor en +10
15 C : limpiar grilla a ceros
18 V : ver fondo sin grilla
19 R : agregar enemigos del tipo seleccionado al azar
22 NOTA: los mapas se guardan con las funciones especiales de Allegro
23 para salvar los integers en un formato standard, de esa manera,
24 me ahorro los problemas con diferentes tama~os de enteros segun
33 /* Tama¤o del fondo */
42 long grilla
[W_FONDO
/ W_GR
][H_FONDO
/ H_GR
];
44 /* En vgrilla pasar -1 para dibujarla, o 0 para ver el bitmap suelto */
47 int xp
= 0, yp
= 0, vp
= 1; /* x,y, valor a colocar */
49 // cache de sprites de los enemigos, para mostrarlos en pantalla... :)
50 // funciona si esta presenta krapmain.dat en el lugar
51 #define MAX_SPR 100 // sprites cargados 0..MAX_SPR - 1
52 BITMAP
*sprite
[MAX_SPR
];
53 DATAFILE
*data
= NULL
; // datafile
54 /* Bitmap cargado en RAM del fondo */
56 PALETTE pal
; /* paleta */
58 /* Buffer de dibujo */
62 // Esto carga de disco el cache de sprites
64 void cargar_cache_sprites()
66 DATAFILE
*p
= NULL
; // punteros necesarios
68 char str
[1024]; // string de uso general
70 for (i
= 0; i
< MAX_SPR
; i
++) sprite
[i
] = NULL
;
72 data
= load_datafile("krapmain.dat");
74 if (data
== NULL
) return; // no esta presente el archivo - DEBUG, informar, o algo... :P
76 p
= find_datafile_object(data
, "enemigos");
79 unload_datafile(data
);
83 set_config_data((char *)p
->dat
, p
->size
);
85 for (i
=0; i
< MAX_SPR
; i
++)
87 /* Seccion ENEMIGO_n */
88 sprintf(str
,"ENEMIGO_%d", i
);
90 // buscar el 1er cuadro de animacion del enemigo unicamente...
91 p
= find_datafile_object(data
, get_config_string(str
, "spr", "null"));
93 if (p
== NULL
) p
= find_datafile_object(data
, get_config_string(str
, "spr_0", "null"));
95 if (p
!= NULL
) sprite
[i
] = (BITMAP
*)p
->dat
;
99 // NO se debe descargar el datafile, porque suena todo! [los sprites deben permanecer en RAM]
102 // Limpia la grilla con ceros
103 void limpiar_grilla() {
105 /* limpio la grilla a ceros */
106 for (xx
=0; xx
< W_FONDO
/ W_GR
; xx
++)
107 for (yy
=0; yy
< H_FONDO
/ H_GR
; yy
++)
111 // Redibuja la pantalla
116 blit(fnd
, buffer
, 0, yp
* H_GR
,0,0,600,480);
121 for (ix
=0; ix
< W_FONDO
/ W_GR
; ix
++ )
122 line(buffer
, ix
*W_GR
, 0, ix
*W_GR
, 480, makecol(255,255,255));
124 for (iy
=0; iy
< H_FONDO
/ H_GR
; iy
++ )
125 line(buffer
, 0, iy
*H_GR
, fnd
->w
, iy
*H_GR
, makecol(255,255,255));
129 line(buffer
, xp
* W_GR
, 0, (xp
* W_GR
) + W_GR
, H_GR
, makecol(255, 255, 255));
130 line(buffer
, xp
* W_GR
, H_GR
, (xp
* W_GR
) + W_GR
, 0, makecol(255, 255, 255));
132 /* mostrar los valores (o sprite, si esta disponible) que contiene la matriz */
133 text_mode(makecol(0,0,0));
134 for (ix
=0; ix
< W_FONDO
/ W_GR
; ix
++ )
136 for (iy
=0; iy
< H_FONDO
/ H_GR
; iy
++ )
138 if (yp
+ iy
< H_FONDO
/ H_GR
)
140 if (grilla
[ix
][yp
+iy
] != 0)
142 // ver si hay un sprite disponible...
143 if ( (grilla
[ix
][yp
+iy
] > 0) && (grilla
[ix
][yp
+iy
] < MAX_SPR
) )
145 if ( sprite
[grilla
[ix
][yp
+iy
]-1] != NULL
)
148 stretch_sprite(buffer
, sprite
[grilla
[ix
][yp
+iy
]-1], ix
*W_GR
, iy
*H_GR
, W_GR
, H_GR
);
150 draw_sprite(buffer
, sprite
[grilla
[ix
][yp
+iy
]-1],
151 (W_GR
/ 2) - (sprite
[grilla
[ix
][yp
+iy
]-1]->w
/ 2) + (ix
*W_GR
),
152 (H_GR
/ 2) - (sprite
[grilla
[ix
][yp
+iy
]-1]->h
/ 2) + (iy
*H_GR
));
157 textprintf(buffer
, font
,
158 (ix
*W_GR
)+(W_GR
/2), (iy
*H_GR
)+(H_GR
/2), makecol(255,255,255),
159 "%d", (int)grilla
[ix
][yp
+iy
]);
166 /* panel de informacion */
167 text_mode(-1); // texto (-1=trans, 1 solido)
168 textprintf(buffer
, font
, 600,0,makecol(255,255,255),
171 textprintf(buffer
, font
, 600,20,makecol(255,255,255),
174 textprintf(buffer
, font
, 600,40,makecol(255,255,255),
177 if ((vp
> 0) && (vp
< MAX_SPR
))
178 if (sprite
[vp
-1] != NULL
)
179 stretch_sprite(buffer
, sprite
[vp
-1], 600, (text_height(font
)*2)+40, 40, 40);
181 /* mandar a pantalla */
183 blit(buffer
, screen
, 0,0, 0,0,SCREEN_W
, SCREEN_H
);
190 char salvar
[1024]; /* archivo a salvar */;
199 if (k
== KEY_UP
) yp
--;
200 if (k
== KEY_DOWN
) yp
++;
201 if (k
== KEY_LEFT
) xp
--;
202 if (k
== KEY_RIGHT
) xp
++;
203 if (k
== KEY_SPACE
) grilla
[xp
][yp
] = vp
;
204 if (k
== KEY_DEL
) grilla
[xp
][yp
] = 0;
205 if (k
== KEY_PLUS_PAD
) vp
++;
206 if (k
== KEY_MINUS_PAD
) vp
--;
207 if (k
== KEY_0
) vp
= 0;
208 if (k
== KEY_1
) vp
+= 10;
209 if (k
== KEY_2
) vp
-= 10;
211 if (k
== KEY_V
) vgrilla
= !vgrilla
;
214 // agregar 1 enemigo al azar... :P
215 // en una casilla vacia solamente
217 xd
= rand()% (W_FONDO
/ W_GR
);
218 yd
= rand()% (H_FONDO
/ H_GR
);
219 if (grilla
[xd
][yd
] == 0)
222 yp
= yd
; xp
= xd
; // feedback al user
228 if ( alert("Salir de la edicion.", "Esta seguro", "Se perderan los datos no salvados", "Si", "No", 'S', 'N') == 1) return;
232 if ( alert("Limpiar grilla.", "Esta seguro", NULL
, "Si", "No", 'S', 'N') == 1)
233 { limpiar_grilla(); alert("La grilla se reinicio a ceros (0)", NULL
, NULL
, "OK", NULL
, 0, 0); }
237 if (file_select_ex("Archivo de grilla a salvar?", salvar
, NULL
, 512, 0, 0))
241 if ((fp
= pack_fopen(salvar
, F_WRITE
)) != NULL
) {
243 // escribo la grilla en formato Intel de 32 bits
244 for (xx
=0; xx
< W_FONDO
/ W_GR
; xx
++)
245 for (yy
=0; yy
< H_FONDO
/ H_GR
; yy
++)
246 pack_iputl(grilla
[xx
][yy
], fp
);
250 alert("Archivo salvado.", salvar
, NULL
, "OK", NULL
, 0, 0);
253 alert("Fallo la apertura del archivo!", salvar
, NULL
, "OK", NULL
, 0, 0);
260 if (file_select_ex("Archivo a cargar?", salvar
, NULL
, 512, 0, 0))
264 if ((fp
= pack_fopen(salvar
, F_READ
)) != NULL
) {
266 // leo la grilla en formato Intel de 32 bits
267 for (xx
=0; xx
< W_FONDO
/ W_GR
; xx
++)
268 for (yy
=0; yy
< H_FONDO
/ H_GR
; yy
++)
269 grilla
[xx
][yy
] = pack_igetl(fp
);
273 alert("Archivo cargado.", salvar
, NULL
, "OK", NULL
, 0, 0);
277 alert("Fallo la apertura del archivo!", salvar
, NULL
, "OK", NULL
, 0, 0);
283 if (yp
> (H_FONDO
/ H_GR
)-1) yp
= (H_FONDO
/ H_GR
)-1;
286 if (xp
> (W_FONDO
/ W_GR
)-1) xp
= (W_FONDO
/ W_GR
)-1;
297 RGB_MAP tmp_rgb
; /* acelera los calculos de makecol, etc */
298 char leerbmp
[1024]; /* fondo a cargar */
301 int card
= GFX_AUTODETECT
, w
= 640 ,h
= 480 ,color_depth
= 8; /* agregado por Kronoman */
310 set_color_depth(color_depth
);
311 if (set_gfx_mode(card
, w
, h
, 0, 0)) {
312 allegro_message("set_gfx_mode(%d x %d x %d bpp): %s\n", w
,h
, color_depth
, allegro_error
);
318 if (!file_select_ex("Cargue el fondo por favor.", leerbmp
, NULL
, 512, 0, 0)) return 0;
320 fnd
= load_bitmap(leerbmp
, pal
);
321 if (fnd
== NULL
|| fnd
->w
!= W_FONDO
|| fnd
->h
!= H_FONDO
) {
322 allegro_message("No se pueden cargar o es invalido \n %s!\n", leerbmp
);
329 cargar_cache_sprites(); // cargar la cache de sprites... COOL!
331 gui_fg_color
= makecol(255,255,255);
332 gui_bg_color
= makecol(0,0,0);
333 set_mouse_sprite(NULL
);
335 /* esto aumenta un monton los fps (por el makecol acelerado... ) */
336 create_rgb_table(&tmp_rgb
, pal
, NULL
); /* rgb_map es una global de Allegro! */
339 buffer
=create_bitmap(SCREEN_W
, SCREEN_H
);
348 if (data
!= NULL
) unload_datafile(data
);