Skip to content

Instantly share code, notes, and snippets.

@Felipe00
Created January 27, 2016 19:05
Show Gist options
  • Select an option

  • Save Felipe00/f5612e832a2c13108201 to your computer and use it in GitHub Desktop.

Select an option

Save Felipe00/f5612e832a2c13108201 to your computer and use it in GitHub Desktop.
Dúvida sobre colisão no jogo Jumper.
@Override
public void run() {
while (isRunning) {
// Verifica se o holder está pronto para receber os elementos (Desenhos).
if (holder.getSurface().isValid()) {
Canvas canvas = holder.lockCanvas();
// Desenhar o jogo aqui
canvas.drawBitmap(background, 0, 0, null);
bird.drawIn(canvas);
bird.dropBird();
tubes.drawIn(canvas);
tubes.move();
//A colisão vai aqui?
if (new Collision(bird, tubes).hasCollision()) {
new GameOver(screen).drawIn(canvas);
isRunning = false;
}
scoreGame.drawIn(canvas);
holder.unlockCanvasAndPost(canvas);
}
}
}
public boolean hasHorizontalCollisionWith(Bird bird) {
return this.position - bird.X < bird.RADIUS;
}
public boolean hasVerticalCollisionWith(Bird bird) {
return bird.getHeight() - bird.RADIUS < this.superiorTubeHeight
|| bird.getHeight() + bird.RADIUS > this.lowerTubeHeight;
}
public boolean hasCollisionWith(Bird bird) {
for (Tube tube : tubes) {
if (tube.hasHorizontalCollisionWith(bird)
&& tube.hasVerticalCollisionWith(bird)) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment