hi
So i made a simple game app, and am implementing music now
i have easy and hard mode, and game over, as well as home screen
homesecreen now plays music1, loops fine and all...then once player selects to play i want to stop the current music1, and start music 2 in easy mode, or if they selcted hard mode, i want music3 to play. and when its gameover screen, the music should stop then play music 4 for gameover screen.
here is the code for the homescreen activity
import android.content.Intent;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.animation.BounceInterpolator;
import android.widget.Button;
import android.widget.ImageView;
public class HomeScreenActivity extends MainGameActivity implements View.OnClickListener {
private Button playEasyModeButton, playHardModeButton, play_pause_musicButton;
private ImageView logoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_screen_layout);
playEasyModeButton = (Button) findViewById(R.id.playEasyMode_Button);
playHardModeButton = (Button) findViewById(R.id.playHardMode_Button);
logoView = (ImageView) findViewById(R.id.logo);
play_pause_musicButton = (Button) findViewById(R.id.musicButton);
final MediaPlayer music = MediaPlayer.create(HomeScreenActivity.this, R.raw.goldensun_rises);
music.setLooping(true);
music.seekTo(0);
music.start();
play_pause_musicButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (music.isPlaying())
{
music.pause();
play_pause_musicButton.setBackgroundResource(R.drawable.music_on);
}
else {
music.start();
play_pause_musicButton.setBackgroundResource(R.drawable.music_off);
}
}
});
}
@Override
protected void setColorsOnButtons() {
}
@Override
protected void calculatePoints(View view) {
}
public void playEasyMode(View view) {
startActivity(new Intent(this, EasyModeActivity.class));
}
public void playHardMode(View view) {
startActivity(new Intent(this, HardModeActivity.class));
}
@Override
public void onClick(View view) {
}
}
here is code for next activity (easymode activity)
public class EasyModeActivity extends MainGameActivity{
private Button leftButton, rightButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.easy_mode_layout);
setupProgressView();
pointIncrement = 2;
timerIncrement = 2;
leftButton = (Button) findViewById(R.id.left_button);
rightButton = (Button) findViewById(R.id.right_button);
leftButton.setOnClickListener(this);
rightButton.setOnClickListener(this);
resetGame();
setupGameLoop();
startGame();
}
@Override
public void onClick(View view) {
if (!startGame) return;
calculatePoints(view);
setColorsOnButtons();
}
protected void setColorsOnButtons() {
int color = Color.parseColor(Random_Color.getRandomColor());
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
int alpha1, alpha2;
if (Math.random() > 0.5) {
alpha1 = 255;
alpha2 = 185;
} else {
alpha1 = 185;
alpha2 = 255;
}
leftButton.setBackgroundColor(Color.argb(alpha1, red, green, blue));
rightButton.setBackgroundColor(Color.argb(alpha2, red, green, blue));
}
protected void calculatePoints(View clickedView) {
View unclickedView = clickedView == leftButton ? rightButton : leftButton;
ColorDrawable clickedColor = (ColorDrawable) clickedView.getBackground();
ColorDrawable unClickedColor = (ColorDrawable) unclickedView.getBackground();
int alpha1 = Color.alpha(clickedColor.getColor());
int alpha2 = Color.alpha(unClickedColor.getColor());
// correct color tap
if (alpha1 < alpha2) {
updatePoints();
} else { // incorrect color tap
endGame();
}
}
}