supertux
scripted_object.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_SCRIPTED_OBJECT_HPP
18 #define HEADER_SUPERTUX_OBJECT_SCRIPTED_OBJECT_HPP
19 
20 #include "object/moving_sprite.hpp"
21 #include "supertux/physic.hpp"
22 
29 class ScriptedObject final : public MovingSprite
30 {
31 public:
32  static void register_class(ssq::VM& vm);
33 
34 public:
35  ScriptedObject(const ReaderMapping& mapping);
36 
37  virtual void update(float dt_sec) override;
38  virtual void draw(DrawingContext& context) override;
39 
40  virtual void collision_solid(const CollisionHit& hit) override;
41  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
42 
43  static std::string class_name() { return "scriptedobject"; }
44  virtual std::string get_class_name() const override { return class_name(); }
45  virtual std::string get_exposed_class_name() const override { return "ScriptedObject"; }
46  static std::string display_name() { return _("Scripted Object"); }
47  virtual std::string get_display_name() const override { return display_name(); }
48  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(ScriptedObject)); }
49 
50  virtual ObjectSettings get_settings() override;
51 
52  virtual void on_flip(float height) override;
53 
54 #ifdef DOXYGEN_SCRIPTING
55 
60  float get_pos_x() const;
66  float get_pos_y() const;
67 #endif
68 
75  void set_velocity(float x, float y);
80  float get_velocity_x() const;
85  float get_velocity_y() const;
86 
92  void enable_gravity(bool enabled);
97  bool gravity_enabled() const;
98 
105  void set_visible(bool visible);
111  bool is_visible() const;
112 
118  void set_solid(bool solid);
123  bool is_solid() const;
124 
125 private:
126  Physic physic;
127  bool solid;
128  bool physic_enabled;
133  bool visible;
134  std::string hit_script;
135  bool new_vel_set;
136  Vector new_vel;
137  Vector new_size;
138 
139 private:
140  ScriptedObject(const ScriptedObject&) = delete;
141  ScriptedObject& operator=(const ScriptedObject&) = delete;
142 };
143 
144 #endif
145 
146 /* EOF */
void set_visible(bool visible)
Definition: scripted_object.cpp:102
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: scripted_object.cpp:143
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: scripted_object.hpp:48
virtual void collision_solid(const CollisionHit &hit) override
this function is called when the object collided with something solid
Definition: scripted_object.cpp:164
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: scripted_object.cpp:182
float get_velocity_y() const
Returns the Y coordinate of the object&#39;s velocity.
Definition: scripted_object.cpp:96
bool is_visible() const
Definition: scripted_object.cpp:108
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: scripted_object.cpp:156
Physics engine.
Definition: physic.hpp:27
bool is_solid() const
Returns ""true"" if the object is solid.
Definition: scripted_object.cpp:125
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: scripted_object.hpp:47
void enable_gravity(bool enabled)
Enables or disables gravity, according to the value of ""enabled"".
Definition: scripted_object.cpp:137
void set_solid(bool solid)
Changes the solidity, according to the value of ""solid"".
Definition: scripted_object.cpp:114
Definition: object_settings.hpp:39
A ""ScriptedObject"" that was given a name can be controlled by scripts.
Definition: scripted_object.hpp:29
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
float get_velocity_x() const
Returns the X coordinate of the object&#39;s velocity.
Definition: scripted_object.cpp:90
bool gravity_enabled() const
Returns ""true"" if the object&#39;s gravity is enabled.
Definition: scripted_object.cpp:131
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
Definition: reader_mapping.hpp:32
Abstract base class for ""MovingObject""s, that are represented by a sprite.
Definition: moving_sprite.hpp:33
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: scripted_object.cpp:193
void set_velocity(float x, float y)
Makes the object move in a certain ""x"" and ""y"" direction (with a certain speed).
Definition: scripted_object.cpp:83
This class collects data about a collision.
Definition: collision_hit.hpp:44