b913ead73421cdded6c6d9e7f75dad8f0f76866b
[supertux.git] / src / object / camera.h
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
20 #ifndef SUPERTUX_CAMERA_H
21 #define SUPERTUX_CAMERA_H
22
23 #include <vector>
24 #include <cassert>
25
26 #include "math/vector.h"
27 #include "special/game_object.h"
28 #include "video/drawing_context.h"
29 #include "serializable.h"
30 #include "timer.h"
31
32 using namespace SuperTux;
33 namespace lisp {
34 class Lisp;
35 }
36
37 class Sector;
38
39 class Camera : public GameObject, public Serializable
40 {
41 public:
42   Camera(Sector* sector);
43   virtual ~Camera();
44
45   /// parse camera mode from lisp file
46   void parse(const lisp::Lisp& reader);
47   /// write camera mode to a lisp file
48   virtual void write(lisp::Writer& writer);
49
50   /// reset camera postion
51   virtual void reset(const Vector& tuxpos);
52
53   /** @deprecated@ */
54   const Vector& get_translation() const;
55
56   virtual void action(float elapsed_time);
57
58   virtual void draw(DrawingContext& )
59   {
60   }
61
62   // shake camera in a direction 1 time
63   void shake(float speed, float x, float y);
64
65   void set_scrolling(int scroll_x, int scroll_y)
66   {
67     translation.x = scroll_x;
68     translation.y = scroll_y;
69   }
70
71   enum CameraMode
72   {
73     NORMAL, AUTOSCROLL, MANUAL
74   };
75   CameraMode mode;
76
77 private:
78   void scroll_normal(float elapsed_time);
79   void scroll_autoscroll(float elapsed_time);
80   void keep_in_bounds();
81   void shake();
82
83   enum LeftRightScrollChange
84   {
85     NONE, LEFT, RIGHT
86   };
87     
88   Vector translation;
89
90   Sector* sector;
91
92   // normal mode
93   bool do_backscrolling;
94   LeftRightScrollChange scrollchange;
95
96   // autoscroll mode
97   class ScrollPoint {
98   public:
99     Vector position;
100     float speed;
101   };
102   std::vector<ScrollPoint> scrollpoints;
103   size_t auto_idx;
104   float auto_t;
105   Vector current_dir;
106
107   // shaking
108   Timer2 shaketimer;
109   float shakespeed;
110   float shakedepth_x;
111   float shakedepth_y;
112 };
113
114 #endif /*SUPERTUX_CAMERA_H*/
115