move over rewritten lispreader from tuxkart (with additional fixes), generalized...
[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 "defines.h"
27 #include "math/vector.h"
28 #include "special/game_object.h"
29 #include "video/drawing_context.h"
30 #include "serializable.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   void set_scrolling(int scroll_x, int scroll_y)
63   {
64     translation.x = scroll_x;
65     translation.y = scroll_y;
66   }
67
68   enum CameraMode
69   {
70     NORMAL, AUTOSCROLL, MANUAL
71   };
72   CameraMode mode;
73
74 private:
75   void scroll_normal(float elapsed_time);
76   void scroll_autoscroll(float elapsed_time);
77   void keep_in_bounds();
78
79   enum LeftRightScrollChange
80   {
81     NONE, LEFT, RIGHT
82   };
83     
84   Vector translation;
85
86   Sector* sector;
87
88   // normal mode
89   bool do_backscrolling;
90   LeftRightScrollChange scrollchange;
91
92   // autoscroll mode
93   class ScrollPoint {
94   public:
95     Vector position;
96     float speed;
97   };
98   std::vector<ScrollPoint> scrollpoints;
99   size_t auto_idx;
100   float auto_t;
101   Vector current_dir;
102 };
103
104 #endif /*SUPERTUX_CAMERA_H*/
105