[Super-tux-commit] supertux/src worldmap.h,1.46,1.47 title.cpp,1.120,1.121 worldmap.cpp,1.122,1.123
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-10-04 21:11:43
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3420/src Modified Files: worldmap.h title.cpp worldmap.cpp gameloop.cpp Log Message: Added support for tile animation on worldmap. Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.120 retrieving revision 1.121 diff -u -d -r1.120 -r1.121 --- title.cpp 24 Sep 2004 15:10:10 -0000 1.120 +++ title.cpp 4 Oct 2004 21:11:24 -0000 1.121 @@ -192,7 +192,7 @@ std::string map_filename = *it; - worldmap.loadmap(map_filename); + worldmap.set_map_filename(map_filename); // hack to erase the extension unsigned int ext_pos = it->find_last_of("."); Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.122 retrieving revision 1.123 diff -u -d -r1.122 -r1.123 --- worldmap.cpp 22 Sep 2004 17:04:22 -0000 1.122 +++ worldmap.cpp 4 Oct 2004 21:11:24 -0000 1.123 @@ -115,13 +115,12 @@ if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0) { int id = 0; - std::string filename = "<invalid>"; Tile* tile = new Tile; tile->north = tile->east = tile->south = tile->west = true; tile->stop = true; tile->auto_walk = false; - + LispReader reader(lisp_cdr(element)); reader.read_int("id", id); @@ -148,7 +147,6 @@ reader.read_bool("stop", tile->stop); reader.read_bool("auto-walk", tile->auto_walk); - reader.read_string("image", filename); reader.read_string("one-way", temp); tile->one_way = BOTH_WAYS; @@ -164,9 +162,23 @@ tile->one_way = WEST_EAST_WAY; } - tile->sprite = new Surface( - datadir + "/images/worldmap/" + filename, - true); + std::vector<std::string> filenames; + reader.read_string_vector("image", filenames); + + if(filenames.size() == 0) + std::cerr << "Warning: no image specified for tile " << id + << ".\nIgnoring...\n" << std::endl; + + for(int i = 0; i < filenames.size(); i++) + { + Surface* image = new Surface( + datadir + "/images/worldmap/" + filenames[i], true); + tile->images.push_back(image); + } + + tile->anim_speed = 25; + reader.read_int("anim-speed", tile->anim_speed); + if (id >= int(tiles.size())) tiles.resize(id+1); @@ -423,7 +435,31 @@ Tile::~Tile() { - delete sprite; + for(std::vector<Surface*>::iterator i = images.begin(); i != images.end(); i++) + delete *i; +} + + +void +Tile::draw(DrawingContext& context, Vector pos) +{ + // same code as from tile_manager.cpp draw_tile() + + if(!images.size()) + return; + + if(images.size() > 1) + { + size_t frame + = ((global_frame_counter*25) / anim_speed) % images.size(); + +std::cerr << "frame: " << frame << std::endl; + context.draw_surface(images[frame], pos, LAYER_TILES); + } + else if (images.size() == 1) + { + context.draw_surface(images[0], pos, LAYER_TILES); + } } //--------------------------------------------------------------------------- @@ -449,6 +485,9 @@ name = "<no title>"; music = "SALCON.MOD"; + global_frame_counter = 0; + frame_timer.init(true); + total_stats.reset(); } @@ -463,6 +502,7 @@ delete teleporterdot; } +// Don't forget to set map_filename before calling this void WorldMap::load_map() { @@ -812,6 +852,12 @@ void WorldMap::update(float delta) { + if(!frame_timer.check()) + { + frame_timer.start(25); + global_frame_counter++; + } + if (enter_level && !tux->is_moving()) { bool level_finished = true; @@ -1027,8 +1073,7 @@ for(int x = 0; x < width; ++x) { Tile* tile = at(Vector(x, y)); - context.draw_surface(tile->sprite, - Vector(x*32 + offset.x, y*32 + offset.y), LAYER_TILES); + tile->draw(context, Vector(x*32 + offset.x, y*32 + offset.y)); } for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i) Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.186 retrieving revision 1.187 diff -u -d -r1.186 -r1.187 --- gameloop.cpp 20 Sep 2004 19:02:46 -0000 1.186 +++ gameloop.cpp 4 Oct 2004 21:11:24 -0000 1.187 @@ -191,8 +191,10 @@ DrawingContext context; currentsector->background->draw(context); - context.draw_text(gold_text, level->get_name(), Vector(screen->w/2, 160), - CENTER_ALLIGN, LAYER_FOREGROUND1); +// context.draw_text(gold_text, level->get_name(), Vector(screen->w/2, 160), +// CENTER_ALLIGN, LAYER_FOREGROUND1); + context.draw_center_text(gold_text, level->get_name(), Vector(0, 160), + LAYER_FOREGROUND1); sprintf(str, "TUX x %d", player_status.lives); context.draw_text(white_text, str, Vector(screen->w/2, 210), @@ -966,6 +968,7 @@ WorldMapNS::WorldMap worldmap; + worldmap.set_map_filename("icyisland.stwm"); // Load the game or at least set the savegame_file variable worldmap.loadgame(slotfile); Index: worldmap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.h,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- worldmap.h 14 Sep 2004 22:26:23 -0000 1.46 +++ worldmap.h 4 Oct 2004 21:11:23 -0000 1.47 @@ -27,6 +27,7 @@ #include "audio/musicref.h" #include "video/screen.h" #include "statistics.h" +#include "special/timer.h" extern Menu* worldmap_menu; @@ -51,8 +52,11 @@ public: Tile(); ~Tile(); - - Surface* sprite; + + void draw(DrawingContext& context, Vector pos); + + std::vector<Surface*> images; + int anim_speed; // Directions in which Tux is allowed to walk from this tile bool north; @@ -230,6 +234,8 @@ Statistics total_stats; void calculate_total_stats(); + Timer frame_timer; + public: WorldMap(); ~WorldMap(); @@ -257,7 +263,8 @@ /* Save map to slot */ void savegame(const std::string& filename); - /* Load map from slot */ + /* Load map from slot + You should call set_map_filename() before this */ void loadgame(const std::string& filename); /* Load map directly from file */ void loadmap(const std::string& filename); @@ -271,6 +278,9 @@ const int& get_start_y() const { return start_y; } + void set_map_filename(std::string filename) + { map_filename = filename; } + private: void on_escape_press(); }; |