Skip to content

Commit 19c614c

Browse files
committed
Added a play now button
pressing 'M' will now start to play the music
1 parent 3218da7 commit 19c614c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/com/redomar/game/Game.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public class Game extends Canvas implements Runnable {
5555
private Player player;
5656
private Music music = new Music();
5757
public Thread musicThread = new Thread(music);
58+
59+
public boolean notActive = true;
5860

5961
private GameClient socketClient;
6062
private GameServer socketServer;
@@ -111,7 +113,6 @@ public void init() {
111113
public synchronized void start() {
112114
running = true;
113115
new Thread(this).start();
114-
musicThread.start();
115116

116117
if (Jdata_Host == 0) {
117118
socketServer = new GameServer(this);
@@ -206,6 +207,18 @@ public void render() {
206207
}
207208
}
208209
}
210+
211+
if (input.PlayMusic == true && notActive == true){
212+
int musicOption = JOptionPane.showConfirmDialog(this, "You are about to turn on music and can be VERY loud", "Music Options", 2, 2);
213+
if (musicOption == 0){
214+
musicThread.start();
215+
notActive = false;
216+
} else {
217+
System.out.println("Canceled");
218+
input.PlayMusic = false;
219+
}
220+
}
221+
209222

210223
Graphics g = bs.getDrawGraphics();
211224

src/com/redomar/game/InputHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void toggle(boolean isPressed) {
3333
public Key down = new Key();
3434
public Key left = new Key();
3535
public Key right = new Key();
36+
public boolean PlayMusic = false;
3637

3738
public void keyPressed(KeyEvent e) {
3839
toggleKey(e.getKeyCode(), true);
@@ -59,6 +60,9 @@ public void toggleKey(int keyCode, boolean isPressed) {
5960
if (keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_RIGHT) {
6061
right.toggle(isPressed);
6162
}
63+
if (keyCode == KeyEvent.VK_M){
64+
this.PlayMusic = true;
65+
}
6266
}
6367

6468
}

0 commit comments

Comments
 (0)