-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflappybird.java
More file actions
68 lines (59 loc) · 1.77 KB
/
Copy pathflappybird.java
File metadata and controls
68 lines (59 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class flappybird here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class FlappyBird extends World
{
GreenfootImage bgImage = new GreenfootImage("background.png");
Ground ground;
Pipe Pipe;
int pipeCount=0;
/**
* Constructor for objects of class flappybird.
*
*/
public FlappyBird()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1,false);
setBackground(bgImage);
populate();
setPaintOrder(Ground.class, Bird.class, Pipe.class);
}
public void act()
{
createPipe();
createGround();
}
public void populate()
{
Bird bird = new Bird();
addObject(bird, 80, 200);
ground = new Ground();
addObject(ground, 309, getHeight()-25);
}
private void createGround() {
if (getObjects(Ground.class).size()<3) {
Ground additionalGround = new Ground();
addObject(additionalGround, 905, getHeight()-25);
}
}
public void createPipe() {
Pipe topPipe = new Pipe("top");
Pipe botPipe = new Pipe("bottom");
int pipeSpacing =150;
GreenfootImage image = botPipe.getImage();
int numofpipes= Greenfoot.getRandomNumber(10)+4;
pipeCount++;
if (pipeCount> 50) {
if(getObjects(Pipe.class).size()<numofpipes) {
addObject(botPipe,getWidth(),getHeight()/2+image.getHeight()-Greenfoot.getRandomNumber(100)-10);
addObject(topPipe,getWidth(),botPipe.getY()-image.getHeight()-pipeSpacing);
}
pipeCount=0;
}
}
}