I want to play a gameplay music track depending on what the current level is.
E.g.
1 - Play track 1
2 - Play track 1
3 - Play track 2
4 - Play track 2
5 - Play track 3
repeat...
6 - Play track 1
7 - Play track 1
8 - Play track 2
9 - Play track 2
10 - Play track 3
This is what I have, but problem is track 2 will be used at level 6 when it should be track 1.
public static function playGameplayMusic(waveId:Int):Void
{
var gamePlayTrackId:Int;
if (waveId % 5 == 0) {
gamePlayTrackId = 3;
} else if (waveId % 3 == 0 || waveId % 4 == 0) {
gamePlayTrackId = 2;
} else {
gamePlayTrackId = 1;
}
trace('playing gameplay track: ' + gamePlayTrackId);
SoundPlayer.playMusicByName('gameplay/' + gamePlayTrackId, false);
}
Update:
Went with this. Thanks for all your contributions!
public static function playGameplayMusic(waveId:Int):Void
{
var gamePlayTrackId:Int = Math.ceil(((waveId - 1) % 5 + 1) / 2);
SoundPlayer.playMusicByName('gameplay/' + gamePlayTrackId, false);
}
%
does? \$\endgroup\$