+ 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(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) {
+ old_dir = dir;
+ dir = LEFT;
+ dirsign = -1;
+ } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) {
+ old_dir = dir;
+ dir = RIGHT;
+ dirsign = 1;
+ }
+
+ if (input.fire == UP) {
+ ax = dirsign * WALK_ACCELERATION_X;
+ // limit speed
+ if(vx >= MAX_WALK_XM && dirsign > 0) {
+ vx = MAX_WALK_XM;
+ ax = 0;
+ } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
+ vx = -MAX_WALK_XM;
+ ax = 0;
+ }
+ } else {
+ ax = dirsign * RUN_ACCELERATION_X;
+ // limit speed
+ if(vx >= MAX_RUN_XM && dirsign > 0) {
+ vx = MAX_RUN_XM;
+ ax = 0;
+ } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
+ vx = -MAX_RUN_XM;
+ ax = 0;
+ }
+ }
+
+ // we can reach WALK_SPEED without any acceleration
+ if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
+ vx = dirsign * WALK_SPEED;
+ }
+
+ // changing directions?
+ if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
+ if(fabs(vx)>SKID_XM && !skidding_timer.check()) {
+ skidding_timer.start(SKID_TIME);
+ play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
+ ax *= 2.5;
+ } else {
+ ax *= 2;
+ }
+ }
+
+ // we get slower when not pressing any keys
+ if(dirsign == 0) {
+ if(fabs(vx) < WALK_SPEED) {
+ vx = 0;
+ ax = 0;
+ } else if(vx < 0) {
+ ax = WALK_ACCELERATION_X * 1.5;
+ } else {
+ ax = WALK_ACCELERATION_X * -1.5;
+ }
+ }
+
+ // if we're on ice slow down acceleration or deceleration
+ if (isice(base.x, base.y + base.height))
+ {
+ /* the acceleration/deceleration rate on ice is inversely proportional to
+ * the current velocity.
+ */
+
+ // increasing 1 will increase acceleration/deceleration rate
+ // decreasing 1 will decrease acceleration/deceleration rate
+ // must stay above zero, though
+ if (ax != 0) ax *= 1 / fabs(vx);
+ }
+
+ physic.set_velocity(vx, vy);
+ physic.set_acceleration(ax, ay);
+}