-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBird.java
More file actions
102 lines (88 loc) · 2.43 KB
/
Copy pathBird.java
File metadata and controls
102 lines (88 loc) · 2.43 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class bird1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bird extends SharedResources
{
protected int BirdX = 80;
protected int BirdY = 200;
int velocity2 = 0;
private static final double boostSpeed = -6;
GreenfootImage bird_image_1 = new GreenfootImage("flappybird1.png");
GreenfootImage bird_image_2 = new GreenfootImage("flappybird2.png");
GreenfootImage bird_image_3 = new GreenfootImage("flappybird3.png");
static final private double Gravity = .5;
private double velocity = 0;
/**
* Act - do whatever the bird1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
apllyGravity();
checkKeys();
rotateBird();
checkCollisions();
}
public void apllyGravity()
{
addBirdY((int)velocity);
velocity +=Gravity;
animateBird();
setLocation(getBirdX(),getBirdY());
}
public void checkKeys()
{
if(Greenfoot.isKeyDown("space") || Greenfoot.mouseClicked(null))
{
velocity = boostSpeed;
}
}
public void rotateBird()
{
if(velocity < 1) {
setRotation(-30);
} else if(velocity < 8) {
setRotation(0);
} else if(velocity < 12) {
setRotation(30);
} else if(velocity < 90) {
setRotation(90);
}
}
public void animateBird()
{
frame++;
if(frame < 1 * animationDelay) {
setImage(bird_image_1);
}
else if(frame < 2 * animationDelay) {
setImage(bird_image_2);
}
else if(frame < 3 * animationDelay) {
setImage(bird_image_3);
frame = 0;
}
}
public void checkCollisions() {
Actor ground = getOneIntersectingObject(Ground.class);
Actor Pipe = getOneIntersectingObject(Pipe.class);
if(ground != null || Pipe != null) {
setLocation(getX(), 322);
Greenfoot.stop();
}
}
protected int getBirdX() {
return BirdX;
}
protected int getBirdY() {
return BirdY;
}
protected void addBirdY(double x) {
BirdY += (int)x;
}
}