Skip to content

Commit fb07e5d

Browse files
committed
Merge branch 'feature' into aside
2 parents c0217fa + 76b913e commit fb07e5d

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

src/com/redomar/game/InputHandler.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.awt.event.KeyListener;
55

66
import com.redomar.game.lib.SleepThread;
7+
import com.redomar.game.script.PopUp;
78
import com.redomar.game.script.PrintTypes;
89
import com.redomar.game.script.Printing;
910

@@ -31,6 +32,11 @@ public void toggle(boolean isPressed) {
3132
numTimesPressed++;
3233
}
3334
}
35+
36+
public void off(){
37+
pressed = false;
38+
numTimesPressed = 0;
39+
}
3440
}
3541

3642
private Key up = new Key();
@@ -40,7 +46,8 @@ public void toggle(boolean isPressed) {
4046
private Printing print = new Printing();
4147
private boolean PlayMusic = false;
4248
private int map;
43-
private boolean untoggle = false;
49+
private boolean ignoreInput = false;
50+
private PopUp popup = new PopUp();
4451

4552
public void keyPressed(KeyEvent e) {
4653
toggleKey(e.getKeyCode(), true);
@@ -55,7 +62,7 @@ public void keyTyped(KeyEvent e) {
5562
}
5663

5764
public void toggleKey(int keyCode, boolean isPressed) {
58-
if(untoggle == false){
65+
if(isIgnoreInput() == false){
5966
if (keyCode == KeyEvent.VK_W || keyCode == KeyEvent.VK_UP) {
6067
getUp().toggle(isPressed);
6168
}
@@ -68,7 +75,8 @@ public void toggleKey(int keyCode, boolean isPressed) {
6875
if (keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_RIGHT) {
6976
getRight().toggle(isPressed);
7077
}
71-
}else{
78+
}
79+
if(isIgnoreInput() == true){
7280
getUp().toggle(false);
7381
getDown().toggle(false);
7482
getLeft().toggle(false);
@@ -92,6 +100,14 @@ public void toggleKey(int keyCode, boolean isPressed) {
92100
}
93101
}
94102
if (keyCode == KeyEvent.VK_N) {
103+
if (Game.getPlayer().isMoving()){
104+
setIgnoreInput(true);
105+
int n = popup.Warn("Stop moving before spawing dummy AI");
106+
if(n == 0){
107+
setIgnoreInput(false);
108+
}
109+
return;
110+
}
95111
if (Game.isNpc() == false) {
96112
Game.setNpc(true);
97113
Game.npcSpawn();
@@ -127,7 +143,7 @@ public void toggleKey(int keyCode, boolean isPressed) {
127143
}
128144

129145
public void untoggle(boolean toggle){
130-
this.untoggle = toggle;
146+
this.ignoreInput = toggle;
131147
}
132148

133149

@@ -179,12 +195,12 @@ public void setRight(Key right) {
179195
this.right = right;
180196
}
181197

182-
public boolean isUntoggle() {
183-
return untoggle;
198+
public boolean isIgnoreInput() {
199+
return ignoreInput;
184200
}
185201

186-
public void setUntoggle(boolean untoggle) {
187-
this.untoggle = untoggle;
202+
public void setIgnoreInput(boolean ignoreInput) {
203+
this.ignoreInput = ignoreInput;
188204
}
189205

190206
}

src/com/redomar/game/entities/Mob.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ public int getNumSteps() {
225225
public void setMoving(boolean isMoving) {
226226
this.isMoving = isMoving;
227227
}
228+
229+
public boolean isMoving(){
230+
return this.isMoving;
231+
}
228232

229233
public void setMovingDir(int movingDir) {
230234
this.movingDir = movingDir;

src/com/redomar/game/entities/Player.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public void tick() {
4343
double ya = 0;
4444

4545
if (input != null) {
46-
if (input.getUp().isPressed()) {
46+
if (input.getUp().isPressed() && input.isIgnoreInput() == false) {
4747
ya -= speed;
4848
}
49-
if (input.getDown().isPressed()) {
49+
if (input.getDown().isPressed() && input.isIgnoreInput() == false) {
5050
ya += speed;
5151
}
52-
if (input.getLeft().isPressed()) {
52+
if (input.getLeft().isPressed() && input.isIgnoreInput() == false) {
5353
xa -= speed;
5454
}
55-
if (input.getRight().isPressed()) {
55+
if (input.getRight().isPressed() && input.isIgnoreInput() == false) {
5656
xa += speed;
5757
}
5858
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.redomar.game.script;
2+
3+
import javax.swing.JFrame;
4+
import javax.swing.JOptionPane;
5+
6+
import com.redomar.game.Game;
7+
8+
public class PopUp{
9+
10+
private JFrame frame;
11+
12+
public PopUp(){
13+
frame = Game.getFrame();
14+
}
15+
16+
public int Warn(String msg){
17+
Object[] options = {"Continue"};
18+
return JOptionPane.showOptionDialog(frame, msg, "Notice", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE,
19+
null, options, options[0]);
20+
}
21+
}

0 commit comments

Comments
 (0)