Starkdop

Flappy Bird - Épisode 1

Mar 25th, 2014
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package flappybird;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7.  
  8. import javax.swing.JFrame;
  9.  
  10. public class Game extends Canvas {
  11.  
  12.     public static final int HEIGHT = 400;
  13.     public static final int WIDTH = HEIGHT * 4 / 3;
  14.     public static final String NAME = "Flappy Bird";
  15.    
  16.     private JFrame frame;
  17.    
  18.     public Game() {
  19.         frame = new JFrame();
  20.        
  21.         // Configuration JFrame
  22.         Dimension dim = new Dimension(WIDTH, HEIGHT);
  23.         frame.setPreferredSize(dim.getSize());
  24.         frame.setMinimumSize(dim.getSize());
  25.         frame.setMaximumSize(dim.getSize());
  26.         frame.setTitle(NAME);
  27.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28.         frame.add(this);
  29.         frame.pack();
  30.         frame.setVisible(true);
  31.        
  32.         // Configuration Canvas
  33.         setBackground(Color.BLACK);
  34.     }
  35.    
  36.     public void update() {
  37.         System.out.println("test");
  38.     }
  39.    
  40.     public void paint(Graphics g) {
  41.         g.setColor(Color.WHITE);
  42.        
  43.         g.drawRect(10, 10, 100, 100);
  44.     }
  45.    
  46.     public void start() {
  47.         while (true) {
  48.             update();
  49.             paint(getGraphics());
  50.            
  51.             try {
  52.                 Thread.sleep(50);
  53.             } catch (InterruptedException e) {
  54.                 e.printStackTrace();
  55.             }
  56.         }
  57.     }
  58.    
  59.     public static void main(String[] a) {
  60.         Game game = new Game();
  61.        
  62.         game.start();
  63.     }
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment