-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.java
72 lines (65 loc) · 1.99 KB
/
Controller.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Controller{
private static Model model;
private static View view;
public static Timer t;
private static Timer tJumpFire;
final int drawDelay = 75; //msec
final int drawDelayJumpFire = 25;
private Action drawAction;
private Action drawActionJumpFire;
private int actionCtr = 0;
public Controller(){
view = new View();
model = new Model(view.getWidth(), view.getHeight(), view.getImageWidth(), view.getImageHeight());
drawAction = new AbstractAction(){
public void actionPerformed(ActionEvent e){
model.setDirect(view.getDir());
if (view.getActionJumpFire()) {
t.stop();
tJumpFire.start();
} else {
model.updateLocationAndDirection();
view.update(model.getX(), model.getY(), model.getDirect());
view.drawPanel();
}
}
};
drawActionJumpFire = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (actionCtr++ == 7) {
t.start();
tJumpFire.stop();
model.setDirect(view.getDirFromJumpFire(view.getDir()));
model.updateLocationAndDirection();
view.update(model.getX(), model.getY(), model.getDirect());
view.drawPanel();
view.setActionJumpFire(false);
actionCtr = 0;
}
if (view.getActionJumpFire()) {
model.setDirect(view.getDir());
model.updateLocationAndDirection();
view.update(model.getX(), model.getY(), model.getDirect());
view.drawPanel();
}
}
};
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
Controller ctrllr = new Controller();
t = new Timer(ctrllr.drawDelay, ctrllr.drawAction);
tJumpFire = new Timer(ctrllr.drawDelayJumpFire, ctrllr.drawActionJumpFire);
t.start();
}
});
}
}