X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fspecial%2Fsprite.h;h=4906aff5f3763ed5dcaaf033d540d51ee5ee78b4;hb=be7f9f65018ed21515d389e8bd50f6f1eb988375;hp=3e03ee2db572ec6a1373400e16971db92b99edd3;hpb=9c511ea692d3a2339597211f08f18ea74fad35ec;p=supertux.git diff --git a/lib/special/sprite.h b/lib/special/sprite.h index 3e03ee2db..4906aff5f 100644 --- a/lib/special/sprite.h +++ b/lib/special/sprite.h @@ -22,56 +22,104 @@ #include #include - -#include "utils/lispreader.h" -#include "video/surface.h" -#include "math/vector.h" - -class Sprite -{ - private: - std::string name; - - int x_hotspot; - int y_hotspot; - - /** Frames per second */ - float fps; - - /** Number of seconds that a frame is displayed until it is switched - to the next frame */ - float frame_delay; - - float time; - - std::vector surfaces; - - void init_defaults(); - public: - /** cur has to be a pointer to data in the form of ((x-hotspot 5) - (y-hotspot 10) ...) */ - Sprite(lisp_object_t* cur); - ~Sprite(); - - void reset(); - - /** Update the sprite and process to the next frame */ - void update(float delta); - void draw(DrawingContext& context, const Vector& pos, int layer, - Uint32 drawing_effect = NONE_EFFECT); - int get_current_frame() const; - - float get_fps() { return fps; } ; - int get_frames() { return surfaces.size(); } ; - - std::string get_name() const { return name; } - int get_width() const; - int get_height() const; - - Surface* get_frame(unsigned int frame) - { if(frame < surfaces.size()) return surfaces[frame]; - else return surfaces[0]; } -}; +#include + +#include "../utils/lispreader.h" +#include "../video/surface.h" +#include "../math/vector.h" + +namespace SuperTux + { + + class Sprite + { + private: + + struct Action + { + std::string name; + + int x_hotspot; + int y_hotspot; + + /** Frames per second */ + float fps; + + std::vector surfaces; + }; + + public: + /** cur has to be a pointer to data in the form of ((x-hotspot 5) + (y-hotspot 10) ...) */ + Sprite(lisp_object_t* cur); + ~Sprite(); + + /** Draw sprite, automatically calculates next frame */ + void draw(DrawingContext& context, const Vector& pos, int layer, + Uint32 drawing_effect = NONE_EFFECT); + + /** Set action (or state) */ + void set_action(std::string act); + + /* Start an animation + -1 - for infinite + 0 - stopped + 1,2,3 - one, two, three times... */ + void start_animation(int loops); + /** Check if animation is stopped or not */ + bool check_animation(); + /** Reverse the animation */ + void reverse_animation(); + + float get_fps() + { return action->fps; } + /** Get current action total frames */ + int get_frames() + { return action->surfaces.size(); } + /** Get sprite's name */ + std::string get_name() const + { return name; } + /** Get current action name */ + std::string get_action_name() const + { return action->name; } + int get_width(); + int get_height(); + + /** Get current frame */ + int get_frame() + { return (int)frame; } + /** Set current frame */ + void set_frame(int frame_) + { if(frame_ > get_frames()) frame = 0; else frame = frame_; } + Surface* get_frame(unsigned int frame) + { + if(frame < action->surfaces.size()) + return action->surfaces[frame]; + else + return action->surfaces[0]; + } + private: + void init_defaults(Action* act); + void parse_action(LispReader& lispreader); + + void update(); + void reset(); + + std::string name; + + float frame; + int animation_loops; + bool animation_reversed; + float last_tick; + + typedef std::map Actions; + Actions actions; + + Action* action; + std::string next_action; + }; + +} //namespace SuperTux #endif /*SUPERTUX_SPRITE_H*/