supertux
rock.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.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_ROCK_HPP
18 #define HEADER_SUPERTUX_OBJECT_ROCK_HPP
19 
20 #include "object/moving_sprite.hpp"
21 #include "object/portable.hpp"
22 #include "supertux/physic.hpp"
23 
24 class Rock : public MovingSprite,
25  public Portable
26 {
27 public:
28  Rock(const ReaderMapping& reader, const std::string& spritename = "images/objects/rock/rock.sprite");
29  Rock(const Vector& pos, const std::string& spritename = "images/objects/rock/rock.sprite");
30 
31  virtual void collision_solid(const CollisionHit& hit) override;
32  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
33  virtual void update(float dt_sec) override;
34 
35  virtual void grab(MovingObject& object, const Vector& pos, Direction dir) override;
36  virtual void ungrab(MovingObject& object, Direction dir) override;
37 
38  static std::string class_name() { return "rock"; }
39  virtual std::string get_class_name() const override { return class_name(); }
40  static std::string display_name() { return _("Rock"); }
41  virtual std::string get_display_name() const override { return display_name(); }
42  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(Portable)).add(typeid(Rock)); }
43 
44  virtual ObjectSettings get_settings() override;
45  virtual GameObjectTypes get_types() const override;
46  std::string get_default_sprite_name() const override;
47 
49  virtual void add_wind_velocity(const Vector& velocity, const Vector& end_speed);
50  Physic& get_physic() { return physic; }
51 
52 private:
53  enum Type {
54  SMALL,
55  LARGE
56  };
57 
58 protected:
59  Physic physic;
60  bool on_ground;
61  bool on_ice;
62  Vector last_movement;
63  std::string on_grab_script;
64  std::string on_ungrab_script;
65  bool running_grab_script;
66  bool running_ungrab_script;
67 
68 private:
69  Rock(const Rock&) = delete;
70  Rock& operator=(const Rock&) = delete;
71 };
72 
73 #endif
74 
75 /* EOF */
virtual void add_wind_velocity(const Vector &velocity, const Vector &end_speed)
Adds velocity from wind.
Definition: rock.cpp:285
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: rock.cpp:163
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: rock.cpp:94
Physics engine.
Definition: physic.hpp:27
virtual GameObjectTypes get_types() const override
Get all types of the object, if available.
Definition: rock.cpp:73
An object that inherits from this object is considered "portable" and can be carried around by the pl...
Definition: portable.hpp:29
Definition: object_settings.hpp:39
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_sprite.hpp:60
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
virtual void collision_solid(const CollisionHit &hit) override
this function is called when the object collided with something solid
Definition: rock.cpp:135
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: rock.hpp:41
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: rock.hpp:42
virtual void grab(MovingObject &object, const Vector &pos, Direction dir) override
called each frame when the object has been grabbed.
Definition: rock.cpp:227
Definition: reader_mapping.hpp:32
Definition: rock.hpp:24
Abstract base class for ""MovingObject""s, that are represented by a sprite.
Definition: moving_sprite.hpp:33
This class collects data about a collision.
Definition: collision_hit.hpp:44