supertux
conveyor_belt.hpp
1 // SuperTux
2 // Copyright (C) 2022 Raoul1808 <raoulthegeek@gmail.com>
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_CONVEYOR_BELT_HPP
18 #define HEADER_SUPERTUX_OBJECT_CONVEYOR_BELT_HPP
19 
20 #include "object/moving_sprite.hpp"
21 
22 #include "supertux/timer.hpp"
23 
32 class ConveyorBelt final : public MovingSprite
33 {
34 public:
35  static void register_class(ssq::VM& vm);
36 
37 public:
38  ConveyorBelt(const ReaderMapping& reader);
39 
40  ObjectSettings get_settings() override;
41 
42  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
43 
44  static std::string class_name() { return "conveyor-belt"; }
45  virtual std::string get_class_name() const override { return class_name(); }
46  virtual std::string get_exposed_class_name() const override { return "ConveyorBelt"; }
47  static std::string display_name() { return _("Conveyor Belt"); }
48  virtual std::string get_display_name() const override { return display_name(); }
49  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(ConveyorBelt)); }
50 
51  virtual void update(float dt_sec) override;
52  virtual void draw(DrawingContext& context) override;
53 
54  virtual int get_layer() const override { return LAYER_TILES; }
55 
56  virtual void after_editor_set() override;
57 
63  void start();
68  void stop();
73  void move_left();
78  void move_right();
84  void set_speed(float target_speed);
85 
86 private:
87  void update_hitbox() override;
88 
89 private:
90  bool m_running;
91  Direction m_dir;
92  int m_length;
93  float m_speed;
94 
95  float m_frame;
96  int m_frame_index;
97 
98  const float MAX_SPEED = 32.0f;
99 
100 private:
101  ConveyorBelt(const ConveyorBelt&) = delete;
102  ConveyorBelt& operator=(const ConveyorBelt&) = delete;
103 };
104 
105 
106 #endif
107 
108 /* EOF */
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: conveyor_belt.hpp:49
void stop()
Stops the conveyor belt.
Definition: conveyor_belt.cpp:146
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: conveyor_belt.cpp:73
Definition: object_settings.hpp:39
void move_right()
Makes the conveyor shift objects to the right.
Definition: conveyor_belt.cpp:161
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: conveyor_belt.cpp:82
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
void set_speed(float target_speed)
Change the shifting speed of the conveyor.
Definition: conveyor_belt.cpp:169
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: conveyor_belt.hpp:48
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: conveyor_belt.cpp:107
void start()
Starts the conveyor belt.
Definition: conveyor_belt.cpp:139
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
This class represents a platform that moves entities riding it.
Definition: conveyor_belt.hpp:32
void move_left()
Makes the conveyor shift objects to the left.
Definition: conveyor_belt.cpp:153
This class collects data about a collision.
Definition: collision_hit.hpp:44