Beispiel #1
0
 public void checkForHit() {
   if (topWall.getTopBounds().intersects(bird.getBounds())
       || bottomWall.getTopBounds().intersects(bird.getBounds())
       || topWall.getBottomBounds().intersects(bird.getBounds())
       || bottomWall.getBottomBounds().intersects(bird.getBounds())
       || bird.getBounds().intersects(new Rectangle2D.Double(0, 600, 800, 10))) {
     isDead = true;
   }
 }
Beispiel #2
0
 @Override
 public void paintComponent(Graphics g) {
   g.setColor(Color.WHITE);
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   if (isDead) {
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 30));
     g2.drawString("Game Over!", 300, 300);
     g2.drawString("Your final score was " + score, 250, 330);
     moverTimer.stop();
     scoreTimer.stop();
   } else {
     topWall.paint(g2);
     bottomWall.paint(g2);
     bird.paint(g2);
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 20));
     g2.drawString("Score: " + score, 50, 50);
   }
 }