Fixed trailing whitespaces in all(?) source files of supertux, also fixed some svn...
[supertux.git] / src / object / endsequence.cpp
1 //  $Id$
2 //
3 //  SuperTux - End Sequence
4 //  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.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 #include <config.h>
21
22 #include "endsequence.hpp"
23
24 #include <stdexcept>
25 #include <iostream>
26 #include <sstream>
27 #include "main.hpp"
28 #include "resources.hpp"
29 #include "sector.hpp"
30 #include "gettext.hpp"
31 #include "object_factory.hpp"
32 #include "object/player.hpp"
33 #include "video/drawing_context.hpp"
34 #include "lisp/list_iterator.hpp"
35 #include "log.hpp"
36 #include "scripting/level_time.hpp"
37 #include "scripting/squirrel_util.hpp"
38
39 EndSequence::EndSequence()
40 : isrunning(false), isdone(false), tux_may_walk(true)
41 {
42   end_sequence_controller = 0;
43 }
44
45 EndSequence::~EndSequence()
46 {
47   delete end_sequence_controller;
48 }
49
50 void
51 EndSequence::update(float elapsed_time)
52 {
53   if (!isrunning) return;
54   running(elapsed_time);
55 }
56
57 void
58 EndSequence::draw(DrawingContext& /*context*/)
59 {
60 }
61
62 void
63 EndSequence::start()
64 {
65   if (isrunning) return;
66   isrunning = true;
67   isdone = false;
68
69   Player& tux = *Sector::current()->player;
70   end_sequence_controller = new CodeController();
71   tux.set_controller(end_sequence_controller);
72   tux.set_speedlimit(230); //MAX_WALK_XM
73
74   starting();
75 }
76
77 void
78 EndSequence::stop_tux()
79 {
80   tux_may_walk = false;
81 }
82
83 void
84 EndSequence::stop()
85 {
86   if (!isrunning) return;
87   isrunning = false;
88   isdone = true;
89   stopping();
90 }
91
92 bool
93 EndSequence::is_tux_stopped()
94 {
95   return !tux_may_walk;
96 }
97
98  bool
99 EndSequence::is_done()
100 {
101   return isdone;
102 }
103
104 void
105 EndSequence::starting()
106 {
107   last_x_pos = -1;
108   endsequence_timer.start(7.3f);
109 }
110
111 void
112 EndSequence::running(float /*elapsed_time*/)
113 {
114   Player& tux = *Sector::current()->player;
115
116   if (tux_may_walk) {
117     end_sequence_controller->press(Controller::RIGHT);
118     if (int(last_x_pos) == int(tux.get_pos().x)) {
119       end_sequence_controller->press(Controller::JUMP);
120     }
121   }
122
123   last_x_pos = tux.get_pos().x;
124
125   if (endsequence_timer.check()) isdone = true;
126 }
127
128 void
129 EndSequence::stopping()
130 {
131 }