Variable sound duration
This commit is contained in:
parent
1a524b1a1b
commit
e7cbf8bed1
@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -212,6 +213,7 @@ public:
|
||||
float screen_height = 0.0f;
|
||||
Sound note_sounds[MAX_INSTRUMENT_TYPES][LANE_COUNT * OCTAVE_COUNT] = {{0}};
|
||||
bool note_sounds_loaded[MAX_INSTRUMENT_TYPES][LANE_COUNT * OCTAVE_COUNT] = {{false}};
|
||||
std::deque<Sound> note_sounds_playing[LANE_COUNT][MAX_INSTRUMENT_TYPES];
|
||||
static constexpr float PRESS_FLASH_DURATION = 0.12f;
|
||||
static constexpr float MISS_FLASH_DURATION = 0.15f;
|
||||
float press_flash_timer[LANE_COUNT] = {0};
|
||||
@ -327,6 +329,25 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
void stop_playing_released_notes(int lane, float song_time)
|
||||
{
|
||||
for (int i = 0; i < MAX_GAMEPADS; i++)
|
||||
{
|
||||
if (IsGamepadAvailable(i) && IsGamepadButtonDown(i, GAMEPAD_BUTTONS[lane]))
|
||||
{
|
||||
printf("Gamepad %d held lane %d at time: %f\n", i, lane, song_time);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!note_sounds_playing[lane][i].empty())
|
||||
{
|
||||
printf("Stop sound at [%d][%d] at time: %f\n", lane, i, song_time);
|
||||
StopSound(note_sounds_playing[lane][i].front());
|
||||
note_sounds_playing[lane][i].pop_front();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool lane_pressed_by_instrument_owner(int lane, int instrument_slot) const
|
||||
{
|
||||
int physical_id = INSTRUMENT_PHYSICAL_GAMEPAD[instrument_slot];
|
||||
@ -370,7 +391,7 @@ public:
|
||||
return y >= upper_bar_y - HIT_ZONE_MARGIN && y <= hit_line_y + HIT_ZONE_MARGIN;
|
||||
}
|
||||
|
||||
void consume_note(Glyph* n)
|
||||
void consume_note(Glyph* n, float song_time)
|
||||
{
|
||||
auto it = std::find_if(spawned.begin(), spawned.end(), [n](Glyph* p) { return p == n; });
|
||||
if (it != spawned.end())
|
||||
@ -379,8 +400,12 @@ public:
|
||||
spawned.erase(it);
|
||||
completed_notes.insert(n);
|
||||
printf("note lane: %d, note octave: %d\n", n->lane, n->octave);
|
||||
if (note_sounds_loaded[n->instrument_slot][n->octave])
|
||||
PlaySound(note_sounds[n->instrument_slot][n->octave]);
|
||||
if (note_sounds_loaded[n->instrument_slot][n->octave]) {
|
||||
Sound sound = note_sounds[n->instrument_slot][n->octave];
|
||||
PlaySound(sound);
|
||||
printf("push playing sound to [%d][%d] at %f\n", n->lane, n->instrument_slot, song_time);
|
||||
note_sounds_playing[n->lane][n->instrument_slot].push_back(sound);
|
||||
}
|
||||
}
|
||||
combo++;
|
||||
score += 100 + std::min(combo * 10, 50);
|
||||
@ -482,6 +507,7 @@ public:
|
||||
{
|
||||
miss_flash_timer[lane] = 0.0f;
|
||||
}
|
||||
stop_playing_released_notes(lane, song_time);
|
||||
bool pressed = is_lane_pressed(lane);
|
||||
if (pressed)
|
||||
press_flash_timer[lane] = PRESS_FLASH_DURATION;
|
||||
@ -513,9 +539,9 @@ public:
|
||||
best = n;
|
||||
}
|
||||
}
|
||||
if (best != nullptr)
|
||||
if (best != nullptr && pressed)
|
||||
{
|
||||
consume_note(best);
|
||||
consume_note(best, song_time);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user