// Animation Class class Animation { public: Battler *battler; // Battler pointer Pose *pose; // Pose pointer SDL_Rect coords; // Coordinate rect SDL_Rect rect; // Frame rect int frame; // Frame number // Initialization Animation(Battler *battler) { // Set battler this->battler = battler; // Do idle pose set_pose(battler->idle_pose); // Zero coords coords.x = 0; coords.y = 0; rect.x = 0; rect.y = 0; } // Set pose void set_pose(Pose *pose) { // Set pose this->pose = pose; // Set sprite rect dimensions rect.w = pose->surf->w / pose->frames; rect.h = pose->surf->h; // Go to first frame frame = 0; } // Update frame void update() { // Reset to idle if done if (frame > pose->frames) set_pose(battler->idle_pose); // Update rect x rect.x = rect.w * frame; // Increment frame frame++; } // Check if idle bool idle() { return(pose == battler->idle_pose); } // Draw current frame void draw() { SDL_BlitSurface(pose->surf, &rect, screen, &coords); } // Coordinate accessors void set_x(int x) { coords.x = x; } void set_y(int y) { coords.y = y; } int get_x() { return(coords.x); } int get_y() { return(coords.y); } };