Goodbye gettext, Welcome TinyGetText
[supertux.git] / lib / special / sprite.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #ifndef SUPERTUX_SPRITE_H
21 #define SUPERTUX_SPRITE_H
22
23 #include <string>
24 #include <vector>
25 #include <map>
26
27 #include "../utils/lispreader.h"
28 #include "../video/surface.h"
29 #include "../math/vector.h"
30 #include "sprite_data.h"
31
32 namespace SuperTux
33 {
34   class Sprite
35   {
36   public:
37     Sprite(SpriteData& data);
38     Sprite(const Sprite& other);
39     ~Sprite();
40     
41     /** Draw sprite, automatically calculates next frame */
42     void draw(DrawingContext& context, const Vector& pos, int layer,
43         Uint32 drawing_effect = NONE_EFFECT);
44
45     void draw_part(DrawingContext& context, const Vector& source,
46         const Vector& size, const Vector& pos, int layer,
47         Uint32 drawing_effect = NONE_EFFECT);
48
49     /** Set action (or state) */
50     void set_action(std::string act);
51
52     /* Start an animation
53        -1 - for infinite
54        0  - stopped
55        1,2,3  - one, two, three times... */
56     void start_animation(int loops);
57     /* Stop animation */
58     void stop_animation()
59     { start_animation(0); }
60     /** Check if animation is stopped or not */
61     bool check_animation();
62     /** Reverse the animation */
63     void reverse_animation(bool reverse);
64
65     float get_fps() const
66     { return action->fps; }
67     /** Get current action total frames */
68     int get_frames() const
69     { return action->surfaces.size(); }
70     /** Get sprite's name */
71     const std::string& get_name() const
72     { return data.name; }
73     /** Get current action name */
74     const std::string& get_action_name() const
75     { return action->name; }
76
77     int get_width() const;
78     int get_height() const;
79
80     /** Get current frame */
81     int get_frame() const
82     { return (int)frame; }
83     /** Set current frame */
84     void set_frame(int frame_)
85     { if(frame_ > get_frames()) frame = 0; else frame = frame_; }
86     Surface* get_frame(unsigned int frame)
87     {
88       if(frame < action->surfaces.size())
89         return action->surfaces[frame];
90       else
91         return action->surfaces[0];
92     }    
93   private:
94     void update();
95     void reset();
96
97     SpriteData& data;
98
99     float frame;
100     int animation_loops;
101     bool animation_reversed;
102     float last_tick;
103
104     SpriteData::Action* action;
105     std::string next_action;
106   };
107 } //namespace SuperTux
108
109 #endif /*SUPERTUX_SPRITE_H*/
110
111 /* Local Variables: */
112 /* mode:c++ */
113 /* End: */