From 1a8e68e0b68fd70401acbbf92eb78531d1c3023c Mon Sep 17 00:00:00 2001 From: Crizomb Date: Sun, 15 Jun 2025 00:53:36 +0200 Subject: [PATCH] TilePattern lisible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dézo antoine mais tes 7 niveaux d'identation + tes if else partout c'est interdit par la convention de geneve --- SimpleGame/src/Source/TilePattern.cpp | 67 +++++++++------------------ 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/SimpleGame/src/Source/TilePattern.cpp b/SimpleGame/src/Source/TilePattern.cpp index f989fea..2b773cb 100644 --- a/SimpleGame/src/Source/TilePattern.cpp +++ b/SimpleGame/src/Source/TilePattern.cpp @@ -2,61 +2,36 @@ #include "AudioEmitter.hpp" #include "NoteSprite.hpp" #include "NoteTile.hpp" +#include #include #include +NotePlaceEnum getNotePlacement(int index, int notePitch, int prevPitch, + NotePlaceEnum prevPlacement) { + if (index == 0) + return Middle; + + int diff_pitch = notePitch - prevPitch; + int sign_with_zero = (diff_pitch > 0) - (diff_pitch < 0); + int prevPlacementInt = prevPlacement; + int newPlacementInt = std::clamp(prevPlacementInt + sign_with_zero, 0, 2); + + return static_cast(newPlacementInt); +} + void generateTilePattern(std::vector> new_notes, const AudioEmitter &audio_emitter) { int i = -1; float beatDuration = 60.f / audio_emitter.tempo; int previous_note_pitch = 0; - NotePlaceEnum previous_note_placement = static_cast(0); + NotePlaceEnum previous_note_placement = static_cast(1); for (auto note : new_notes) { - i++; - float start_time = note.first; - NotePlaceEnum notePlace = static_cast(i % 3); - if (i == 0) { - notePlace = static_cast(rand()%3); - } - else { - if (note.second == previous_note_pitch) { - notePlace = previous_note_placement; - } - else if (note.second < previous_note_pitch) { - if (previous_note_placement == Left) { - notePlace = Left; - } - else if (previous_note_placement == Middle) { - notePlace = Left; - } - else { - if (rand() % 2 == 0) { - notePlace = Left; - } - else { - notePlace = Middle; - } - } - } - else { - if (previous_note_placement == Right) { - notePlace = Right; - } - else if (previous_note_placement == Middle) { - notePlace = Right; - } - else { - if (rand() % 2 == 0) { - notePlace = Right; - } - else { - notePlace = Middle; - } - } - } - } - previous_note_pitch = note.second; + + NotePlaceEnum notePlace = getNotePlacement( + i, note.second, previous_note_pitch, previous_note_placement); previous_note_placement = notePlace; - NoteTile::create(start_time, beatDuration, notePlace, audio_emitter.getTime()); + previous_note_pitch = note.second; + NoteTile::create(note.first, beatDuration, notePlace, + audio_emitter.getTime()); } }