A game engine for top-down 2D RPG games.
rpg game-engine raylib c99
at main 2.5 kB view raw
1#include <keraforge.h> 2#include <raylib.h> 3#include <stdio.h> 4#include <stdlib.h> 5#include <string.h> 6 7 8static const char *HELP = 9"usage: newgame [options...]\n\n" 10"options:\n" 11"\t-w --width <int> specify width for the world (default: 1024)\n" 12"\t-h --height <int> specify height for the world (default: 1024)\n" 13"\t-s --size <int> specify width and height for the world\n" 14"\t-p --path <str> specify path to save the game in (default: path)\n" 15"\t-f --force create the new game even if the directory exists, this will delete data\n" 16"\t --no-force opposite of -f (default)\n" 17"\t-c --compress compress the world after creating it (recommended)\n" 18"\t --no-compress don't compress the world after creating it (default)\n" 19"\t --help display this message\n" 20; 21 22 23int main(int argc, char *argv[]) 24{ 25 char *path = "data"; 26 int width = 1024, height = 1024; 27 bool compress = false; 28 bool force = false; 29 30 for (int i = 1 ; i < argc ; i++) 31 { 32 char *arg = argv[i]; 33 34# define _checkshort(SHORT) (strncmp(arg, "-" SHORT, strlen("-" SHORT)) == 0) 35# define _checklong(LONG) (strncmp(arg, "--" LONG, strlen("--" LONG)) == 0) 36# define _check(SHORT, LONG) (_checkshort(SHORT) || _checklong(LONG)) 37 38 if (_check("w", "width")) 39 width = atoi(argv[++i]); 40 else if (_check("h", "height")) 41 height = atoi(argv[++i]); 42 else if (_check("s", "size")) 43 width = height = atoi(argv[++i]); 44 else if (_check("p", "path")) 45 path = argv[++i]; 46 else if (_check("c", "compress")) 47 compress = true; 48 else if (_checklong("no-compress")) 49 compress = false; 50 else if (_check("f", "force")) 51 force = true; 52 else if (_checklong("no-force")) 53 force = false; 54 else if (_checklong("help")) 55 { 56 kf_loginfo("%s", HELP); 57 exit(0); 58 } 59 else 60 { 61 kf_logerr("invalid argument: %s", arg); 62 exit(1); 63 } 64 65# undef _checkshort 66# undef _checklong 67# undef _check 68 } 69 70 if (!force && DirectoryExists(path)) 71 KF_THROW("path exists: %s", path); 72 73 struct kf_world *world = NULL; 74 75 kf_loginfo("creating world"); 76 kf_timeit("create world", { 77 world = kf_world_new(width, height, 2); 78 }); 79 80 /* path for our map.bin */ 81 char worldpath[4096] = {0}; 82 strcpy(worldpath, path); 83 strcpy(&worldpath[0] + strlen(path), compress ? "/tmp/map.bin" : "/map.bin"); 84 MakeDirectory(GetDirectoryPath(worldpath)); 85 86 size_t len = kf_world_getsize(world); 87 kf_loginfo("saving world to %s (%lu bytes uncompressed)", worldpath, len); 88 kf_timeit("save world", kf_world_save(world, compress, worldpath)); 89 90 free(world); 91}