-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelUpdateLogic.java
More file actions
72 lines (61 loc) · 2.18 KB
/
ModelUpdateLogic.java
File metadata and controls
72 lines (61 loc) · 2.18 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Arvin:
* ModelUpdateLogic class holds all methods pertaining to updating
* the model. Controller should now call this class's updateLocationAndDirection()
* to update values in Model
*/
public class ModelUpdateLogic {
private Model model;
public ModelUpdateLogic(Model m) {
this.model = m;
}
private int jumpStart=-1;
private int fireStart=-1;
public void updateLocationAndDirection(int tick_counter){ // move logic out of model into controller
//if(!isMoving) return;
//jump action needs to pre-empt like everything else...
if(!model.getIsMoving()) {
model.setAction(OrcImage.idle(model.getOrcDir()));
return;
} else {
model.setAction(OrcImage.forward(model.getOrcDir()));
}
if((model.getX()+model.getImageWidth()>model.getWidth()) || model.getX()<0)
model.setXDir(-1);
if((model.getY()+model.getImageHeight()>model.getHeight()) || model.getY()<0)
model.setYDir(-1);
model.setX(model.getXIncr()*model.getXDir());
model.setY(model.getYIncr()*model.getYDir());
if(model.getXDir()>0 && model.getYDir()>0) //x+,y+: d+r
model.setOrcDir(Direction.SOUTHEAST);
else if(model.getXDir()>0 && model.getYDir()<0)//x+,y-: u+r
model.setOrcDir(Direction.NORTHEAST);
else if(model.getXDir()<0 && model.getYDir()>0)//x-,y+: d+l
model.setOrcDir(Direction.SOUTHWEST);
else if(model.getXDir()<0 && model.getYDir()<0)//x-,y-: u+l
model.setOrcDir(Direction.NORTHWEST);
if(model.getIsJumping()) {
model.setAction(OrcImage.jump(model.getOrcDir()));
if(jumpStart<0) //start the animation timer
jumpStart=tick_counter;
if(tick_counter >= jumpStart+model.getAction().frameCount()) { //if enough time has passed for a jump
model.toggleJumping(); //toggle the animation flag
jumpStart=-1; // reset the animation timer
}
}
if(model.getIsFire()) { // Arvin : moved Dan's fire update code from Model into ModelUpdateLogic
model.setAction(OrcImage.fire(model.getOrcDir()));
model.setXIncr(0);
model.setYIncr(0);
if(fireStart<0) {
fireStart=tick_counter;
}
if(tick_counter >= fireStart+model.getAction().frameCount()) {
model.toggleFire();
fireStart=-1;
model.setXIncr(8);
model.setYIncr(2);
}
}
}
}