Skip to content

Commit d1f392f

Browse files
committed
Merge remote-tracking branch 'origin/updater'
2 parents aff4414 + 6b30cad commit d1f392f

File tree

6 files changed

+229
-23
lines changed

6 files changed

+229
-23
lines changed

src/com/redomar/game/Game.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.redomar.game.net.GameClient;
2828
import com.redomar.game.net.GameServer;
2929
import com.redomar.game.net.packets.Packet00Login;
30+
import com.redomar.game.script.Printing;
3031
import com.thehowtotutorial.splashscreen.JSplash;
3132

3233
public class Game extends Canvas implements Runnable {
@@ -40,6 +41,7 @@ public class Game extends Canvas implements Runnable {
4041
private static final int SCALE = 3;
4142
private static final String NAME = "Game";
4243
private static Game game;
44+
private static Time time = new Time();
4345
private static int Jdata_Host;
4446
private static String Jdata_UserName = "";
4547
private static String Jdata_IP = "127.0.0.1";
@@ -66,7 +68,6 @@ public class Game extends Canvas implements Runnable {
6668
private Player player;
6769
private Dummy dummy;
6870
private Music music = new Music();
69-
private Time time = new Time();
7071
private Font font = new Font();
7172
private Thread musicThread = new Thread(music, "MUSIC");
7273
private String nowPlaying;
@@ -75,6 +76,7 @@ public class Game extends Canvas implements Runnable {
7576
private int trigger = 0;
7677
private GameClient socketClient;
7778
private GameServer socketServer;
79+
private Printing print = new Printing();
7880

7981

8082
public Game() {
@@ -247,7 +249,8 @@ public void render() {
247249
musicThread.start();
248250
notActive = false;
249251
} else {
250-
System.out.println("[GAME] Canceled music option");
252+
//System.out.println("[GAME] Canceled music option");
253+
print.print(" Canceled music option", 1);
251254
input.setPlayMusic(false);
252255
}
253256
}
@@ -306,9 +309,14 @@ public void render() {
306309
}
307310

308311
public static void main(String[] args) {
312+
play();
313+
}
314+
315+
public static void play(){
309316
try {
310317
JSplash splash = new JSplash(Game.class.getResource("/splash/splash.png"), true, true, false, game_Version, null, Color.RED, Color.ORANGE);
311318
splash.toFront();
319+
splash.requestFocus();
312320
splash.splashOn();
313321
splash.setProgress(10, "Initializing Game");
314322
Thread.sleep(250);
@@ -346,7 +354,6 @@ public static void main(String[] args) {
346354
} catch (Exception e) {
347355
e.printStackTrace();
348356
}
349-
350357
}
351358

352359
public JFrame getFrame() {
@@ -381,6 +388,14 @@ public void setLevel(LevelHandler level) {
381388
this.level = level;
382389
}
383390

391+
public static Time getTime() {
392+
return Game.time;
393+
}
394+
395+
public void setTime(Time time) {
396+
Game.time = time;
397+
}
398+
384399
public WindowHandler getWindow() {
385400
return window;
386401
}

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

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,70 @@
44
import java.awt.event.MouseListener;
55
import java.awt.event.MouseMotionListener;
66

7+
import com.redomar.game.Game;
8+
import com.redomar.game.menu.Menu;
9+
710
public class Mouse implements MouseListener, MouseMotionListener{
811

912
public void mouseDragged(MouseEvent e) {
10-
System.out.println("Dragged");
13+
1114
}
1215

1316
public void mouseMoved(MouseEvent e) {
14-
System.out.println("Moved");
17+
if (e.getX() > 35 && e.getX() < 440){
18+
//START is being selected
19+
if(e.getY() > 35 && e.getY() < 125){
20+
Menu.setSelectedStart(true);
21+
}else{
22+
Menu.setSelectedStart(false);
23+
}
24+
//EXIT is being selected
25+
if(e.getY() > 160 && e.getY() < 250){
26+
Menu.setSelectedExit(true);
27+
}else{
28+
Menu.setSelectedExit(false);
29+
}
30+
}else{
31+
Menu.setSelectedStart(false);
32+
Menu.setSelectedExit(false);
33+
}
34+
1535
}
1636

1737
public void mouseClicked(MouseEvent e) {
18-
System.out.println("Clicked");
38+
if(Menu.isRunning()){
39+
if (e.getX() > 35 && e.getX() < 440){
40+
//START game
41+
if(e.getY() > 35 && e.getY() < 125){
42+
Menu.setRunning(false);
43+
Menu.getFrame().setVisible(false);
44+
Menu.getFrame().stopFrame();
45+
Game.play();
46+
}
47+
//EXIT game
48+
if(e.getY() > 160 && e.getY() < 250){
49+
Menu.setRunning(false);
50+
Menu.getFrame().setVisible(false);
51+
Menu.getFrame().stopFrame();
52+
}
53+
}
54+
}
1955
}
2056

2157
public void mouseEntered(MouseEvent e) {
22-
System.out.println("Enter");
58+
2359
}
2460

2561
public void mouseExited(MouseEvent e) {
26-
System.out.println("Exit");
62+
2763
}
2864

2965
public void mousePressed(MouseEvent e) {
30-
System.out.println("Press");
66+
3167
}
3268

3369
public void mouseReleased(MouseEvent e) {
34-
System.out.println("Release");
70+
3571
}
3672

3773
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public Time(){
99

1010
}
1111

12-
public String getTime(){
12+
public synchronized String getTime(){
1313
Calendar cal = Calendar.getInstance();
1414
cal.getTime();
1515
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

src/com/redomar/game/menu/DedicatedJFrame.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ public void setFrame(JFrame frame) {
3434
DedicatedJFrame.frame = frame;
3535
}
3636

37+
public void stopFrame(){
38+
getFrame().dispose();
39+
}
40+
3741

3842
}

src/com/redomar/game/menu/Menu.java

Lines changed: 108 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import java.awt.Color;
44
import java.awt.Graphics;
5+
import java.awt.event.MouseListener;
6+
import java.awt.event.MouseMotionListener;
57
import java.awt.image.BufferStrategy;
68

79
import com.redomar.game.lib.Font;
10+
import com.redomar.game.lib.Mouse;
811

912

1013

@@ -15,18 +18,24 @@ public class Menu implements Runnable{
1518
private static final int SCALE = 3;
1619
private static final String NAME = "Menu";
1720

18-
private DedicatedJFrame frame = new DedicatedJFrame(WIDTH, HEIGHT, SCALE, NAME);
21+
private static boolean running = false;
22+
private static boolean selectedStart = false;
23+
private static boolean selectedExit = false;
24+
private static boolean gameOver = false;
25+
26+
private static DedicatedJFrame frame = new DedicatedJFrame(WIDTH, HEIGHT, SCALE, NAME);
1927
private Font font = new Font();
28+
private MouseListener Mouse = new Mouse();
2029

21-
private boolean running = false;
22-
private boolean selected = true;
30+
private Color selected = new Color(0xFFFF8800);
31+
private Color deSelected = new Color(0xFFCC5500);
2332

2433
public synchronized void start() {
2534
running = true;
26-
new Thread(this).start();
35+
new Thread(this, "MENU").start();
2736
}
2837

29-
public synchronized void stop() {
38+
public static synchronized void stop() {
3039
running = false;
3140
}
3241

@@ -74,6 +83,8 @@ public void run() {
7483

7584
private void render() {
7685
//frame.getFrame().getContentPane().setBackground(Color.GREEN);
86+
frame.addMouseMotionListener((MouseMotionListener) Mouse);
87+
frame.addMouseListener(Mouse);
7788
BufferStrategy bs = frame.getBufferStrategy();
7889
if (bs == null) {
7990
frame.createBufferStrategy(3);
@@ -82,29 +93,50 @@ private void render() {
8293
Graphics g = bs.getDrawGraphics();
8394
g.setColor(Color.BLACK);
8495
g.fillRect(0, 0, frame.getWidth(), frame.getHeight());
96+
g.setColor(new Color(0xFF660000));
97+
g.fillRect(12, 12, (WIDTH*3)-30, (HEIGHT*3)-53);
8598
g.setColor(new Color(0xFFFF9900));
8699
g.setFont(font.getArial());
87-
//g.drawString("Testing Phase...",40,30);
100+
if(isGameOver()){
101+
g.drawString("GAME OVER... What will you do now?",35,30);
102+
}else{
103+
g.drawString("Welcome to JavaGame",35,30);
104+
}
105+
g.drawLine(10, (HEIGHT*3)-40, 10, 10);
106+
g.drawLine(10, 10, (WIDTH*3)-17, 10);
107+
g.drawLine((WIDTH*3)-17, 10, (WIDTH*3)-17, (HEIGHT*3)-40);
108+
g.drawLine(10, (HEIGHT*3)-40, (WIDTH*3)-17, (HEIGHT*3)-40);
88109
//(LEFT,DOWN,WIDTH,HEIGHT)
89-
if (selected == true){
110+
if (isSelectedStart() == true){
90111
//START
91-
g.setColor(new Color(0xFFFF8800));
112+
g.setColor(getSelected());
92113
g.fillRect(35, 35, (frame.getWidth()-70), 90);
93114
g.setColor(Color.BLACK);
94115
g.drawString("Start", 220, 85);
95116
//EXIT
96-
g.setColor(new Color(0xFFFF8800));
117+
g.setColor(getDeSelected());
97118
g.fillRect(35, 160, (frame.getWidth()-70), 90);
98119
g.setColor(Color.BLACK);
99120
g.drawString("Exit", 220, 210);
100-
} else {
121+
} else if (isSelectedExit() == true){
101122
//START
102-
g.setColor(new Color(0xFFFF8833));
123+
g.setColor(getDeSelected());
103124
g.fillRect(35, 35, (frame.getWidth()-70), 90);
104125
g.setColor(Color.BLACK);
105126
g.drawString("Start", 220, 85);
106127
//EXIT
107-
g.setColor(new Color(0xFFFF8833));
128+
g.setColor(getSelected());
129+
g.fillRect(35, 160, (frame.getWidth()-70), 90);
130+
g.setColor(Color.BLACK);
131+
g.drawString("Exit", 220, 210);
132+
}else{
133+
//START
134+
g.setColor(getDeSelected());
135+
g.fillRect(35, 35, (frame.getWidth()-70), 90);
136+
g.setColor(Color.BLACK);
137+
g.drawString("Start", 220, 85);
138+
//EXIT
139+
g.setColor(getDeSelected());
108140
g.fillRect(35, 160, (frame.getWidth()-70), 90);
109141
g.setColor(Color.BLACK);
110142
g.drawString("Exit", 220, 210);
@@ -117,5 +149,69 @@ private void render() {
117149
public static void main(String[] args) {
118150
new Menu().start();
119151
}
152+
153+
public static DedicatedJFrame getFrame() {
154+
return Menu.frame;
155+
}
156+
157+
public static void setFrame(DedicatedJFrame frame) {
158+
Menu.frame = frame;
159+
}
160+
161+
public static boolean isRunning() {
162+
return running;
163+
}
164+
165+
public static void setRunning(boolean running) {
166+
Menu.running = running;
167+
}
168+
169+
public static boolean isSelectedStart() {
170+
return selectedStart;
171+
}
172+
173+
public static void setSelectedStart(boolean selectedStart) {
174+
Menu.selectedStart = selectedStart;
175+
}
176+
177+
public static boolean isSelectedExit() {
178+
return selectedExit;
179+
}
180+
181+
public static void setSelectedExit(boolean selectedExit) {
182+
Menu.selectedExit = selectedExit;
183+
}
184+
185+
public Color getSelected() {
186+
return selected;
187+
}
188+
189+
public void setSelected(Color selected) {
190+
this.selected = selected;
191+
}
192+
193+
public Color getDeSelected() {
194+
return deSelected;
195+
}
196+
197+
public void setDeSelected(Color deSelected) {
198+
this.deSelected = deSelected;
199+
}
200+
201+
public static int getWidth() {
202+
return WIDTH;
203+
}
204+
205+
public static int getHeight() {
206+
return HEIGHT;
207+
}
208+
209+
public static boolean isGameOver() {
210+
return gameOver;
211+
}
212+
213+
public static void setGameOver(boolean gameOver) {
214+
Menu.gameOver = gameOver;
215+
}
120216

121217
}

0 commit comments

Comments
 (0)