-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStar.java
59 lines (49 loc) · 1.35 KB
/
Star.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
package com.lud.root.jetfighter;
import java.util.Random;
public class Star {
private int x;
private int y;
private int speed;
private int maxX;
private int maxY;
private int minX;
private int minY;
public Star(int screenX, int screenY){
maxX = screenX;
maxY = screenY;
minX = 0;
minY = 0;
Random generator = new Random();
speed = generator.nextInt(10);
//generate random coordinate but keeping them inside the screen
x = generator.nextInt(maxX);
y = generator.nextInt(maxY);
}
public void update(){
//To animate the stars on the left side
//Used here is the player's speed
x -= 10;
x -=speed;
if(x < 0){
//Again start the stars from the right edge
//Thus creating an infinite background effect
x = maxX;
Random generator = new Random();
y = generator.nextInt(maxY);
speed = generator.nextInt(15);
}
}
public float getStarWidth(){
//Randomising the star width , for aesthetics
float minX = 1.0f;
float maxX = 4.0f;
Random rand = new Random();
return rand.nextFloat() * (maxX - minX) + minX;
}
public int getY() {
return y;
}
public int getX() {
return x;
}
}