-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStars.java
57 lines (43 loc) · 1.01 KB
/
Stars.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
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.util.Random;
public class Stars extends Rectangle{
int width, height = width;
int x,y;
public int starsdx;
int delay = 120, timer = delay;
Color col;
Random rand;
int c;
public Stars() {
rand = new Random();
width = rand.nextInt(10)+1;
x = rand.nextInt(1000) + rand.nextInt(900);
y = rand.nextInt(830);
starsdx = rand.nextInt(50)+1;
c = rand.nextInt(155)+100;
this.setLocation(x,y);
this.setSize(width, width);
col = new Color (c,c,c);
}
public void moveAndDraw(Graphics2D win) {
if (timer<delay) {
starsdx = 2*rand.nextInt(50)+1;
timer++;
}
else {
starsdx = rand.nextInt(50)+1;
}
if(GameDriverV4.Keys[KeyEvent.VK_V]) {
timer = 0;
}
if (this.getMinX() <= 0) {
this.setLocation(x,y);
}
this.translate (-starsdx,0);
win.setColor(col);
win.fill(this);
}
}