50 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
| #include <stdio.h>
 | |
| 
 | |
| FILE *tiles_c;
 | |
| FILE *tiles_h;
 | |
| 
 | |
| void convert(char *file_name, char *var_name) {
 | |
|     int i, n;
 | |
|     unsigned char buffer[16];
 | |
| 
 | |
|     FILE *infile=fopen(file_name, "r");
 | |
| 
 | |
|     fprintf(tiles_c, "unsigned char %s[] = {\n", var_name);
 | |
|     while ((n = fread(buffer, 1, 16, infile)))
 | |
|     {
 | |
|         for (i = 0; i < n; i++) {
 | |
|           fprintf(tiles_c, "0x%2.2x,", buffer[i]);
 | |
|         }
 | |
|     }
 | |
|   fprintf(tiles_c, "\n};\n");
 | |
|   fprintf(tiles_c, "unsigned int %s_length = %d;\n\n", var_name, ftell(infile));
 | |
|   fprintf(tiles_h, "extern unsigned char %s[];\n", var_name);
 | |
|   fprintf(tiles_h, "extern unsigned int %s_length;\n\n", var_name);
 | |
| }
 | |
| 
 | |
| int main(int argc, char **argv) {
 | |
|   tiles_c = fopen("tiles/tiles.c", "w");
 | |
|   tiles_h = fopen("tiles/tiles.h", "w");
 | |
|   fprintf(tiles_h, "/** WARNING - THIS FILE IS AUTOGENERATED BY pack_tiles, EDITS TO THIS FILE MAY BE OVERWRITTEN **/\n");
 | |
|   fprintf(tiles_c, "/** WARNING - THIS FILE IS AUTOGENERATED BY pack_tiles, EDITS TO THIS FILE MAY BE OVERWRITTEN **/\n");
 | |
|   fprintf(tiles_h, "#ifndef TILES_H\n#define TILES_H\n");
 | |
|   fprintf(tiles_h, "#define TILE_WIDTH 16\n#define TILE_HEIGHT 32\n");
 | |
| 
 | |
|   convert("tiles/font.png", "font_images");
 | |
|   convert("tiles/font_mini.png", "font_mini_images");
 | |
|   convert("tiles/ui.png", "ui_images");
 | |
|   convert("tiles/players.png", "player_images");
 | |
|   convert("tiles/items.png", "item_images");
 | |
|   convert("tiles/npcs.png", "npc_images");
 | |
|   convert("tiles/walls.png", "wall_images");
 | |
|   convert("tiles/floors.png", "floor_images");
 | |
|   convert("tiles/doors.png", "door_images");
 | |
|   convert("tiles/shadows.png", "shadow_images");
 | |
| 
 | |
|   fprintf(tiles_h, "#endif\n");
 | |
|   fclose(tiles_c);
 | |
|   fclose(tiles_h);
 | |
| 
 | |
|   return 0;
 | |
| }
 |