Skip to content

Commit

Permalink
feat(beat_guideline): adjust color and use two colors for guideline
Browse files Browse the repository at this point in the history
  • Loading branch information
LiteHell committed Jun 9, 2024
1 parent cd31b91 commit 7ebac75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion game/src/game/game_player/chart_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ impl ChartPlayer<'_> {
let length_ratio = timing_of_one_beat * speed_ratio;
let length = *length_ratio.numer() as f64 / *length_ratio.denom() as f64;

let even_beat =
((*timing_of_one_beat.denom() * tick as i64) / *timing_of_one_beat.numer()) % 2 == 0;

let position = {
//position_ratio = tick % timing_of_one_beat as i128;
let mut position_ratio = Rational64::new(
Expand All @@ -188,7 +191,11 @@ impl ChartPlayer<'_> {
*position_ratio.numer() as f64 / *position_ratio.denom() as f64
};

Some(BeatGuideline { length, position })
Some(BeatGuideline {
length,
position,
even_beat,
})
}

pub fn draw(
Expand Down
14 changes: 12 additions & 2 deletions game/src/game/game_player/chart_player_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use super::timing_judge::NoteAccuracy;
pub struct BeatGuideline {
pub position: f64,
pub length: f64,
pub even_beat: bool,
}

pub struct ChartPlayerUI<'a> {
Expand Down Expand Up @@ -230,9 +231,17 @@ impl ChartPlayerUI<'_> {
while position < 0.0 {
position += beat_guideline.length;
}
let thickness: u32 = 2;
let thicknesses: [u32; 2] = [4, 4];
let mut white = beat_guideline.even_beat;
loop {
let distance_between_centers = (position * note_width_max as f64) as i32;
let thickness = thicknesses[if white { 0 } else { 1 }];
let color = if white {
Color::RGBA(255, 255, 255, 60)
} else {
Color::RGBA(255, 255, 255, 30)
};

if distance_between_centers
> (background_width + (judgement_line_width + thickness) / 2) as i32
{
Expand All @@ -245,7 +254,7 @@ impl ChartPlayerUI<'_> {
+ distance_between_centers
+ (judgement_line_width / 2 - thickness / 2) as i32,
] {
canvas.set_draw_color(Color::RGBA(255, 255, 255, 220));
canvas.set_draw_color(color);
canvas
.fill_rect(Rect::new(
line_x,
Expand All @@ -257,6 +266,7 @@ impl ChartPlayerUI<'_> {
}

position += beat_guideline.length;
white = !white;
}
}

Expand Down

0 comments on commit 7ebac75

Please sign in to comment.