2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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/>.
17 #ifndef HEADER_SUPERTUX_SUPERTUX_TIMER_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_TIMER_HPP
20 extern float game_time;
21 extern float real_time;
24 * Simple timer designed to be used in the update functions of objects
32 /** start the timer with the given period (in seconds).
33 * If cyclic=true then the timer will be reset after each period.
34 * Set period to zero if you want to disable the timer.
36 void start(float period, bool cyclic = false);
37 /** returns true if a period (or more) passed since start call or last
45 /** returns the period of the timer or 0 if it isn't started */
46 float get_period() const
48 float get_timeleft() const
49 { return period - (game_time - cycle_start); }
50 float get_timegone() const
51 { return game_time - cycle_start; }
53 { return period != 0 && get_timeleft() > 0; }