fixed walking animation
This commit is contained in:
parent
9ee498cb07
commit
8898695506
@ -11,7 +11,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
static final int CANVAS_HEIGHT = 10;
|
static final int CANVAS_HEIGHT = 10;
|
||||||
|
|
||||||
private static boolean canPersonMove;
|
private static boolean canPersonMove;
|
||||||
private static boolean preventDoubleMove;
|
private static int nextMove;
|
||||||
private static boolean isReadyToPaint;
|
private static boolean isReadyToPaint;
|
||||||
|
|
||||||
static final int KEY_LEFT = 37;
|
static final int KEY_LEFT = 37;
|
||||||
@ -24,6 +24,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
private JLayeredPane lp;
|
private JLayeredPane lp;
|
||||||
private static Map map;
|
private static Map map;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
private Timer inputTimer;
|
||||||
|
|
||||||
public static Map getMap() {
|
public static Map getMap() {
|
||||||
return map;
|
return map;
|
||||||
@ -52,7 +53,6 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
public WindowOfFreeMove() {
|
public WindowOfFreeMove() {
|
||||||
isReadyToPaint = false;
|
isReadyToPaint = false;
|
||||||
canPersonMove = true;
|
canPersonMove = true;
|
||||||
preventDoubleMove = true;
|
|
||||||
lp = getLayeredPane();
|
lp = getLayeredPane();
|
||||||
|
|
||||||
canvas = new Canvas();
|
canvas = new Canvas();
|
||||||
@ -67,13 +67,40 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
dialogBar.setBackground(Color.BLACK);
|
dialogBar.setBackground(Color.BLACK);
|
||||||
dialogBar.setVisible(false);
|
dialogBar.setVisible(false);
|
||||||
|
|
||||||
|
inputTimer = new Timer(17, new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
if (!map.getPerson().getIsMoving()) {
|
||||||
|
map.getPerson().setDirectionMove(nextMove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e) {
|
||||||
|
if (!map.getPerson().getIsMoving()) {
|
||||||
|
map.getPerson().setDirectionMove(nextMove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
addKeyListener(new KeyAdapter() {
|
addKeyListener(new KeyAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
if (canPersonMove && !map.getPerson().getIsMoving() && preventDoubleMove) {
|
nextMove = e.getKeyCode();
|
||||||
map.getPerson().setDirectionMove(e.getKeyCode());
|
inputTimer.start();
|
||||||
|
// if (canPersonMove && !map.getPerson().getIsMoving() && preventDoubleMove) {
|
||||||
|
// map.getPerson().setDirectionMove(e.getKeyCode());
|
||||||
|
// }
|
||||||
|
// preventDoubleMove = !map.getPerson().getIsMoving();
|
||||||
}
|
}
|
||||||
preventDoubleMove = !map.getPerson().getIsMoving();
|
});
|
||||||
|
|
||||||
|
addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {
|
||||||
|
inputTimer.stop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -159,13 +186,11 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
//setCanPersonMove(false);
|
//setCanPersonMove(false);
|
||||||
// lp.add(jf, JLayeredPane.POPUP_LAYER);
|
// lp.add(jf, JLayeredPane.POPUP_LAYER);
|
||||||
|
|
||||||
timer = new Timer( 16, new ActionListener() {
|
timer = new Timer(13, new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
if (!map.getPerson().getIsMoving()) {
|
|
||||||
map.getPerson().move();
|
map.getPerson().move();
|
||||||
}
|
canvas.repaint(new Rectangle(CELL_SIZE, CELL_SIZE, CELL_SIZE * 8, CELL_SIZE * 8));
|
||||||
canvas.repaint();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user