From: Ingo Ruhnke Date: Fri, 19 Mar 2004 23:49:20 +0000 (+0000) Subject: - added level starting from command line thingy X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=81d9d93bbc51d890f18cc8255e51d516d571e49a;p=supertux.git - added level starting from command line thingy - made it possible to run worldmap via command line SVN-Revision: 267 --- diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 5a39f066e..638219bb4 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -357,8 +357,18 @@ int game_action(void) player_level_begin(&tux); set_defaults(); level_free(¤t_level); - if(level_load(¤t_level,level_subset,level) != 0) - return 0; + + if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE) + { + if(level_load(¤t_level, level_subset) != 0) + return 0; + } + else + { + if(level_load(¤t_level,level_subset,level) != 0) + return 0; + } + arrays_free(); arrays_init(); activate_bad_guys(); @@ -579,14 +589,24 @@ int gameloop(char * subset, int levelnb, int mode) st_gl_mode = mode; level = levelnb; - strcpy(level_subset,subset); /* Init the game: */ arrays_init(); set_defaults(); - if(level_load(¤t_level,level_subset,level) != 0) - exit(1); + strcpy(level_subset,subset); + + if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE) + { + if (level_load(¤t_level, level_subset)) + exit(1); + } + else + { + if(level_load(¤t_level, level_subset, level) != 0) + exit(1); + } + level_load_gfx(¤t_level); activate_bad_guys(); level_load_song(¤t_level); @@ -598,10 +618,9 @@ int gameloop(char * subset, int levelnb, int mode) loadshared(); - if(st_gl_mode == ST_GL_PLAY) + if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE) levelintro(); - timer_init(&time_left,YES); start_timers(); diff --git a/src/gameloop.h b/src/gameloop.h index 8dd56caf0..0d68c23c2 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -22,6 +22,7 @@ #define ST_GL_PLAY 0 #define ST_GL_TEST 1 #define ST_GL_LOAD_GAME 2 +#define ST_GL_LOAD_LEVEL_FILE 3 extern int game_started; extern st_level current_level; diff --git a/src/globals.cpp b/src/globals.cpp index d49c899c7..20ad5e620 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -17,6 +17,9 @@ text_type black_text, gold_text, blue_text, red_text, yellow_nums, white_text, w int use_gl, use_joystick, use_fullscreen, debug_mode, show_fps; +char* level_startup_file = 0; +bool launch_worldmap_mode = false; + /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */ char *st_dir, *st_save_dir; diff --git a/src/globals.h b/src/globals.h index 8695868ff..502aa685c 100644 --- a/src/globals.h +++ b/src/globals.h @@ -23,6 +23,9 @@ extern text_type black_text, gold_text, white_text, white_small_text, white_big_ extern int use_gl, use_joystick, use_fullscreen, debug_mode, show_fps; +extern char* level_startup_file; +extern bool launch_worldmap_mode; + /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */ extern char *st_dir, *st_save_dir; diff --git a/src/level.cpp b/src/level.cpp index de04dd32a..6a12430b0 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -144,17 +144,23 @@ void subset_free(st_subset* st_subset) /* Returns -1, if the loading of the level failed. */ int level_load(st_level* plevel, char *subset, int level) { - int y,x; - FILE * fi; - char str[80]; char filename[1024]; - char * line; /* Load data file: */ snprintf(filename, 1024, "%s/levels/%s/level%d.dat", st_dir, subset, level); if(!faccessible(filename)) snprintf(filename, 1024, "%s/levels/%s/level%d.dat", DATA_PREFIX, subset, level); + + return level_load(plevel, filename); +} + +int level_load(st_level* plevel, const char* filename) +{ + char str[80]; + int x, y; + char * line; + FILE * fi; fi = fopen(filename, "r"); if (fi == NULL) { @@ -162,7 +168,6 @@ int level_load(st_level* plevel, char *subset, int level) return -1; } - /* Load header info: */ diff --git a/src/level.h b/src/level.h index d2fbf8242..62aca1b53 100644 --- a/src/level.h +++ b/src/level.h @@ -51,6 +51,7 @@ typedef struct st_level /*It is easier to read the sources IMHO, if we don't wri extern texture_type img_bkgd, img_bkgd_tile[2][4], img_solid[4], img_brick[2]; int level_load(st_level* plevel, char * subset, int level); +int level_load(st_level* plevel, const char* filename); void level_save(st_level* plevel, char * subset, int level); void level_free(st_level* plevel); void level_load_gfx(st_level* plevel); diff --git a/src/setup.cpp b/src/setup.cpp index ecc64baec..9afdeb473 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -856,6 +856,10 @@ void parseargs(int argc, char * argv[]) use_fullscreen = YES; } + else if (strcmp(argv[i], "--worldmap") == 0) + { + launch_worldmap_mode = true; + } else if (strcmp(argv[i], "--show-fps") == 0) { /* Use full screen: */ @@ -919,9 +923,11 @@ void parseargs(int argc, char * argv[]) { /* Show help: */ printf("Super Tux " VERSION "\n\n"); - + printf("Usage: %s [OPTIONS] FILENAME", argv[0]); printf("---------- Command-line options ----------\n\n"); + printf(" --worldmap - Start in worldmap-mode (EXPERIMENTAL)\n\n"); + printf(" --opengl - If opengl support was compiled in, this will enable the EXPERIMENTAL OpenGL mode.\n\n"); printf(" --disable-sound - If sound support was compiled in, this will\n disable sound for this session of the game.\n\n"); @@ -950,6 +956,10 @@ void parseargs(int argc, char * argv[]) exit(0); } + else if (argv[i][0] != '-') + { + level_startup_file = argv[i]; + } else { /* Unknown - complain! */ diff --git a/src/supertux.cpp b/src/supertux.cpp index 44aebe5f3..555495a7b 100644 --- a/src/supertux.cpp +++ b/src/supertux.cpp @@ -10,7 +10,6 @@ April 11, 2000 - March 15, 2004 */ - #include "supertux.h" @@ -32,19 +31,30 @@ int main(int argc, char * argv[]) st_joystick_setup(); st_general_setup(); st_menu(); + + if (launch_worldmap_mode) + { + worldmap_run(); + } + else if (level_startup_file) + { + gameloop(level_startup_file, 1, ST_GL_LOAD_LEVEL_FILE); + } + else + { + done = intro(); - done = intro(); - - done = 0; + done = 0; - while (!done) - { - done = title(); + while (!done) + { + done = title(); + } } clearscreen(0, 0, 0); updatescreen(); - + st_shutdown(); return(0); diff --git a/src/worldmap.cpp b/src/worldmap.cpp index d4a024c28..6d981181d 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -31,7 +31,7 @@ TileManager* TileManager::instance_ = 0; TileManager::TileManager() { lisp_stream_t stream; - FILE* in = fopen(DATA_PREFIX "tiles/antarctica.scm", "r"); + FILE* in = fopen(DATA_PREFIX "images/worldmap/antarctica.scm", "r"); assert(in); lisp_stream_init_file (&stream, in); lisp_object_t* root_obj = lisp_read (&stream); @@ -44,7 +44,6 @@ TileManager::TileManager() { lisp_object_t* element = lisp_car(cur); - lisp_dump (element, stdout); if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0) { int id = 0; @@ -102,17 +101,6 @@ WorldMap::WorldMap() width = 20; height = 15; tux_moving = false; - tilemap.resize(width * height); - - tilemap[0] = 5; - tilemap[1] = 1; - tilemap[2] = 6; - tilemap[3] = 1; - tilemap[4] = 3; - tilemap[4+20] = 2; - tilemap[4+40] = 7; - tilemap[4+60] = 2; - tilemap[4+80] = 4; texture_load(&tux_sprite, DATA_PREFIX "/images/worldmap/tux.png", USE_ALPHA); @@ -124,6 +112,8 @@ WorldMap::WorldMap() input_direction = NONE; tux_direction = NONE; enter_level = false; + + load_map(); } WorldMap::~WorldMap() @@ -131,6 +121,22 @@ WorldMap::~WorldMap() } void +WorldMap::load_map() +{ + tilemap.resize(width * height); + + tilemap[0] = 5; + tilemap[1] = 1; + tilemap[2] = 6; + tilemap[3] = 1; + tilemap[4] = 3; + tilemap[4+20] = 2; + tilemap[4+40] = 7; + tilemap[4+60] = 2; + tilemap[4+80] = 4; +} + +void WorldMap::get_input() { SDL_Event event; diff --git a/src/worldmap.h b/src/worldmap.h index ba2948268..2f97619f6 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -99,6 +99,8 @@ public: /** Busy loop */ void display(); + + void load_map(); void get_input();