supertux
worldmap_object.hpp
1 // SuperTux
2 // Copyright (C) 2016 Hume2 <teratux.mail@gmail.com>
3 // 2023 Vankata453
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_WORLDMAP_WORLDMAP_OBJECT_HPP
19 #define HEADER_SUPERTUX_WORLDMAP_WORLDMAP_OBJECT_HPP
20 
21 #include "object/moving_sprite.hpp"
22 
23 #include "math/vector.hpp"
24 
25 class DrawingContext;
26 class ReaderMapping;
27 
28 namespace worldmap {
29 
31 {
32 protected:
33  static bool in_worldmap();
34 
35 public:
36  WorldMapObject(const ReaderMapping& mapping, const std::string& default_sprite);
37  WorldMapObject(const ReaderMapping& mapping);
38  WorldMapObject(const Vector& pos, const std::string& default_sprite);
39  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(WorldMapObject)); }
40 
41  static std::string class_name() { return "worldmap-object"; }
42  virtual std::string get_class_name() const override { return class_name(); }
43 
44  void draw(DrawingContext& context) override;
45 
47  virtual void draw_worldmap(DrawingContext& context);
48 
49  void update(float) override;
50 
51  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override { return FORCE_MOVE; }
52  virtual ObjectSettings get_settings() override;
53  virtual void move_to(const Vector& pos) override;
54 
55  Vector get_tile_pos() const { return { m_tile_x, m_tile_y }; }
56 
57 private:
58  void initialize();
59 
60  void draw_normal(DrawingContext& context);
61  void update_pos();
62 
63 private:
64  int m_tile_x;
65  int m_tile_y;
66 
67 private:
68  WorldMapObject(const WorldMapObject&) = delete;
69  WorldMapObject& operator=(const WorldMapObject&) = delete;
70 };
71 
72 } // namespace worldmap
73 
74 #endif
75 
76 /* EOF */
virtual void draw_worldmap(DrawingContext &context)
Draws the object, when on a worldmap.
Definition: worldmap_object.cpp:93
void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: worldmap_object.cpp:84
Definition: worldmap_object.hpp:30
Definition: object_settings.hpp:39
void update(float) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: worldmap_object.cpp:110
Definition: object_settings.hpp:32
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
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: worldmap_object.hpp:51
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: worldmap_object.hpp:39
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 collects data about a collision.
Definition: collision_hit.hpp:44