-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
52 lines (39 loc) · 1.38 KB
/
Controller.java
File metadata and controls
52 lines (39 loc) · 1.38 KB
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
import java.awt.EventQueue;
import javax.swing.Timer;
import javax.swing.AbstractAction;
import javax.swing.Action;
import java.awt.event.ActionEvent;
public class Controller{
private Model model;
private View view;
final int drawDelay = 30; //msec
Action drawOrc;
public Controller() {
view = new View();
model = new Model(view.getWidth(), view.getHeight() - (view.getButtonHeight() * 3), view.getImageWidth(), view.getImageHeight());
drawOrc = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
animate();
}
};
}
//run the simulation
public void animate() {
if(view.isUpdating()){
//increment the x and y coordinates, alter direction if necessary
model.updateLocationAndDirection(view.isLeftCBSelected(), view.isRightCBSelected(), view.isUpCBSelected(), view.isDownCBSelected(), view.isFiring(), view.isJumping());
//update the view
view.update(model.getX(), model.getY(), model.getDirect(), model.getFireDirect(), model.getJumpDirect());
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
Controller controller = new Controller();
Timer t = new Timer(controller.drawDelay, controller.drawOrc);
t.start();
}
});
}
}