Sorry, was too early for that patch.
authorWolfgang Becker <uafr@gmx.de>
Tue, 2 Jan 2007 17:07:50 +0000 (17:07 +0000)
committerWolfgang Becker <uafr@gmx.de>
Tue, 2 Jan 2007 17:07:50 +0000 (17:07 +0000)
SVN-Revision: 4524

42 files changed:
src/badguy/angrystone.cpp
src/badguy/badguy.cpp
src/badguy/bomb.cpp
src/badguy/bouncing_snowball.cpp
src/badguy/dart.cpp
src/badguy/fish.cpp
src/badguy/flyingsnowball.cpp
src/badguy/jumpy.cpp
src/badguy/kugelblitz.cpp
src/badguy/mole.cpp
src/badguy/mole_rock.cpp
src/badguy/mriceblock.cpp
src/badguy/mrrocket.cpp
src/badguy/plant.cpp
src/badguy/skullyhop.cpp
src/badguy/snail.cpp
src/badguy/spidermite.cpp
src/badguy/sspiky.cpp
src/badguy/stalactite.cpp
src/badguy/stumpy.cpp
src/badguy/toad.cpp
src/badguy/totem.cpp
src/badguy/walking_badguy.cpp
src/badguy/yeti.cpp
src/badguy/zeekling.cpp
src/object/bullet.cpp
src/object/camera.cpp
src/object/falling_coin.cpp
src/object/growup.cpp
src/object/oneup.cpp
src/object/player.cpp
src/object/powerup.cpp
src/object/pushbutton.cpp
src/object/rock.cpp
src/object/scripted_object.cpp
src/object/skull_tile.cpp
src/object/star.cpp
src/object/trampoline.cpp
src/object/unstable_tile.cpp
src/physic.cpp
src/physic.hpp
src/scripting/functions.cpp

index 3315291..865e430 100644 (file)
@@ -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);
     }
   }
 
index 9cf5ece..75e59d3 100644 (file)
@@ -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<Player*>(&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);
 }
 
index 309ea60..670baa5 100644 (file)
@@ -61,7 +61,7 @@ void
 Bomb::collision_solid(const CollisionHit& hit)
 {
   if(hit.bottom)
-    physic.vy = 0;
+    physic.set_velocity_y(0);
 }
 
 HitResponse
index b28b03e..f84561b 100644 (file)
@@ -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());
   }
 }
 
index 4726a01..393474e 100644 (file)
@@ -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));
index 43ceb5e..8035120 100644 (file)
@@ -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();
 }
 
index b002ba2..fd68430 100644 (file)
@@ -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) {
index 817e12f..706a7d7 100644 (file)
@@ -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");
 }
 
index 0d14a5a..c6242e6 100644 (file)
@@ -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);
       }
     }
index 635e084..d3e4e46 100644 (file)
@@ -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
index 7bef50b..c9252ff 100644 (file)
 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");
 }
 
index 8cf9481..697fed9 100644 (file)
@@ -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);
index 7e90629..3f6cc3b 100644 (file)
@@ -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);
   }
 }
index f734a77..5830d2b 100644 (file)
@@ -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;
     }
   }
index 79d9f21..8bf61d7 100644 (file)
@@ -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());
   }
 }
 
index 8c04c09..1f21922 100644 (file)
@@ -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();
        }
 
       }
index af88274..ee9eac9 100644 (file)
@@ -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);
   }
index 4316b18..ad80b8d 100644 (file)
@@ -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");
 }
 
index 46d16f6..60857fb 100644 (file)
@@ -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);
   }
 }
 
index 7654292..f451546 100644 (file)
@@ -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;
index f416d8a..1657a9b 100644 (file)
@@ -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;
   }
index 893eb06..139aa14 100644 (file)
@@ -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());
 }
 
 
index 4943a0f..37816dc 100644 (file)
@@ -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);
 }
 
 
index 438b5b5..51f9c13 100644 (file)
@@ -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();
index 4cdec6a..64a4566 100644 (file)
@@ -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;
index e9a7c1a..564b7ba 100644 (file)
@@ -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();
index 97867ec..b9d0097 100644 (file)
@@ -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)
index 33d3d2d..8e091a5 100644 (file)
@@ -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()
index 4a6e0ce..1d256db 100644 (file)
@@ -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
index bafe8bd..bdbaa5e 100644 (file)
@@ -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
index 89face7..004a838 100644 (file)
@@ -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;
   }
 }
index bb18953..09a7470 100644 (file)
@@ -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());
   }
 }
 
index 38f1119..45012f3 100644 (file)
@@ -53,10 +53,10 @@ PushButton::collision(GameObject& other, const CollisionHit& hit)
 {
   Player* player = dynamic_cast<Player*>(&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;
index 2d85ff2..e5f10b3 100644 (file)
@@ -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<MovingObject*> (&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;
 }
index 591053d..b3c1158 100644 (file)
@@ -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);
   }
 }
 
index b82a099..26b86bd 100644 (file)
@@ -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);
index 87e2c11..316f572 100644 (file)
@@ -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());
   }
 }
 
index e3e32fd..4871cf6 100644 (file)
@@ -70,7 +70,7 @@ Trampoline::collision(GameObject& other, const CollisionHit& hit)
     Player* player = dynamic_cast<Player*> (&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;
index f9e05ce..089a18d 100644 (file)
@@ -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;
 
index 84eb892..d7993cd 100644 (file)
 #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,
index 0d45834..abfdba5 100644 (file)
@@ -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;
 };
index ecc2bf9..236a12a 100644 (file)
@@ -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()