Hardware Reference
In-Depth Information
Listing 11-4. moveTone() Sound Functions for Stack It, Part 1 of 3
void moveTone() {
if (moveToneflag) {
if (movetonecount >= 2) {
GD.voice(0, 0, movetonecount*1000,127,127);
}
if (movetonecount == 5){
GD.voice(0, 0, 0,0,0);
movetonecount = 0 ;
}
movetonecount++;
} // end if moveToneflag
} // end moveTone
Listing 11-4 part 2 is the WinTone() sound function, and is used to signify the final win. WinTone() plays six tones
(750 Hz, 1000 Hz, 1250 HZ, 1000 Hz, 750 Hz, and 500 Hz) twice in a row to give the player a pleasant audio reward for
completion. The function should be called from the IncreaseLevel() function just after the call to dispaySprites()
within the if statement used to roll the game back to the first level when the player surpasses the game limits.
Listing 11-4. moveTone() Sound Functions for Stack It, Part 2 of 3
void WinTone() {
for (int t =0 ; t < 2 ; t ++) {
for(int i = 3 ; i < 5 ; i++) {
GD.voice(0, 0, i*1000, 254, 254);
delay (150);
}
for(int i = 5 ; i > 1 ; i--) {
GD.voice(0, 0, i*1000,254,254);;
delay (150);
}
GD.voice(0, 0, 0,0,0);
} // end for loop that plays the tone twice
} // end WinTone
In part 3, the third sound function, LossTone() , creates a sound that plays four notes in descending frequency:
1250 HZ, 1000 Hz, 750 Hz, and 500 Hz. This tone is only played once—when the player has missed the last sprite
available. This function needs to be called from the checkWin() function inside the if statement that checking for a
win before the play resets back to the first level.
Listing 11-4. moveTone() Sound Functions for Stack It, Part 3 of 3
void LossTone() {
for(int i = 5 ; i > 1 ; i--) {
GD.voice(0, 0, i*500, 254, 254);
delay (150);
}
GD.voice(0, 0, 0, 0, 0);
} // end loss tone
 
Search WWH ::




Custom Search