Skip to content

Commit 2f241a9

Browse files
committed
Improved the way the player stops
Restuctured they code that stops the player while inventory window opens Player still animated while stopped - imporvement needed
1 parent 18af6b0 commit 2f241a9

File tree

4 files changed

+102
-17
lines changed

4 files changed

+102
-17
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public DedicatedJFrame(int WIDTH, int HEIGHT, int SCALE, String NAME) {
2929
public JFrame getFrame() {
3030
return frame;
3131
}
32+
33+
public static JFrame getFrameStatic(){
34+
return frame;
35+
}
3236

3337
public void setFrame(JFrame frame) {
3438
DedicatedJFrame.frame = frame;

src/com/redomar/game/objects/Inventory.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,49 @@ public class Inventory {
77
public static int x;
88
public static int y;
99
public static boolean open = false;
10+
public static boolean closing;
11+
public static boolean reset;
1012
private static InventoryWindow inv_window = new InventoryWindow();
11-
13+
1214
public static void activate() {
1315
x = Game.getPlayer().getX();
1416
y = Game.getPlayer().getY();
15-
16-
if(Game.getLevel().getTile(x >> 3, y >> 3).getId() == 8){
17-
if(!open){
18-
System.out.println("Opened\nInside this Bag their is:"+inside());
19-
open = true;
20-
Game.getPlayer().setMoving(false);
21-
//Game.getInput().untoggle(true);
22-
inv_window.start();
17+
18+
if (Game.getLevel().getTile(x >> 3, y >> 3).getId() == 8) {
19+
if (!reset) {
20+
if (!open) {
21+
if (!closing) {
22+
System.out.println("Opened\nInside this Bag their is:"
23+
+ inside());
24+
open = true;
25+
Game.getPlayer().setMoving(false);
26+
Game.getInput().untoggle(true);
27+
inv_window.start();
28+
}
29+
} else {
30+
if (closing) {
31+
Game.getPlayer().setMoving(true);
32+
Game.getInput().untoggle(false);
33+
inv_window.stop();
34+
inv_window.getFrame().setVisible(false);
35+
inv_window.getFrame().stopFrame();
36+
if (Game.getLevel().getTile(x >> 3, y >> 3).getId() == 8) {
37+
reset = true;
38+
System.out.println("rest");
39+
}
40+
}
41+
}
2342
}
24-
}else{
25-
if(open){
43+
} else {
44+
if (open == true || reset == true || closing == true) {
45+
reset = false;
2646
open = false;
27-
//Game.getInput().untoggle(false);
28-
inv_window.stop();
29-
inv_window.getFrame().setVisible(false);
30-
inv_window.getFrame().stopFrame();
47+
closing = false;
3148
}
3249
}
3350
}
34-
35-
private static String inside(){
51+
52+
private static String inside() {
3653
String items = " ";
3754
for (Items item : Items.values()) {
3855
items = items + item.toString() + ", ";
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.redomar.game.objects;
2+
3+
import java.awt.event.WindowEvent;
4+
import java.awt.event.WindowListener;
5+
6+
import com.redomar.game.menu.DedicatedJFrame;
7+
8+
public class InventoryHandler implements WindowListener {
9+
10+
@SuppressWarnings("unused")
11+
private DedicatedJFrame frame;
12+
13+
public InventoryHandler(DedicatedJFrame frame) {
14+
this.frame = frame;
15+
DedicatedJFrame.getFrameStatic().addWindowListener(this);
16+
}
17+
18+
@Override
19+
public void windowActivated(WindowEvent e) {
20+
21+
}
22+
23+
@Override
24+
public void windowClosed(WindowEvent e) {
25+
26+
}
27+
28+
public void windowClosing(WindowEvent e) {
29+
Inventory.closing = true;
30+
System.out.println("CLOSING");
31+
}
32+
33+
@Override
34+
public void windowDeactivated(WindowEvent e) {
35+
36+
}
37+
38+
@Override
39+
public void windowDeiconified(WindowEvent e) {
40+
41+
}
42+
43+
@Override
44+
public void windowIconified(WindowEvent e) {
45+
46+
}
47+
48+
@Override
49+
public void windowOpened(WindowEvent e) {
50+
51+
}
52+
53+
}

src/com/redomar/game/objects/InventoryWindow.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class InventoryWindow implements Runnable{
1616
private static boolean running = false;
1717

1818
private static DedicatedJFrame frame;
19+
private static InventoryHandler window;
1920

2021
public synchronized void start(){
2122
running = true;
@@ -36,6 +37,8 @@ public void run() {
3637

3738
long lastTimer = System.currentTimeMillis();
3839
double delta = 0;
40+
41+
setWindow(new InventoryHandler(getFrame()));
3942

4043
while (running) {
4144
long now = System.nanoTime();
@@ -93,4 +96,12 @@ public DedicatedJFrame getFrame() {
9396
public static void setFrame(DedicatedJFrame frame) {
9497
InventoryWindow.frame = frame;
9598
}
99+
100+
public static InventoryHandler getWindow() {
101+
return window;
102+
}
103+
104+
public static void setWindow(InventoryHandler inventoryHandler) {
105+
InventoryWindow.window = inventoryHandler;
106+
}
96107
}

0 commit comments

Comments
 (0)