コード例 #1
0
ファイル: movement.cpp プロジェクト: tryzombie501/anaconda
void Movement::move(double x, double y)
{
    add_x += x;
    add_y += y;
    double xx = floor(add_x);
    double yy = floor(add_y);
    add_x -= xx;
    add_y -= yy;
    old_x = instance->x;
    old_y = instance->y;
    instance->set_position(instance->x + xx,
                           instance->y + yy);
    clear_collisions();
}
コード例 #2
0
ファイル: movement.cpp プロジェクト: joaormatos/anaconda
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);
}