Removed trailing whitespace from all *.?pp files
[supertux.git] / src / object / camera.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_CAMERA_HPP
18 #define HEADER_SUPERTUX_OBJECT_CAMERA_HPP
19
20 #include <memory>
21
22 #include "math/vector.hpp"
23 #include "supertux/game_object.hpp"
24 #include "supertux/script_interface.hpp"
25 #include "supertux/timer.hpp"
26 #include "util/reader_fwd.hpp"
27
28 class Sector;
29 class Path;
30 class PathWalker;
31 class CameraConfig;
32
33 class Camera : public GameObject,
34                public ScriptInterface
35 {
36 public:
37   Camera(Sector* sector, std::string name = "");
38   virtual ~Camera();
39
40   /// parse camera mode from lisp file
41   void parse(const Reader& reader);
42
43   /// reset camera position
44   void reset(const Vector& tuxpos);
45
46   /** return camera position */
47   const Vector& get_translation() const;
48
49   virtual void update(float elapsed_time);
50
51   virtual void draw(DrawingContext& );
52
53   virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
54   virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
55
56   // shake camera in a direction 1 time
57   void shake(float speed, float x, float y);
58
59   void set_scrolling(int scroll_x, int scroll_y)
60   {
61     translation.x = scroll_x;
62     translation.y = scroll_y;
63   }
64
65   /**
66    * scroll the upper left edge of the camera in scrolltime seconds
67    * to the position goal
68    */
69   void scroll_to(const Vector& goal, float scrolltime);
70
71   void reload_config();
72
73   enum CameraMode
74   {
75     NORMAL, AUTOSCROLL, SCROLLTO, MANUAL
76   };
77   CameraMode mode;
78
79   /**
80    * get the coordinates of the point directly in the center of this camera
81    */
82   Vector get_center() const;
83
84 private:
85   void update_scroll_normal(float elapsed_time);
86   void update_scroll_autoscroll(float elapsed_time);
87   void update_scroll_to(float elapsed_time);
88   void keep_in_bounds(Vector& vector);
89   void shake();
90
91 private:
92   /**
93    * The camera basically provides lookahead on the left or right side
94    * or is undecided.
95    */
96   enum LookaheadMode {
97     LOOKAHEAD_NONE, LOOKAHEAD_LEFT, LOOKAHEAD_RIGHT
98   };
99
100 private:
101   Vector translation;
102
103   Sector* sector;
104
105   // normal mode
106   LookaheadMode lookahead_mode;
107   float changetime;
108   Vector lookahead_pos;
109   Vector peek_pos;
110   Vector cached_translation;
111
112   // autoscroll mode
113   std::unique_ptr<Path> autoscroll_path;
114   std::unique_ptr<PathWalker> autoscroll_walker;
115
116   // shaking
117   Timer shaketimer;
118   float shakespeed;
119   float shakedepth_x;
120   float shakedepth_y;
121
122   // scrollto mode
123   Vector scroll_from;
124   Vector scroll_goal;
125   float scroll_to_pos;
126   float scrollspeed;
127
128   CameraConfig *config;
129
130 private:
131   Camera(const Camera&);
132   Camera& operator=(const Camera&);
133 };
134
135 #endif /*SUPERTUX_CAMERA_H*/
136
137 /* EOF */