Пример #1
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int centerX = getWidth() / 2;
    int centerY = getHeight() / 2;

    Graphics2D g2d = (Graphics2D) g.create();

    g2d.translate(centerX, centerY); // Set Graphics2D transform origin to center of panel

    g2d.setColor(fgColor);
    bar.setFrame(-barWidth / 2, -barHeight / 2 + barHeight * barPosition, barWidth, barHeight);
    g2d.fill(bar);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    for (Spike spike : spikes) {
      if (spike != null) {
        double opacity = 255;
        if (spike.getDirection() == 0) {
          opacity = getWidth() * 0.5 - 70 - spike.getPosition().getX();
        } else {
          opacity = spike.getPosition().getX() + getWidth() * 0.5 - 70;
        }
        g2d.setColor(new Color(0, 0, 0, (int) clamp(opacity * 10, 0, 255)));
        g2d.fill(spike);
      }
    }
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2d.setColor(Color.BLACK);
    g2d.draw(barCross);
    g2d.setStroke(new BasicStroke(2));
    g2d.draw(barFrame);
    g2d.dispose();
  }
Пример #2
0
 public boolean gameOver() {
   for (Spike spike : spikes) {
     if (spike != null && spike.intersects(bar)) {
       System.out.println("Game Over - Dodge");
       return true;
     }
   }
   return false;
 }
Пример #3
0
 public void k() {
   fgColor = new Color(48, 48, 48);
   bgColor = new Color(193, 193, 193);
   setBackground(bgColor);
   for (Spike s : spikes) {
     if (s != null) {
       s.k();
     }
   }
 }