Game Development Reference
In-Depth Information
Figure 15-19 . Create an empty .playAudioClip() method in the Bagel.java class and add a call to it inside of .update()
Inside of the playAudioClip() method body, we need to create conditional if() struc-
tures, similar to what we did for the sprite movement that we created in Chapter 12 .
We'll match KeyEvent handling (left, right, up, down, w, s) to audio files that speak
each of the keys (AudioClip objects iSound0 through iSound5) via an invinciBa-
gel.playiSound() object reference and method call inside of the conditional if() state-
ments, seen in Figure 15-20 , using this Java code:
private void playAudioClip() {
if(invinciBagel.isLeft()) {
invinciBagel.playiSound0(); }
if(invinciBagel.isRight())
{ invinciBagel.playiSound1(); }
if(invinciBagel.isUp())
{
invinciBagel.playiSound2(); }
if(invinciBagel.isDown()) {
invinciBagel.playiSound3(); }
if(invinciBagel.iswKey()) {
invinciBagel.playiSound4(); }
if(invinciBagel.issKey()) {
 
 
Search WWH ::




Custom Search