Skip to content

Commit

Permalink
fix clouds speed if paused or speed higher than 100
Browse files Browse the repository at this point in the history
  • Loading branch information
dvincent56 committed Feb 10, 2024
1 parent 38944cb commit baaadda
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/graphics/clouds.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "core/random.h"
#include "core/speed.h"
#include "game/settings.h"
#include "game/state.h"
#include "graphics/renderer.h"

#include <math.h>
Expand Down Expand Up @@ -270,14 +271,22 @@ void clouds_draw(int x_offset, int y_offset, int x_limit, int y_limit, float bas
cloud->status = STATUS_INACTIVE;
continue;
}
speed_set_target(&cloud->speed.x, -CLOUD_SPEED, SPEED_CHANGE_IMMEDIATE, 1);
speed_set_target(&cloud->speed.y, CLOUD_SPEED / 2, SPEED_CHANGE_IMMEDIATE, 1);

double cloudSpeed = 0;

if (!game_state_is_paused()) {
double speedShift = (100 - setting_game_speed()) / 100;
cloudSpeed = CLOUD_SPEED - speedShift;
}

speed_set_target(&cloud->speed.x, -cloudSpeed, SPEED_CHANGE_IMMEDIATE, 1);
speed_set_target(&cloud->speed.y, cloudSpeed / 2, SPEED_CHANGE_IMMEDIATE, 1);

graphics_renderer()->draw_image_advanced(&cloud->img,
(cloud->x - x_offset) / base_scale, (cloud->y - y_offset) / base_scale, COLOR_MASK_NONE,
cloud->scale_x * base_scale, cloud->scale_y * base_scale, cloud->angle, 1);

cloud->x += speed_get_delta(&cloud->speed.x) * (setting_game_speed() / 10);
cloud->y += speed_get_delta(&cloud->speed.y) * (setting_game_speed() / 10);
cloud->x += speed_get_delta(&cloud->speed.x);
cloud->y += speed_get_delta(&cloud->speed.y);
}
}

0 comments on commit baaadda

Please sign in to comment.