-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfly.java
More file actions
98 lines (81 loc) · 1.98 KB
/
fly.java
File metadata and controls
98 lines (81 loc) · 1.98 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
import java.awt.*;
import javax.swing.JPanel;
public class fly extends JPanel
{
private int x, y;
private boolean alive;
private boolean isGolden;
//CONSTRUCTOR
public fly(int x, int y){
this.x = x;
this.y = y;
alive = false;
isGolden = false;
}
//MOVES FLY
public void move(int amount){
x = x + amount;
}
//CHANGES VERTICAL POSITION
public void moveHeight(){
y = (int)(Math.random() * 200) + 110;
}
//SETS ALIVE ATTRIBUTE TO TRUE
public void aliveYes(){
alive = true;
}
//SETS ALIVE ATTRIBUTE TO FALSE
public void aliveNo(){
alive = false;
}
//RETURNS X POSITION
public int getX(){
return x;
}
//RETURNS Y POSITION
public int getY(){
return y;
}
//RETURNS ALIVE ATTRIBUTE
public boolean life(){
return alive;
}
//SETS ISGOLDEN ATTRIBUTE BASED ON PARAMETER
public void setGoldStatus(boolean isGold){
isGolden = isGold;
}
//RETURNS WHETHER OR NOT FLY IS GOLDEN
public boolean getGoldStatus(){
return isGolden;
}
//BECOMES GOLD
public void transform(){
int x = (int)(Math.random() * 10);
if(isGolden){
isGolden = !isGolden;
} else if(x == 9){
isGolden = true;
}
}
//PAINTS FLY
public void paintComponent(Graphics g){
super.paintComponent(g);
if (alive == true){
//BODY
if(!isGolden){
g.setColor(new Color(57, 59, 63));
} else{
g.setColor(new Color(252, 201, 61));
}
g.fillRect(x, y, 85, 85);
//WINGS
if(!isGolden){
g.setColor(Color.GRAY);
} else{
g.setColor(new Color(163, 132, 3));
}
g.fillRect(x+50, y-10, 90, 65);
g.fillRect(x-50, y-10, 90, 65);
}
}
}