Skip to content

Commit c6fd12d

Browse files
committed
Fix pony speed after toggling small-ponies option.
Also changed diagonal speed to the configured speed (from *1.41 as it was implemented in Desktop Ponies)
1 parent c75d47d commit c6fd12d

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

src/behavior.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ Behavior::Behavior(Pony* parent, const QString filepath, const std::vector<QVari
122122
duration_min = options[4].toFloat();
123123
speed = options[5].toFloat();
124124

125-
if(ConfigWindow::getSetting<bool>("general/small-ponies")){
126-
speed /= 2.0;
127-
// FIXME: when unchecking small-ponies, the speed is still halved. Move this to update.
128-
}
129125
animation_right = options[6].toString();
130126
animation_left = options[7].toString();
131127

@@ -427,6 +423,13 @@ void Behavior::update()
427423

428424
QRect screen = QApplication::desktop()->availableGeometry(parent);
429425

426+
float real_speed = speed;
427+
428+
// Change speed if the pony is small
429+
if(ConfigWindow::getSetting<bool>("general/small-ponies")){
430+
real_speed *= .5f;
431+
}
432+
430433
// If we are moving to a destanation point, calculate direction and move there
431434
if(state == State::Following || state == State::MovingToPoint) {
432435
// Check if we are close enough to destanation point
@@ -480,17 +483,17 @@ void Behavior::update()
480483
// Move only if we are within the screen boundaries
481484
// Else we may go offscreen when two ponies are following each other
482485
if((parent->x() >= screen.left()) && (dir_x < 0)) {
483-
parent->x_pos += dir_x * speed;
486+
parent->x_pos += dir_x * real_speed;
484487
}
485488
if((parent->x() <= screen.right() - width) && (dir_x > 0)) {
486-
parent->x_pos += dir_x * speed;
489+
parent->x_pos += dir_x * real_speed;
487490
}
488491

489492
if((parent->y() >= screen.top()) && (dir_y < 0)){
490-
parent->y_pos += dir_y * speed;
493+
parent->y_pos += dir_y * real_speed;
491494
}
492495
if((parent->y() <= screen.bottom() - height) && (dir_y > 0)){
493-
parent->y_pos += dir_y * speed;
496+
parent->y_pos += dir_y * real_speed;
494497
}
495498

496499
parent->move(parent->x_pos-x_center,parent->y_pos-y_center);
@@ -520,8 +523,8 @@ void Behavior::update()
520523
}
521524

522525
// Calculate the velocity
523-
float vel_x = direction_h * speed;
524-
float vel_y = direction_v * speed;
526+
float vel_x = direction_h * real_speed;
527+
float vel_y = direction_v * real_speed;
525528

526529
// Update posiotion depending on movement type
527530
if(movement == Movement::Horizontal){
@@ -531,8 +534,8 @@ void Behavior::update()
531534
parent->y_pos += vel_y;
532535
}
533536
if(movement == Movement::Diagonal){
534-
vel_x = std::sqrt(speed*speed*2) * std::cos(angle);
535-
vel_y = -std::sqrt(speed*speed*2) * std::sin(angle);
537+
vel_x = real_speed * std::cos(angle);
538+
vel_y = -real_speed * std::sin(angle);
536539
parent->x_pos += vel_x;
537540
parent->y_pos += vel_y;
538541
}

0 commit comments

Comments
 (0)