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();
}
}
ESTÁS LEYENDO
Copypastas bien culeros 2
Humor"Si Copypastas bien culeros es tan bueno... ¿Por qué no hay Copypastas bien culeros 2?" Aquí está, la secuela que nadie pidió y nadie necesitaba.