X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsprite%2Fsprite_data.cpp;h=e8128b27d6de3a822479df5d4a493b0f2cf0e29e;hb=1eb64ffd2a23eea4b399c1bb8b9dc10293c334d7;hp=cf0b7a7ccdd4560f29a41d42ea58a1b011d62157;hpb=07ddaed2a657e4d2a3d038fed223fc5827159caf;p=supertux.git diff --git a/src/sprite/sprite_data.cpp b/src/sprite/sprite_data.cpp index cf0b7a7cc..e8128b27d 100644 --- a/src/sprite/sprite_data.cpp +++ b/src/sprite/sprite_data.cpp @@ -34,7 +34,9 @@ SpriteData::Action::Action() { x_offset = 0; y_offset = 0; - z_order = 0; + hitbox_w = 0; + hitbox_h = 0; + z_order = 0; fps = 10; } @@ -58,7 +60,7 @@ SpriteData::SpriteData(const lisp::Lisp* lisp, const std::string& basedir) } } if(actions.empty()) - throw std::runtime_error("Error: Sprite wihtout actions."); + throw std::runtime_error("Error: Sprite without actions."); } SpriteData::~SpriteData() @@ -77,8 +79,14 @@ SpriteData::parse_action(const lisp::Lisp* lisp, const std::string& basedir) throw std::runtime_error( "If there are more than one action, they need names!"); } - lisp->get("x-offset", action->x_offset); - lisp->get("y-offset", action->y_offset); + std::vector hitbox; + if (lisp->get_vector("hitbox", hitbox)) { + if (hitbox.size() != 4) throw std::runtime_error("hitbox must specify exactly 4 coordinates"); + action->x_offset = hitbox[0]; + action->y_offset = hitbox[1]; + action->hitbox_w = hitbox[2]; + action->hitbox_h = hitbox[3]; + } lisp->get("z-order", action->z_order); lisp->get("fps", action->fps); @@ -90,12 +98,18 @@ SpriteData::parse_action(const lisp::Lisp* lisp, const std::string& basedir) throw std::runtime_error("Could not mirror action. Action not found\n" "Mirror actions must be defined after the real one!"); } else { + float max_w = 0; + float max_h = 0; for(int i = 0; static_cast(i) < act_tmp->surfaces.size(); i++) { Surface* surface = new Surface(*(act_tmp->surfaces[i])); surface->hflip(); + max_w = std::max(max_w, (float) surface->get_width()); + max_h = std::max(max_h, (float) surface->get_height()); action->surfaces.push_back(surface); } + if (action->hitbox_w < 1) action->hitbox_w = max_w; + if (action->hitbox_h < 1) action->hitbox_h = max_h; } } else { // Load images std::vector images; @@ -106,9 +120,16 @@ SpriteData::parse_action(const lisp::Lisp* lisp, const std::string& basedir) throw std::runtime_error(msg.str()); } + float max_w = 0; + float max_h = 0; for(std::vector::size_type i = 0; i < images.size(); i++) { - action->surfaces.push_back(new Surface(basedir + images[i])); + Surface* surface = new Surface(basedir + images[i]); + max_w = std::max(max_w, (float) surface->get_width()); + max_h = std::max(max_h, (float) surface->get_height()); + action->surfaces.push_back(surface); } + if (action->hitbox_w < 1) action->hitbox_w = max_w; + if (action->hitbox_h < 1) action->hitbox_h = max_h; } actions[action->name] = action; } @@ -122,4 +143,3 @@ SpriteData::get_action(std::string act) } return i->second; } -