-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pipe.java
51 lines (45 loc) · 1.47 KB
/
Pipe.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
import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.awt.image.BufferedImage;
class Pipe extends JComponent{
int x;
int topY;
int bottomY;
int topHeight;
int width;
int bottomHeight;
BufferedImage topPipe;
BufferedImage bottomPipe;
final int vel = 5;
final int WIDTH = 10;
Random rand = new Random();
public boolean passed;
public Pipe(int x){
this.x = x;
this.topHeight = 600;
this.bottomHeight = 600;
this.passed = false;
this.bottomPipe = utils.loadImage("assets\\pipe.png");
this.bottomPipe = utils.scaleImage(this.bottomPipe, 1, 1.75);
this.topPipe = utils.rotateImage(this.bottomPipe, 180);
this.width = this.topPipe.getWidth();
this.setHeight();
}
public void paintComponent(Graphics g){
//g.setColor(Color.GREEN);
//g.fillRect(this.x, this.topY, this.WIDTH, this.topHeight);
//g.fillRect(this.x, this.bottomY, this.WIDTH, this.bottomHeight);
g.drawImage(this.topPipe, this.x, this.topY, this);
g.drawImage(this.bottomPipe, this.x, this.bottomY, this);
}
public void move(){
this.x -= vel; // do we access it with 'this' or no
}
private void setHeight(){
int gap = 100; //70
int height = rand.nextInt(350) + 50;
this.topY = height - this.topHeight;
this.bottomY = gap + height;
}
}