[Super-tux-commit] supertux/src collision_grid.cpp,1.1,1.2 collision_grid.h,1.2,1.3 gameloop.cpp,1.2
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-12-05 16:57:28
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16796/src Modified Files: collision_grid.cpp collision_grid.h gameloop.cpp sector.cpp sector.h worldmap.cpp worldmap.h Log Message: -Incorporated Marcin KoÅcielnicki patch that reintroduces the flying snowball, thanks -Changed worldmapfile format to support intro texts -Moved intro.txt extro.txt and extro-bonus.txt to levels/world1 and levels/bonus1 -Added a new text mode to the textfile system display that aligns the text at the left side. This is alot easier to read than all text centered. Still the current font is hard to read for long texts and should be improved/replaced somehow... -Use new translation system in the .txt files Index: sector.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.h,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- sector.h 29 Nov 2004 16:03:32 -0000 1.29 +++ sector.h 5 Dec 2004 16:57:14 -0000 1.30 @@ -139,6 +139,8 @@ typedef std::vector<GameObject*> GameObjects; GameObjects gameobjects; + Rectangle get_active_region(); + private: void fix_old_tiles(); Index: collision_grid.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/collision_grid.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- collision_grid.h 1 Dec 2004 15:58:38 -0000 1.2 +++ collision_grid.h 5 Dec 2004 16:57:13 -0000 1.3 @@ -25,6 +25,8 @@ void check_collisions(); private: + friend class CollisionGridIterator; + struct ObjectWrapper { MovingObject* object; @@ -58,6 +60,7 @@ float height; float cell_width; float cell_height; + int iterator_timestamp; }; extern CollisionGrid* bla; Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.138 retrieving revision 1.139 diff -u -d -r1.138 -r1.139 --- worldmap.cpp 2 Dec 2004 01:41:57 -0000 1.138 +++ worldmap.cpp 5 Dec 2004 16:57:14 -0000 1.139 @@ -49,6 +49,8 @@ Menu* worldmap_menu = 0; +static const float TUXSPEED = 200; + namespace WorldMapNS { Direction reverse_dir(Direction direction) @@ -220,8 +222,8 @@ } else { - // Let tux walk a few pixels (20 pixel/sec) - offset += 20.0f * delta; + // Let tux walk + offset += TUXSPEED * delta; if (offset > 32) { // We reached the next tile, so we check what to do now @@ -349,6 +351,7 @@ name = "<no title>"; music = "salcon.mod"; + intro_displayed = false; total_stats.reset(); } @@ -393,6 +396,7 @@ const lisp::Lisp* props = iter.lisp(); props->get("name", name); props->get("music", music); + props->get("intro-filename", intro_filename); props->get("start_pos_x", start_x); props->get("start_pos_y", start_y); } else if(iter.item() == "special-tiles") { @@ -827,14 +831,13 @@ } /* The porpose of the next checking is that if the player lost the level (in case there is one), don't show anything */ - if(level_finished) - { - if (!level->extro_filename.empty()) - { + if(level_finished) { + if (!level->extro_filename.empty()) { // Display a text file - display_text_file(level->extro_filename, SCROLL_SPEED_MESSAGE, - white_big_text , white_text, white_small_text, blue_text ); - } + std::string filename = levels_path + level->extro_filename; + display_text_file(filename, SCROLL_SPEED_MESSAGE, + white_big_text , white_text, white_small_text, blue_text ); + } if (!level->next_worldmap.empty()) { @@ -1035,50 +1038,47 @@ song = SoundManager::get()->load_music(datadir + "/music/" + music); SoundManager::get()->play_music(song); - FrameRate frame_rate(10); - frame_rate.set_frame_limit(false); - - frame_rate.start(); + if(!intro_displayed && intro_filename != "") { + std::string filename = levels_path + intro_filename; + display_text_file(filename, SCROLL_SPEED_MESSAGE, + white_big_text, white_text, white_small_text, blue_text); + intro_displayed = true; + } + Uint32 lastticks = SDL_GetTicks(); DrawingContext context; - while(!quit) - { - float delta = frame_rate.get(); - - delta *= 1.3f; - - if (delta > 10.0f) - delta = .3f; - - frame_rate.update(); - - Vector tux_pos = tux->get_pos(); - if (1) - { - offset.x = -tux_pos.x + screen->w/2; - offset.y = -tux_pos.y + screen->h/2; - - if (offset.x > 0) offset.x = 0; - if (offset.y > 0) offset.y = 0; + while(!quit) { + Uint32 ticks = SDL_GetTicks(); + float elapsed_time = float(ticks - lastticks) / 1000; + global_time += elapsed_time; + lastticks = ticks; + + // 40 fps minimum + if(elapsed_time > .025) + elapsed_time = .025; + + Vector tux_pos = tux->get_pos(); + + offset.x = -tux_pos.x + screen->w/2; + offset.y = -tux_pos.y + screen->h/2; - if (offset.x < screen->w - width*32) offset.x = screen->w - width*32; - if (offset.y < screen->h - height*32) offset.y = screen->h - height*32; - } + if (offset.x > 0) offset.x = 0; + if (offset.y > 0) offset.y = 0; - draw(context, offset); - get_input(); - update(delta); + if (offset.x < screen->w - width*32) offset.x = screen->w - width*32; + if (offset.y < screen->h - height*32) offset.y = screen->h - height*32; + + draw(context, offset); + get_input(); + update(elapsed_time); - if(Menu::current()) - { - Menu::current()->draw(context); - mouse_cursor->draw(context); - } - - context.do_drawing(); - - SDL_Delay(20); + if(Menu::current()) { + Menu::current()->draw(context); + mouse_cursor->draw(context); } + + context.do_drawing(); + } } void @@ -1110,6 +1110,7 @@ writer.write_string("title", std::string(name + " - " + nb_solved_levels_str+"/"+total_levels_str)); writer.write_string("map", map_filename); + writer.write_bool("intro-displayed", intro_displayed); writer.write_int("lives", player_status.lives); writer.write_int("distros", player_status.lives); writer.write_int("max-score-multiplier", player_status.max_score_multiplier); @@ -1163,6 +1164,7 @@ savegame->get("map", map_filename); load_map(); + savegame->get("intro-displayed", intro_displayed); savegame->get("lives", player_status.lives); savegame->get("distros", player_status.distros); savegame->get("max-score-multiplier", player_status.max_score_multiplier); @@ -1232,8 +1234,3 @@ } } // namespace WorldMapNS - -/* Local Variables: */ -/* mode:c++ */ -/* End: */ - Index: collision_grid.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/collision_grid.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- collision_grid.cpp 29 Nov 2004 16:03:30 -0000 1.1 +++ collision_grid.cpp 5 Dec 2004 16:57:13 -0000 1.2 @@ -4,11 +4,13 @@ #include "collision_grid.h" #include "special/collision.h" #include "sector.h" +#include "collision_grid_iterator.h" static const float DELTA = .001; CollisionGrid::CollisionGrid(float newwidth, float newheight) - : width(newwidth), height(newheight), cell_width(128), cell_height(128) + : width(newwidth), height(newheight), cell_width(128), cell_height(128), + iterator_timestamp(0) { cells_x = size_t(width / cell_width) + 1; cells_y = size_t(height / cell_height) + 1; @@ -116,8 +118,8 @@ void CollisionGrid::check_collisions() { - for(Objects::iterator i = objects.begin(); i != objects.end(); ++i) { - ObjectWrapper* wrapper = *i; + CollisionGridIterator iter(*this, Sector::current()->get_active_region()); + while(ObjectWrapper* wrapper = iter.next_wrapper()) { MovingObject* object = wrapper->object; if(!object->is_valid()) continue; @@ -140,8 +142,7 @@ void CollisionGrid::collide_object(ObjectWrapper* wrapper) { - static int timestamp = 0; - timestamp++; + iterator_timestamp++; const Rectangle& bbox = wrapper->object->bbox; for(float y = bbox.p1.y; y < bbox.p2.y; y += cell_height) { @@ -158,13 +159,13 @@ entry = entry->next) { ObjectWrapper* wrapper2 = entry->object_wrapper; // only check each object once (even if it is in multiple cells) - if(wrapper2->timestamp == timestamp) + if(wrapper2->timestamp == iterator_timestamp) continue; // don't collide with objects we already collided with if(wrapper2->id <= wrapper->id) continue; - wrapper->timestamp = timestamp; + wrapper->timestamp = iterator_timestamp; collide_object_object(wrapper, wrapper2); } } Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.210 retrieving revision 1.211 diff -u -d -r1.210 -r1.211 --- gameloop.cpp 2 Dec 2004 00:25:27 -0000 1.210 +++ gameloop.cpp 5 Dec 2004 16:57:13 -0000 1.211 @@ -964,12 +964,6 @@ stream << slot; std::string slotfile = st_save_dir + "/slot" + stream.str() + ".stsg"; - if (access(slotfile.c_str(), F_OK) != 0) - { - shrink_fade(Vector(screen->w/2,screen->h/2), 600); - draw_intro(); - } - fadeout(256); DrawingContext context; context.draw_text(white_text, "Loading...", Index: worldmap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.h,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -r1.53 -r1.54 --- worldmap.h 2 Dec 2004 00:25:27 -0000 1.53 +++ worldmap.h 5 Dec 2004 16:57:14 -0000 1.54 @@ -199,6 +199,9 @@ Vector offset; std::string savegame_file; + + std::string intro_filename; + bool intro_displayed; void get_level_title(Level& level); Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.58 retrieving revision 1.59 diff -u -d -r1.58 -r1.59 --- sector.cpp 1 Dec 2004 23:26:30 -0000 1.58 +++ sector.cpp 5 Dec 2004 16:57:13 -0000 1.59 @@ -43,6 +43,7 @@ #include "resources.h" #include "statistics.h" #include "collision_grid.h" +#include "collision_grid_iterator.h" #include "special/collision.h" #include "math/rectangle.h" #include "math/aatriangle.h" @@ -55,6 +56,7 @@ #include "badguy/snowball.h" #include "badguy/bouncing_snowball.h" #include "badguy/flame.h" +#include "badguy/flyingsnowball.h" #include "badguy/mriceblock.h" #include "badguy/mrbomb.h" #include "badguy/dispenser.h" @@ -133,6 +135,8 @@ return new BouncingSnowball(reader); } else if(name == "flame") { return new Flame(reader); + } else if(name == "flyingsnowball") { + return new FlyingSnowBall(reader); } else if(name == "mriceblock") { return new MrIceBlock(reader); } else if(name == "mrbomb") { @@ -466,11 +470,28 @@ return best_reset_point; } +Rectangle +Sector::get_active_region() +{ + return Rectangle( + camera->get_translation() - Vector(1600, 1200), + camera->get_translation() + Vector(1600, 1200)); +} + void Sector::action(float elapsed_time) { player->check_bounds(camera); - + +#if 0 + CollisionGridIterator iter(*grid, get_active_region()); + while(MovingObject* object = iter.next()) { + if(!object->is_valid()) + continue; + + object->action(elapsed_time); + } +#else /* update objects */ for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) { @@ -480,7 +501,8 @@ object->action(elapsed_time); } - +#endif + /* Handle all possible collisions. */ collision_handler(); update_game_objects(); @@ -555,7 +577,16 @@ { context.push_transform(); context.set_translation(camera->get_translation()); - + +#if 0 + CollisionGridIterator iter(*grid, get_active_region()); + while(MovingObject* object = iter.next()) { + if(!object->is_valid()) + continue; + + object->draw(context); + } +#else for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) { GameObject* object = *i; @@ -564,6 +595,7 @@ object->draw(context); } +#endif context.pop_transform(); } |