From: Wolfgang Becker Date: Tue, 2 Jan 2007 16:14:53 +0000 (+0000) Subject: [ Patch #1793 ] Turn physic into POD X-Git-Url: https://git.octo.it/?p=supertux.git;a=commitdiff_plain;h=714a30abd887def6331a193216387e66cbfbd1bb [ Patch #1793 ] Turn physic into POD Date: 2007-Jan-02 16:30 Submitted By: tuxdev SVN-Revision: 4523 --- diff --git a/src/badguy/angrystone.cpp b/src/badguy/angrystone.cpp index 865e43061..331529130 100644 --- a/src/badguy/angrystone.cpp +++ b/src/badguy/angrystone.cpp @@ -47,9 +47,9 @@ AngryStone::write(lisp::Writer& writer) void AngryStone::activate() { - physic.set_velocity_x(0); - physic.set_velocity_y(0); - physic.enable_gravity(true); + physic.vx = 0; + physic.vy = 0; + physic.gravity_enabled = 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.set_velocity_x(0); - physic.set_velocity_y(0); - physic.enable_gravity(true); + physic.vx = 0; + physic.vy = 0; + physic.gravity_enabled = 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.enable_gravity(false); - physic.set_velocity_x(SPEED * attackDirection.x); - physic.set_velocity_y(SPEED * attackDirection.y); + physic.gravity_enabled = false; + physic.vx = SPEED * attackDirection.x; + physic.vy = 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.enable_gravity(true); - physic.set_velocity_x(0); - physic.set_velocity_y(0); + physic.gravity_enabled = true; + physic.vx = 0; + physic.vy = 0; } } @@ -166,9 +166,9 @@ AngryStone::active_update(float elapsed_time) { if (timer.check()) { state = IDLE; sprite->set_action("idle"); - physic.enable_gravity(true); - physic.set_velocity_x(0); - physic.set_velocity_y(0); + physic.gravity_enabled = true; + physic.vx = 0; + physic.vy = 0; } } diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 75e59d348..9cf5eceba 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.set_velocity_x(0); - physic.set_velocity_y(0); + physic.vx = 0; + physic.vy = 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.enable_gravity(true); - physic.set_velocity_x(0); - physic.set_velocity_y(0); + physic.gravity_enabled = true; + physic.vx = 0; + physic.vy = 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.set_velocity_y(0); - physic.enable_gravity(true); + physic.vy = 0; + physic.gravity_enabled = true; set_state(STATE_FALLING); } diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index 670baa554..309ea603f 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.set_velocity_y(0); + physic.vy = 0; } HitResponse diff --git a/src/badguy/bouncing_snowball.cpp b/src/badguy/bouncing_snowball.cpp index f84561b74..b28b03ed5 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.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); + physic.vx = (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.set_velocity_y(JUMPSPEED); + physic.vy = JUMPSPEED; } else { - physic.set_velocity_y(0); + physic.vy = 0; } } else if(hit.top) { - physic.set_velocity_y(0); + physic.vy = 0; } if(hit.left || hit.right) { // left or right collision dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); + physic.vx = -physic.vx; } } diff --git a/src/badguy/dart.cpp b/src/badguy/dart.cpp index 393474e31..4726a0148 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.enable_gravity(false); + physic.gravity_enabled = 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.enable_gravity(false); + physic.gravity_enabled = 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.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED); + physic.vx = (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 803512096..43ceb5e70 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.enable_gravity(true); + physic.gravity_enabled = true; } Fish::Fish(const Vector& pos) : BadGuy(pos, "images/creatures/fish/fish.sprite", LAYER_TILES-1), stop_y(0) { - physic.enable_gravity(true); + physic.gravity_enabled = true; } void @@ -75,7 +75,7 @@ HitResponse Fish::hit(const CollisionHit& hit) { if(hit.top) { - physic.set_velocity_y(0); + physic.vy = 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.get_velocity_y() >= 0)) { + if ((tile_attributes & Tile::WATER) && (physic.vy >= 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.get_velocity_y() < 0 ? "normal" : "down"); + sprite->set_action(physic.vy < 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.set_velocity_y(0); - physic.enable_gravity(true); + physic.vy = 0; + physic.gravity_enabled = true; } } @@ -126,15 +126,15 @@ Fish::start_waiting() { waiting.start(FISH_WAIT_TIME); set_group(COLGROUP_DISABLED); - physic.enable_gravity(false); - physic.set_velocity_y(0); + physic.gravity_enabled = false; + physic.vy = 0; } void Fish::jump() { - physic.set_velocity_y(FISH_JUMP_POWER); - physic.enable_gravity(true); + physic.vy = FISH_JUMP_POWER; + physic.gravity_enabled = true; set_group(COLGROUP_MOVING); } @@ -142,7 +142,7 @@ void Fish::freeze() { BadGuy::freeze(); - sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down"); + sprite->set_action(physic.vy < 0 ? "iced" : "iced-down"); waiting.stop(); } diff --git a/src/badguy/flyingsnowball.cpp b/src/badguy/flyingsnowball.cpp index fd684304f..b002ba2a9 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.enable_gravity(false); + physic.gravity_enabled = false; } FlyingSnowBall::FlyingSnowBall(const Vector& pos) : BadGuy(pos, "images/creatures/flying_snowball/flying_snowball.sprite") { - physic.enable_gravity(false); + physic.gravity_enabled = false; } void @@ -62,7 +62,7 @@ FlyingSnowBall::activate() { sprite->set_action(dir == LEFT ? "left" : "right"); mode = FLY_UP; - physic.set_velocity_y(FLYSPEED); + physic.vy = 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.set_velocity_y(0); + physic.vy = 0; } } @@ -89,14 +89,14 @@ FlyingSnowBall::active_update(float elapsed_time) if(timer.check()) { if(mode == FLY_UP) { mode = FLY_DOWN; - physic.set_velocity_y(-FLYSPEED); + physic.vy = -FLYSPEED; // stop puffing puff_timer.stop(); } else if(mode == FLY_DOWN) { mode = FLY_UP; - physic.set_velocity_y(FLYSPEED); + physic.vy = 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 706a7d7bb..817e12f59 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.set_velocity_y(frozen ? 0 : JUMPSPEED); + physic.vy = (frozen ? 0 : JUMPSPEED); // TODO create a nice sound for this... //sound_manager->play("sounds/skid.wav"); } else if(chit.top) { - physic.set_velocity_y(0); + physic.vy = 0; } return CONTINUE; @@ -106,7 +106,7 @@ void Jumpy::freeze() { BadGuy::freeze(); - physic.set_velocity_y(std::max(0.0f, physic.get_velocity_y())); + physic.vy = std::max(0.0f, physic.vy); sprite->set_action(dir == LEFT ? "left-iced" : "right-iced"); } diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index c6242e6ad..0d14a5a86 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.enable_gravity(false); + physic.gravity_enabled = false; } void @@ -54,8 +54,8 @@ Kugelblitz::write(lisp::Writer& writer) void Kugelblitz::activate() { - physic.set_velocity_y(300); - physic.set_velocity_x(-20); //fall a little to the left + physic.vy = 300; + physic.vx = -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.set_velocity_y(0); + physic.vy = 0; //Set random initial speed and direction direction = systemRandom.rand(2)? 1: -1; int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction; - physic.set_velocity_x(speed); + physic.vx = speed; movement_timer.start(MOVETIME); lifetime.start(LIFETIME); } else if(hit.top) { // bumped on roof - physic.set_velocity_y(0); + physic.vy = 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.set_velocity_x(speed); + physic.vx = speed; movement_timer.start(MOVETIME); } } diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index d3e4e4687..635e08492 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.enable_gravity(false); + physic.gravity_enabled = false; } Mole::Mole(const Vector& pos) : BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING) { - physic.enable_gravity(false); + physic.gravity_enabled = false; } void diff --git a/src/badguy/mole_rock.cpp b/src/badguy/mole_rock.cpp index c9252ff05..7bef50b83 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.enable_gravity(true); + physic.gravity_enabled = 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.enable_gravity(true); + physic.gravity_enabled = true; countMe = false; } @@ -67,7 +67,8 @@ MoleRock::write(lisp::Writer& writer) void MoleRock::activate() { - physic.set_velocity(initial_velocity); + physic.vx = initial_velocity.x; + physic.vy = initial_velocity.y; sprite->set_action("default"); } diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index 697fed9d7..8cf9481de 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.set_velocity_y(0); + physic.vy = 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.set_velocity_x(-KICKSPEED); + physic.vx = -KICKSPEED; } else if(hit.left && dir == LEFT) { dir = RIGHT; sound_manager->play("sounds/iceblock_bump.wav", get_pos()); - physic.set_velocity_x(KICKSPEED); + physic.vx = KICKSPEED; } sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); break; } case ICESTATE_FLAT: - physic.set_velocity_x(0); + physic.vx = 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.set_velocity_x(0); - physic.set_velocity_y(0); + physic.vx = 0; + physic.vy = 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.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED); + physic.vx = (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 3f6cc3b7a..7e90629c1 100644 --- a/src/badguy/mrrocket.cpp +++ b/src/badguy/mrrocket.cpp @@ -47,8 +47,8 @@ MrRocket::write(lisp::Writer& writer) void MrRocket::activate() { - physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED); - physic.enable_gravity(false); + physic.vx = (dir == LEFT ? -SPEED : SPEED); + physic.gravity_enabled = 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.set_velocity_y(0); + physic.vy = 0; } else if(hit.left || hit.right) { sprite->set_action(dir == LEFT ? "collision-left" : "collision-right"); - physic.set_velocity_x(0); + physic.vx = 0; collision_timer.start(0.2, true); } } diff --git a/src/badguy/plant.cpp b/src/badguy/plant.cpp index 5830d2b01..f734a7707 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.set_velocity_x(0); + physic.vx = 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.set_velocity_y(0); + physic.vy = 0; } else if(hit.left || hit.right) { dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); + physic.vx = -physic.vx; } } @@ -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.set_velocity_x(-physic.get_velocity_x()); + physic.vx = -physic.vx; } 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.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); + physic.vx = (dir == LEFT ? -WALKSPEED : WALKSPEED); state = PLANT_WALKING; } } diff --git a/src/badguy/skullyhop.cpp b/src/badguy/skullyhop.cpp index 8bf61d7da..79d9f2122 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.set_velocity_x(0); - physic.set_velocity_y(0); + physic.vx = 0; + physic.vy = 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.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); - physic.set_velocity_y(VERTICAL_SPEED); + physic.vx = (dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); + physic.vy = 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.get_velocity_y() > 0 ) { + if(hit.bottom && physic.vy > 0 ) { set_state(STANDING); } // check if we hit the roof while climbing if(hit.top) { - physic.set_velocity_y(0); + physic.vy = 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.set_velocity_x(-0.25*physic.get_velocity_x()); + physic.vx = -0.25*physic.vx; } } diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index 1f21922af..8c04c090b 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.set_velocity_x(0); - physic.set_velocity_y(0); + physic.vx = 0; + physic.vy = 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.set_velocity_x(0); - physic.set_velocity_y(0); + physic.vx = 0; + physic.vy = 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.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED); - physic.set_velocity_y(KICKSPEED_Y); + physic.vx = (dir == LEFT ? -KICKSPEED : KICKSPEED); + physic.vy = KICKSPEED_Y; state = STATE_KICKED; } BadGuy::active_update(elapsed_time); break; case STATE_KICKED: - 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(); + physic.vx = physic.vx * pow(0.99, elapsed_time/0.02); + if (fabsf(physic.vx) < 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.set_velocity_y(0); + physic.vy = 0; } if(hit.left || hit.right) { } break; case STATE_KICKED_DELAY: if(hit.top || hit.bottom) { - physic.set_velocity_y(0); + physic.vy = 0; } if(hit.left || hit.right) { - physic.set_velocity_x(0); + physic.vy = 0; } break; case STATE_KICKED: if(hit.top || hit.bottom) { - physic.set_velocity_y(0); + physic.vy = 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.set_velocity_x(-physic.get_velocity_x()*0.75); - if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal(); + physic.vx = -physic.vx*0.75; + if (fabsf(physic.vx) < walk_speed) be_normal(); } } diff --git a/src/badguy/spidermite.cpp b/src/badguy/spidermite.cpp index ee9eac956..af88274f4 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.enable_gravity(false); + physic.gravity_enabled = false; } SpiderMite::SpiderMite(const Vector& pos) : BadGuy(pos, "images/creatures/spidermite/spidermite.sprite") { - physic.enable_gravity(false); + physic.gravity_enabled = false; } void @@ -53,7 +53,7 @@ SpiderMite::activate() { sprite->set_action(dir == LEFT ? "left" : "right"); mode = FLY_UP; - physic.set_velocity_y(FLYSPEED); + physic.vy = 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.set_velocity_y(0); + physic.vy = 0; } } @@ -79,10 +79,10 @@ SpiderMite::active_update(float elapsed_time) if(timer.check()) { if(mode == FLY_UP) { mode = FLY_DOWN; - physic.set_velocity_y(-FLYSPEED); + physic.vy = -FLYSPEED; } else if(mode == FLY_DOWN) { mode = FLY_UP; - physic.set_velocity_y(FLYSPEED); + physic.vy = FLYSPEED; } timer.start(FLYTIME); } diff --git a/src/badguy/sspiky.cpp b/src/badguy/sspiky.cpp index ad80b8de8..4316b189f 100644 --- a/src/badguy/sspiky.cpp +++ b/src/badguy/sspiky.cpp @@ -42,7 +42,7 @@ void SSpiky::activate() { state = SSPIKY_SLEEPING; - physic.set_velocity_x(0); + physic.vx = 0; sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right"); } diff --git a/src/badguy/stalactite.cpp b/src/badguy/stalactite.cpp index 60857fb3f..46d16f6e4 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.enable_gravity(true); + physic.gravity_enabled = 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.set_velocity_y(0); + physic.vy = 0; } } diff --git a/src/badguy/stumpy.cpp b/src/badguy/stumpy.cpp index f4515461f..7654292c2 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.set_velocity_x(0); + physic.vx = 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.set_velocity_y(0); + physic.vy = 0; } if(hit.left || hit.right) { - physic.set_velocity_x(0); + physic.vx = 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.set_velocity_y(0); + physic.vy = 0; } if(hit.left || hit.right) { - physic.set_velocity_x(0); + physic.vx = 0; } return CONTINUE; break; diff --git a/src/badguy/toad.cpp b/src/badguy/toad.cpp index 1657a9b26..f416d8aa0 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.set_velocity_x(0); - physic.set_velocity_y(0); + physic.vx = 0; + physic.vy = 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.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); - physic.set_velocity_y(VERTICAL_SPEED); + physic.vx = (dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); + physic.vy = 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.get_velocity_x() < 0) && hit.left) || ((physic.get_velocity_x() > 0) && hit.right)) { + if(((physic.vx < 0) && hit.left) || ((physic.vx > 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.set_velocity_x(-0.25*physic.get_velocity_x()); + physic.vx = -0.25*physic.vx; } // 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.set_velocity_y(0); + physic.vy = 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.get_velocity_y() > 0)) { + if ((state == JUMPING) && (physic.vy > 0)) { set_state(FALLING); return; } diff --git a/src/badguy/totem.cpp b/src/badguy/totem.cpp index 139aa14df..893eb068f 100644 --- a/src/badguy/totem.cpp +++ b/src/badguy/totem.cpp @@ -77,7 +77,7 @@ void Totem::activate() { if (!carried_by) { - physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); + physic.vx = (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.set_velocity_y(JUMP_ON_SPEED_Y); + physic.vy = 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.set_velocity_y(0); + physic.vy = 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.set_velocity_y(JUMP_OFF_SPEED_Y); + physic.vy = 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.set_velocity_x(base->physic.get_velocity_x()); - physic.set_velocity_y(base->physic.get_velocity_y()); + physic.vx = base->physic.vx; + physic.vy = base->physic.vy; } diff --git a/src/badguy/walking_badguy.cpp b/src/badguy/walking_badguy.cpp index 37816dc68..4943a0f13 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.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed); + physic.vx = (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.get_velocity_y() < 0) physic.set_velocity_y(0); + if (physic.vy < 0) physic.vy = 0; } if (hit.bottom) { - if (physic.get_velocity_y() > 0) physic.set_velocity_y(0); + if (physic.vy > 0) physic.vy = 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.set_velocity_x(-physic.get_velocity_x()); + physic.vx = -physic.vx; } void WalkingBadguy::freeze() { BadGuy::freeze(); - physic.set_velocity_x(0); + physic.vx = 0; } void @@ -127,13 +127,13 @@ WalkingBadguy::unfreeze() float WalkingBadguy::get_velocity_y() const { - return physic.get_velocity_y(); + return physic.vy; } void WalkingBadguy::set_velocity_y(float vy) { - physic.set_velocity_y(vy); + physic.vy = vy; } diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 51f9c13ce..438b5b58e 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.set_velocity_x((dir==RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX); + physic.vx = (dir==RIGHT?JUMP_DOWN_VX:-JUMP_DOWN_VX); break; case RUN: - physic.set_velocity_x((dir==RIGHT)?+RUN_VX:-RUN_VX); + physic.vx = (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.set_velocity_x((dir==RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX); + physic.vx = (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.set_velocity_y(STOMP_VY); + physic.vy = 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.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX)); - physic.set_velocity_y(JUMP_DOWN_VY); + physic.vx = (dir==RIGHT?JUMP_DOWN_VX:-JUMP_DOWN_VX); + physic.vy = JUMP_DOWN_VY; state = JUMP_DOWN; } @@ -128,8 +128,8 @@ void Yeti::run() { sprite->set_action((dir==RIGHT)?"run-right":"run-left"); - physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX)); - physic.set_velocity_y(0); + physic.vx = (dir==RIGHT?RUN_VX:-RUN_VX); + physic.vy = 0; state = RUN; } @@ -137,8 +137,8 @@ void Yeti::jump_up() { sprite->set_action((dir==RIGHT)?"jump-right":"jump-left"); - physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX)); - physic.set_velocity_y(JUMP_UP_VY); + physic.vx = (dir==RIGHT?JUMP_UP_VX:-JUMP_UP_VX); + physic.vy = 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.set_velocity_x(0); - physic.set_velocity_y(0); + physic.vx = 0; + physic.vy = 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.enable_gravity(true); - physic.set_velocity_x(0); - physic.set_velocity_y(0); + physic.gravity_enabled = true; + physic.vx = 0; + physic.vy = 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.set_velocity_y(0); + physic.vy = 0; switch (state) { case JUMP_DOWN: run(); diff --git a/src/badguy/zeekling.cpp b/src/badguy/zeekling.cpp index 64a45669e..4cdec6a5a 100644 --- a/src/badguy/zeekling.cpp +++ b/src/badguy/zeekling.cpp @@ -52,8 +52,8 @@ void Zeekling::activate() { speed = systemRandom.rand(130, 171); - physic.set_velocity_x(dir == LEFT ? -speed : speed); - physic.enable_gravity(false); + physic.vx = (dir == LEFT ? -speed : speed); + physic.gravity_enabled = 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.set_velocity_x(dir == LEFT ? -speed : speed); + physic.vx = (dir == LEFT ? -speed : speed); } else if (state == DIVING) { dir = (dir == LEFT ? RIGHT : LEFT); state = FLYING; sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(dir == LEFT ? -speed : speed); - physic.set_velocity_y(0); + physic.vx = (dir == LEFT ? -speed : speed); + physic.vy = 0; } else if (state == CLIMBING) { dir = (dir == LEFT ? RIGHT : LEFT); sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(dir == LEFT ? -speed : speed); + physic.vx = (dir == LEFT ? -speed : speed); } else { assert(false); } @@ -92,16 +92,16 @@ Zeekling::onBumpHorizontal() { void Zeekling::onBumpVertical() { if (state == FLYING) { - physic.set_velocity_y(0); + physic.vy = 0; } else if (state == DIVING) { state = CLIMBING; - physic.set_velocity_y(-speed); + physic.vy = -speed; sprite->set_action(dir == LEFT ? "left" : "right"); } else if (state == CLIMBING) { state = FLYING; - physic.set_velocity_y(0); + physic.vy = 0; } } @@ -172,7 +172,7 @@ Zeekling::active_update(float elapsed_time) { if (state == FLYING) { if (should_we_dive()) { state = DIVING; - physic.set_velocity_y(2*fabsf(physic.get_velocity_x())); + physic.vy = 2*fabsf(physic.vx); 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.set_velocity_y(0); + physic.vy = 0; } BadGuy::active_update(elapsed_time); return; diff --git a/src/object/bullet.cpp b/src/object/bullet.cpp index 564b7ba0f..e9a7c1a0d 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.set_velocity_x(speed + xm); + physic.vx = 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.set_velocity_y(-physic.get_velocity_y()); + physic.vy = -physic.vy; life_count--; } else if(hit.left || hit.right) { if(type == ICE_BONUS) { - physic.set_velocity_x(-physic.get_velocity_x()); + physic.vx = -physic.vx; life_count--; } else remove_me(); diff --git a/src/object/camera.cpp b/src/object/camera.cpp index b9d0097bb..97867ec19 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.get_velocity_x() * 1.3)); + float maxv = 130 + (fabsf(player->physic.vx * 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 8e091a5d3..33d3d2dc2 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.set_velocity_y(-800); - physic.set_velocity_x(vel_x); + physic.vy = -800; + physic.vx = vel_x; } FallingCoin::~FallingCoin() diff --git a/src/object/growup.cpp b/src/object/growup.cpp index 1d256dbb7..4a6e0ce36 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.enable_gravity(true); - physic.set_velocity_x((direction == LEFT)?-100:100); + physic.gravity_enabled = true; + physic.vx = (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.set_velocity_y(0); + physic.vy = 0; if(hit.left || hit.right) - physic.set_velocity_x(-physic.get_velocity_x()); + physic.vx = -physic.vx; } HitResponse diff --git a/src/object/oneup.cpp b/src/object/oneup.cpp index bdbaa5e9a..bafe8bda2 100644 --- a/src/object/oneup.cpp +++ b/src/object/oneup.cpp @@ -29,7 +29,8 @@ OneUp::OneUp(const Vector& pos, Direction direction) : MovingSprite(pos, "images/powerups/1up/1up.sprite", LAYER_FLOATINGOBJECTS, COLGROUP_TOUCHABLE) { - physic.set_velocity((direction == LEFT)?-100:100, -400); + physic.vx = ((direction == LEFT)?-100:100); + physic.vy = -400; } void diff --git a/src/object/player.cpp b/src/object/player.cpp index 004a838b2..89face716 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.reset(); + physic = Physic(); } 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.get_velocity_x()) > MAX_WALK_XM) { + if(fabsf(physic.vx) > 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.get_velocity_x()) >= 0) { - physic.set_velocity_y(250); + if ((floor_normal.x * physic.vx) >= 0) { + physic.vy = 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.set_velocity_x(100 * backflip_direction); + if (backflip_timer.started()) physic.vx = 100 * backflip_direction; } // set fall mode... @@ -341,26 +341,26 @@ Player::is_big() void Player::apply_friction() { - 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); + 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; } else { - physic.set_acceleration_x(WALK_ACCELERATION_X * -1.5); + physic.ax = WALK_ACCELERATION_X * -1.5; } } void Player::handle_horizontal_input() { - 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 vx = physic.vx; + float vy = physic.vy; + float ax = physic.ax; + float ay = physic.ay; float dirsign = 0; - if(!duck || physic.get_velocity_y() != 0) { + if(!duck || physic.vy != 0) { if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) { old_dir = dir; dir = LEFT; @@ -421,8 +421,10 @@ Player::handle_horizontal_input() } } - physic.set_velocity(vx, vy); - physic.set_acceleration(ax, ay); + physic.vx = vx; + physic.vy = vy; + physic.ax = ax; + physic.ay = ay; // we get slower when not pressing any keys if(dirsign == 0) { @@ -446,7 +448,7 @@ Player::do_duck() { if (!is_big()) return; - if (physic.get_velocity_y() != 0) + if (physic.vy != 0) return; if (!on_ground()) return; @@ -505,7 +507,7 @@ Player::do_jump(float yspeed) { if (!on_ground()) return; - physic.set_velocity_y(yspeed); + physic.vy = yspeed; //bbox.move(Vector(0, -1)); jumping = true; on_ground_flag = false; @@ -526,17 +528,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.get_velocity_x() != 0) || (controller->hold(Controller::LEFT)) || (controller->hold(Controller::RIGHT))) do_jump(-300); else do_backflip(); + if ((physic.vx != 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.get_velocity_x()) > MAX_WALK_XM) do_jump(-580); else do_jump(-520); + if (fabs(physic.vx) > 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.get_velocity_y() < 0) { + if (!backflipping && jumping && physic.vy < 0) { jumping = false; - physic.set_velocity_y(0); + physic.vy = 0; } } @@ -551,11 +553,11 @@ Player::handle_vertical_input() butt_jump = false; // swimming - physic.set_acceleration_y(0); + physic.ay = 0; if (swimming) { if (controller->hold(Controller::UP) || controller->hold(Controller::JUMP)) - physic.set_acceleration_y(-2000); - physic.set_velocity_y(physic.get_velocity_y() * 0.94); + physic.ay = -2000; + physic.vy = physic.vy * 0.94; } } @@ -596,7 +598,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.get_velocity_x(), dir)) + physic.vx, dir)) shooting_timer.start(SHOOTING_TIME); } @@ -684,8 +686,10 @@ Player::handle_input_ghost() if (controller->hold(Controller::ACTION)) { set_ghost_mode(false); } - physic.set_velocity(vx, vy); - physic.set_acceleration(0, 0); + physic.vx = vx; + physic.vy = vy; + physic.ax = 0; + physic.ay = 0; } void @@ -876,7 +880,7 @@ Player::draw(DrawingContext& context) } else { - if (fabsf(physic.get_velocity_x()) < 1.0f) // standing + if (fabsf(physic.vx) < 1.0f) // standing { if(dir == LEFT) tux_body->set_action("stand-left"); @@ -905,7 +909,7 @@ Player::draw(DrawingContext& context) } // Tux is holding something - if ((grabbed_object != 0 && physic.get_velocity_y() == 0) || + if ((grabbed_object != 0 && physic.vy == 0) || (shooting_timer.get_timeleft() > 0 && !shooting_timer.check())) { if (duck) @@ -969,18 +973,18 @@ void Player::collision_solid(const CollisionHit& hit) { if(hit.bottom) { - if(physic.get_velocity_y() > 0) - physic.set_velocity_y(0); + if(physic.vy > 0) + physic.vy = 0; on_ground_flag = true; floor_normal = hit.slope_normal; } else if(hit.top) { - if(physic.get_velocity_y() < 0) - physic.set_velocity_y(.2); + if(physic.vy < 0) + physic.vy = .2; } if(hit.left || hit.right) { - physic.set_velocity_x(0); + physic.vx = 0; } // crushed? @@ -1049,7 +1053,7 @@ Player::kill(bool completely) sound_manager->play("sounds/hurt.wav"); - physic.set_velocity_x(0); + physic.vx = 0; if(!completely && is_big()) { if(player_status->bonus == FIRE_BONUS @@ -1071,9 +1075,11 @@ Player::kill(bool completely) Vector(systemRandom.rand(5), systemRandom.rand(-32,18)), systemRandom.rand(-100,100))); } - physic.enable_gravity(true); - physic.set_acceleration(0, 0); - physic.set_velocity(0, -700); + physic.gravity_enabled = true; + physic.vx = 0; + physic.vy = -700; + physic.ax = 0; + physic.ay = 0; player_status->coins -= 25; set_bonus(NO_BONUS, true); dying = true; @@ -1100,7 +1106,7 @@ Player::move(const Vector& vector) duck = false; last_ground_y = vector.y; - physic.reset(); + physic = Physic(); } void @@ -1134,29 +1140,30 @@ Player::check_bounds(Camera* camera) void Player::add_velocity(const Vector& velocity) { - physic.set_velocity(physic.get_velocity() + velocity); + physic.vx += velocity.x; + physic.vy += velocity.y; } void Player::add_velocity(const Vector& velocity, const Vector& end_speed) { if (end_speed.x > 0) - physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x)); + physic.vx = std::min(physic.vx + velocity.x, end_speed.x); if (end_speed.x < 0) - physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x)); + physic.vx = std::max(physic.vx + velocity.x, end_speed.x); if (end_speed.y > 0) - physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y)); + physic.vy = std::min(physic.vy + velocity.y, end_speed.y); if (end_speed.y < 0) - physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y)); + physic.vy = std::max(physic.vy + velocity.y, end_speed.y); } void Player::bounce(BadGuy& ) { if(controller->hold(Controller::JUMP)) - physic.set_velocity_y(-520); + physic.vy = -520; else - physic.set_velocity_y(-300); + physic.vy = -300; } //Scripting Functions Below @@ -1167,10 +1174,10 @@ Player::deactivate() if (deactivated) return; deactivated = true; - physic.set_velocity_x(0); - physic.set_velocity_y(0); - physic.set_acceleration_x(0); - physic.set_acceleration_y(0); + physic.vx = 0; + physic.vy = 0; + physic.ax = 0; + physic.ay = 0; } void @@ -1183,7 +1190,7 @@ Player::activate() void Player::walk(float speed) { - physic.set_velocity_x(speed); + physic.vx = speed; } void @@ -1195,12 +1202,12 @@ Player::set_ghost_mode(bool enable) if (enable) { ghost_mode = true; set_group(COLGROUP_DISABLED); - physic.enable_gravity(false); + physic.gravity_enabled = 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.enable_gravity(true); + physic.gravity_enabled = true; log_debug << "You feel solid again." << std::endl; } } diff --git a/src/object/powerup.cpp b/src/object/powerup.cpp index 09a747063..bb1895387 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.enable_gravity(true); + physic.gravity_enabled = 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.set_velocity_y(0); + physic.vy = 0; } if(hit.right || hit.left) { - physic.set_velocity_x(-physic.get_velocity_x()); + physic.vx = -physic.vx; } } diff --git a/src/object/pushbutton.cpp b/src/object/pushbutton.cpp index 45012f33b..38f111980 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.get_velocity_y(); + float vy = player->physic.vy; //player->add_velocity(Vector(0, -150)); - player->physic.set_velocity_y(-150); + player->physic.vy = -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 e5f10b37d..2d85ff2ff 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.set_velocity_x(0); + if (on_ground) physic.vx = 0; movement = physic.get_movement(elapsed_time); } @@ -73,11 +73,12 @@ void Rock::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) - physic.set_velocity_y(0); + physic.vy = 0; if(hit.left || hit.right) - physic.set_velocity_x(0); + physic.vx = 0; if(hit.crush) - physic.set_velocity(0, 0); + physic.vx = 0; + physic.vy = 0; if(hit.bottom && !on_ground) { sound_manager->play(ROCK_SOUND, get_pos()); @@ -89,7 +90,7 @@ HitResponse Rock::collision(GameObject& other, const CollisionHit& hit) { if(!on_ground) { - if(hit.bottom && physic.get_velocity_y() > 200) { + if(hit.bottom && physic.vy > 200) { MovingObject* moving_object = dynamic_cast (&other); if(moving_object) { //Getting a rock on the head hurts. A lot. @@ -118,9 +119,11 @@ Rock::ungrab(MovingObject& , Direction dir) set_group(COLGROUP_MOVING_STATIC); on_ground = false; if (last_movement.norm() > 1) { - physic.set_velocity((dir == RIGHT) ? 200 : -200, -200); + physic.vx = ((dir == RIGHT) ? 200 : -200); + physic.vy = -200; } else { - physic.set_velocity(0, 0); + physic.vx = 0; + physic.vy = 0; } grabbed = false; } diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index b3c1158b1..591053d0b 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.reset(); + physic = Physic(); } float @@ -104,13 +104,13 @@ ScriptedObject::set_velocity(float x, float y) float ScriptedObject::get_velocity_x() { - return physic.get_velocity_x(); + return physic.vx; } float ScriptedObject::get_velocity_y() { - return physic.get_velocity_y(); + return physic.vy; } void @@ -168,7 +168,8 @@ ScriptedObject::update(float elapsed_time) return; if(new_vel_set) { - physic.set_velocity(new_vel.x, new_vel.y); + physic.vx = new_vel.x; + physic.vy = new_vel.y; new_vel_set = false; } movement = physic.get_movement(elapsed_time); @@ -190,14 +191,14 @@ ScriptedObject::collision_solid(const CollisionHit& hit) return; if(hit.bottom) { - if(physic.get_velocity_y() > 0) - physic.set_velocity_y(0); + if(physic.vy > 0) + physic.vy = 0; } else if(hit.top) { - physic.set_velocity_y(.1); + physic.vy = .1; } if(hit.left || hit.right) { - physic.set_velocity_x(0); + physic.vx = 0; } } diff --git a/src/object/skull_tile.cpp b/src/object/skull_tile.cpp index 26b86bd56..b82a0996a 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.enable_gravity(true); + physic.gravity_enabled = true; timer.stop(); } else if(!timer.started()) { timer.start(FALLTIME); diff --git a/src/object/star.cpp b/src/object/star.cpp index 316f572d3..87e2c11a6 100644 --- a/src/object/star.cpp +++ b/src/object/star.cpp @@ -33,7 +33,8 @@ static const float JUMPSPEED = -300; Star::Star(const Vector& pos, Direction direction) : MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING) { - physic.set_velocity((direction == LEFT) ? -SPEED : SPEED, INITIALJUMP); + physic.vx = ((direction == LEFT) ? -SPEED : SPEED); + physic.vy = INITIALJUMP; } void @@ -46,11 +47,11 @@ void Star::collision_solid(const CollisionHit& hit) { if(hit.bottom) { - physic.set_velocity_y(JUMPSPEED); + physic.vy = JUMPSPEED; } else if(hit.top) { - physic.set_velocity_y(0); + physic.vy = 0; } else if(hit.left || hit.right) { - physic.set_velocity_x(-physic.get_velocity_x()); + physic.vx = -physic.vx; } } diff --git a/src/object/trampoline.cpp b/src/object/trampoline.cpp index 4871cf639..e3e32fd61 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.get_velocity_y(); + float vy = player->physic.vy; //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.set_velocity_y(vy); + player->physic.vy = 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 089a18d62..f9e05ce3a 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.enable_gravity(true); + physic.gravity_enabled = true; } break; diff --git a/src/physic.cpp b/src/physic.cpp index d7993cd30..84eb8923c 100644 --- a/src/physic.cpp +++ b/src/physic.cpp @@ -23,140 +23,14 @@ #include "physic.hpp" Physic::Physic() - : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true), gravity(1000) + : ax(0), ay(0), vx(0), vy(0), gravity_enabled(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_flag ? gravity : 0; + float grav = gravity_enabled ? gravity : 0; Vector result( vx * elapsed_time + ax * elapsed_time * elapsed_time, diff --git a/src/physic.hpp b/src/physic.hpp index abfdba530..0d45834cf 100644 --- a/src/physic.hpp +++ b/src/physic.hpp @@ -31,58 +31,15 @@ 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 out calculations? - bool gravity_enabled_flag; + /// should we respect gravity in our calculations? + bool gravity_enabled; /// current gravity to apply to object, if enabled float gravity; }; diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 236a12ad2..ecc2bf96d 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.set_velocity_x(tux->physic.get_velocity_x()*3); + tux->physic.vx = tux->physic.vx*3; } void invincible()