-
Notifications
You must be signed in to change notification settings - Fork 0
/
Base.java
40 lines (32 loc) · 964 Bytes
/
Base.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
import javax.swing.JComponent;
import java.awt.*;
import java.awt.image.BufferedImage;
class Base extends JComponent{
int x1;
int x2;
int y;
int vel;
int width;
BufferedImage image;
public Base(int y, int vel){
this.y = y;
this.vel = 5;
x1 = 0;
this.image = utils.loadImage("assets\\base.png");
this.image = utils.scaleImage(this.image, 1.4, 1);
this.width = this.image.getWidth();
this.x2 = this.width-1;
}
public void paintComponent(Graphics g){
g.drawImage(this.image, this.x1, this.y, this);
g.drawImage(this.image, this.x2, this.y, this);
}
public void move(){
this.x1 -= this.vel;
this.x2 -= this.vel;
if (this.x1 + this.width < 0)
this.x1 = this.x2 + this.width-1;
if (this.x2 + this.width < 0)
this.x2 = this.x1 + this.width-1;
}
}