#include "sprite.hpp"
#include "video/drawing_context.hpp"
+#include "msg.hpp"
Sprite::Sprite(SpriteData& newdata)
: data(newdata), frame(0), animation_loops(-1)
SpriteData::Action* newaction = data.get_action(name);
if(!newaction) {
-#ifdef DEBUG
- std::cerr << "Action '" << name << "' not found.\n";
-#endif
+ msg_debug("Action '" << name << "' not found.");
return;
}
}
bool
-Sprite::check_animation()
+Sprite::animation_done()
{
return animation_loops == 0;
}
void
Sprite::update()
{
- if(animation_loops == 0)
+ if(animation_done())
return;
Uint32 ticks = SDL_GetTicks();
frame += frame_inc;
if(frame >= get_frames()) {
- frame = fmodf(frame+get_frames(), get_frames());
-
+ frame = fmodf(frame, get_frames());
+
animation_loops--;
- if(animation_loops == 0)
- frame = 0;
+ if(animation_done())
+ frame = get_frames()-1;
}
}
update();
if((int)frame >= get_frames() || (int)frame < 0)
- std::cerr << "Warning: frame out of range: " << (int)frame
+ msg_warning("frame out of range: " << (int)frame
<< "/" << get_frames() << " at " << get_name()
- << "/" << get_action_name() << std::endl;
+ << "/" << get_action_name());
else
context.draw_surface(action->surfaces[(int)frame],
pos - Vector(action->x_offset, action->y_offset),
update();
if((int)frame >= get_frames() || (int)frame < 0)
- std::cerr << "Warning: frame out of range: " << (int)frame
+ msg_warning("frame out of range: " << (int)frame
<< "/" << get_frames() << " at sprite: " << get_name()
- << "/" << get_action_name() << std::endl;
+ << "/" << get_action_name());
else
context.draw_surface_part(action->surfaces[(int)frame], source, size,
pos - Vector(action->x_offset, action->y_offset),