Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created June 8, 2021 02:12
Show Gist options
  • Save codeforfun-jp/20523b620bb72555a9c33988042ed578 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/20523b620bb72555a9c33988042ed578 to your computer and use it in GitHub Desktop.
CTB 6-8
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;
}
// Pink
float pinkCenterX = pinkX + pink.getWidth() / 2;
float pinkCenterY = pinkY + pink.getHeight() / 2;
if (hitStatus(pinkCenterX, pinkCenterY)) {
pinkX = -10.0f;
score += 30;
}
// 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;
}
// 結果画面へ
}
}
public boolean hitStatus(float centerX, float centerY) {
return (0 <= centerX && centerX <= boxSize &&
boxY <= centerY && centerY <= boxY + boxSize) ? true : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment