supertux
moving_sprite.hpp
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 HEADER_SUPERTUX_OBJECT_MOVING_SPRITE_HPP
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 
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:
63  void set_action(const std::string& action, int loops);
64 
68  void set_action_centered(const std::string& action, int loops);
69 
73  void set_action(const std::string& action, int loops, AnchorPoint anchorPoint);
74 
75 protected:
76  std::string m_sprite_name;
77 
79  std::string m_default_sprite_name;
80  SpritePtr m_sprite;
81  int m_layer;
83 private:
84  MovingSprite(const MovingSprite&) = delete;
85  MovingSprite& operator=(const MovingSprite&) = delete;
86 };
87 
88 #endif
89 
90 /* EOF */
Simple two dimensional vector.
Definition: vector.hpp:24
void set_action(const std::string &action, int loops)
set new action for sprite and resize bounding box.
Definition: moving_sprite.cpp:118
int m_layer
Sprite&#39;s z-position.
Definition: moving_sprite.hpp:81
Definition: object_settings.hpp:35
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: moving_sprite.cpp:107
std::string m_default_sprite_name
The default sprite for this MovingObject.
Definition: moving_sprite.hpp:79
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: moving_sprite.cpp:101
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:31
void set_action_centered(const std::string &action, int loops)
set new action for sprite and re-center bounding box.
Definition: moving_sprite.cpp:125
Definition: reader_mapping.hpp:31
Abstract base class for MovingObjects that are represented by a Sprite.
Definition: moving_sprite.hpp:29
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42