[Super-tux-commit] supertux/lib/special sprite.cpp,1.24,1.25 sprite.h,1.14,1.15
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-09-09 10:00:13
|
Update of /cvsroot/super-tux/supertux/lib/special In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9119/lib/special Modified Files: sprite.cpp sprite.h Log Message: Implemented mirroring in Sprite, so that now it's possible to adjust left offsets. Index: sprite.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- sprite.cpp 8 Sep 2004 14:12:48 -0000 1.24 +++ sprite.cpp 9 Sep 2004 10:00:00 -0000 1.25 @@ -75,17 +75,7 @@ lispreader.read_int("z-order", action->z_order); lispreader.read_float("fps", action->fps); - std::vector<std::string> images; - if(!lispreader.read_string_vector("images", images)) - Termination::abort("Sprite contains no images: ", action->name.c_str()); - - for(std::vector<std::string>::size_type i = 0; i < images.size(); i++) - { - action->surfaces.push_back( - new Surface(datadir + "/images/" + images[i], true)); - } - - // TODO: add a top filter entry + /* TODO: add a top filter entry */ std::vector <int> mask_color; lispreader.read_int_vector("apply-mask", mask_color); if(mask_color.size() == 4) @@ -97,6 +87,33 @@ } } + action->mirror = false; + std::string mirror_action; + lispreader.read_string("mirror-action", mirror_action); + if(!mirror_action.empty()) + { + action->mirror = true; + Action* act_tmp = get_action(mirror_action); + if(act_tmp == NULL) + std::cerr << "Warning: Could not mirror action. Action not found\n" + "Mirror actions must be defined after the real one!\n"; + else + action->surfaces = act_tmp->surfaces; + } + + // Load images + if(!action->mirror) + { + std::vector<std::string> images; + if(!lispreader.read_string_vector("images", images)) + Termination::abort("Sprite contains no images: ", action->name.c_str()); + + for(std::vector<std::string>::size_type i = 0; i < images.size(); i++) + { + action->surfaces.push_back( + new Surface(datadir + "/images/" + images[i], true)); + } + } actions[action->name] = action; } @@ -133,6 +150,18 @@ action = i->second; } +Sprite::Action* +Sprite::get_action(std::string act) +{ +Actions::iterator i = actions.find(act); +if(i == actions.end()) + { + std::cerr << "Warning: Action '" << act << "' not found on Sprite '" << name << "'\n"; + return NULL; + } +return i->second; +} + void Sprite::start_animation(int loops) { Index: sprite.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- sprite.h 27 Aug 2004 11:20:27 -0000 1.14 +++ sprite.h 9 Sep 2004 10:00:00 -0000 1.15 @@ -48,6 +48,10 @@ /** Frames per second */ float fps; + /** Mirror is used to avoid duplicating left and right side + sprites */ + bool mirror; + std::vector<Surface*> surfaces; }; @@ -112,6 +116,9 @@ void init_defaults(Action* act); void parse_action(LispReader& lispreader); + /** Get an action */ + Action* get_action(std::string act); + void update(); void reset(); |