Skip to content

Commit a404bf0

Browse files
committed
Merge remote-tracking branch 'origin/aside'
2 parents 9aaf4a5 + 19c614c commit a404bf0

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

res/music/Towards The End.mp3

1.42 MB
Binary file not shown.

src/com/redomar/game/Game.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public class Game extends Canvas implements Runnable {
3434
public static final String NAME = "Game";
3535
public static Game game;
3636
private static int Jdata_Host;
37-
private static String Jdata_UserName = "";
37+
private static String Jdata_UserName = "";
38+
private static String Jdata_IP = "127.0.0.1";
3839

3940
private JFrame frame;
4041

@@ -53,6 +54,9 @@ public class Game extends Canvas implements Runnable {
5354
private LevelHandler level;
5455
private Player player;
5556
private Music music = new Music();
57+
public Thread musicThread = new Thread(music);
58+
59+
public boolean notActive = true;
5660

5761
private GameClient socketClient;
5862
private GameServer socketServer;
@@ -108,15 +112,14 @@ public void init() {
108112

109113
public synchronized void start() {
110114
running = true;
111-
new Thread(music).start();
112115
new Thread(this).start();
113116

114117
if (Jdata_Host == 0) {
115118
socketServer = new GameServer(this);
116119
socketServer.start();
117120
}
118121

119-
setSocketClient(new GameClient(this, "127.0.0.1"));
122+
setSocketClient(new GameClient(this, Jdata_IP));
120123
getSocketClient().start();
121124
}
122125

@@ -204,6 +207,18 @@ public void render() {
204207
}
205208
}
206209
}
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+
207222

208223
Graphics g = bs.getDrawGraphics();
209224

@@ -237,6 +252,9 @@ public static void main(String[] args) {
237252
splash.setProgress(92, "Aquring data: Multiplayer");
238253
Thread.sleep(200);
239254
Jdata_Host = JOptionPane.showConfirmDialog(game, "Do you want to be the HOST?");
255+
if (Jdata_Host == 1){
256+
Jdata_IP = JOptionPane.showInputDialog(game, "Enter the name \nleave blank for local");
257+
}
240258
Thread.sleep(200);
241259
splash.setProgress(95, "Aquring data: Username");
242260
Thread.sleep(200);

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
}

src/com/redomar/game/lib/Music.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.BufferedInputStream;
44
import java.io.InputStream;
5+
import java.util.Random;
56

67
import com.redomar.game.Game;
78

@@ -11,6 +12,10 @@ public class Music implements Runnable{
1112

1213
private InputStream file;
1314
private Player musicPlayer;
15+
private String songName[] = {"/music/yoshi.mp3", "/music/Towards The End.mp3"};
16+
private int songNumber;
17+
18+
private static Random rand = new Random();
1419

1520
public Music(InputStream url){
1621
this.file = url;
@@ -33,18 +38,25 @@ public void Play(){
3338

3439
@Override
3540
public void run() {
36-
Music music = new Music(Game.class.getResourceAsStream("/music/yoshi.mp3"));
37-
while(true){
41+
try {
42+
Thread.sleep(300);
43+
initSongNumber();
44+
System.out.println("[MUSIC] loading song: " + songName[songNumber].substring(7, (songName[songNumber].length() - 4)));
45+
Music music = new Music(Game.class.getResourceAsStream(songName[songNumber]));
46+
Thread.sleep(100);
47+
System.out.println("[MUSIC] playing song: " + songName[songNumber].substring(7, (songName[songNumber].length() - 4)));
3848
music.Play();
49+
this.run();
50+
} catch (InterruptedException e) {
51+
System.out.println("[ERROR][MUSIC] Could not stop, nothing currenly playing");
3952
}
4053
}
4154

4255
public void stop() {
43-
Music music = new Music(Game.class.getResourceAsStream("/music/yoshi.mp3"));
44-
while(true){
45-
music.stop();
46-
}
56+
57+
}
58+
59+
private void initSongNumber() {
60+
this.songNumber = rand.nextInt(2);
4761
}
48-
49-
5062
}

0 commit comments

Comments
 (0)