From: Wolfgang Becker Date: Tue, 2 Jan 2007 17:07:50 +0000 (+0000) Subject: Sorry, was too early for that patch. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3655d32f63f75b2af054ec68d4176e55a561ba96;p=supertux.git Sorry, was too early for that patch. SVN-Revision: 4524 --- diff --git a/src/badguy/angrystone.cpp b/src/badguy/angrystone.cpp index 331529130..865e43061 100644 --- a/src/badguy/angrystone.cpp +++ b/src/badguy/angrystone.cpp @@ -47,9 +47,9 @@ AngryStone::write(lisp::Writer& writer) void AngryStone::activate() { - physic.vx = 0; - physic.vy = 0; - physic.gravity_enabled = true; + physic.set_velocity_x(0); + physic.set_velocity_y(0); + physic.enable_gravity(true); sprite->set_action("idle"); } @@ -63,9 +63,9 @@ AngryStone::collision_solid(const CollisionHit& hit) (hit.normal.x == -attackDirection.x) && (hit.normal.y == attackDirection.y)) { state = IDLE; sprite->set_action("idle"); - physic.vx = 0; - physic.vy = 0; - physic.gravity_enabled = true; + physic.set_velocity_x(0); + physic.set_velocity_y(0); + physic.enable_gravity(true); oldWallDirection.x = attackDirection.x; oldWallDirection.y = attackDirection.y; } @@ -143,9 +143,9 @@ AngryStone::active_update(float elapsed_time) { sprite->set_action("attacking"); timer.start(ATTACK_TIME); state = ATTACKING; - physic.gravity_enabled = false; - physic.vx = SPEED * attackDirection.x; - physic.vy = SPEED * attackDirection.y; + physic.enable_gravity(false); + physic.set_velocity_x(SPEED * attackDirection.x); + physic.set_velocity_y(SPEED * attackDirection.y); oldWallDirection.x = 0; oldWallDirection.y = 0; } @@ -156,9 +156,9 @@ AngryStone::active_update(float elapsed_time) { timer.start(RECOVER_TIME); state = RECOVERING; sprite->set_action("idle"); - physic.gravity_enabled = true; - physic.vx = 0; - physic.vy = 0; + physic.enable_gravity(true); + physic.set_velocity_x(0); + physic.set_velocity_y(0); } } @@ -166,9 +166,9 @@ AngryStone::active_update(float elapsed_time) { if (timer.check()) { state = IDLE; sprite->set_action("idle"); - physic.gravity_enabled = true; - physic.vx = 0; - physic.vy = 0; + physic.enable_gravity(true); + physic.set_velocity_x(0); + physic.set_velocity_y(0); } } diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 9cf5eceba..75e59d348 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -228,8 +228,8 @@ BadGuy::collision(GameObject& other, const CollisionHit& hit) void BadGuy::collision_solid(const CollisionHit& hit) { - physic.vx = 0; - physic.vy = 0; + physic.set_velocity_x(0); + physic.set_velocity_y(0); update_on_ground_flag(hit); } @@ -309,9 +309,9 @@ void BadGuy::kill_squished(GameObject& object) { sound_manager->play("sounds/squish.wav", get_pos()); - physic.gravity_enabled = true; - physic.vx = 0; - physic.vy = 0; + physic.enable_gravity(true); + physic.set_velocity_x(0); + physic.set_velocity_y(0); set_state(STATE_SQUISHED); set_group(COLGROUP_MOVING_ONLY_STATIC); Player* player = dynamic_cast(&object); @@ -326,8 +326,8 @@ BadGuy::kill_fall() { sound_manager->play("sounds/fall.wav", get_pos()); if (countMe) Sector::current()->get_level()->stats.badguys++; - physic.vy = 0; - physic.gravity_enabled = true; + physic.set_velocity_y(0); + physic.enable_gravity(true); set_state(STATE_FALLING); } diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index 309ea603f..670baa554 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -61,7 +61,7 @@ void Bomb::collision_solid(const CollisionHit& hit) { if(hit.bottom) - physic.vy = 0; + physic.set_velocity_y(0); } HitResponse diff --git a/src/badguy/bouncing_snowball.cpp b/src/badguy/bouncing_snowball.cpp index b28b03ed5..f84561b74 100644 --- a/src/badguy/bouncing_snowball.cpp +++ b/src/badguy/bouncing_snowball.cpp @@ -48,7 +48,7 @@ BouncingSnowball::write(lisp::Writer& writer) void BouncingSnowball::activate() { - physic.vx = (dir == LEFT ? -WALKSPEED : WALKSPEED); + physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } @@ -65,18 +65,18 @@ BouncingSnowball::collision_solid(const CollisionHit& hit) { if(hit.bottom) { if(get_state() == STATE_ACTIVE) { - physic.vy = JUMPSPEED; + physic.set_velocity_y(JUMPSPEED); } else { - physic.vy = 0; + physic.set_velocity_y(0); } } else if(hit.top) { - physic.vy = 0; + physic.set_velocity_y(0); } if(hit.left || hit.right) { // left or right collision dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "left" : "right"); - physic.vx = -physic.vx; + physic.set_velocity_x(-physic.get_velocity_x()); } } diff --git a/src/badguy/dart.cpp b/src/badguy/dart.cpp index 4726a0148..393474e31 100644 --- a/src/badguy/dart.cpp +++ b/src/badguy/dart.cpp @@ -31,7 +31,7 @@ static const std::string SOUNDFILE = "sounds/flame.wav"; Dart::Dart(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/dart/dart.sprite"), parent(0) { - physic.gravity_enabled = false; + physic.enable_gravity(false); countMe = false; sound_manager->preload("sounds/darthit.wav"); sound_manager->preload("sounds/stomp.wav"); @@ -40,7 +40,7 @@ Dart::Dart(const lisp::Lisp& reader) Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0) : BadGuy(pos, d, "images/creatures/dart/dart.sprite"), parent(parent) { - physic.gravity_enabled = false; + physic.enable_gravity(false); countMe = false; sound_manager->preload("sounds/darthit.wav"); sound_manager->preload("sounds/stomp.wav"); @@ -80,7 +80,7 @@ Dart::write(lisp::Writer& writer) void Dart::activate() { - physic.vx = (dir == LEFT ? -::SPEED : ::SPEED); + physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED); sprite->set_action(dir == LEFT ? "flying-left" : "flying-right"); sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); diff --git a/src/badguy/fish.cpp b/src/badguy/fish.cpp index 43ceb5e70..803512096 100644 --- a/src/badguy/fish.cpp +++ b/src/badguy/fish.cpp @@ -30,13 +30,13 @@ static const float FISH_WAIT_TIME = 1; Fish::Fish(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/fish/fish.sprite", LAYER_TILES-1), stop_y(0) { - physic.gravity_enabled = true; + physic.enable_gravity(true); } Fish::Fish(const Vector& pos) : BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1), stop_y(0) { - physic.gravity_enabled = true; + physic.enable_gravity(true); } void @@ -75,7 +75,7 @@ HitResponse Fish::hit(const CollisionHit& hit) { if(hit.top) { - physic.vy = 0; + physic.set_velocity_y(0); } return CONTINUE; @@ -84,7 +84,7 @@ Fish::hit(const CollisionHit& hit) void Fish::collision_tile(uint32_t tile_attributes) { - if ((tile_attributes & Tile::WATER) && (physic.vy >= 0)) { + if ((tile_attributes & Tile::WATER) && (physic.get_velocity_y() >= 0)) { // initialize stop position if uninitialized if (stop_y == 0) stop_y = get_pos().y + get_bbox().get_height(); @@ -111,13 +111,13 @@ Fish::active_update(float elapsed_time) // set sprite if(!frozen) - sprite->set_action(physic.vy < 0 ? "normal" : "down"); + sprite->set_action(physic.get_velocity_y() < 0 ? "normal" : "down"); // we can't afford flying out of the tilemap, 'cause the engine would remove us. if ((get_pos().y - 31.8) < 0) // too high, let us fall { - physic.vy = 0; - physic.gravity_enabled = true; + physic.set_velocity_y(0); + physic.enable_gravity(true); } } @@ -126,15 +126,15 @@ Fish::start_waiting() { waiting.start(FISH_WAIT_TIME); set_group(COLGROUP_DISABLED); - physic.gravity_enabled = false; - physic.vy = 0; + physic.enable_gravity(false); + physic.set_velocity_y(0); } void Fish::jump() { - physic.vy = FISH_JUMP_POWER; - physic.gravity_enabled = true; + physic.set_velocity_y(FISH_JUMP_POWER); + physic.enable_gravity(true); set_group(COLGROUP_MOVING); } @@ -142,7 +142,7 @@ void Fish::freeze() { BadGuy::freeze(); - sprite->set_action(physic.vy < 0 ? "iced" : "iced-down"); + sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down"); waiting.stop(); } diff --git a/src/badguy/flyingsnowball.cpp b/src/badguy/flyingsnowball.cpp index b002ba2a9..fd684304f 100644 --- a/src/badguy/flyingsnowball.cpp +++ b/src/badguy/flyingsnowball.cpp @@ -37,13 +37,13 @@ namespace { FlyingSnowBall::FlyingSnowBall(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/flying_snowball/flying_snowball.sprite") { - physic.gravity_enabled = false; + physic.enable_gravity(false); } FlyingSnowBall::FlyingSnowBall(const Vector& pos) : BadGuy(pos, "images/creatures/flying_snowball/flying_snowball.sprite") { - physic.gravity_enabled = false; + physic.enable_gravity(false); } void @@ -62,7 +62,7 @@ FlyingSnowBall::activate() { sprite->set_action(dir == LEFT ? "left" : "right"); mode = FLY_UP; - physic.vy = FLYSPEED; + physic.set_velocity_y(FLYSPEED); timer.start(FLYTIME/2); puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX)); } @@ -79,7 +79,7 @@ void FlyingSnowBall::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } } @@ -89,14 +89,14 @@ FlyingSnowBall::active_update(float elapsed_time) if(timer.check()) { if(mode == FLY_UP) { mode = FLY_DOWN; - physic.vy = -FLYSPEED; + physic.set_velocity_y(-FLYSPEED); // stop puffing puff_timer.stop(); } else if(mode == FLY_DOWN) { mode = FLY_UP; - physic.vy = FLYSPEED; + physic.set_velocity_y(FLYSPEED); // roll a dice whether to start puffing if (systemRandom.randf(0, 1) < PUFF_PROBABILITY) { diff --git a/src/badguy/jumpy.cpp b/src/badguy/jumpy.cpp index 817e12f59..706a7d7bb 100644 --- a/src/badguy/jumpy.cpp +++ b/src/badguy/jumpy.cpp @@ -63,11 +63,11 @@ Jumpy::hit(const CollisionHit& chit) groundhit_pos_set = true; } - physic.vy = (frozen ? 0 : JUMPSPEED); + physic.set_velocity_y(frozen ? 0 : JUMPSPEED); // TODO create a nice sound for this... //sound_manager->play("sounds/skid.wav"); } else if(chit.top) { - physic.vy = 0; + physic.set_velocity_y(0); } return CONTINUE; @@ -106,7 +106,7 @@ void Jumpy::freeze() { BadGuy::freeze(); - physic.vy = std::max(0.0f, physic.vy); + physic.set_velocity_y(std::max(0.0f, physic.get_velocity_y())); sprite->set_action(dir == LEFT ? "left-iced" : "right-iced"); } diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index 0d14a5a86..c6242e6ad 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -38,7 +38,7 @@ Kugelblitz::Kugelblitz(const lisp::Lisp& reader) { reader.get("x", start_position.x); sprite->set_action("falling"); - physic.gravity_enabled = false; + physic.enable_gravity(false); } void @@ -54,8 +54,8 @@ Kugelblitz::write(lisp::Writer& writer) void Kugelblitz::activate() { - physic.vy = 300; - physic.vx = -20; //fall a little to the left + physic.set_velocity_y(300); + physic.set_velocity_x(-20); //fall a little to the left direction = 1; dying = false; } @@ -107,16 +107,16 @@ Kugelblitz::hit(const CollisionHit& hit) groundhit_pos_set = true; } sprite->set_action("flying"); - physic.vy = 0; + physic.set_velocity_y(0); //Set random initial speed and direction direction = systemRandom.rand(2)? 1: -1; int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction; - physic.vx = speed; + physic.set_velocity_x(speed); movement_timer.start(MOVETIME); lifetime.start(LIFETIME); } else if(hit.top) { // bumped on roof - physic.vy = 0; + physic.set_velocity_y(0); } return CONTINUE; @@ -133,7 +133,7 @@ Kugelblitz::active_update(float elapsed_time) if (movement_timer.check()) { if (direction == 1) direction = -1; else direction = 1; int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction; - physic.vx = speed; + physic.set_velocity_x(speed); movement_timer.start(MOVETIME); } } diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index 635e08492..d3e4e4687 100644 --- a/src/badguy/mole.cpp +++ b/src/badguy/mole.cpp @@ -35,13 +35,13 @@ static const float THROW_VELOCITY = 400; /**< initial velocity of thrown rocks * Mole::Mole(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING) { - physic.gravity_enabled = false; + physic.enable_gravity(false); } Mole::Mole(const Vector& pos) : BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING) { - physic.gravity_enabled = false; + physic.enable_gravity(false); } void diff --git a/src/badguy/mole_rock.cpp b/src/badguy/mole_rock.cpp index 7bef50b83..c9252ff05 100644 --- a/src/badguy/mole_rock.cpp +++ b/src/badguy/mole_rock.cpp @@ -25,14 +25,14 @@ MoleRock::MoleRock(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), parent(0), initial_velocity(Vector(0, -400)) { - physic.gravity_enabled = true; + physic.enable_gravity(true); countMe = false; } MoleRock::MoleRock(const Vector& pos, const Vector& velocity, const BadGuy* parent = 0) : BadGuy(pos, LEFT, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), parent(parent), initial_velocity(velocity) { - physic.gravity_enabled = true; + physic.enable_gravity(true); countMe = false; } @@ -67,8 +67,7 @@ MoleRock::write(lisp::Writer& writer) void MoleRock::activate() { - physic.vx = initial_velocity.x; - physic.vy = initial_velocity.y; + physic.set_velocity(initial_velocity); sprite->set_action("default"); } diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index 8cf9481de..697fed9d7 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -92,7 +92,7 @@ MrIceBlock::collision_solid(const CollisionHit& hit) update_on_ground_flag(hit); if(hit.top || hit.bottom) { // floor or roof - physic.vy = 0; + physic.set_velocity_y(0); return; } @@ -105,17 +105,17 @@ MrIceBlock::collision_solid(const CollisionHit& hit) if(hit.right && dir == RIGHT) { dir = LEFT; sound_manager->play("sounds/iceblock_bump.wav", get_pos()); - physic.vx = -KICKSPEED; + physic.set_velocity_x(-KICKSPEED); } else if(hit.left && dir == LEFT) { dir = RIGHT; sound_manager->play("sounds/iceblock_bump.wav", get_pos()); - physic.vx = KICKSPEED; + physic.set_velocity_x(KICKSPEED); } sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); break; } case ICESTATE_FLAT: - physic.vx = 0; + physic.set_velocity_x(0); break; case ICESTATE_GRABBED: break; @@ -220,8 +220,8 @@ MrIceBlock::set_state(IceState state) break; case ICESTATE_FLAT: sound_manager->play("sounds/stomp.wav", get_pos()); - physic.vx = 0; - physic.vy = 0; + physic.set_velocity_x(0); + physic.set_velocity_y(0); sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); flat_timer.start(4); @@ -229,7 +229,7 @@ MrIceBlock::set_state(IceState state) case ICESTATE_KICKED: sound_manager->play("sounds/kick.wav", get_pos()); - physic.vx = (dir == LEFT ? -KICKSPEED : KICKSPEED); + physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED); sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); // we should slide above 1 block holes now... bbox.set_size(34, 31.8); diff --git a/src/badguy/mrrocket.cpp b/src/badguy/mrrocket.cpp index 7e90629c1..3f6cc3b7a 100644 --- a/src/badguy/mrrocket.cpp +++ b/src/badguy/mrrocket.cpp @@ -47,8 +47,8 @@ MrRocket::write(lisp::Writer& writer) void MrRocket::activate() { - physic.vx = (dir == LEFT ? -SPEED : SPEED); - physic.gravity_enabled = false; + physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED); + physic.enable_gravity(false); sprite->set_action(dir == LEFT ? "left" : "right"); } @@ -78,10 +78,10 @@ void MrRocket::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } else if(hit.left || hit.right) { sprite->set_action(dir == LEFT ? "collision-left" : "collision-right"); - physic.vx = 0; + physic.set_velocity_x(0); collision_timer.start(0.2, true); } } diff --git a/src/badguy/plant.cpp b/src/badguy/plant.cpp index f734a7707..5830d2b01 100644 --- a/src/badguy/plant.cpp +++ b/src/badguy/plant.cpp @@ -48,7 +48,7 @@ Plant::activate() dir = dir == LEFT ? RIGHT : LEFT; state = PLANT_SLEEPING; - physic.vx = 0; + physic.set_velocity_x(0); sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right"); } @@ -56,11 +56,11 @@ void Plant::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } else if(hit.left || hit.right) { dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "left" : "right"); - physic.vx = -physic.vx; + physic.set_velocity_x(-physic.get_velocity_x()); } } @@ -72,7 +72,7 @@ Plant::collision_badguy(BadGuy& , const CollisionHit& hit) if(hit.left || hit.right) { dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "left" : "right"); - physic.vx = -physic.vx; + physic.set_velocity_x(-physic.get_velocity_x()); } return CONTINUE; @@ -107,7 +107,7 @@ Plant::active_update(float elapsed_time) { if(timer.check()) { // start walking sprite->set_action(dir == LEFT ? "left" : "right"); - physic.vx = (dir == LEFT ? -WALKSPEED : WALKSPEED); + physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); state = PLANT_WALKING; } } diff --git a/src/badguy/skullyhop.cpp b/src/badguy/skullyhop.cpp index 79d9f2122..8bf61d7da 100644 --- a/src/badguy/skullyhop.cpp +++ b/src/badguy/skullyhop.cpp @@ -63,8 +63,8 @@ void SkullyHop::set_state(SkullyHopState newState) { if (newState == STANDING) { - physic.vx = 0; - physic.vy = 0; + physic.set_velocity_x(0); + physic.set_velocity_y(0); sprite->set_action(dir == LEFT ? "standing-left" : "standing-right"); float recover_time = systemRandom.randf(MIN_RECOVER_TIME,MAX_RECOVER_TIME); @@ -75,8 +75,8 @@ SkullyHop::set_state(SkullyHopState newState) } else if (newState == JUMPING) { sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right"); - physic.vx = (dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); - physic.vy = VERTICAL_SPEED; + physic.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); + physic.set_velocity_y(VERTICAL_SPEED); sound_manager->play( HOP_SOUND, get_pos()); } @@ -104,19 +104,19 @@ SkullyHop::collision_solid(const CollisionHit& hit) return; // check if we hit the floor while falling - if(hit.bottom && physic.vy > 0 ) { + if(hit.bottom && physic.get_velocity_y() > 0 ) { set_state(STANDING); } // check if we hit the roof while climbing if(hit.top) { - physic.vy = 0; + physic.set_velocity_y(0); } // check if we hit left or right while moving in either direction if(hit.left || hit.right) { dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right"); - physic.vx = -0.25*physic.vx; + physic.set_velocity_x(-0.25*physic.get_velocity_x()); } } diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index 8c04c090b..1f21922af 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -79,8 +79,8 @@ Snail::be_flat() sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); sprite->set_fps(64); - physic.vx = 0; - physic.vy = 0; + physic.set_velocity_x(0); + physic.set_velocity_y(0); flat_timer.start(4); } @@ -92,8 +92,8 @@ Snail::be_kicked() sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); sprite->set_fps(64); - physic.vx = 0; - physic.vy = 0; + physic.set_velocity_x(0); + physic.set_velocity_y(0); // start a timer to delay addition of upward movement until we are (hopefully) out from under the player kicked_delay_timer.start(0.05); @@ -125,16 +125,16 @@ Snail::active_update(float elapsed_time) case STATE_KICKED_DELAY: if (kicked_delay_timer.check()) { - physic.vx = (dir == LEFT ? -KICKSPEED : KICKSPEED); - physic.vy = KICKSPEED_Y; + physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED); + physic.set_velocity_y(KICKSPEED_Y); state = STATE_KICKED; } BadGuy::active_update(elapsed_time); break; case STATE_KICKED: - physic.vx = physic.vx * pow(0.99, elapsed_time/0.02); - if (fabsf(physic.vx) < walk_speed) be_normal(); + physic.set_velocity_x(physic.get_velocity_x() * pow(0.99, elapsed_time/0.02)); + if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal(); BadGuy::active_update(elapsed_time); break; @@ -152,22 +152,22 @@ Snail::collision_solid(const CollisionHit& hit) break; case STATE_FLAT: if(hit.top || hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } if(hit.left || hit.right) { } break; case STATE_KICKED_DELAY: if(hit.top || hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } if(hit.left || hit.right) { - physic.vy = 0; + physic.set_velocity_x(0); } break; case STATE_KICKED: if(hit.top || hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } if(hit.left || hit.right) { sound_manager->play("sounds/iceblock_bump.wav", get_pos()); @@ -176,8 +176,8 @@ Snail::collision_solid(const CollisionHit& hit) dir = (dir == LEFT) ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); - physic.vx = -physic.vx*0.75; - if (fabsf(physic.vx) < walk_speed) be_normal(); + physic.set_velocity_x(-physic.get_velocity_x()*0.75); + if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal(); } } diff --git a/src/badguy/spidermite.cpp b/src/badguy/spidermite.cpp index af88274f4..ee9eac956 100644 --- a/src/badguy/spidermite.cpp +++ b/src/badguy/spidermite.cpp @@ -28,13 +28,13 @@ static const float FLYSPEED = -100.0; SpiderMite::SpiderMite(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/spidermite/spidermite.sprite") { - physic.gravity_enabled = false; + physic.enable_gravity(false); } SpiderMite::SpiderMite(const Vector& pos) : BadGuy(pos, "images/creatures/spidermite/spidermite.sprite") { - physic.gravity_enabled = false; + physic.enable_gravity(false); } void @@ -53,7 +53,7 @@ SpiderMite::activate() { sprite->set_action(dir == LEFT ? "left" : "right"); mode = FLY_UP; - physic.vy = FLYSPEED; + physic.set_velocity_y(FLYSPEED); timer.start(FLYTIME/2); } @@ -69,7 +69,7 @@ void SpiderMite::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) { // hit floor or roof? - physic.vy = 0; + physic.set_velocity_y(0); } } @@ -79,10 +79,10 @@ SpiderMite::active_update(float elapsed_time) if(timer.check()) { if(mode == FLY_UP) { mode = FLY_DOWN; - physic.vy = -FLYSPEED; + physic.set_velocity_y(-FLYSPEED); } else if(mode == FLY_DOWN) { mode = FLY_UP; - physic.vy = FLYSPEED; + physic.set_velocity_y(FLYSPEED); } timer.start(FLYTIME); } diff --git a/src/badguy/sspiky.cpp b/src/badguy/sspiky.cpp index 4316b189f..ad80b8de8 100644 --- a/src/badguy/sspiky.cpp +++ b/src/badguy/sspiky.cpp @@ -42,7 +42,7 @@ void SSpiky::activate() { state = SSPIKY_SLEEPING; - physic.vx = 0; + physic.set_velocity_x(0); sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right"); } diff --git a/src/badguy/stalactite.cpp b/src/badguy/stalactite.cpp index 46d16f6e4..60857fb3f 100644 --- a/src/badguy/stalactite.cpp +++ b/src/badguy/stalactite.cpp @@ -59,7 +59,7 @@ Stalactite::active_update(float elapsed_time) } else if(state == STALACTITE_SHAKING) { if(timer.check()) { state = STALACTITE_FALLING; - physic.gravity_enabled = true; + physic.enable_gravity(true); } } else if(state == STALACTITE_FALLING || state == STALACTITE_SQUISHED) { movement = physic.get_movement(elapsed_time); @@ -85,7 +85,7 @@ Stalactite::collision_solid(const CollisionHit& hit) if (hit.bottom) squish(); } if(state == STALACTITE_SQUISHED) { - physic.vy = 0; + physic.set_velocity_y(0); } } diff --git a/src/badguy/stumpy.cpp b/src/badguy/stumpy.cpp index 7654292c2..f4515461f 100644 --- a/src/badguy/stumpy.cpp +++ b/src/badguy/stumpy.cpp @@ -61,7 +61,7 @@ Stumpy::activate() case STATE_INVINCIBLE: sprite->set_action(dir == LEFT ? "dizzy-left" : "dizzy-right"); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); - physic.vx = 0; + physic.set_velocity_x(0); break; case STATE_NORMAL: WalkingBadguy::activate(); @@ -132,10 +132,10 @@ Stumpy::collision_solid(const CollisionHit& hit) switch (mystate) { case STATE_INVINCIBLE: if(hit.top || hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } if(hit.left || hit.right) { - physic.vx = 0; + physic.set_velocity_x(0); } break; case STATE_NORMAL: @@ -150,10 +150,10 @@ Stumpy::collision_badguy(BadGuy& badguy, const CollisionHit& hit) switch (mystate) { case STATE_INVINCIBLE: if(hit.top || hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } if(hit.left || hit.right) { - physic.vx = 0; + physic.set_velocity_x(0); } return CONTINUE; break; diff --git a/src/badguy/toad.cpp b/src/badguy/toad.cpp index f416d8aa0..1657a9b26 100644 --- a/src/badguy/toad.cpp +++ b/src/badguy/toad.cpp @@ -62,16 +62,16 @@ void Toad::set_state(ToadState newState) { if (newState == IDLE) { - physic.vx = 0; - physic.vy = 0; + physic.set_velocity_x(0); + physic.set_velocity_y(0); sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); recover_timer.start(RECOVER_TIME); } else if (newState == JUMPING) { sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right"); - physic.vx = (dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); - physic.vy = VERTICAL_SPEED; + physic.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); + physic.set_velocity_y(VERTICAL_SPEED); sound_manager->play( HOP_SOUND, get_pos()); } else if (newState == FALLING) { @@ -108,7 +108,7 @@ Toad::collision_solid(const CollisionHit& hit) } // check if we hit left or right while moving in either direction - if(((physic.vx < 0) && hit.left) || ((physic.vx > 0) && hit.right)) { + if(((physic.get_velocity_x() < 0) && hit.left) || ((physic.get_velocity_x() > 0) && hit.right)) { /* dir = dir == LEFT ? RIGHT : LEFT; if (state == JUMPING) { @@ -117,7 +117,7 @@ Toad::collision_solid(const CollisionHit& hit) sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); } */ - physic.vx = -0.25*physic.vx; + physic.set_velocity_x(-0.25*physic.get_velocity_x()); } // check if we hit the floor while falling @@ -128,7 +128,7 @@ Toad::collision_solid(const CollisionHit& hit) // check if we hit the roof while climbing if ((state == JUMPING) && hit.top) { - physic.vy = 0; + physic.set_velocity_y(0); } } @@ -148,7 +148,7 @@ Toad::active_update(float elapsed_time) BadGuy::active_update(elapsed_time); // change sprite when we are falling - if ((state == JUMPING) && (physic.vy > 0)) { + if ((state == JUMPING) && (physic.get_velocity_y() > 0)) { set_state(FALLING); return; } diff --git a/src/badguy/totem.cpp b/src/badguy/totem.cpp index 893eb068f..139aa14df 100644 --- a/src/badguy/totem.cpp +++ b/src/badguy/totem.cpp @@ -77,7 +77,7 @@ void Totem::activate() { if (!carried_by) { - physic.vx = (dir == LEFT ? -WALKSPEED : WALKSPEED); + physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "walking-left" : "walking-right"); return; } else { @@ -120,7 +120,7 @@ Totem::active_update(float elapsed_time) float dx = (p1.x - p2.x); if (fabsf(dx - 128) > 2) continue; - physic.vy = JUMP_ON_SPEED_Y; + physic.set_velocity_y(JUMP_ON_SPEED_Y); p1.y -= 1; this->set_pos(p1); break; @@ -168,7 +168,7 @@ Totem::collision_solid(const CollisionHit& hit) // If we hit something from above or below: stop moving in this direction if (hit.top || hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } // If we are hit from the direction we are facing: turn around @@ -259,7 +259,7 @@ Totem::jump_off() { bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); - physic.vy = JUMP_OFF_SPEED_Y; + physic.set_velocity_y(JUMP_OFF_SPEED_Y); } void @@ -275,8 +275,8 @@ Totem::synchronize_with(Totem* base) pos.y -= sprite->get_current_hitbox_height(); set_pos(pos); - physic.vx = base->physic.vx; - physic.vy = base->physic.vy; + physic.set_velocity_x(base->physic.get_velocity_x()); + physic.set_velocity_y(base->physic.get_velocity_y()); } diff --git a/src/badguy/walking_badguy.cpp b/src/badguy/walking_badguy.cpp index 4943a0f13..37816dc68 100644 --- a/src/badguy/walking_badguy.cpp +++ b/src/badguy/walking_badguy.cpp @@ -52,7 +52,7 @@ WalkingBadguy::activate() return; sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); - physic.vx = (dir == LEFT ? -walk_speed : walk_speed); + physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed); } void @@ -76,10 +76,10 @@ WalkingBadguy::collision_solid(const CollisionHit& hit) update_on_ground_flag(hit); if (hit.top) { - if (physic.vy < 0) physic.vy = 0; + if (physic.get_velocity_y() < 0) physic.set_velocity_y(0); } if (hit.bottom) { - if (physic.vy > 0) physic.vy = 0; + if (physic.get_velocity_y() > 0) physic.set_velocity_y(0); } if ((hit.left && (hit.slope_normal.y == 0) && (dir == LEFT)) || (hit.right && (hit.slope_normal.y == 0) && (dir == RIGHT))) { @@ -106,14 +106,14 @@ WalkingBadguy::turn_around() return; dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action); - physic.vx = -physic.vx; + physic.set_velocity_x(-physic.get_velocity_x()); } void WalkingBadguy::freeze() { BadGuy::freeze(); - physic.vx = 0; + physic.set_velocity_x(0); } void @@ -127,13 +127,13 @@ WalkingBadguy::unfreeze() float WalkingBadguy::get_velocity_y() const { - return physic.vy; + return physic.get_velocity_y(); } void WalkingBadguy::set_velocity_y(float vy) { - physic.vy = vy; + physic.set_velocity_y(vy); } diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 438b5b58e..51f9c13ce 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -88,20 +88,20 @@ Yeti::active_update(float elapsed_time) { switch(state) { case JUMP_DOWN: - physic.vx = (dir==RIGHT?JUMP_DOWN_VX:-JUMP_DOWN_VX); + physic.set_velocity_x((dir==RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX); break; case RUN: - physic.vx = (dir==RIGHT?RUN_VX:-RUN_VX); + physic.set_velocity_x((dir==RIGHT)?+RUN_VX:-RUN_VX); if (((dir == RIGHT) && (get_pos().x >= RIGHT_JUMP_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_JUMP_X))) jump_up(); break; case JUMP_UP: - physic.vx = (dir==RIGHT?JUMP_UP_VX:-JUMP_UP_VX); + physic.set_velocity_x((dir==RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX); if (((dir == RIGHT) && (get_pos().x >= RIGHT_STAND_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_STAND_X))) be_angry(); break; case BE_ANGRY: if(state_timer.check()) { sound_manager->play("sounds/yeti_gna.wav"); - physic.vy = STOMP_VY; + physic.set_velocity_y(STOMP_VY); sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left"); } break; @@ -119,8 +119,8 @@ void Yeti::jump_down() { sprite->set_action((dir==RIGHT)?"jump-right":"jump-left"); - physic.vx = (dir==RIGHT?JUMP_DOWN_VX:-JUMP_DOWN_VX); - physic.vy = JUMP_DOWN_VY; + physic.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX)); + physic.set_velocity_y(JUMP_DOWN_VY); state = JUMP_DOWN; } @@ -128,8 +128,8 @@ void Yeti::run() { sprite->set_action((dir==RIGHT)?"run-right":"run-left"); - physic.vx = (dir==RIGHT?RUN_VX:-RUN_VX); - physic.vy = 0; + physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX)); + physic.set_velocity_y(0); state = RUN; } @@ -137,8 +137,8 @@ void Yeti::jump_up() { sprite->set_action((dir==RIGHT)?"jump-right":"jump-left"); - physic.vx = (dir==RIGHT?JUMP_UP_VX:-JUMP_UP_VX); - physic.vy = JUMP_UP_VY; + physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX)); + physic.set_velocity_y(JUMP_UP_VY); state = JUMP_UP; } @@ -149,8 +149,8 @@ Yeti::be_angry() dir = (dir==RIGHT)?LEFT:RIGHT; sprite->set_action((dir==RIGHT)?"stand-right":"stand-left"); - physic.vx = 0; - physic.vy = 0; + physic.set_velocity_x(0); + physic.set_velocity_y(0); if (hit_points < INITIAL_HITPOINTS) summon_snowball(); stomp_count = 0; state = BE_ANGRY; @@ -191,9 +191,9 @@ void Yeti::take_hit(Player& ) if(hit_points <= 0) { // We're dead - physic.gravity_enabled = true; - physic.vx = 0; - physic.vy = 0; + physic.enable_gravity(true); + physic.set_velocity_x(0); + physic.set_velocity_y(0); state = SQUISHED; state_timer.start(SQUISH_TIME); @@ -270,7 +270,7 @@ Yeti::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) { // hit floor or roof - physic.vy = 0; + physic.set_velocity_y(0); switch (state) { case JUMP_DOWN: run(); diff --git a/src/badguy/zeekling.cpp b/src/badguy/zeekling.cpp index 4cdec6a5a..64a45669e 100644 --- a/src/badguy/zeekling.cpp +++ b/src/badguy/zeekling.cpp @@ -52,8 +52,8 @@ void Zeekling::activate() { speed = systemRandom.rand(130, 171); - physic.vx = (dir == LEFT ? -speed : speed); - physic.gravity_enabled = false; + physic.set_velocity_x(dir == LEFT ? -speed : speed); + physic.enable_gravity(false); sprite->set_action(dir == LEFT ? "left" : "right"); } @@ -71,19 +71,19 @@ Zeekling::onBumpHorizontal() { if (state == FLYING) { dir = (dir == LEFT ? RIGHT : LEFT); sprite->set_action(dir == LEFT ? "left" : "right"); - physic.vx = (dir == LEFT ? -speed : speed); + physic.set_velocity_x(dir == LEFT ? -speed : speed); } else if (state == DIVING) { dir = (dir == LEFT ? RIGHT : LEFT); state = FLYING; sprite->set_action(dir == LEFT ? "left" : "right"); - physic.vx = (dir == LEFT ? -speed : speed); - physic.vy = 0; + physic.set_velocity_x(dir == LEFT ? -speed : speed); + physic.set_velocity_y(0); } else if (state == CLIMBING) { dir = (dir == LEFT ? RIGHT : LEFT); sprite->set_action(dir == LEFT ? "left" : "right"); - physic.vx = (dir == LEFT ? -speed : speed); + physic.set_velocity_x(dir == LEFT ? -speed : speed); } else { assert(false); } @@ -92,16 +92,16 @@ Zeekling::onBumpHorizontal() { void Zeekling::onBumpVertical() { if (state == FLYING) { - physic.vy = 0; + physic.set_velocity_y(0); } else if (state == DIVING) { state = CLIMBING; - physic.vy = -speed; + physic.set_velocity_y(-speed); sprite->set_action(dir == LEFT ? "left" : "right"); } else if (state == CLIMBING) { state = FLYING; - physic.vy = 0; + physic.set_velocity_y(0); } } @@ -172,7 +172,7 @@ Zeekling::active_update(float elapsed_time) { if (state == FLYING) { if (should_we_dive()) { state = DIVING; - physic.vy = 2*fabsf(physic.vx); + physic.set_velocity_y(2*fabsf(physic.get_velocity_x())); sprite->set_action(dir == LEFT ? "diving-left" : "diving-right"); } BadGuy::active_update(elapsed_time); @@ -184,7 +184,7 @@ Zeekling::active_update(float elapsed_time) { // stop climbing when we're back at initial height if (get_pos().y <= start_position.y) { state = FLYING; - physic.vy = 0; + physic.set_velocity_y(0); } BadGuy::active_update(elapsed_time); return; diff --git a/src/object/bullet.cpp b/src/object/bullet.cpp index e9a7c1a0d..564b7ba0f 100644 --- a/src/object/bullet.cpp +++ b/src/object/bullet.cpp @@ -37,7 +37,7 @@ Bullet::Bullet(const Vector& pos, float xm, int dir, BonusType type) : life_count(3), type(type) { float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM; - physic.vx = speed + xm; + physic.set_velocity_x(speed + xm); if(type == FIRE_BONUS) { sprite.reset(sprite_manager->create("images/objects/bullets/firebullet.sprite")); @@ -84,11 +84,11 @@ void Bullet::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) { - physic.vy = -physic.vy; + physic.set_velocity_y(-physic.get_velocity_y()); life_count--; } else if(hit.left || hit.right) { if(type == ICE_BONUS) { - physic.vx = -physic.vx; + physic.set_velocity_x(-physic.get_velocity_x()); life_count--; } else remove_me(); diff --git a/src/object/camera.cpp b/src/object/camera.cpp index 97867ec19..b9d0097bb 100644 --- a/src/object/camera.cpp +++ b/src/object/camera.cpp @@ -279,7 +279,7 @@ Camera::update_scroll_normal(float elapsed_time) float speed_x = delta_x / elapsed_time; // limit our speed - float maxv = 130 + (fabsf(player->physic.vx * 1.3)); + float maxv = 130 + (fabsf(player->physic.get_velocity_x() * 1.3)); if(speed_x > maxv) speed_x = maxv; else if(speed_x < -maxv) diff --git a/src/object/falling_coin.cpp b/src/object/falling_coin.cpp index 33d3d2dc2..8e091a5d3 100644 --- a/src/object/falling_coin.cpp +++ b/src/object/falling_coin.cpp @@ -29,8 +29,8 @@ FallingCoin::FallingCoin(const Vector& start_position, const int vel_x) { pos = start_position; sprite = sprite_manager->create("images/objects/coin/coin.sprite"); - physic.vy = -800; - physic.vx = vel_x; + physic.set_velocity_y(-800); + physic.set_velocity_x(vel_x); } FallingCoin::~FallingCoin() diff --git a/src/object/growup.cpp b/src/object/growup.cpp index 4a6e0ce36..1d256dbb7 100644 --- a/src/object/growup.cpp +++ b/src/object/growup.cpp @@ -30,8 +30,8 @@ GrowUp::GrowUp(Direction direction) : MovingSprite(Vector(0,0), "images/powerups/egg/egg.sprite", LAYER_OBJECTS, COLGROUP_MOVING) { - physic.gravity_enabled = true; - physic.vx = (direction == LEFT?-100:100); + physic.enable_gravity(true); + physic.set_velocity_x((direction == LEFT)?-100:100); sound_manager->preload("sounds/grow.wav"); } @@ -45,9 +45,9 @@ void GrowUp::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) - physic.vy = 0; + physic.set_velocity_y(0); if(hit.left || hit.right) - physic.vx = -physic.vx; + physic.set_velocity_x(-physic.get_velocity_x()); } HitResponse diff --git a/src/object/oneup.cpp b/src/object/oneup.cpp index bafe8bda2..bdbaa5e9a 100644 --- a/src/object/oneup.cpp +++ b/src/object/oneup.cpp @@ -29,8 +29,7 @@ OneUp::OneUp(const Vector& pos, Direction direction) : MovingSprite(pos, "images/powerups/1up/1up.sprite", LAYER_FLOATINGOBJECTS, COLGROUP_TOUCHABLE) { - physic.vx = ((direction == LEFT)?-100:100); - physic.vy = -400; + physic.set_velocity((direction == LEFT)?-100:100, -400); } void diff --git a/src/object/player.cpp b/src/object/player.cpp index 89face716..004a838b2 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -166,7 +166,7 @@ Player::init() on_ground_flag = false; grabbed_object = NULL; - physic = Physic(); + physic.reset(); } void @@ -236,7 +236,7 @@ Player::update(float elapsed_time) // extend/shrink tux collision rectangle so that we fall through/walk over 1 // tile holes - if(fabsf(physic.vx) > MAX_WALK_XM) { + if(fabsf(physic.get_velocity_x()) > MAX_WALK_XM) { set_width(34); } else { set_width(31.8); @@ -245,8 +245,8 @@ Player::update(float elapsed_time) // on downward slopes, adjust vertical velocity so tux walks smoothly down if (on_ground()) { if(floor_normal.y != 0) { - if ((floor_normal.x * physic.vx) >= 0) { - physic.vy = 250; + if ((floor_normal.x * physic.get_velocity_x()) >= 0) { + physic.set_velocity_y(250); } } } @@ -255,7 +255,7 @@ Player::update(float elapsed_time) if (backflipping) { //prevent player from changing direction when backflipping dir = (backflip_direction == 1) ? LEFT : RIGHT; - if (backflip_timer.started()) physic.vx = 100 * backflip_direction; + if (backflip_timer.started()) physic.set_velocity_x(100 * backflip_direction); } // set fall mode... @@ -341,26 +341,26 @@ Player::is_big() void Player::apply_friction() { - if ((on_ground()) && (fabs(physic.vx) < WALK_SPEED)) { - physic.vx = 0; - physic.ax = 0; - } else if(physic.vx < 0) { - physic.ax = WALK_ACCELERATION_X * 1.5; + if ((on_ground()) && (fabs(physic.get_velocity_x()) < WALK_SPEED)) { + physic.set_velocity_x(0); + physic.set_acceleration_x(0); + } else if(physic.get_velocity_x() < 0) { + physic.set_acceleration_x(WALK_ACCELERATION_X * 1.5); } else { - physic.ax = WALK_ACCELERATION_X * -1.5; + physic.set_acceleration_x(WALK_ACCELERATION_X * -1.5); } } void Player::handle_horizontal_input() { - float vx = physic.vx; - float vy = physic.vy; - float ax = physic.ax; - float ay = physic.ay; + float vx = physic.get_velocity_x(); + float vy = physic.get_velocity_y(); + float ax = physic.get_acceleration_x(); + float ay = physic.get_acceleration_y(); float dirsign = 0; - if(!duck || physic.vy != 0) { + if(!duck || physic.get_velocity_y() != 0) { if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) { old_dir = dir; dir = LEFT; @@ -421,10 +421,8 @@ Player::handle_horizontal_input() } } - physic.vx = vx; - physic.vy = vy; - physic.ax = ax; - physic.ay = ay; + physic.set_velocity(vx, vy); + physic.set_acceleration(ax, ay); // we get slower when not pressing any keys if(dirsign == 0) { @@ -448,7 +446,7 @@ Player::do_duck() { if (!is_big()) return; - if (physic.vy != 0) + if (physic.get_velocity_y() != 0) return; if (!on_ground()) return; @@ -507,7 +505,7 @@ Player::do_jump(float yspeed) { if (!on_ground()) return; - physic.vy = yspeed; + physic.set_velocity_y(yspeed); //bbox.move(Vector(0, -1)); jumping = true; on_ground_flag = false; @@ -528,17 +526,17 @@ Player::handle_vertical_input() if(controller->pressed(Controller::JUMP) && (can_jump)) { if (duck) { // when running, only jump a little bit; else do a backflip - if ((physic.vx != 0) || (controller->hold(Controller::LEFT)) || (controller->hold(Controller::RIGHT))) do_jump(-300); else do_backflip(); + if ((physic.get_velocity_x() != 0) || (controller->hold(Controller::LEFT)) || (controller->hold(Controller::RIGHT))) do_jump(-300); else do_backflip(); } else { // jump a bit higher if we are running; else do a normal jump - if (fabs(physic.vx) > MAX_WALK_XM) do_jump(-580); else do_jump(-520); + if (fabs(physic.get_velocity_x()) > MAX_WALK_XM) do_jump(-580); else do_jump(-520); } } // Let go of jump key else if(!controller->hold(Controller::JUMP)) { - if (!backflipping && jumping && physic.vy < 0) { + if (!backflipping && jumping && physic.get_velocity_y() < 0) { jumping = false; - physic.vy = 0; + physic.set_velocity_y(0); } } @@ -553,11 +551,11 @@ Player::handle_vertical_input() butt_jump = false; // swimming - physic.ay = 0; + physic.set_acceleration_y(0); if (swimming) { if (controller->hold(Controller::UP) || controller->hold(Controller::JUMP)) - physic.ay = -2000; - physic.vy = physic.vy * 0.94; + physic.set_acceleration_y(-2000); + physic.set_velocity_y(physic.get_velocity_y() * 0.94); } } @@ -598,7 +596,7 @@ Player::handle_input() if(Sector::current()->add_bullet( get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2) : Vector(32, bbox.get_height()/2)), - physic.vx, dir)) + physic.get_velocity_x(), dir)) shooting_timer.start(SHOOTING_TIME); } @@ -686,10 +684,8 @@ Player::handle_input_ghost() if (controller->hold(Controller::ACTION)) { set_ghost_mode(false); } - physic.vx = vx; - physic.vy = vy; - physic.ax = 0; - physic.ay = 0; + physic.set_velocity(vx, vy); + physic.set_acceleration(0, 0); } void @@ -880,7 +876,7 @@ Player::draw(DrawingContext& context) } else { - if (fabsf(physic.vx) < 1.0f) // standing + if (fabsf(physic.get_velocity_x()) < 1.0f) // standing { if(dir == LEFT) tux_body->set_action("stand-left"); @@ -909,7 +905,7 @@ Player::draw(DrawingContext& context) } // Tux is holding something - if ((grabbed_object != 0 && physic.vy == 0) || + if ((grabbed_object != 0 && physic.get_velocity_y() == 0) || (shooting_timer.get_timeleft() > 0 && !shooting_timer.check())) { if (duck) @@ -973,18 +969,18 @@ void Player::collision_solid(const CollisionHit& hit) { if(hit.bottom) { - if(physic.vy > 0) - physic.vy = 0; + if(physic.get_velocity_y() > 0) + physic.set_velocity_y(0); on_ground_flag = true; floor_normal = hit.slope_normal; } else if(hit.top) { - if(physic.vy < 0) - physic.vy = .2; + if(physic.get_velocity_y() < 0) + physic.set_velocity_y(.2); } if(hit.left || hit.right) { - physic.vx = 0; + physic.set_velocity_x(0); } // crushed? @@ -1053,7 +1049,7 @@ Player::kill(bool completely) sound_manager->play("sounds/hurt.wav"); - physic.vx = 0; + physic.set_velocity_x(0); if(!completely && is_big()) { if(player_status->bonus == FIRE_BONUS @@ -1075,11 +1071,9 @@ Player::kill(bool completely) Vector(systemRandom.rand(5), systemRandom.rand(-32,18)), systemRandom.rand(-100,100))); } - physic.gravity_enabled = true; - physic.vx = 0; - physic.vy = -700; - physic.ax = 0; - physic.ay = 0; + physic.enable_gravity(true); + physic.set_acceleration(0, 0); + physic.set_velocity(0, -700); player_status->coins -= 25; set_bonus(NO_BONUS, true); dying = true; @@ -1106,7 +1100,7 @@ Player::move(const Vector& vector) duck = false; last_ground_y = vector.y; - physic = Physic(); + physic.reset(); } void @@ -1140,30 +1134,29 @@ Player::check_bounds(Camera* camera) void Player::add_velocity(const Vector& velocity) { - physic.vx += velocity.x; - physic.vy += velocity.y; + physic.set_velocity(physic.get_velocity() + velocity); } void Player::add_velocity(const Vector& velocity, const Vector& end_speed) { if (end_speed.x > 0) - physic.vx = std::min(physic.vx + velocity.x, end_speed.x); + physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x)); if (end_speed.x < 0) - physic.vx = std::max(physic.vx + velocity.x, end_speed.x); + physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x)); if (end_speed.y > 0) - physic.vy = std::min(physic.vy + velocity.y, end_speed.y); + physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y)); if (end_speed.y < 0) - physic.vy = std::max(physic.vy + velocity.y, end_speed.y); + physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y)); } void Player::bounce(BadGuy& ) { if(controller->hold(Controller::JUMP)) - physic.vy = -520; + physic.set_velocity_y(-520); else - physic.vy = -300; + physic.set_velocity_y(-300); } //Scripting Functions Below @@ -1174,10 +1167,10 @@ Player::deactivate() if (deactivated) return; deactivated = true; - physic.vx = 0; - physic.vy = 0; - physic.ax = 0; - physic.ay = 0; + physic.set_velocity_x(0); + physic.set_velocity_y(0); + physic.set_acceleration_x(0); + physic.set_acceleration_y(0); } void @@ -1190,7 +1183,7 @@ Player::activate() void Player::walk(float speed) { - physic.vx = speed; + physic.set_velocity_x(speed); } void @@ -1202,12 +1195,12 @@ Player::set_ghost_mode(bool enable) if (enable) { ghost_mode = true; set_group(COLGROUP_DISABLED); - physic.gravity_enabled = false; + physic.enable_gravity(false); log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl; } else { ghost_mode = false; set_group(COLGROUP_MOVING); - physic.gravity_enabled = true; + physic.enable_gravity(true); log_debug << "You feel solid again." << std::endl; } } diff --git a/src/object/powerup.cpp b/src/object/powerup.cpp index bb1895387..09a747063 100644 --- a/src/object/powerup.cpp +++ b/src/object/powerup.cpp @@ -36,7 +36,7 @@ PowerUp::PowerUp(const lisp::Lisp& lisp) lisp.get("script", script); no_physics = false; lisp.get("disable-physics", no_physics); - physic.gravity_enabled = true; + physic.enable_gravity(true); sound_manager->preload("sounds/grow.wav"); sound_manager->preload("sounds/fire-flower.wav"); } @@ -45,10 +45,10 @@ void PowerUp::collision_solid(const CollisionHit& hit) { if(hit.bottom) { - physic.vy = 0; + physic.set_velocity_y(0); } if(hit.right || hit.left) { - physic.vx = -physic.vx; + physic.set_velocity_x(-physic.get_velocity_x()); } } diff --git a/src/object/pushbutton.cpp b/src/object/pushbutton.cpp index 38f111980..45012f33b 100644 --- a/src/object/pushbutton.cpp +++ b/src/object/pushbutton.cpp @@ -53,10 +53,10 @@ PushButton::collision(GameObject& other, const CollisionHit& hit) { Player* player = dynamic_cast(&other); if (!player) return FORCE_MOVE; - float vy = player->physic.vy; + float vy = player->physic.get_velocity_y(); //player->add_velocity(Vector(0, -150)); - player->physic.vy = -150; + player->physic.set_velocity_y(-150); if (state != OFF) return FORCE_MOVE; if (!hit.top) return FORCE_MOVE; diff --git a/src/object/rock.cpp b/src/object/rock.cpp index 2d85ff2ff..e5f10b37d 100644 --- a/src/object/rock.cpp +++ b/src/object/rock.cpp @@ -64,7 +64,7 @@ Rock::update(float elapsed_time) if( grabbed ) return; - if (on_ground) physic.vx = 0; + if (on_ground) physic.set_velocity_x(0); movement = physic.get_movement(elapsed_time); } @@ -73,12 +73,11 @@ void Rock::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) - physic.vy = 0; + physic.set_velocity_y(0); if(hit.left || hit.right) - physic.vx = 0; + physic.set_velocity_x(0); if(hit.crush) - physic.vx = 0; - physic.vy = 0; + physic.set_velocity(0, 0); if(hit.bottom && !on_ground) { sound_manager->play(ROCK_SOUND, get_pos()); @@ -90,7 +89,7 @@ HitResponse Rock::collision(GameObject& other, const CollisionHit& hit) { if(!on_ground) { - if(hit.bottom && physic.vy > 200) { + if(hit.bottom && physic.get_velocity_y() > 200) { MovingObject* moving_object = dynamic_cast (&other); if(moving_object) { //Getting a rock on the head hurts. A lot. @@ -119,11 +118,9 @@ Rock::ungrab(MovingObject& , Direction dir) set_group(COLGROUP_MOVING_STATIC); on_ground = false; if (last_movement.norm() > 1) { - physic.vx = ((dir == RIGHT) ? 200 : -200); - physic.vy = -200; + physic.set_velocity((dir == RIGHT) ? 200 : -200, -200); } else { - physic.vx = 0; - physic.vy = 0; + physic.set_velocity(0, 0); } grabbed = false; } diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index 591053d0b..b3c1158b1 100644 --- a/src/object/scripted_object.cpp +++ b/src/object/scripted_object.cpp @@ -79,7 +79,7 @@ ScriptedObject::set_pos(float x, float y) { printf("SetPos: %f %f\n", x, y); bbox.set_pos(Vector(x, y)); - physic = Physic(); + physic.reset(); } float @@ -104,13 +104,13 @@ ScriptedObject::set_velocity(float x, float y) float ScriptedObject::get_velocity_x() { - return physic.vx; + return physic.get_velocity_x(); } float ScriptedObject::get_velocity_y() { - return physic.vy; + return physic.get_velocity_y(); } void @@ -168,8 +168,7 @@ ScriptedObject::update(float elapsed_time) return; if(new_vel_set) { - physic.vx = new_vel.x; - physic.vy = new_vel.y; + physic.set_velocity(new_vel.x, new_vel.y); new_vel_set = false; } movement = physic.get_movement(elapsed_time); @@ -191,14 +190,14 @@ ScriptedObject::collision_solid(const CollisionHit& hit) return; if(hit.bottom) { - if(physic.vy > 0) - physic.vy = 0; + if(physic.get_velocity_y() > 0) + physic.set_velocity_y(0); } else if(hit.top) { - physic.vy = .1; + physic.set_velocity_y(.1); } if(hit.left || hit.right) { - physic.vx = 0; + physic.set_velocity_x(0); } } diff --git a/src/object/skull_tile.cpp b/src/object/skull_tile.cpp index b82a0996a..26b86bd56 100644 --- a/src/object/skull_tile.cpp +++ b/src/object/skull_tile.cpp @@ -70,7 +70,7 @@ SkullTile::update(float elapsed_time) } else if(hit) { if(timer.check()) { falling = true; - physic.gravity_enabled = true; + physic.enable_gravity(true); timer.stop(); } else if(!timer.started()) { timer.start(FALLTIME); diff --git a/src/object/star.cpp b/src/object/star.cpp index 87e2c11a6..316f572d3 100644 --- a/src/object/star.cpp +++ b/src/object/star.cpp @@ -33,8 +33,7 @@ static const float JUMPSPEED = -300; Star::Star(const Vector& pos, Direction direction) : MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING) { - physic.vx = ((direction == LEFT) ? -SPEED : SPEED); - physic.vy = INITIALJUMP; + physic.set_velocity((direction == LEFT) ? -SPEED : SPEED, INITIALJUMP); } void @@ -47,11 +46,11 @@ void Star::collision_solid(const CollisionHit& hit) { if(hit.bottom) { - physic.vy = JUMPSPEED; + physic.set_velocity_y(JUMPSPEED); } else if(hit.top) { - physic.vy = 0; + physic.set_velocity_y(0); } else if(hit.left || hit.right) { - physic.vx = -physic.vx; + physic.set_velocity_x(-physic.get_velocity_x()); } } diff --git a/src/object/trampoline.cpp b/src/object/trampoline.cpp index e3e32fd61..4871cf639 100644 --- a/src/object/trampoline.cpp +++ b/src/object/trampoline.cpp @@ -70,7 +70,7 @@ Trampoline::collision(GameObject& other, const CollisionHit& hit) Player* player = dynamic_cast (&other); //Trampoline works for player if(player) { - float vy = player->physic.vy; + float vy = player->physic.get_velocity_y(); //player is falling down on trampoline if(hit.top && vy >= 0) { if(player->get_controller()->hold(Controller::JUMP)) { @@ -78,7 +78,7 @@ Trampoline::collision(GameObject& other, const CollisionHit& hit) } else { vy = VY_INITIAL; } - player->physic.vy = vy; + player->physic.set_velocity_y(vy); sound_manager->play(TRAMPOLINE_SOUND); sprite->set_action("swinging", 1); return FORCE_MOVE; diff --git a/src/object/unstable_tile.cpp b/src/object/unstable_tile.cpp index f9e05ce3a..089a18d62 100644 --- a/src/object/unstable_tile.cpp +++ b/src/object/unstable_tile.cpp @@ -63,7 +63,7 @@ UnstableTile::update(float elapsed_time) state = STATE_DISINTEGRATING; sprite->set_action("disintegrating", 1); set_group(COLGROUP_DISABLED); - physic.gravity_enabled = true; + physic.enable_gravity(true); } break; diff --git a/src/physic.cpp b/src/physic.cpp index 84eb8923c..d7993cd30 100644 --- a/src/physic.cpp +++ b/src/physic.cpp @@ -23,14 +23,140 @@ #include "physic.hpp" Physic::Physic() - : ax(0), ay(0), vx(0), vy(0), gravity_enabled(true), gravity(1000) + : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true), gravity(1000) { } +Physic::~Physic() +{ +} + +void +Physic::reset() +{ + ax = ay = vx = vy = 0; + gravity_enabled_flag = true; +} + +void +Physic::set_velocity_x(float nvx) +{ + vx = nvx; +} + +void +Physic::set_velocity_y(float nvy) +{ + vy = nvy; +} + +void +Physic::set_velocity(float nvx, float nvy) +{ + vx = nvx; + vy = nvy; +} + +void +Physic::set_velocity(const Vector& vector) +{ + vx = vector.x; + vy = vector.y; +} + +void Physic::inverse_velocity_x() +{ + vx = -vx; +} + +void Physic::inverse_velocity_y() +{ + vy = -vy; +} + +float +Physic::get_velocity_x() const +{ + return vx; +} + +float +Physic::get_velocity_y() const +{ + return vy; +} + +Vector +Physic::get_velocity() const +{ + return Vector(vx, vy); +} + +void +Physic::set_acceleration_x(float nax) +{ + ax = nax; +} + +void +Physic::set_acceleration_y(float nay) +{ + ay = nay; +} + +void +Physic::set_acceleration(float nax, float nay) +{ + ax = nax; + ay = nay; +} + +float +Physic::get_acceleration_x() const +{ + return ax; +} + +float +Physic::get_acceleration_y() const +{ + return ay; +} + +Vector +Physic::get_acceleration() const +{ + return Vector(ax, ay); +} + +void +Physic::enable_gravity(bool enable_gravity) +{ + gravity_enabled_flag = enable_gravity; +} + +bool +Physic::gravity_enabled() const +{ + return gravity_enabled_flag; +} + +void +Physic::set_gravity(float gravity) +{ + this->gravity = gravity; +} + +float +Physic::get_gravity() const +{ + return gravity; +} + Vector Physic::get_movement(float elapsed_time) { - float grav = gravity_enabled ? gravity : 0; + float grav = gravity_enabled_flag ? gravity : 0; Vector result( vx * elapsed_time + ax * elapsed_time * elapsed_time, diff --git a/src/physic.hpp b/src/physic.hpp index 0d45834cf..abfdba530 100644 --- a/src/physic.hpp +++ b/src/physic.hpp @@ -31,15 +31,58 @@ class Physic { public: Physic(); + ~Physic(); + + /// Resets all velocities and accelerations to 0. + void reset(); + + /// Sets velocity to a fixed value. + void set_velocity(float vx, float vy); + void set_velocity(const Vector& vector); + + void set_velocity_x(float vx); + void set_velocity_y(float vy); + + /// Velocities invertion. + void inverse_velocity_x(); + void inverse_velocity_y(); + + Vector get_velocity() const; + float get_velocity_x() const; + float get_velocity_y() const; + + /// Set acceleration. + /** Sets acceleration applied to the object. (Note that gravity is + * eventually added to the vertical acceleration) + */ + void set_acceleration(float ax, float ay); + + void set_acceleration_x(float ax); + void set_acceleration_y(float ay); + + Vector get_acceleration() const; + float get_acceleration_x() const; + float get_acceleration_y() const; + + /// Enables or disables handling of gravity. + void enable_gravity(bool gravity_enabled); + bool gravity_enabled() const; + + /// Set gravity to apply to object when enabled + void set_gravity(float gravity); + + /// Get gravity to apply to object when enabled + float get_gravity() const; Vector get_movement(float elapsed_time); +private: /// horizontal and vertical acceleration float ax, ay; /// horizontal and vertical velocity float vx, vy; - /// should we respect gravity in our calculations? - bool gravity_enabled; + /// should we respect gravity in out calculations? + bool gravity_enabled_flag; /// current gravity to apply to object, if enabled float gravity; }; diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index ecc2bf96d..236a12ad2 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -203,7 +203,7 @@ void grease() { if (!validate_sector_player()) return; ::Player* tux = Sector::current()->player; // Scripting::Player != ::Player - tux->physic.vx = tux->physic.vx*3; + tux->physic.set_velocity_x(tux->physic.get_velocity_x()*3); } void invincible()