void step_coinrun()

in coinrun/coinrun.cpp [1290:1361]


  void step_coinrun(int game_type)
  {
    support = false;

    int near_x = int(x + .5);
    char test_is_ladder1 = maze->get_elem(near_x, int(y + 0.2));
    char test_is_ladder2 = maze->get_elem(near_x, int(y - 0.2));

    if (test_is_ladder1 == LADDER || test_is_ladder2 == LADDER) {
      if (action_dy != 0)
        ladder_mode = true;
    } else {
      ladder_mode = false;
    }

    float max_jump = maze->max_jump;
    float max_speed = maze->max_speed;
    float mix_rate = maze->mix_rate;

    if (ladder_mode) {
      vx = (1-LADDER_MIXRATE)*vx + LADDER_MIXRATE*max_speed*(action_dx + 0.2*(near_x - x));
      vx = clip_abs(vx, LADDER_V);
      vy = (1-LADDER_MIXRATE)*vy + LADDER_MIXRATE*max_speed*action_dy;
      vy = clip_abs(vy, LADDER_V);

    } else if (spring > 0 && vy==0 && action_dy==0) {
      vy = max_jump;

      spring = 0;
      support = true;
    } else {
      vy -= maze->gravity;
    }

    vy = clip_abs(vy, max_jump);
    vx = clip_abs(vx, max_speed);

    int num_sub_steps = 2;
    float pct = 1.0 / num_sub_steps;

    for (int s = 0; s < num_sub_steps; s++) {
      sub_step(vx * pct, vy * pct);
      if (vx == 0 && vy == 0) {
        break;
      }
    }

    if (support) {
      if (action_dy > 0)
        spring += sign(action_dy) * max_jump/4; // four jump heights
      if (action_dy < 0)
        spring = -0.01;
      if (action_dy == 0 && spring < 0)
        spring = 0;

      spring = clip_abs(spring, max_jump);
      vx = (1-mix_rate)*vx;
      if (spring==0) vx += mix_rate*max_speed*action_dx;
      if (fabs(vx) < mix_rate*max_speed) vx = 0;

    } else {
      spring = 0;
      float ac = maze->air_control;
      vx = (1-ac*mix_rate)*vx + ac*mix_rate*action_dx;
    }

    if (vx < 0) {
      is_facing_right = false;
    } else if (vx > 0) {
      is_facing_right = true;
    }
  }