animation_offset = 0;
texture_left = texture_right = 0;
physic.reset();
- timer_init(&timer, true);
+ timer.init(true);
if(kind == BAD_BSOD) {
physic.set_velocity(-1.3, 0);
}
// Handle dying timer:
- if (dying == DYING_SQUISHED && !timer_check(&timer))
+ if (dying == DYING_SQUISHED && !timer.check())
{
/* Remove it if time's up: */
remove_me();
/* Handle mode timer: */
if (mode == FLAT)
{
- if(!timer_check(&timer))
+ if(!timer.check())
{
mode = NORMAL;
set_texture(img_laptop_left, img_laptop_right, 4, 5);
if(mode == NORMAL) {
mode = BOMB_TICKING;
- timer_start(&timer, TICKINGTIME);
- } else if(!timer_check(&timer)) {
+ timer.start(TICKINGTIME);
+ } else if(!timer.check()) {
if(mode == BOMB_TICKING) {
mode = BOMB_EXPLODE;
set_texture(img_mrbomb_explosion, img_mrbomb_explosion, 1);
dying = DYING_NOT; // now the bomb hurts
- timer_start(&timer, EXPLODETIME);
+ timer.start(EXPLODETIME);
} else if(mode == BOMB_EXPLODE) {
remove_me();
return;
// near
if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
&& tux.base.y + tux.base.height > base.y) {
- timer_start(&timer, SHAKETIME);
+ timer.start(SHAKETIME);
mode = STALACTITE_SHAKING;
}
} if(mode == STALACTITE_SHAKING) {
base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
- if(!timer_check(&timer)) {
+ if(!timer.check()) {
mode = STALACTITE_FALL;
}
} else if(mode == STALACTITE_FALL) {
/* Destroy if we collides with land */
if(issolid(base.x+base.width/2, base.y+base.height))
{
- timer_start(&timer, 2000);
+ timer.start(2000);
dying = DYING_SQUISHED;
mode = FLAT;
set_texture(img_stalactite_broken, img_stalactite_broken, 1);
// move
physic.apply(frame_ratio, base.x, base.y);
- if(dying == DYING_SQUISHED && !timer_check(&timer))
+ if(dying == DYING_SQUISHED && !timer.check())
remove_me();
}
set_texture(0, 0);
physic.set_velocity(0, 0);
physic.enable_gravity(false);
- timer_start(&timer, WAITTIME);
+ timer.start(WAITTIME);
}
- else if(mode == FISH_WAIT && !timer_check(&timer))
+ else if(mode == FISH_WAIT && !timer.check())
{
// jump again
set_texture(img_fish, img_fish, 2, 1.5);
collision_swept_object_map(&old_base, &base);
// Handle dying timer:
- if (dying == DYING_SQUISHED && !timer_check(&timer))
+ if (dying == DYING_SQUISHED && !timer.check())
{
/* Remove it if time's up: */
remove_me();
if(dying == DYING_NOT && mode == NORMAL) {
mode = FLY_UP;
physic.set_velocity(physic.get_velocity_x(), FLYINGSPEED);
- timer_start(&timer, DIRCHANGETIME/2);
+ timer.start(DIRCHANGETIME/2);
}
- if(dying == DYING_NOT && !timer_check(&timer)) {
+ if(dying == DYING_NOT && !timer.check()) {
if(mode == FLY_UP) {
mode = FLY_DOWN;
physic.set_velocity(physic.get_velocity_x(), -FLYINGSPEED);
mode = FLY_UP;
physic.set_velocity(physic.get_velocity_x(), FLYINGSPEED);
}
- timer_start(&timer, DIRCHANGETIME);
+ timer.start(DIRCHANGETIME);
}
if(dying != DYING_NOT)
collision_swept_object_map(&old_base, &base);
// Handle dying timer:
- if (dying == DYING_SQUISHED && !timer_check(&timer))
+ if (dying == DYING_SQUISHED && !timer.check())
{
/* Remove it if time's up: */
remove_me();
player_status.score_multiplier++;
dying = DYING_SQUISHED;
- timer_start(&timer, 2000);
+ timer.start(2000);
physic.set_velocity(0, 0);
}
set_texture(img_laptop_flat_left, img_laptop_flat_right, 1);
physic.set_velocity(0, physic.get_velocity_y());
- timer_start(&timer, 4000);
+ timer.start(4000);
} else if (mode == FLAT) {
/* Kick! */
play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
Button::Button(std::string icon_file, std::string ninfo, SDLKey nshortcut, int x, int y, int mw, int mh)
{
- timer_init(&popup_timer,false);
+ popup_timer.init(false);
char filename[1024];
void Button::draw()
{
if(state == BUTTON_HOVER)
- if(!timer_check(&popup_timer))
+ if(!popup_timer.check())
show_info = true;
fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200);
}
else if(event.type == SDL_MOUSEMOTION)
{
- timer_start(&popup_timer, 1500);
+ popup_timer.start(1500);
if(show_info)
{
world = new World; // &::global_world;
- timer_init(&fps_timer, true);
- timer_init(&frame_timer, true);
+ fps_timer.init(true);
+ frame_timer.init(true);
world->load(filename);
}
world = new World; // &::global_world;
- timer_init(&fps_timer, true);
- timer_init(&frame_timer, true);
+ fps_timer.init(true);
+ frame_timer.init(true);
st_gl_mode = mode;
if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE)
levelintro();
- timer_init(&time_left,true);
+ time_left.init(true);
start_timers();
if(st_gl_mode == ST_GL_LOAD_GAME)
void
GameSession::start_timers()
{
- timer_start(&time_left, world->get_level()->time_left*1000);
+ time_left.start(world->get_level()->time_left*1000);
st_pause_ticks_init();
update_time = st_get_ticks();
}
break;
case SDLK_INSERT:
if(debug_mode)
- timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
+ tux.invincible_timer.start(TUX_INVINCIBLE_TIME);
break;
case SDLK_l:
if(debug_mode)
global_frame_counter = 0;
game_pause = false;
- timer_init(&fps_timer,true);
- timer_init(&frame_timer,true);
+
+ fps_timer.init(true);
+ frame_timer.init(true);
+
last_update_time = st_get_ticks();
fps_cnt = 0;
if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85;
- if(!timer_check(&frame_timer))
+ if(!frame_timer.check())
{
- timer_start(&frame_timer,25);
+ frame_timer.start(25);
++global_frame_counter;
}
SDL_Delay((11 - (update_time - last_update_time))/2);*/
/* Handle time: */
- if (timer_check(&time_left))
+ if (time_left.check())
{
/* are we low on time ? */
if ((timer_get_left(&time_left) < TIME_WARNING)
++fps_cnt;
fps_fps = (1000.0 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt;
- if(!timer_check(&fps_timer))
+ if(!fps_timer.check())
{
- timer_start(&fps_timer,1000);
+ fps_timer.start(1000);
fps_cnt = 0;
}
}
base.xm = xm;
base.ym = ym;
- timer_init(&timer, true);
- timer_start(&timer,200);
+ timer.init(true);
+ timer.start(200);
}
void
base.x = base.x + base.xm * frame_ratio;
base.y = base.y + base.ym * frame_ratio;
- if (!timer_check(&timer))
+ if (!timer.check())
World::current()->broken_bricks.erase(static_cast<std::vector<BrokenBrick>::iterator>(this));
}
{
base.x = x;
base.y = y - 16;
- timer_init(&timer,true);
- timer_start(&timer,1000);
+ timer.init(true);
+ timer.start(1000);
value = s;
}
{
base.y = base.y - 2 * frame_ratio;
- if(!timer_check(&timer))
+ if(!timer.check())
World::current()->floating_scores.erase(static_cast<std::vector<FloatingScore>::iterator>(this));
}
int i;
timer_type maxdelay;
timer_type mindelay;
- timer_init(&maxdelay,false);
- timer_init(&mindelay,false);
+
+ maxdelay.init(false);
+ mindelay.init(false);
if(max_delay < min_delay)
max_delay = min_delay;
- timer_start(&maxdelay,max_delay);
- timer_start(&mindelay,min_delay);
+ maxdelay.start(max_delay);
+ mindelay.start(min_delay);
if(empty_events)
while (SDL_PollEvent(&event))
/* Handle events: */
- for(i = 0; timer_check(&maxdelay) || !i; ++i)
+ for(i = 0; maxdelay.check() || !i; ++i)
{
while (SDL_PollEvent(&event))
{
- if(!timer_check(&mindelay))
+ if(!mindelay.check())
{
if (event.type == SDL_QUIT)
{
scene = 0;
i = 0;
- timer_init(&timer, false);
- timer_start(&timer,10000);
+ timer.init(false);
+ timer.start(10000);
- while (timer_check(&timer) && !done && !quit)
+ while (timer.check() && !done && !quit)
{
if(current_menu == select_tilegroup_menu)
{
- if(timer_check(&select_tilegroup_menu_effect))
+ if(select_tilegroup_menu_effect.check())
{
select_tilegroup_menu->set_pos(screen->w - 64 + timer_get_left(&select_tilegroup_menu_effect),82,-0.5,0.5);
}
texture_load(&le_selection, datadir + "/images/leveleditor/select.png", USE_ALPHA);
- timer_init(&select_tilegroup_menu_effect,false);
+ select_tilegroup_menu_effect.init(false);
/* Load buttons */
le_save_level_bt = new Button("/images/icons/save.png","Save level", SDLK_F6,screen->w-64,32);
if(le_tilegroup_bt->get_state() == BUTTON_CLICKED)
{
Menu::set_current(select_tilegroup_menu);
- timer_start(&select_tilegroup_menu_effect,200);
+ select_tilegroup_menu_effect.start(200);
select_tilegroup_menu->set_pos(screen->w - 64,100,-0.5,0.5);
show_menu = true;
}
if(tmp->last_menu != pmenu)
current_menu->last_menu = tmp;
- timer_start(&pmenu->effect, 500);
+ pmenu->effect.start(500);
}
}
active_item = 0;
last_menu = 0;
item = NULL;
- timer_init(&effect,false);
+ effect.init(false);
}
void Menu::set_pos(int x, int y, float rw, float rh)
{
- pos_x = x + (int)((float)width() * rw);
- pos_y = y + (int)((float)height() * rh);
+ pos_x = x + (int)((float)width() * rw);
+ pos_y = y + (int)((float)height() * rh);
}
void
int effect_offset = 0;
{
int effect_time = 0;
- if(timer_check(&effect))
+ if(effect.check())
effect_time = timer_get_left(&effect) / 4;
effect_offset = (index % 2) ? effect_time : -effect_time;
cur_frame = 0;
tot_frames = frames;
- timer_init(&timer, false);
- timer_start(&timer,MC_FRAME_PERIOD);
+ timer.init(false);
+ timer.start(MC_FRAME_PERIOD);
SDL_ShowCursor(SDL_DISABLE);
}
if(cur_frame++ >= tot_frames)
cur_frame = 0;
- timer_start(&timer,MC_FRAME_PERIOD);
+ timer.start(MC_FRAME_PERIOD);
}
texture_draw_part(&cursor, w*cur_frame, h*cur_state , x, y, w, h);
keymap.right = SDLK_RIGHT;
keymap.fire = SDLK_LCTRL;
- timer_init(&invincible_timer,true);
- timer_init(&skidding_timer,true);
- timer_init(&safe_timer,true);
- timer_init(&frame_timer,true);
+ invincible_timer.init(true);
+ skidding_timer.init(true);
+ safe_timer.init(true);
+ frame_timer.init(true);
physic.reset();
}
player_input_init(&input);
- timer_init(&invincible_timer,true);
- timer_init(&skidding_timer,true);
- timer_init(&safe_timer,true);
- timer_init(&frame_timer,true);
+ invincible_timer.init(true);
+ skidding_timer.init(true);
+ safe_timer.init(true);
+ frame_timer.init(true);
+
physic.reset();
}
}
- timer_check(&safe_timer);
+ safe_timer.check();
/* ---- DONE HANDLING TUX! --- */
/* Handle invincibility timer: */
- if (get_current_music() == HERRING_MUSIC && !timer_check(&invincible_timer))
+ if (get_current_music() == HERRING_MUSIC && !invincible_timer.check())
{
/*
no, we are no more invincible
// skid if we're too fast
if(dir != newdir && on_ground() && fabs(physic.get_velocity_x()) > SKID_XM
- && !timer_started(&skidding_timer))
+ && !skidding_timer.started())
{
- timer_start(&skidding_timer, SKID_TIME);
+ skidding_timer.start(SKID_TIME);
play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
return;
}
if ((newdir ? (vx < 0) : (vx > 0)) && !isice(base.x, base.y + base.height) &&
- !timer_started(&skidding_timer))
+ !skidding_timer.started())
{
//vx = 0;
}
/* (Tux): */
- if(!timer_check(&frame_timer))
+ if(!frame_timer.check())
{
- timer_start(&frame_timer,25);
+ frame_timer.start(25);
if (input.right == UP && input.left == UP)
{
frame_main = 1;
void
Player::draw()
{
- if (!timer_started(&safe_timer) || (global_frame_counter % 2) == 0)
+ if (!safe_timer.started() || (global_frame_counter % 2) == 0)
{
if (size == SMALL)
{
- if (timer_started(&invincible_timer))
+ if (invincible_timer.started())
{
/* Draw cape: */
}
else
{
- if (timer_started(&invincible_timer))
+ if (invincible_timer.started())
{
/* Draw cape: */
if (dir == RIGHT)
{
if (!duck)
{
- if (!timer_started(&skidding_timer))
+ if (!skidding_timer.started())
{
if (!jumping || physic.get_velocity_y() > 0)
{
if (!duck)
{
- if (!timer_started(&skidding_timer))
+ if (!skidding_timer.started())
{
if (!jumping || physic.get_velocity_y() > 0)
{
/* Hurt the player if he just touched it: */
if (!pbad_c->dying && !dying &&
- !timer_started(&safe_timer) &&
+ !safe_timer.started() &&
pbad_c->mode != HELD)
{
if (pbad_c->mode == FLAT && input.fire == DOWN)
else
{
/* Hurt if you get hit by kicked laptop: */
- if (!timer_started(&invincible_timer))
+ if (!invincible_timer.started())
{
kill(SHRINK);
}
}
else
{
- if (!timer_started(&invincible_timer ))
+ if (!invincible_timer.started())
{
kill(SHRINK);
}
size = SMALL;
base.height = 32;
- timer_start(&safe_timer,TUX_SAFE_TIME);
+ safe_timer.start(TUX_SAFE_TIME);
}
else
{
else if (kind == UPGRADE_HERRING)
{
play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
- timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
+ pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME);
/* play the herring song ^^ */
if (get_current_music() != HURRYUP_MUSIC)
{
st_pause_count = 0;
}
-void timer_init(timer_type* ptimer, bool st_ticks)
+void
+timer_type::init(bool st_ticks)
{
- ptimer->period = 0;
- ptimer->time = 0;
- ptimer->get_ticks = st_ticks ? st_get_ticks : SDL_GetTicks;
+ period = 0;
+ time = 0;
+ get_ticks = st_ticks ? st_get_ticks : SDL_GetTicks;
}
-void timer_start(timer_type* ptimer, unsigned int period)
+void
+timer_type::start(unsigned int period_)
{
- ptimer->time = ptimer->get_ticks();
- ptimer->period = period;
+ time = get_ticks();
+ period = period_;
}
-void timer_stop(timer_type* ptimer)
+void
+timer_type::stop()
{
- if(ptimer->get_ticks == st_get_ticks)
- timer_init(ptimer,true);
+ if(get_ticks == st_get_ticks)
+ init(true);
else
- timer_init(ptimer,false);
+ init(false);
}
-int timer_check(timer_type* ptimer)
+int
+timer_type::check()
{
- if((ptimer->time != 0) && (ptimer->time + ptimer->period > ptimer->get_ticks()))
+ if((time != 0) && (time + period > get_ticks()))
return true;
else
{
- ptimer->time = 0;
+ time = 0;
return false;
}
}
-int timer_started(timer_type* ptimer)
+int
+timer_type::started()
{
- if(ptimer->time != 0)
+ if(time != 0)
return true;
else
return false;
#ifndef SUPERTUX_TIMER_H
#define SUPERTUX_TIMER_H
-/* Timer type */
-struct timer_type
-{
- unsigned int period;
- unsigned int time;
- unsigned int (*get_ticks) (void);
-};
-
extern unsigned int st_pause_ticks, st_pause_count;
unsigned int st_get_ticks(void);
void st_pause_ticks_init(void);
void st_pause_ticks_start(void);
void st_pause_ticks_stop(void);
-void timer_init(timer_type* ptimer, bool st_ticks);
-void timer_start(timer_type* ptimer, unsigned int period);
-void timer_stop(timer_type* ptimer);
-/*======================================================================
- int timer_check(timer_type* ptimer);
+
+class timer_type
+{
+ public:
+ unsigned int period;
+ unsigned int time;
+ unsigned int (*get_ticks) (void);
+
+ public:
+ void init(bool st_ticks);
+ void start(unsigned int period);
+ void stop();
+
+ /*======================================================================
+ int timer_check(timer_type* ptimer);
- param : pointer to a timer which needs to be checked
- return: NO = the timer is not started
- or it is over
- YES = otherwise
-======================================================================*/
-int timer_check(timer_type* ptimer);
-int timer_started(timer_type* ptimer);
+ param : pointer to a timer which needs to be checked
+ return: NO = the timer is not started
+ or it is over
+ YES = otherwise
+ ======================================================================*/
+ int check();
+ int started();
+};
/*======================================================================
- int timer_get_left(timer_type* ptimer);
+ int timer_get_left(timer_type* ptimer);
- param : pointer to a timer that you want to get the time left
- return: the time left (in millisecond)
- note : the returned value can be negative
-======================================================================*/
+ param : pointer to a timer that you want to get the time left
+ return: the time left (in millisecond)
+ note : the returned value can be negative
+ ======================================================================*/
int timer_get_left(timer_type* ptimer);
int timer_get_gone(timer_type* ptimer);
void timer_fwrite(timer_type* ptimer, FILE* fi);
#endif /*SUPERTUX_TIMER_H*/
+/* Local Variables: */
+/* mode:c++ */
+/* End */
global_frame_counter++;
tux->key_event(SDLK_RIGHT,DOWN);
- if(timer_check(&random_timer))
+ if(random_timer.check())
{
if(walking)
tux->key_event(SDLK_UP,UP);
}
else
{
- timer_start(&random_timer, rand() % 3000 + 3000);
+ random_timer.start(rand() % 3000 + 3000);
walking = !walking;
}
string_list_type level_subsets;
st_subset subset;
level_subsets = dsubdirs("/levels", "info");
- timer_init(&random_timer, true);
+ random_timer.init(true);
walking = true;
load_hs();
update_time = st_get_ticks();
- timer_start(&random_timer, rand() % 2000 + 2000);
+ random_timer.start(rand() % 2000 + 2000);
while (!done)
{
}
- timer_init(&timer, SDL_GetTicks());
- timer_start(&timer, 50);
+ timer.init(SDL_GetTicks());
+ timer.start(50);
scroll = 0;
speed = 2;
if(timer_get_left(&timer) < 0)
{
frame++;
- timer_start(&timer, 50);
+ timer.start(50);
}
}
string_list_free(&names);