Repository navigation
Expand file tree
/
Copy pathPixelGame.java
More file actions
157 lines (137 loc) · 5.09 KB
/
Copy pathPixelGame.java
File metadata and controls
157 lines (137 loc) · 5.09 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PixelGame extends JFrame {
private String version = "V0.1_432CD";
private boolean updateAvailable = false;
public PixelGame() {
setTitle("Pixel Game - " + version);
setSize(800, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
JButton startButton = new JButton("Start");
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showLoadingScreen();
// Simulate loading process for 10-15 seconds
new Timer(1000, new ActionListener() {
int progress = 0;
@Override
public void actionPerformed(ActionEvent e) {
progress += 10;
if (progress >= 100) {
((Timer) e.getSource()).stop();
closeLoadingScreen();
// Set background, blocks, and add the circle
setGameBackground("Images/water/Water.png");
setBlocks("Images/Gorund/Gorund.png");
addCircle();
} else {
// Update progress bar
updateProgressBar(progress);
}
}
}).start();
}
});
add(startButton);
JButton optionsButton = new JButton("Options");
optionsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showOptions();
}
});
add(optionsButton);
JButton creditsButton = new JButton("Credits");
creditsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showCredits();
}
});
add(creditsButton);
JButton updateButton = new JButton("Update");
updateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateGame();
}
});
if(updateAvailable) {
add(updateButton);
}
}
private void showLoadingScreen() {
JDialog loadingDialog = new JDialog(this, "Loading", true);
loadingDialog.setSize(300, 100);
loadingDialog.setLocationRelativeTo(this);
JProgressBar progressBar = new JProgressBar();
progressBar.setIndeterminate(true);
progressBar.setStringPainted(true);
progressBar.setString("Loading...");
loadingDialog.add(progressBar);
loadingDialog.setVisible(true);
}
private void closeLoadingScreen() {
// Close the loading screen dialog
for (Window window : Window.getWindows()) {
if (window instanceof JDialog) {
JDialog dialog = (JDialog) window;
if (dialog.getTitle().equals("Loading")) {
dialog.dispose();
break;
}
}
}
}
private void updateProgressBar(int progress) {
// Update the progress bar in the loading screen
for (Window window : Window.getWindows()) {
if (window instanceof JDialog) {
JDialog dialog = (JDialog) window;
if (dialog.getTitle().equals("Loading")) {
Component[] components = dialog.getContentPane().getComponents();
for (Component component : components) {
if (component instanceof JProgressBar) {
((JProgressBar) component).setValue(progress);
break;
}
}
break;
}
}
}
}
private void setGameBackground(String imagePath) {
// Set background of the game
}
private void setBlocks(String imagePath) {
// Set blocks in the game
}
private void addCircle() {
// Add circle to the game
// Implement controls for circle movement
}
private void showOptions() {
// Implement Options menu
}
private void showCredits() {
// Implement Credits menu
}
private void updateGame() {
// Open new version of the game
String newVersion = "V2/Game.java";
JOptionPane.showMessageDialog(this, "Updating to " + newVersion);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new PixelGame().setVisible(true);
}
});
}
}