[Super-tux-commit] supertux/src collision.cpp,1.17,1.18 collision.h,1.10,1.11 gameloop.cpp,1.109,1.1
Brought to you by:
wkendrick
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21270 Modified Files: collision.cpp collision.h gameloop.cpp gameloop.h level.cpp level.h tile.cpp tile.h timer.cpp timer.h Log Message: - new more bulletprof endsequence code patch from MatzeB Index: tile.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tile.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- tile.h 26 Apr 2004 12:21:22 -0000 1.14 +++ tile.h 26 Apr 2004 19:11:54 -0000 1.15 @@ -62,6 +62,12 @@ /** Tile is a distro/coin */ bool distro; + /** the level should be finished when touching a goaltile. + * if data is 0 then the endsequence should be triggered, if data is 1 + * then we can finish the level instantly. + */ + bool goal; + /** General purpose data attached to a tile (content of a box, type of coin) */ int data; Index: collision.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/collision.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- collision.h 22 Apr 2004 19:15:22 -0000 1.10 +++ collision.h 26 Apr 2004 19:11:53 -0000 1.11 @@ -55,5 +55,14 @@ bool isice(float x, float y); bool isfullbox(float x, float y); +typedef void* (*tiletestfunction)(Tile* tile); +/** invokes the function for each tile the baserectangle collides with. The + * function aborts and returns true as soon as the tiletestfunction returns + * != 0 then this value is returned. returns 0 if all tests failed. + */ +void* collision_func(const base_type& base, tiletestfunction* function); + +Tile* collision_goal(const base_type& base); + #endif /*SUPERTUX_COLLISION_H*/ Index: timer.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/timer.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- timer.h 20 Apr 2004 11:09:34 -0000 1.13 +++ timer.h 26 Apr 2004 19:11:54 -0000 1.14 @@ -36,6 +36,8 @@ unsigned int (*get_ticks) (void); public: + Timer(); + void init(bool st_ticks); void start(unsigned int period); void stop(); Index: collision.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/collision.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- collision.cpp 22 Apr 2004 19:15:22 -0000 1.17 +++ collision.cpp 26 Apr 2004 19:11:53 -0000 1.18 @@ -79,6 +79,31 @@ return false; } +void* collision_func(const base_type& base, tiletestfunction function) +{ + for(float x = base.x; x < base.x + base.width; x += 32) { + for(float y = base.y; y < base.y + base.height; y += 32) { + Tile* tile = gettile(x, y); + void* result = function(tile); + if(result != 0) + return result; + } + } + + return 0; +} + +static void* test_goal_tile_function(Tile* tile) +{ + if(tile->goal) + return tile; + return 0; +} + +Tile* collision_goal(const base_type& base) +{ + return (Tile*) collision_func(base, test_goal_tile_function); +} void collision_swept_object_map(base_type* old, base_type* current) { Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- level.h 24 Apr 2004 14:49:03 -0000 1.37 +++ level.h 26 Apr 2004 19:11:54 -0000 1.38 @@ -87,8 +87,6 @@ int width; int start_pos_x; int start_pos_y; - int endpos; - bool use_endsequence; float gravity; std::vector<BadGuyData> badguy_data; Index: gameloop.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.h,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- gameloop.h 25 Apr 2004 23:46:30 -0000 1.46 +++ gameloop.h 26 Apr 2004 19:11:53 -0000 1.47 @@ -47,6 +47,7 @@ private: Timer fps_timer; Timer frame_timer; + Timer endsequence_timer; World* world; int st_gl_mode; int levelnb; Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -r1.53 -r1.54 --- level.cpp 26 Apr 2004 12:21:22 -0000 1.53 +++ level.cpp 26 Apr 2004 19:11:54 -0000 1.54 @@ -245,8 +245,6 @@ bkgd_bottom.red = 255; bkgd_bottom.green = 255; bkgd_bottom.blue = 255; - endpos = 0; - use_endsequence = false; for(int i = 0; i < 15; ++i) { @@ -312,8 +310,6 @@ LispReader reader(lisp_cdr(root_obj)); version = 0; reader.read_int("version", &version); - use_endsequence = false; - reader.read_bool("use-endsequence", &use_endsequence); if(!reader.read_int("width", &width)) st_abort("No width specified for level.", ""); if (!reader.read_int("start_pos_x", &start_pos_x)) start_pos_x = 100; @@ -513,14 +509,6 @@ } } - // Mark the end position of this level! - // FIXME: -10 is a rather random value, we still need some kind of - // real levelend gola - if (use_endsequence) - endpos = 32*(width-30); - else - endpos = 32*(width-15); - lisp_free(root_obj); fclose(fi); return 0; Index: timer.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/timer.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- timer.cpp 20 Apr 2004 11:09:34 -0000 1.11 +++ timer.cpp 26 Apr 2004 19:11:54 -0000 1.12 @@ -53,6 +53,11 @@ st_pause_count = 0; } +Timer::Timer() +{ + init(true); +} + void Timer::init(bool st_ticks) { Index: tile.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tile.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- tile.cpp 26 Apr 2004 12:21:22 -0000 1.15 +++ tile.cpp 26 Apr 2004 19:11:54 -0000 1.16 @@ -93,6 +93,7 @@ tile->water = false; tile->fullbox = false; tile->distro = false; + tile->goal = false; tile->data = 0; tile->next_tile = 0; tile->anim_speed = 25; @@ -105,6 +106,8 @@ reader.read_bool("water", &tile->water); reader.read_bool("fullbox", &tile->fullbox); reader.read_bool("distro", &tile->distro); + reader.read_bool("goal", &tile->goal); + if(tile->goal) printf("Goal!.\n"); reader.read_int("data", &tile->data); reader.read_int("anim-speed", &tile->anim_speed); reader.read_int("next-tile", &tile->next_tile); Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.109 retrieving revision 1.110 diff -u -d -r1.109 -r1.110 --- gameloop.cpp 26 Apr 2004 15:03:23 -0000 1.109 +++ gameloop.cpp 26 Apr 2004 19:11:53 -0000 1.110 @@ -407,43 +407,47 @@ } } - void GameSession::check_end_conditions() { Player* tux = world->get_tux(); /* End of level? */ - if (tux->base.x >= World::current()->get_level()->endpos + 32 * (get_level()->use_endsequence ? 22 : 10)) + int endpos = (World::current()->get_level()->width-10) * 32; + Tile* endtile = collision_goal(tux->base); + printf("EndTile: %p.\n", endtile); + // fallback in case the other endpositions don't trigger + if (tux->base.x >= endpos || (endtile && endtile->data >= 1) + || (end_sequence && !endsequence_timer.check())) { exit_status = LEVEL_FINISHED; + return; } - else if (tux->base.x >= World::current()->get_level()->endpos && !end_sequence) + else if(!end_sequence && endtile && endtile->data == 0) { end_sequence = true; last_x_pos = -1; music_manager->halt_music(); + endsequence_timer.start(5000); // 5 seconds until we finish the map } - else + else if (!end_sequence && tux->is_dead()) { - // Check End conditions - if (tux->is_dead()) - { - player_status.lives -= 1; - - if (player_status.lives < 0) - { // No more lives!? - if(st_gl_mode != ST_GL_TEST) - drawendscreen(); - - exit_status = GAME_OVER; - } - else - { // Still has lives, so reset Tux to the levelstart - restart_level(); - } + player_status.lives -= 1; + + if (player_status.lives < 0) + { // No more lives!? + if(st_gl_mode != ST_GL_TEST) + drawendscreen(); + + exit_status = GAME_OVER; } - } + else + { // Still has lives, so reset Tux to the levelstart + restart_level(); + } + + return; + } } void |