Skip to content

Commit

Permalink
feat(sound effects): buttons, correct alternative, win, lost sound ef…
Browse files Browse the repository at this point in the history
…fects added and working. Also configuration of music and sound working as intended
  • Loading branch information
jcrucesdeveloper committed Mar 5, 2023
1 parent 4f1ecf8 commit 8221eb9
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 37 deletions.
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

8 changes: 4 additions & 4 deletions app/src/main/assets/metro_santiago.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@
<station>Cerrillos</station>
</line>
<line name="TEST" color="#A53CEB">
<station>Los Leones</station>
<station>Cerrillos</station>
<station>Cerrillos</station>
<station>Cerrillos</station>
<station>station 1</station>
<station>station 2</station>
<station>station 3</station>
<station>station 4</station>
</line>

</metro>
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ protected void onStop() {
}

public void goToLinesMenuActivity(View view) {
// Sound Effect
MediaPlayerReproducer.getInstance().reproduceClickSound(this);

Intent intent = new Intent(this, MenuMetroActivity.class);
startActivity(intent);
}
Expand All @@ -62,6 +65,8 @@ public void goToMetroInfoActivity(View view) {
}

public void showConfigurationDialog(View view) {
// Sound Effect
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
// Show dialog
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.configuration_dialog);
Expand All @@ -80,22 +85,34 @@ public void showConfigurationDialog(View view) {


switchSoundConfiguration.setOnClickListener(switchSound -> {
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
MediaPlayerReproducer.getInstance().changeAudioReproducing();
});

switchMusicConfiguration.setOnClickListener(switchSound -> {
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
MediaPlayerReproducer.getInstance().changeMusicReproducing();
// Stop Music
if (MediaPlayerReproducer.getInstance().getMusicBoolean()) {
BackgroundMusic.onStart(this);
} else {
BackgroundMusic.forceStop();

}
});

// ImageView
ImageView goBackImageView = (ImageView) dialog.findViewById(R.id.goBackButtonConfiguration);
goBackImageView.setOnClickListener(imageView -> {
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
dialog.dismiss();
});
dialog.show();
}

public void showConfirmationResetDialog(View view) {
// Sound Effect
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
// Show dialog
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.confirmation_reset_dialog);
Expand All @@ -108,10 +125,12 @@ public void showConfirmationResetDialog(View view) {


buttonGoBack.setOnClickListener(button -> {
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
dialog.dismiss();
});

buttonResetSharedPreferences.setOnClickListener(button -> {
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
this.resetSharedPreferences();
dialog.dismiss();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.jorgecruces.metrometro.model.Metro;
import com.jorgecruces.metrometro.model.MetroMenu;
import com.jorgecruces.metrometro.sound.BackgroundMusic;
import com.jorgecruces.metrometro.sound.MediaPlayerReproducer;

import java.util.ArrayList;

Expand All @@ -47,7 +48,6 @@ protected void onStart() {
BackgroundMusic.onStart(this);
}


@Override
protected void onStop() {
super.onStop();
Expand Down Expand Up @@ -93,13 +93,19 @@ private boolean getLevelStarSharedPreferences(String lineName) {
}

public void goToMainActivity(View view) {
// Sound Effect
MediaPlayerReproducer.getInstance().reproduceClickSound(this);

Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}

@Override
public void onBackPressed() {
super.onBackPressed();
// Sound Effect
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
this.goToMainActivity(null);

super.onBackPressed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.jorgecruces.metrometro.R;
import com.jorgecruces.metrometro.model.MetroMenu;
import com.jorgecruces.metrometro.sound.MediaPlayerReproducer;

import java.util.ArrayList;

Expand Down Expand Up @@ -51,6 +52,7 @@ public void onBindViewHolder(@NonNull MenuMetroRecyclerViewAdapter.MyViewHolder
holder.lineaMetroName.setText(lineName);
holder.backgroundMetroMenu.setColorFilter(color);
holder.constraintLayoutContainer.setOnClickListener(view -> {
MediaPlayerReproducer.getInstance().reproduceClickSound(this.context.getApplicationContext());
Intent intent = new Intent(this.context.getApplicationContext(), PlayGameActivity.class);
intent.putExtra("LINEA", lineName);
this.context.startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.jorgecruces.metrometro.R;
import com.jorgecruces.metrometro.customViews.ZoomableImageView;
import com.jorgecruces.metrometro.sound.BackgroundMusic;
import com.jorgecruces.metrometro.sound.MediaPlayerReproducer;

public class MetroInformationActivity extends AppCompatActivity {

Expand Down Expand Up @@ -39,6 +40,9 @@ protected void onStop() {
}

public void goToMainActivity(View view) {
// Sound Effect
MediaPlayerReproducer.getInstance().reproduceClickSound(this);

Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class PlayGameActivity extends AppCompatActivity {
private ArrayList<StationView> stationViews;

// Music
private MediaPlayer mediaPlayer;
private MediaPlayer mediaPlayerMusicGameplay;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -96,15 +96,15 @@ private void drawStationView(float marginStart, String stationName, String color

private void reproduceMusic() {
if (MediaPlayerReproducer.getInstance().getMusicBoolean()) {
this.mediaPlayer = MediaPlayer.create(this, R.raw.music_gameplay_loop);
this.mediaPlayer.setLooping(true);
this.mediaPlayer.start();
this.mediaPlayerMusicGameplay = MediaPlayer.create(this, R.raw.music_gameplay_loop);
this.mediaPlayerMusicGameplay.setLooping(true);
this.mediaPlayerMusicGameplay.start();
}
}

private void stopMusic() {
if (this.mediaPlayer != null) {
this.mediaPlayer.stop();
if (this.mediaPlayerMusicGameplay != null) {
this.mediaPlayerMusicGameplay.stop();
}
}

Expand Down Expand Up @@ -291,6 +291,8 @@ private void checkAlternative(String alternativeString) {
}

private void onCorrectAlternative() {
// Reproduce Correct alternative sound
MediaPlayerReproducer.getInstance().reproduceCorrectAlternativeSound(this);
this.position = this.position + 1;
if (this.position < (this.stations.size() - 1)) {
this.setCurrentStationQuestion(this.position);
Expand All @@ -300,6 +302,9 @@ private void onCorrectAlternative() {
}

public void onWinLevel() {
this.mediaPlayerMusicGameplay.stop();
// Reproduce win sound
MediaPlayerReproducer.getInstance().reproduceSoundWinLevel(this);
this.updateProgressInfo();
this.showWinningDialog();
}
Expand Down Expand Up @@ -352,6 +357,10 @@ private void onIncorrectAlternative() {
}

private void onLostLevel() {
// Stop Gameplay Music
this.mediaPlayerMusicGameplay.stop();
MediaPlayerReproducer.getInstance().reproduceLostSound(this);

// TODO - Ads
Dialog lostDialog = new Dialog(this);
lostDialog.setCancelable(false);
Expand All @@ -361,13 +370,15 @@ private void onLostLevel() {
ImageView resetLevelImageView = (ImageView) lostDialog.findViewById(R.id.imageViewResetLevel);

resetLevelImageView.setOnClickListener(listener-> {
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
this.resetLevel();
});

lostDialog.show();
}

public void goBackToMenu(View view) {
MediaPlayerReproducer.getInstance().reproduceClickSound(this);
Intent intent = new Intent(this, MenuMetroActivity.class);
startActivity(intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ public abstract class BackgroundMusic {
private static int startCounter = 0;

public static void onStart(Context context) {
if (!MediaPlayerReproducer.getInstance().getMusicBoolean()) {
return;
}
startCounter++;
Log.d("COUNTER START",Integer.toString(startCounter));
if (startCounter == 1) {
mediaPlayer = MediaPlayer.create(context,R.raw.music_menu_loop);
mediaPlayer.setLooping(true);
Expand All @@ -22,11 +24,19 @@ public static void onStart(Context context) {
}

public static void onStop(Context context) {
if (!MediaPlayerReproducer.getInstance().getMusicBoolean()) {
return;
}
startCounter--;
Log.d("COUNTER STOP",Integer.toString(startCounter));
if (startCounter == 0) {
mediaPlayer.stop();
mediaPlayer.release();
}
}

public static void forceStop() {
startCounter = 0;
mediaPlayer.stop();
mediaPlayer.release();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,31 @@ public boolean getMusicBoolean() {
*/
public void reproduceClickSound(Context context)
{
reproduceSound(context, R.raw.click);
reproduceSound(context, R.raw.sound_click_all);
}

public void reproduceLostSound(Context context) {
reproduceSound(context, R.raw.sound_lost);
}

public void reproduceCorrectAlternativeSound(Context context) {
reproduceSound(context, R.raw.sound_correct_alternative);
}

public void reproduceSoundWinLevel(Context context) {
reproduceSound(context, R.raw.sound_win);

}


/**
* Reproduce Win Sound
* @param context activity
*/
public void reproduceWinSound(Context context)
{
reproduceSound(context, R.raw.win_sound);
}
// public void reproduceWinSound(Context context)
// {
// reproduceSound(context, R.raw.win_sound);
// }

public void reproduceMusicMainMenu(Context context) {
if (!isMusicOn || isMusicReproducing) {return;}
Expand All @@ -81,7 +95,6 @@ public void stopMusicMainMenu(Context context) {
if (isMusicReproducing && musicIntent != null) {

//Stop music

isMusicReproducing = false;
}
}
Expand Down
Binary file removed app/src/main/res/raw/click.mp3
Binary file not shown.
Binary file added app/src/main/res/raw/sound_click_all.wav
Binary file not shown.
Binary file not shown.
Binary file added app/src/main/res/raw/sound_lost.wav
Binary file not shown.
Binary file added app/src/main/res/raw/sound_win.wav
Binary file not shown.
Binary file removed app/src/main/res/raw/win_sound.mp3
Binary file not shown.

0 comments on commit 8221eb9

Please sign in to comment.