-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackgroundManager.java
More file actions
87 lines (57 loc) · 2.31 KB
/
BackgroundManager.java
File metadata and controls
87 lines (57 loc) · 2.31 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
import java.awt.Graphics2D;
import javax.swing.JFrame;
public class BackgroundManager {
// Array of file paths for different background images
private String bgImages[] = {"images/background/background1.png"};
private String bgImages1[] = {"images/background/background2.png"};
private String bgImages2[] = {"images/background/background3.png"};
private int numBackgrounds;
private int moveAmountX[] = {10, 1};
private int moveAmountY[] = {50, 0};
private Background[] backgrounds;
private Background[] backgrounds1;
private Background[] backgrounds2;
// Constructor to initialize the BackgroundManager
public BackgroundManager(JFrame window, int moveSize, double displayScale) {
numBackgrounds = bgImages.length;
backgrounds = new Background[numBackgrounds];
backgrounds1 = new Background[numBackgrounds];
backgrounds2 = new Background[numBackgrounds];
for (int i = 0; i < numBackgrounds; i++) {
backgrounds[i] = new Background(window, ImageManager.loadImage(bgImages[i]), moveAmountX[i], moveAmountY[i], displayScale);
}
for (int i = 0; i < bgImages1.length; i++) {
backgrounds1[i] = new Background(window, ImageManager.loadImage(bgImages1[i]), moveAmountX[i], moveAmountY[i], displayScale);
}
for (int i = 0; i < bgImages2.length; i++) {
backgrounds2[i] = new Background(window, ImageManager.loadImage(bgImages2[i]), moveAmountX[i], moveAmountY[i], displayScale);
}
}
// Moves all backgrounds to the right, creating a scrolling effect
public void moveRight() {
for (int i=0; i < numBackgrounds; i++){
//backgrounds[i].moveRight();
}
}
// Moves all backgrounds to the left, creating a scrolling effect
public void moveLeft() {
for (int i=0; i < numBackgrounds; i++){
//backgrounds[i].moveLeft();
}
}
// Draws the backgrounds based on the current level
public void draw(Graphics2D g2, int level) {
if (level == 1){
for (int i=0; i < numBackgrounds; i++)
backgrounds[i].draw(g2);
}
if (level == 2){
for (int i=0; i < 1; i++)
backgrounds1[i].draw(g2);
}
if (level == 3){
for (int i=0; i < 1; i++)
backgrounds1[i].draw(g2);
}
}
}