-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bird.java
121 lines (97 loc) · 3.5 KB
/
Bird.java
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package strategictoastinsertion;
import org.newdawn.slick.*;
/*
Creators: Matthew Godfrey, Seth Thomson, Jonah Monaghan
Created: May 18th, 2016
Purpose: the bird class that objectifies the player
*/
public class Bird extends STIObject {
static int score;//int to hold players score
int width, height;//ints for birds width, birds height
String birdShoot, birdDead = "res/images/hiyoko.png";//strings for bird animation
static String playerName = "GADFREY";//string for player name (default is GADFREY)
Sound screech;//sound to play when player dies
//Constructors
public Bird() {
//initialization of variables
xPos = 25;
yPos = 100;
speed = 7;
imageString = "res/images/oh noes.jpg";
score = 0;
width = 75;
height = 75;
}
public Bird(String birdImage, String birdShoot, String birdScreech) {
this();//call constructor
this.imageString = birdImage;//set image string to image passed into constructor
this.birdShoot = birdShoot;//set image string to image passed into
try {//try/catch for audio: catch slickexception
screech = new Sound(birdScreech);//nitialize bird screech
} catch (SlickException ex) {
System.out.println("Audio Error");
}
}
public Bird(String birdType, String birdShoot, String birdScreech, int x, int y, int width, int height) {
this(birdType, birdShoot, birdScreech);//constructor call
xPos = x;//init x
yPos = y;//init y
this.width = width;//init birdwidth
this.height = height;//init birdheight
}
//Getters and setters
public int getScore() {//return score
return score;
}
public void setScore(int score) {//set score
this.score = score;
}
public String getBirdShoot() {//return shooting string
return birdShoot;
}
public void setBirdShoot(String birdShoot) {//set shooting string
this.birdShoot = birdShoot;
}
public int getWidth() {//return width
return width;
}
public void setWidth(int width) {//set width
this.width = width;
}
public int getHeight() {//return height
return height;
}
public void setHeight(int height) {//set height
this.height = height;
}
public String getBirdDead() {//return bird dead string
return birdDead;
}
public void setBirdDead(String birdDead) {//set bird dead string
this.birdDead = birdDead;
}
public static String getPlayerName() {//return players name
return playerName;
}
public static void setPlayerName(String playerName) {//set players name
Bird.playerName = playerName;
}
public void moveUp() {//move up
if (yPos > 0) {//if y position is lower than max
yPos -= speed;//move up
}
}
public void moveDown() {//move down
if (yPos < Menu.height - height) {//if y position is higher than min
yPos += speed;//move down
}
}
public void die() {//die
screech.play();//play bird screech
Play.isAlive = false;//tell game that bird is dead
}
public ToastBullet shoot() throws SlickException {//shoot
ToastBullet bullet = new ToastBullet(xPos + Menu.birdWidth + 1, yPos + 5);//create a new bullet
return bullet;//return it
}
}