void EightDirections::update(float dt) { if (max_speed == 0) return; bool on = false; int dir = get_joystick_direction(1); if (dir == 8) dir = instance->direction; else { on = true; dir *= 4; instance->set_direction(dir, false); } double mul = instance->frame->timer_mul; double change; if (on) change = get_accelerator(acceleration); else change = -get_accelerator(deceleration); set_speed(int_max(0, int_min(speed + change * mul, max_speed))); if (speed == 0) return; double add_x, add_y; get_dir(instance->direction, add_x, add_y); double m = get_pixels(speed) * mul; move(add_x * m, add_y * m); last_move = m; }
void BallMovement::update() { if (stop_speed != 0 || speed == 0) { instance->set_animation(STOPPED); return; } else instance->set_animation(WALKING); double add_x, add_y; get_dir(instance->direction, add_x, add_y); double m = get_pixels(speed) * instance->frame->timer_mul; if (speed > 100 && has_back_col) { double move_x = add_x * m; double move_y = add_y * m; int steps = 4; move_x /= steps; move_y /= steps; old_x = instance->x; old_y = instance->y; clear_collisions(); for (int i = 0; i < steps; ++i) { this->add_x += move_x; this->add_y += move_y; double xx = floor(this->add_x); double yy = floor(this->add_y); this->add_x -= xx; this->add_y -= yy; instance->set_position(instance->x + xx, instance->y + yy); if (instance->overlaps_background()) break; } } else { move(add_x * m, add_y * m); } if (deceleration != 0) speed_change -= get_accelerator(deceleration) * instance->frame->timer_mul; int change = (int)speed_change; speed_change -= change; speed = int_max(0, speed + change); }