autoscoll Camera now references Path, just like the Platform does
[supertux.git] / src / object / camera.hpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #ifndef SUPERTUX_CAMERA_H
20 #define SUPERTUX_CAMERA_H
21
22 #include <vector>
23 #include <cassert>
24
25 #include "math/vector.hpp"
26 #include "game_object.hpp"
27 #include "video/drawing_context.hpp"
28 #include "serializable.hpp"
29 #include "timer.hpp"
30 #include "object/path.hpp"
31
32 namespace lisp {
33 class Lisp;
34 }
35
36 class Sector;
37
38 class Camera : public GameObject, public Serializable
39 {
40 public:
41   Camera(Sector* sector);
42   virtual ~Camera();
43
44   /// parse camera mode from lisp file
45   void parse(const lisp::Lisp& reader);
46   /// write camera mode to a lisp file
47   virtual void write(lisp::Writer& writer);
48
49   /// reset camera postion
50   virtual void reset(const Vector& tuxpos);
51
52   /** return camera position */
53   const Vector& get_translation() const;
54
55   virtual void update(float elapsed_time);
56
57   virtual void draw(DrawingContext& )
58   {
59   }
60
61   // shake camera in a direction 1 time
62   void shake(float speed, float x, float y);
63
64   void set_scrolling(int scroll_x, int scroll_y)
65   {
66     translation.x = scroll_x;
67     translation.y = scroll_y;
68   }
69
70   /**
71    * scroll the upper left edge of the camera in scrolltime seconds
72    * to the position goal
73    */
74   void scroll_to(const Vector& goal, float scrolltime);
75
76   enum CameraMode
77   {
78     NORMAL, AUTOSCROLL, SCROLLTO, MANUAL
79   };
80   CameraMode mode;
81
82 private:
83   void update_scroll_normal(float elapsed_time);
84   void update_scroll_autoscroll(float elapsed_time);
85   void update_scroll_to(float elapsed_time);
86   void keep_in_bounds(Vector& vector);
87   void shake();
88
89   enum LeftRightScrollChange
90   {
91     NONE, LEFT, RIGHT
92   };
93
94   Vector translation;
95
96   Sector* sector;
97
98   // normal mode
99   bool do_backscrolling;
100   LeftRightScrollChange scrollchange;
101
102   // autoscroll mode
103   Path* autoscrollPath;
104
105   // shaking
106   Timer shaketimer;
107   float shakespeed;
108   float shakedepth_x;
109   float shakedepth_y;
110
111   // scrollto mode
112   Vector scroll_from;
113   Vector scroll_goal;
114   float scroll_to_pos;
115   float scrollspeed;
116 };
117
118 #endif /*SUPERTUX_CAMERA_H*/
119