codigo para hacer flappy bird en java

11 2 0
                                    

import javax.swing.; import java.awt.; import java.awt.event.*;

public class FlappyBird extends JFrame implements ActionListener, MouseListener {

private Timer timer;

private int x, y, speed, score;

private Image bird, bg, pipe;

private boolean isRunning;


public FlappyBird() { 

          setTitle("Flappy Bird"); 

          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

          setSize(600, 800); 

         setLocationRelativeTo(null); 

         setResizable(false); 


         bird = new ImageIcon(getClass().getResource("bird.png")).getImage(); 

         bg = new ImageIcon(getClass().getResource("bg.png")).getImage(); 

         pipe = new ImageIcon(getClass().getResource("pipe.png")).getImage(); 


         x = 100; 

         y = 300; 

         speed = 0; 

         score = 0; 

         isRunning = true; 


        addMouseListener(this); 


        timer = new Timer(10, this); 

       timer.start(); 


       setVisible(true);

}


public void paint(Graphics g) { 

          g.drawImage(bg, 0, 0, null); 

         g.drawImage(bird, x, y, null); 

         g.drawImage(pipe, 400, 0, null); 

         g.drawImage(pipe, 400, 600, null); 

         g.setColor(Color.WHITE); 

         g.setFont(new Font("Arial", Font.BOLD, 20)); 

         g.drawString("Score: " + score, 10, 30);

}


public void actionPerformed(ActionEvent e) { 

          if (isRunning) { 

               y += speed; 

               speed += 1; 

               score++; 


               if (y > 550) { 

                    isRunning = false; 

               } 

       } 

         repaint();

}

public void mousePressed(MouseEvent e) { 

        speed = -15;

}


public void mouseClicked(MouseEvent e) {}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

public void mouseReleased(MouseEvent e) {}


public static void main(String[] args) { 

            new FlappyBird();

     }

}  

Copypastas bien culeros 2Donde viven las historias. Descúbrelo ahora