X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsprite%2Fsprite_data.cpp;h=8d223af4cbff25551bddc87c6a26af18fc29515d;hb=4434ccd7364d603d6bf952ff1df56e28e1978a63;hp=16207ff300b30ceb45c846cf67f01afc4664a0b6;hpb=c0093d25093395cb62fc2526ab42be65a9f015b8;p=supertux.git diff --git a/src/sprite/sprite_data.cpp b/src/sprite/sprite_data.cpp index 16207ff30..8d223af4c 100644 --- a/src/sprite/sprite_data.cpp +++ b/src/sprite/sprite_data.cpp @@ -1,7 +1,7 @@ // $Id$ // // SuperTux -// Copyright (C) 2004 Ingo Ruhnke +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include @@ -23,17 +24,19 @@ #include #include -#include "sprite_data.h" -#include "app/globals.h" -#include "app/setup.h" -#include "video/drawing_context.h" -#include "lisp/list_iterator.h" +#include "sprite_data.hpp" +#include "resources.hpp" +#include "video/drawing_context.hpp" +#include "lisp/list_iterator.hpp" +#include "log.hpp" SpriteData::Action::Action() { x_offset = 0; y_offset = 0; - z_order = 0; + hitbox_w = 0; + hitbox_h = 0; + z_order = 0; fps = 10; } @@ -44,20 +47,18 @@ SpriteData::Action::~Action() delete *i; } -SpriteData::SpriteData(const lisp::Lisp* lisp) +SpriteData::SpriteData(const lisp::Lisp* lisp, const std::string& basedir) { lisp::ListIterator iter(lisp); while(iter.next()) { if(iter.item() == "name") { iter.value()->get(name); } else if(iter.item() == "action") { - parse_action(iter.lisp()); + parse_action(iter.lisp(), basedir); } else { - std::cerr << "Unknown sprite field: " << iter.item() << "\n"; + log_warning << "Unknown sprite field: " << iter.item() << std::endl; } } - if(name.empty()) - throw std::runtime_error("Error: Sprite wihtout name."); if(actions.empty()) throw std::runtime_error("Error: Sprite wihtout actions."); } @@ -69,7 +70,7 @@ SpriteData::~SpriteData() } void -SpriteData::parse_action(const lisp::Lisp* lisp) +SpriteData::parse_action(const lisp::Lisp* lisp, const std::string& basedir) { Action* action = new Action; @@ -78,8 +79,14 @@ SpriteData::parse_action(const lisp::Lisp* lisp) 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); @@ -91,13 +98,18 @@ SpriteData::parse_action(const lisp::Lisp* lisp) 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(sdl_surface_from_sdl_surface( - act_tmp->surfaces[i]->impl->get_sdl_surface(), true), true); - surface->apply_filter(HORIZONTAL_FLIP_FILTER); + Surface* surface = new Surface(*(act_tmp->surfaces[i])); + surface->hflip(); + max_w = std::max(max_w, surface->get_width()); + max_h = std::max(max_h, 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; @@ -108,10 +120,16 @@ SpriteData::parse_action(const lisp::Lisp* lisp) 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(datadir + "/images/" + images[i], true)); + Surface* surface = new Surface(basedir + images[i]); + max_w = std::max(max_w, surface->get_width()); + max_h = std::max(max_h, 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; } @@ -125,4 +143,3 @@ SpriteData::get_action(std::string act) } return i->second; } -