d333ce48931bd889b574d80330e058567315f6dc
[supertux.git] / src / object / moving_sprite.hpp
1 //  $Id$
2 //
3 //  SuperTux - MovingSprite Base Class
4 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.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 __MOVING_SPRITE_H__
21 #define __MOVING_SPRITE_H__
22
23 #include <string>
24
25 #include "moving_object.hpp"
26 #include "video/drawing_request.hpp"
27 #include "object/anchor_point.hpp"
28
29 namespace lisp {
30 class Lisp;
31 }
32 class Sprite;
33
34 /**
35  * Abstract base class for MovingObjects that are represented by a Sprite
36  */
37 class MovingSprite : public MovingObject
38 {
39 public:
40   MovingSprite(const Vector& pos, const std::string& sprite_name, int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING);
41   MovingSprite(const lisp::Lisp& reader, const Vector& pos, int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING);
42   MovingSprite(const lisp::Lisp& reader, const std::string& sprite_name, int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING);
43   MovingSprite(const lisp::Lisp& reader, int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING);
44   MovingSprite(const MovingSprite& moving_sprite);
45   MovingSprite& operator=(const MovingSprite& moving_sprite);
46   ~MovingSprite();
47
48   virtual void draw(DrawingContext& context);
49   virtual void update(float elapsed_time);
50
51 protected:
52   std::string sprite_name;
53   Sprite* sprite;
54   int layer; /**< Sprite's z-position. Refer to video/drawing_context.hpp for sensible values. */
55
56   /**
57    * set new action for sprite and resize bounding box.
58    * use with care as you can easily get stuck when resizing the bounding box.
59    */
60   void set_action(const std::string& action, int loops);
61
62   /**
63    * set new action for sprite and re-center bounding box.
64    * use with care as you can easily get stuck when resizing the bounding box.
65    */
66   void set_action_centered(const std::string& action, int loops);
67
68   /**
69    * set new action for sprite and align bounding boxes at anchorPoint.
70    * use with care as you can easily get stuck when resizing the bounding box.
71    */
72   void set_action(const std::string& action, int loops, AnchorPoint anchorPoint);
73 };
74
75 #endif