Facebook
From Daniel Hatakeyama, 2 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 103
  1. Bird flappy;
  2. Pipe pipe;
  3. Background background;
  4. Foreground foreground;
  5. boolean gameOver = false;
  6.  
  7. int score = 0;
  8.  
  9. void setup() {
  10.   size(600,500);
  11.  
  12.   flappy = new Bird();
  13.   pipe = new Pipe();
  14.   background = new Background();
  15.   foreground = new Foreground();
  16. }
  17.  
  18. void draw() {  
  19.   if(gameOver) {
  20.     // When the game is over run the stuff in here
  21.    
  22.   } else {
  23.     game();
  24.   }
  25. }
  26.  
  27. void game() {
  28.   score ++;
  29.  
  30.   // Hit Actions
  31.   if(pipe.hit(flappy)) { // If hit
  32.     pipe.pipeColor = #FC6666; // Red
  33.     gameOver = true;
  34.   } else {
  35.     pipe.pipeColor = #21FC61; // Green
  36.   }
  37.  
  38.   // "Background Layer"
  39.   background.update();
  40.   background.show();
  41.  
  42.   // "Game Layer"
  43.   flappy.update();
  44.   flappy.show();
  45.  
  46.   pipe.update();
  47.   pipe.show();
  48.  
  49.   // "Foreground"
  50.   foreground.update();
  51.   foreground.show();
  52.  
  53.   textSize(24);
  54.   text(str(score), width/2-20, height/8);
  55. }
  56.  
  57. void keyPressed() {
  58.   if(key == ' ') {
  59.     flappy.jump();
  60.   }
  61. }