Created
January 27, 2016 19:05
-
-
Save Felipe00/f5612e832a2c13108201 to your computer and use it in GitHub Desktop.
Dúvida sobre colisão no jogo Jumper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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