From: Ingo Ruhnke Date: Sun, 11 Apr 2004 15:28:26 +0000 (+0000) Subject: - made frame ration local X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2398b134147461d9b4e096f1c15dbf889c0f2d41;p=supertux.git - made frame ration local SVN-Revision: 477 --- diff --git a/src/badguy.cpp b/src/badguy.cpp index 82529e97f..2c803c95d 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -198,7 +198,7 @@ BadGuy::init(float x, float y, BadGuyKind kind_) } void -BadGuy::action_bsod() +BadGuy::action_bsod(float frame_ratio) { static const float BSODJUMP = 2; @@ -223,13 +223,13 @@ BadGuy::action_bsod() } // move - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if(dying != DYING_FALLING) collision_swept_object_map(&old_base, &base); } void -BadGuy::action_laptop() +BadGuy::action_laptop(float frame_ratio) { Player& tux = *World::current()->get_tux(); @@ -239,7 +239,7 @@ BadGuy::action_laptop() if (mode == NORMAL || mode == KICK) { // move - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if (dying != DYING_FALLING) collision_swept_object_map(&old_base,&base); } @@ -386,7 +386,7 @@ BadGuy::remove_me() } void -BadGuy::action_money() +BadGuy::action_money(float frame_ratio) { Player& tux = *World::current()->get_tux(); @@ -414,26 +414,26 @@ BadGuy::action_money() dir = LEFT; // move - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if(dying == DYING_NOT) collision_swept_object_map(&old_base, &base); } void -BadGuy::action_mrbomb() +BadGuy::action_mrbomb(float frame_ratio) { if (dying == DYING_NOT) check_horizontal_bump(true); fall(); - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if (dying != DYING_FALLING) collision_swept_object_map(&old_base,&base); } void -BadGuy::action_bomb() +BadGuy::action_bomb(float frame_ratio) { static const int TICKINGTIME = 1000; static const int EXPLODETIME = 1000; @@ -456,12 +456,12 @@ BadGuy::action_bomb() } // move - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); collision_swept_object_map(&old_base,&base); } void -BadGuy::action_stalactite() +BadGuy::action_stalactite(float frame_ratio) { Player& tux = *World::current()->get_tux(); @@ -496,14 +496,14 @@ BadGuy::action_stalactite() } // move - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if(dying == DYING_SQUISHED && !timer_check(&timer)) remove_me(); } void -BadGuy::action_flame() +BadGuy::action_flame(float frame_ratio) { static const float radius = 100; static const float speed = 0.02; @@ -514,7 +514,7 @@ BadGuy::action_flame() } void -BadGuy::action_fish() +BadGuy::action_fish(float frame_ratio) { static const float JUMPV = 6; static const int WAITTIME = 1000; @@ -539,13 +539,13 @@ BadGuy::action_fish() physic.enable_gravity(true); } - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if(dying == DYING_NOT) collision_swept_object_map(&old_base, &base); } void -BadGuy::action_bouncingsnowball() +BadGuy::action_bouncingsnowball(float frame_ratio) { static const float JUMPV = 4.5; @@ -565,7 +565,7 @@ BadGuy::action_bouncingsnowball() // check for right/left collisions check_horizontal_bump(); - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if(dying == DYING_NOT) collision_swept_object_map(&old_base, &base); @@ -579,7 +579,7 @@ BadGuy::action_bouncingsnowball() } void -BadGuy::action_flyingsnowball() +BadGuy::action_flyingsnowball(float frame_ratio) { static const float FLYINGSPEED = 1; static const int DIRCHANGETIME = 1000; @@ -605,7 +605,7 @@ BadGuy::action_flyingsnowball() if(dying != DYING_NOT) physic.enable_gravity(true); - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if(dying == DYING_NOT || dying == DYING_SQUISHED) collision_swept_object_map(&old_base, &base); @@ -619,7 +619,7 @@ BadGuy::action_flyingsnowball() } void -BadGuy::action_spiky() +BadGuy::action_spiky(float frame_ratio) { if (dying == DYING_NOT) check_horizontal_bump(); @@ -634,26 +634,26 @@ BadGuy::action_spiky() } #endif - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if (dying != DYING_FALLING) collision_swept_object_map(&old_base,&base); } void -BadGuy::action_snowball() +BadGuy::action_snowball(float frame_ratio) { if (dying == DYING_NOT) check_horizontal_bump(); fall(); - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if (dying != DYING_FALLING) collision_swept_object_map(&old_base,&base); } void -BadGuy::action() +BadGuy::action(float frame_ratio) { // Remove if it's far off the screen: if (base.x < scroll_x - OFFSCREEN_DISTANCE) @@ -678,51 +678,51 @@ BadGuy::action() switch (kind) { case BAD_BSOD: - action_bsod(); + action_bsod(frame_ratio); break; case BAD_LAPTOP: - action_laptop(); + action_laptop(frame_ratio); break; case BAD_MONEY: - action_money(); + action_money(frame_ratio); break; case BAD_MRBOMB: - action_mrbomb(); + action_mrbomb(frame_ratio); break; case BAD_BOMB: - action_bomb(); + action_bomb(frame_ratio); break; case BAD_STALACTITE: - action_stalactite(); + action_stalactite(frame_ratio); break; case BAD_FLAME: - action_flame(); + action_flame(frame_ratio); break; case BAD_FISH: - action_fish(); + action_fish(frame_ratio); break; case BAD_BOUNCINGSNOWBALL: - action_bouncingsnowball(); + action_bouncingsnowball(frame_ratio); break; case BAD_FLYINGSNOWBALL: - action_flyingsnowball(); + action_flyingsnowball(frame_ratio); break; case BAD_SPIKY: - action_spiky(); + action_spiky(frame_ratio); break; case BAD_SNOWBALL: - action_snowball(); + action_snowball(frame_ratio); break; } } diff --git a/src/badguy.h b/src/badguy.h index d338d48e7..84675d015 100644 --- a/src/badguy.h +++ b/src/badguy.h @@ -108,7 +108,7 @@ private: public: void init(float x, float y, BadGuyKind kind); - void action(); + void action(float frame_ratio); void draw(); void collision(void* p_c_object, int c_object, @@ -120,18 +120,18 @@ public: void kill_me(); private: - void action_bsod(); - void action_laptop(); - void action_money(); - void action_bomb(); - void action_mrbomb(); - void action_stalactite(); - void action_flame(); - void action_fish(); - void action_bouncingsnowball(); - void action_flyingsnowball(); - void action_spiky(); - void action_snowball(); + void action_bsod(float frame_ratio); + void action_laptop(float frame_ratio); + void action_money(float frame_ratio); + void action_bomb(float frame_ratio); + void action_mrbomb(float frame_ratio); + void action_stalactite(float frame_ratio); + void action_flame(float frame_ratio); + void action_fish(float frame_ratio); + void action_bouncingsnowball(float frame_ratio); + void action_flyingsnowball(float frame_ratio); + void action_spiky(float frame_ratio); + void action_snowball(float frame_ratio); /** handles falling down. disables gravity calculation when we're back on * ground */ diff --git a/src/gameloop.cpp b/src/gameloop.cpp index fdae0a629..d2aadba86 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -338,7 +338,7 @@ GameSession::process_events() } int -GameSession::action() +GameSession::action(double frame_ratio) { Player& tux = *world->get_tux(); @@ -428,9 +428,9 @@ GameSession::action() play_current_music(); } - tux.action(); + tux.action(frame_ratio); - world->action(); + world->action(frame_ratio); return -1; } @@ -496,7 +496,7 @@ GameSession::run() while (!done && !quit) { /* Calculate the movement-factor */ - frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); + double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); 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; @@ -555,7 +555,7 @@ GameSession::run() frame_ratio = 1; while(z >= 1) {*/ - if (action() == 0) + if (action(frame_ratio) == 0) { /* == 0: no more lives */ /* == -1: continues */ diff --git a/src/gameloop.h b/src/gameloop.h index dc1e3c140..203306e2b 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -62,7 +62,7 @@ class GameSession int run(); void draw(); - int action(); + int action(double frame_ratio); Level* get_level() { return world->get_level(); } World* get_world() { return world; } diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index 5bd9dd71e..228814fa1 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -31,7 +31,7 @@ BouncyDistro::init(float x, float y) } void -BouncyDistro::action() +BouncyDistro::action(double frame_ratio) { base.y = base.y + base.ym * frame_ratio; @@ -64,7 +64,7 @@ BrokenBrick::init(Tile* tile_, float x, float y, float xm, float ym) } void -BrokenBrick::action() +BrokenBrick::action(double frame_ratio) { base.x = base.x + base.xm * frame_ratio; base.y = base.y + base.ym * frame_ratio; @@ -103,10 +103,9 @@ BouncyBrick::init(float x, float y) } void -BouncyBrick::action() +BouncyBrick::action(double frame_ratio) { - offset = (offset + - offset_m * frame_ratio); + offset = (offset + offset_m * frame_ratio); /* Go back down? */ if (offset < -BOUNCY_BRICK_MAX_OFFSET) @@ -166,7 +165,7 @@ FloatingScore::init(float x, float y, int s) } void -FloatingScore::action() +FloatingScore::action(double frame_ratio) { base.y = base.y - 2 * frame_ratio; diff --git a/src/gameobjs.h b/src/gameobjs.h index 1b759a605..72b9ee789 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -35,7 +35,7 @@ class BouncyDistro base_type base; void init(float x, float y); - void action(); + void action(double frame_ratio); void draw(); }; @@ -54,7 +54,7 @@ class BrokenBrick Tile* tile; void init(Tile* tile, float x, float y, float xm, float ym); - void action(); + void action(double frame_ratio); void draw(); }; @@ -67,7 +67,7 @@ class BouncyBrick base_type base; void init(float x, float y); - void action(); + void action(double frame_ratio); void draw(); }; @@ -79,7 +79,7 @@ class FloatingScore base_type base; void init(float x, float y, int s); - void action(); + void action(double frame_ratio); void draw(); }; diff --git a/src/physic.cpp b/src/physic.cpp index 319919957..232475d69 100644 --- a/src/physic.cpp +++ b/src/physic.cpp @@ -79,7 +79,7 @@ Physic::enable_gravity(bool enable_gravity) } void -Physic::apply(float &x, float &y) +Physic::apply(float frame_ratio, float &x, float &y) { float gravity = World::current()->get_level()->gravity; float grav; diff --git a/src/physic.h b/src/physic.h index c5a82d2e0..37b6302ff 100644 --- a/src/physic.h +++ b/src/physic.h @@ -43,7 +43,7 @@ public: void enable_gravity(bool gravity_enabled); /** applies the physical simulation to given x and y coordinates */ - void apply(float &x, float &y); + void apply(float frame_ratio, float &x, float &y); private: /// horizontal and vertical acceleration diff --git a/src/player.cpp b/src/player.cpp index 1fbe91ccb..607e8ae83 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -157,7 +157,7 @@ Player::level_begin() } void -Player::action() +Player::action(double frame_ratio) { bool jumped_in_solid = false; @@ -169,7 +169,7 @@ Player::action() /* Move tux: */ previous_base = base; - physic.apply(base.x, base.y); + physic.apply(frame_ratio, base.x, base.y); if (!dying) { diff --git a/src/player.h b/src/player.h index 13240e9ca..49115d835 100644 --- a/src/player.h +++ b/src/player.h @@ -121,7 +121,7 @@ class Player void init(); int key_event(SDLKey key, int state); void level_begin(); - void action(); + void action(double frame_ratio); void handle_input(); void grabdistros(); void draw(); diff --git a/src/scene.cpp b/src/scene.cpp index d916e505e..a4cb09547 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -21,7 +21,6 @@ float scroll_x; unsigned int global_frame_counter; timer_type time_left; -double frame_ratio; // EOF // diff --git a/src/scene.h b/src/scene.h index 435dc2dc0..c9547c376 100644 --- a/src/scene.h +++ b/src/scene.h @@ -29,11 +29,9 @@ struct PlayerStatus extern PlayerStatus player_status; -extern timer_type super_bkgd_timer; extern float scroll_x; extern unsigned int global_frame_counter; extern timer_type time_left; -extern double frame_ratio; #endif /*SUPERTUX_SCENE_H*/ diff --git a/src/special.cpp b/src/special.cpp index 218751ec8..787537fce 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -53,7 +53,7 @@ Bullet::init(float x, float y, float xm, int dir) } void -Bullet::action() +Bullet::action(double frame_ratio) { base.x = base.x + base.xm * frame_ratio; base.y = base.y + base.ym * frame_ratio; @@ -128,7 +128,7 @@ Upgrade::init(float x_, float y_, int dir_, int kind_) } void -Upgrade::action() +Upgrade::action(double frame_ratio) { if (base.height < 32) { diff --git a/src/special.h b/src/special.h index c246bd8ef..fe68107b5 100644 --- a/src/special.h +++ b/src/special.h @@ -39,7 +39,7 @@ class Upgrade base_type old_base; void init(float x, float y, int dir, int kind); - void action(); + void action(double frame_ratio); void draw(); void collision(void* p_c_object, int c_object); }; @@ -51,7 +51,7 @@ class Bullet base_type old_base; void init(float x, float y, float xm, int dir); - void action(); + void action(double frame_ratio); void draw(); void collision(int c_object); }; diff --git a/src/title.cpp b/src/title.cpp index 78c877cb6..3acba935f 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -63,7 +63,7 @@ void draw_background() texture_draw_bg(&bkg_title); } -void draw_demo(GameSession* session) +void draw_demo(GameSession* session, double frame_ratio) { World::set_current(session->get_world()); //World* world = session->get_world(); @@ -118,8 +118,10 @@ void draw_demo(GameSession* session) scroll_x = tux->base.x - 320; } + + float last_tux_x_pos = tux->base.x; - tux->action(); + tux->action(frame_ratio); // Jump if tux stays in the same position for one loop, ie. if he is // stuck behind a wall @@ -176,7 +178,7 @@ bool title(void) while (!done) { /* Calculate the movement-factor */ - frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); + double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); 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; /* Lower the frame_ratio that Tux doesn't jump to hectically throught the demo. */ @@ -209,7 +211,7 @@ bool title(void) /* Draw the background: */ draw_background(); - draw_demo(&session); + draw_demo(&session, frame_ratio); if (current_menu == main_menu) texture_draw(&logo, 160, 30); diff --git a/src/world.cpp b/src/world.cpp index 57d1b8a50..83374e29f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -208,15 +208,15 @@ World::draw() } void -World::action() +World::action(double frame_ratio) { /* Handle bouncy distros: */ for (unsigned int i = 0; i < bouncy_distros.size(); i++) - bouncy_distros[i].action(); + bouncy_distros[i].action(frame_ratio); /* Handle broken bricks: */ for (unsigned int i = 0; i < broken_bricks.size(); i++) - broken_bricks[i].action(); + broken_bricks[i].action(frame_ratio); /* Handle distro counting: */ if (counting_distros) @@ -229,19 +229,19 @@ World::action() // Handle all kinds of game objects for (unsigned int i = 0; i < bouncy_bricks.size(); i++) - bouncy_bricks[i].action(); + bouncy_bricks[i].action(frame_ratio); for (unsigned int i = 0; i < floating_scores.size(); i++) - floating_scores[i].action(); + floating_scores[i].action(frame_ratio); for (unsigned int i = 0; i < bullets.size(); ++i) - bullets[i].action(); + bullets[i].action(frame_ratio); for (unsigned int i = 0; i < upgrades.size(); i++) - upgrades[i].action(); + upgrades[i].action(frame_ratio); for (unsigned int i = 0; i < bad_guys.size(); i++) - bad_guys[i].action(); + bad_guys[i].action(frame_ratio); /* update particle systems */ std::vector::iterator p; diff --git a/src/world.h b/src/world.h index 935918087..5aa2700d8 100644 --- a/src/world.h +++ b/src/world.h @@ -67,7 +67,7 @@ class World void set_defaults(); void draw(); - void action(); + void action(double frame_ratio); /** Checks for all possible collisions. And calls the collision_handlers, which the collision_objects provide for this