Skip to content

Commit c5822ec

Browse files
committed
Updated the closing speed
Slowed down the speed in which the game closes when 'Q' is pressed
1 parent ed090c3 commit c5822ec

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/com/redomar/game/Game.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public class Game extends Canvas implements Runnable {
5353
private static int fps;
5454
private static int tps;
5555
private static int steps;
56-
private static boolean[] devMode = new boolean[2];
56+
private static boolean devMode;
57+
private static boolean closingMode;
5758

5859
private static JFrame frame;
5960

@@ -100,7 +101,7 @@ public Game() {
100101
getFrame().setVisible(true);
101102

102103
setDevMode(false);
103-
setDevTime(false);
104+
setClosing(false);
104105
}
105106

106107
public void init() {
@@ -312,7 +313,7 @@ public void render() {
312313
g.drawString("Press Q to quit", (getWidth()/2)-("Press Q to quit".length()*3), getHeight() -17);
313314
g.setColor(Color.YELLOW);
314315
g.drawString(time.getTime(), (getWidth() - 58), (getHeight() - 3));
315-
status(g, isDevMode());
316+
status(g, isDevMode(), isClosing());
316317
g.setColor(Color.WHITE);
317318
if (noAudioDevice == true) {
318319
g.setColor(Color.RED);
@@ -347,7 +348,7 @@ public void render() {
347348
bs.show();
348349
}
349350

350-
private void status(Graphics g, boolean TerminalMode) {
351+
private void status(Graphics g, boolean TerminalMode, boolean TerminalQuit) {
351352
if (TerminalMode == true){
352353
g.setColor(Color.GREEN);
353354
g.drawString("JavaGame Stats", 0, 10);
@@ -358,6 +359,13 @@ private void status(Graphics g, boolean TerminalMode) {
358359
g.drawString("Foot Steps: " + steps, 0, 40);
359360
g.drawString("NPC: " + WordUtils.capitalize(String.valueOf(isNpc())) , 0, 55);
360361
}
362+
if (TerminalQuit == true){
363+
g.setColor(Color.BLACK);
364+
g.fillRect(0, 0, getWidth(), getHeight());
365+
g.setColor(Color.RED);
366+
g.drawString("Shutting down the Game", (getWidth()/2)-70, (getHeight()/2)-8);
367+
g.dispose();
368+
}
361369
}
362370

363371
public static void main(String[] args) {
@@ -545,19 +553,19 @@ public void setInput(InputHandler input) {
545553
}
546554

547555
public static boolean isDevMode() {
548-
return devMode[0];
556+
return devMode;
549557
}
550558

551559
public static void setDevMode(boolean devMode) {
552-
Game.devMode[0] = devMode;
560+
Game.devMode = devMode;
553561
}
554562

555-
public static boolean isDevTime() {
556-
return devMode[1];
563+
public static boolean isClosing() {
564+
return closingMode;
557565
}
558566

559-
public static void setDevTime(boolean devTime) {
560-
Game.devMode[1] = devTime;
567+
public static void setClosing(boolean closing) {
568+
Game.closingMode = closing;
561569
}
562570

563571
}

src/com/redomar/game/InputHandler.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,21 @@ public void toggleKey(int keyCode, boolean isPressed) {
106106
}
107107
}
108108
if (keyCode == KeyEvent.VK_Q){
109+
Game.setClosing(true);
110+
try {
111+
Thread.sleep(1000);
112+
} catch (InterruptedException e) {
113+
e.printStackTrace();
114+
}
109115
Game.getLevel().removeEntity(Game.getPlayer().getSantizedUsername());
110116
Game.setRunning(false);
111117
Game.getFrame().dispose();
112118
System.exit(1);
113119
}
114120

115121
if (keyCode == KeyEvent.VK_BACK_QUOTE){
116-
if (Game.isDevTime() == false && Game.isDevMode() == false){
122+
if (Game.isClosing() == false && Game.isDevMode() == false){
117123
Game.setDevMode(true);
118-
Game.setDevTime(true);
119124
new Thread(new SleepThread());
120125
}
121126
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class SleepThread implements Runnable{
77
public void run() {
88
try {
99
Thread.sleep(1500);
10-
Game.setDevTime(false);
10+
Game.setClosing(false);
1111
System.out.println("time up");
1212
} catch (InterruptedException e) {
1313
e.printStackTrace();

0 commit comments

Comments
 (0)