コード例 #1
0
ファイル: Enviroment.java プロジェクト: BuyouT/COP3502
 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;
   }
 }
コード例 #2
0
  public void keyPressed(KeyEvent ke) {

    if (ke.getKeyCode() == KeyEvent.VK_SPACE) {

      bird.setTime(0, height);
    } // end if
  } // end AP
コード例 #3
0
  public void paint(Graphics g) {
    super.paint(g);
    g.setFont(fotn);
    Random generator1 = new Random();
    height = bird.getBirdy();

    g.drawImage(Backgroundtop, 0, 0, 450, 644, null);
    g.drawImage(Bird, 100, height, 40, 30, null);

    if (firstrun == true) { // intiate threads
      pipethread[currentthreads].start();
      birdthread.start();
      firstrun = false;
    }

    for (int index = 0; index <= currentthreads; index++) {
      g.drawImage(Pipes, pipeob[index].getpipex(), pipeob[index].getpipey(), null);
    }

    g.drawImage(Backgroundbottom, 0, 644, 450, 156, null);

    g.setColor(Color.black);

    if (pipeob[currentthreads].getpipex() <= 550) {
      currentthreads++;
      pipethread[currentthreads].start();
      score++;
    }
    g.drawString("Score: " + score + "", 50, 50);

    for (int index = 0; index < currentthreads; index++) {
      if (((height < pipeob[index].getpipey() + 730) || (height > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 100) && (pipeob[index].getpipex() + 72 > 100))
          || ((height < pipeob[index].getpipey() + 730)
                  || (height > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 140) && (pipeob[index].getpipex() + 72 > 140))
          || ((height + 30 < pipeob[index].getpipey() + 730)
                  || (height + 30 > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 100) && (pipeob[index].getpipex() + 72 > 100))
          || ((height + 30 < pipeob[index].getpipey() + 730)
                  || (height + 30 > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 140) && (pipeob[index].getpipex() + 72 > 140))
          || ((height + 30 >= 644))) {
        g.drawImage(gameover, 125, 200, null);
        JOptionPane.showMessageDialog(
            null, "You Dead. \n you scored " + score, "Oh no!", JOptionPane.INFORMATION_MESSAGE);
      }
    }
    for (int counter = 0; counter <= 50000000; counter++) {
      counter++;
      counter--;
    }
    do {
      repaint();
    } while (replay = true);
  }
コード例 #4
0
ファイル: Enviroment.java プロジェクト: BuyouT/COP3502
 @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);
   }
 }