Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float obspos, obsw = 20, h, d, obsspeed = 5;
- boolean gameover = false;
- PImage flappy;
- float xpos = 100, ypos = 400, birdsize = 40, speed = 4;
- void setup(){
- size(500, 800);
- obspos = width;
- h = random(50, 600);
- d = random(50, 150);
- flappy = loadImage("flappy.png");
- }
- void draw(){
- if (!gameover){
- background(0, 0, 255);
- obstacle();
- bird();
- collision();
- } else {
- textSize(50);
- text("Game over", 100, 200);
- }
- }
- void obstacle(){
- fill(0, 255, 0);
- rect(obspos, 0, obsw, h);
- rect(obspos, h + d, obsw, height - (h + d));
- obspos = obspos - obsspeed;
- if (obspos < 0){
- obspos = width;
- h = random(50, 600);
- d = random(50, 150);
- }
- }
- void bird(){
- image(flappy, xpos, ypos, birdsize, birdsize);
- if (keyPressed && key == ' '){
- ypos -= speed;
- } else {
- ypos += speed;
- }
- }
- void collision(){
- if (ypos + birdsize > height){
- gameover = true;
- }
- if (xpos + birdsize > obspos && xpos < obspos + obsw){
- if (ypos < h || ypos + birdsize > h + d){
- gameover = true;
- }
- }
- }
Add Comment
Please, Sign In to add comment