| 1 | // SuperTux - MovingSprite Base Class |
| 2 | // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de> |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | #ifndef HEADER_SUPERTUX_OBJECT_MOVING_SPRITE_HPP |
| 18 | #define |
| 19 | |
| 20 | #include "math/anchor_point.hpp" |
| 21 | #include "sprite/sprite.hpp" |
| 22 | #include "sprite/sprite_ptr.hpp" |
| 23 | #include "supertux/moving_object.hpp" |
| 24 | #include "video/drawing_context.hpp" |
| 25 | |
| 26 | class ReaderMapping; |
| 27 | |
| 28 | /** Abstract base class for MovingObjects that are represented by a Sprite */ |
| 29 | class MovingSprite : public MovingObject |
| 30 | { |
| 31 | public: |
| 32 | MovingSprite(const Vector& pos, |
| 33 | const std::string& sprite_name, |
| 34 | int layer = LAYER_OBJECTS, |
| 35 | CollisionGroup collision_group = COLGROUP_MOVING); |
| 36 | MovingSprite(const ReaderMapping& reader, |
| 37 | const Vector& pos, |
| 38 | int layer = LAYER_OBJECTS, |
| 39 | CollisionGroup collision_group = COLGROUP_MOVING); |
| 40 | MovingSprite(const ReaderMapping& reader, |
| 41 | const std::string& sprite_name, |
| 42 | int layer = LAYER_OBJECTS, |
| 43 | CollisionGroup collision_group = COLGROUP_MOVING); |
| 44 | MovingSprite(const ReaderMapping& reader, |
| 45 | int layer = LAYER_OBJECTS, |
| 46 | CollisionGroup collision_group = COLGROUP_MOVING); |
| 47 | |
| 48 | virtual void draw(DrawingContext& context) override; |
| 49 | virtual void update(float dt_sec) override; |
| 50 | virtual std::string get_class() const override { return "moving-sprite" ; } |
| 51 | virtual std::string get_default_sprite_name() const { return m_default_sprite_name; } |
| 52 | |
| 53 | virtual ObjectSettings get_settings() override; |
| 54 | virtual void after_editor_set() override; |
| 55 | |
| 56 | std::string get_sprite_name() const; |
| 57 | void change_sprite(const std::string& new_sprite_name); |
| 58 | void spawn_explosion_sprites(int count, const std::string& sprite_path); |
| 59 | |
| 60 | protected: |
| 61 | /** set new action for sprite and resize bounding box. use with |
| 62 | care as you can easily get stuck when resizing the bounding box. */ |
| 63 | void set_action(const std::string& action, int loops); |
| 64 | |
| 65 | /** set new action for sprite and re-center bounding box. use with |
| 66 | care as you can easily get stuck when resizing the bounding |
| 67 | box. */ |
| 68 | void set_action_centered(const std::string& action, int loops); |
| 69 | |
| 70 | /** set new action for sprite and align bounding boxes at |
| 71 | anchorPoint. use with care as you can easily get stuck when |
| 72 | resizing the bounding box. */ |
| 73 | void set_action(const std::string& action, int loops, AnchorPoint anchorPoint); |
| 74 | |
| 75 | protected: |
| 76 | std::string m_sprite_name; |
| 77 | |
| 78 | /** The default sprite for this MovingObject */ |
| 79 | std::string m_default_sprite_name; |
| 80 | SpritePtr m_sprite; |
| 81 | int m_layer; /**< Sprite's z-position. Refer to video/drawing_context.hpp for sensible values. */ |
| 82 | |
| 83 | private: |
| 84 | MovingSprite(const MovingSprite&) = delete; |
| 85 | MovingSprite& operator=(const MovingSprite&) = delete; |
| 86 | }; |
| 87 | |
| 88 | #endif |
| 89 | |
| 90 | /* EOF */ |
| 91 | |