renamed all .h to .hpp
[supertux.git] / src / sprite / sprite.hpp
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 <cassert>
26 #include <map>
27
28 #include "video/surface.hpp"
29 #include "math/vector.hpp"
30 #include "sprite_data.hpp"
31
32 class Sprite
33 {
34 public:
35         Sprite(SpriteData& data);
36         Sprite(const Sprite& other);
37         ~Sprite();
38         
39         /** Draw sprite, automatically calculates next frame */
40         void draw(DrawingContext& context, const Vector& pos, int layer);
41
42         void draw_part(DrawingContext& context, const Vector& source,
43             const Vector& size, const Vector& pos, int layer);
44
45         /** Set action (or state) */
46         void set_action(std::string act, int loops = -1);
47
48         /* Stop animation */
49         void stop_animation()
50         { animation_loops = 0; }
51         /** Check if animation is stopped or not */
52         bool check_animation();
53
54         float get_fps() const
55         { return action->fps; }
56         /** Get current action total frames */
57         int get_frames() const
58         { return action->surfaces.size(); }
59         /** Get sprite's name */
60         const std::string& get_name() const
61         { return data.name; }
62         /** Get current action name */
63         const std::string& get_action_name() const
64         { return action->name; }
65
66         int get_width() const;
67         int get_height() const;
68
69         /** Get current frame */
70         int get_frame() const
71         { return (int)frame; }
72         /** Set current frame */
73         void set_frame(int frame_)
74         { if(frame_ > get_frames()) frame = 0; else frame = frame_; }
75         Surface* get_frame(unsigned int frame)
76         {
77           assert(frame < action->surfaces.size());
78           return action->surfaces[frame];
79         }    
80
81 private:
82         void update();
83
84         SpriteData& data;
85
86         float frame;
87         int animation_loops;
88         Uint32 last_ticks;
89
90         SpriteData::Action* action;
91 };
92
93 #endif
94