Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created June 10, 2021 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/ca729fd262362245f5469f15a4df1cab to your computer and use it in GitHub Desktop.
Save codeforfun-jp/ca729fd262362245f5469f15a4df1cab to your computer and use it in GitHub Desktop.
CTB 11-4
public void hitCheck() {
// Orange
float orangeCenterX = orangeX + orange.getWidth() / 2;
float orangeCenterY = orangeY + orange.getHeight() / 2;
if (hitStatus(orangeCenterX, orangeCenterY)) {
orangeX = -10.0f;
score += 10;
soundPlayer.playHitSound();
}
// Pink
float pinkCenterX = pinkX + pink.getWidth() / 2;
float pinkCenterY = pinkY + pink.getHeight() / 2;
if (hitStatus(pinkCenterX, pinkCenterY)) {
pinkX = -10.0f;
score += 30;
soundPlayer.playHitSound();
}
// Black
float blackCenterX = blackX + black.getWidth() / 2;
float blackCenterY = blackY + black.getHeight() / 2;
if (hitStatus(blackCenterX, blackCenterY)) {
// Game Over!
if (timer != null) {
timer.cancel();
timer = null;
soundPlayer.playOverSound();
}
// 結果画面へ
Intent intent = new Intent(getApplicationContext(), ResultActivity.class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment