supertux
granito.hpp
1 // SuperTux
2 // Copyright (C) 2023 MatusGuy
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_BADGUY_GRANITO_HPP
18 #define HEADER_SUPERTUX_BADGUY_GRANITO_HPP
19 
20 #include "badguy/walking_badguy.hpp"
21 
22 class GranitoBig;
23 
34 class Granito : public WalkingBadguy
35 {
36 public:
37  static void register_class(ssq::VM& vm);
38 
39 public:
40  Granito(const ReaderMapping& reader,
41  const std::string& sprite_name = "images/creatures/granito/granito.sprite",
42  int layer = LAYER_OBJECTS);
43 
44  virtual void active_update(float dt_sec) override;
45 
46  virtual HitResponse collision_player(Player& player, const CollisionHit& hit) override;
47  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
48 
49  static std::string class_name() { return "granito"; }
50  virtual std::string get_class_name() const override { return class_name(); }
51  virtual std::string get_exposed_class_name() const override { return "Granito"; }
52  static std::string display_name() { return _("Granito"); }
53  virtual std::string get_display_name() const override { return display_name(); }
54  virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(Granito)); }
55 
56  virtual bool is_snipable() const override { return false; }
57  virtual bool is_freezable() const override { return false; }
58  virtual bool is_flammable() const override { return false; }
59 
60  virtual void kill_fall() override;
61 
62  virtual ObjectSettings get_settings() override;
63  virtual GameObjectTypes get_types() const override;
64  virtual void after_editor_set() override;
65 
66  virtual GranitoBig* get_carrier() const;
67  void turn(const Direction& direction);
68 
73  virtual void wave();
74 
79  virtual void sit();
80 
86  void turn(const std::string& direction);
87 
93  void set_walking(bool walking)
94  {
95  if (walking)
96  walk();
97  else
98  stand();
99  }
100 
105  void walk();
106 
112  void walk_for(float seconds);
113 
118  void stand();
119 
124  virtual void jump();
125 
130  virtual void eject();
131 
136  int get_state() const { return static_cast<int>(m_state); }
137 
142  std::string get_carrier_name() const;
143 
150  void reset_detection() { m_has_waved = false; }
151 
152 protected:
153  virtual void initialize() override;
154  virtual void update_hitbox() override;
155 
156  void activate() override;
157 
158 protected:
159  enum Type { DEFAULT, STAND, WALK, SCRIPTABLE, SIT };
160 
167  enum State
168  {
169  STATE_SIT = 0,
175  };
176 
177 protected:
178  virtual bool try_wave();
179  virtual bool try_jump();
180 
181  void restore_original_state();
182 
183 protected:
184  Timer m_walk_interval;
185  State m_state;
186  State m_original_state;
187 
188  bool m_has_waved;
189  bool m_stepped_on;
190  bool m_airborne;
192  std::string m_detect_script;
193  std::string m_carried_script;
195 private:
196  Granito(const Granito&) = delete;
197  Granito& operator=(const Granito&) = delete;
198 };
199 
200 #endif
201 
202 /* EOF */
void reset_detection()
Resets the player detection used for waving, allowing the Detect Script to be ran again...
Definition: granito.hpp:150
void walk()
Makes the Granito walk.
Definition: granito.cpp:479
std::string m_detect_script
Unfortunately, on_ground() sucks.
Definition: granito.hpp:192
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
Called when a collision with another object occurred.
Definition: granito.cpp:211
virtual void initialize() override
called immediately before the first call to initialize
Definition: granito.cpp:327
A ""GranitoBig"" that was given a name can be controlled by scripts.
Definition: granito_big.hpp:29
State
NOTE: Make sure to expose any new enumerators to Squirrel.
Definition: granito.hpp:167
virtual bool is_snipable() const override
Can enemy be sniped by sliding or swimboosting Tux? Returns false if enemy is spiky or too large...
Definition: granito.hpp:56
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: walking_badguy.hpp:55
Definition: granito.hpp:171
virtual void sit()
Makes the Granito sit.
Definition: granito.cpp:420
Definition: granito.hpp:173
int get_state() const
Gets the current Granito state.
Definition: granito.hpp:136
void stand()
Makes the Granito stand, or stop if walking.
Definition: granito.cpp:497
std::string get_carrier_name() const
Gets the name of the Big Granito that is carrying the Granito.
Definition: granito.cpp:320
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: granito.hpp:54
Base class for Badguys that walk on the floor.
Definition: walking_badguy.hpp:25
void activate() override
called when the badguy has been activated.
Definition: granito.cpp:266
Definition: object_settings.hpp:39
Definition: granito.hpp:169
virtual GameObjectTypes get_types() const override
Get all types of the object, if available.
Definition: granito.cpp:273
virtual void jump()
Makes the Granito jump.
Definition: granito.cpp:547
virtual void eject()
Eject itself from the Big Granito.
Definition: granito.cpp:553
virtual void update_hitbox() override
Update hitbox, based on sprite.
Definition: granito.cpp:360
void walk_for(float seconds)
Makes the Granito walk for a specified amount of seconds.
Definition: granito.cpp:489
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
virtual void kill_fall() override
Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned ups...
Definition: granito.cpp:247
Interactable friendly NPC.
Definition: granito.hpp:34
bool m_airborne
True if tux was on top of granito last frame.
Definition: granito.hpp:190
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
void set_walking(bool walking)
Sets the walking state for the Granito.
Definition: granito.hpp:93
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
virtual bool is_flammable() const override
Returns whether to call ignite() when a badguy gets hit by a fire bullet.
Definition: granito.hpp:58
Definition: granito.hpp:174
Definition: granito.hpp:170
virtual void wave()
Makes the Granito wave.
Definition: granito.cpp:406
Definition: reader_mapping.hpp:32
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: granito.hpp:53
This module contains methods controlling the player.
Definition: player.hpp:47
Definition: granito.hpp:172
virtual HitResponse collision_player(Player &player, const CollisionHit &hit) override
Called when the badguy collided with a player.
Definition: granito.cpp:187
This class collects data about a collision.
Definition: collision_hit.hpp:44
virtual void active_update(float dt_sec) override
called each frame when the badguy is activated.
Definition: granito.cpp:51