Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Argon Level Format Map Generator
- #include <stdio.h>
- #define ARG_VERSION 0x01
- void alf_WriteHeader (FILE *file)
- {
- char buf [5] = {0};
- char *bufp = buf;
- *bufp = ARG_VERSION;
- bufp ++;
- *((int*)bufp) = 0;
- fwrite (buf, 1, 5, file);
- return;
- }
- int numrooms = 0;
- void alf_WriteRoomHeader (FILE *file, short x, short y, short flags)
- {
- char buf [6] = {0};
- char *bufp = buf;
- *((short*)bufp) = x;
- *((short*)bufp) = y;
- *((short*)bufp) = flags;
- numrooms ++;
- fwrite (buf, 2, 3, file);
- return;
- }
- int numblocks = 0;
- void alf_WriteBlock (FILE *file, char tileset)
- {
- printf ("%i", (int)tileset);
- numblocks ++;
- if (!(numblocks % 16))
- printf ("\n");
- fwrite (&tileset, 1, 1, file);
- return;
- }
- int main (int argc, char **argv)
- {
- char *date = __DATE__;
- char inc;
- FILE *in = NULL, *out = NULL;
- printf ("alf generator version 0.0.1 compiled on %s\n", date);
- if (argc < 3)
- {
- printf ("usage: alfgen <input> <output>\n");
- return 1;
- }
- in = fopen (argv [1], "r");
- out = fopen (argv [2], "w");
- if (!in)
- {
- printf ("error: couldn't open input file %s\n", argv [1]);
- return 1;
- }
- if (!out)
- {
- printf ("error: couldn't open output file %s\n", argv [2]);
- return 1;
- }
- alf_WriteHeader (out);
- alf_WriteRoomHeader (out, 0, 0, 0);
- while ((inc = fgetc (in)) != EOF)
- {
- if (inc == '+')
- alf_WriteBlock (out, 1);
- else if (inc == '-')
- alf_WriteBlock (out, 0);
- }
- printf ("success: wrote %i rooms and %i blocks to %s\n", numrooms, numblocks, argv [2]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement