-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Jumping #2
Comments
Alright I started going down the path of "handle the action logic in the view" and that turned out to be really annoying. The view should just display stuff, not switch between actions. We should move towards a model in which we define the orc's action in the model, and then update it in the controller. |
Here's what the logic looks like to resolve the action in the View. Starts to get really gross, and I don't have enough information available to smoothly and reliably start/stop the Jump action. if(this.xDir>0 && this.yDir>0) //x+,y+: d+r
this.action=OrcImage.FORWARD_SE;
else if(this.xDir>0 && this.yDir<0)//x+,y-: u+r
this.action=OrcImage.FORWARD_NE;
else if(this.xDir<0 && this.yDir>0)//x-,y+: d+l
this.action=OrcImage.FORWARD_SW;
else if(this.xDir<0 && this.yDir<0)//x-,y-: u+l
this.action=OrcImage.FORWARD_NW;
if(!model.isMoving())
switch(this.action) {
case FORWARD_SE: this.action=OrcImage.IDLE_SE; break;
case FORWARD_NE: this.action=OrcImage.IDLE_NE; break;
case FORWARD_SW: this.action=OrcImage.IDLE_SW; break;
case FORWARD_NW: this.action=OrcImage.IDLE_NW; break;
}
if(model.isJumping()) {
this.picNum = 0;
switch(this.action) {
case FORWARD_SE: this.action=OrcImage.JUMP_SE; break;
case FORWARD_NE: this.action=OrcImage.JUMP_NE; break;
case FORWARD_SW: this.action=OrcImage.JUMP_SW; break;
case FORWARD_NW: this.action=OrcImage.JUMP_NW; break;
}
if((this.picNum+1)==this.action.frameCount()) {
model.toggleJumping();
switch(this.action) {
case JUMP_SE: this.action=OrcImage.FORWARD_SE; break;
case JUMP_NE: this.action=OrcImage.FORWARD_NE; break;
case JUMP_SW: this.action=OrcImage.FORWARD_SW; break;
case JUMP_NW: this.action=OrcImage.FORWARD_NW; break;
}
}
} You can see I sort of hackily depend on this.picNum and it's gross. We should look into better ways to time the jump animation. |
Implement an ActionPerformed method so that the orc animation switches to "jump" (for the duration of the jump animation) when the "J" key is pressed.
This might involved refactoring the Model/View such that the actions aren't set in the View (based on the model) but rather in the Model itself. Need to discuss the best possible solution here.
Right now you can see that the orc's action is determined in the View's update method. Is this wrong? Should we determine the orc's action in the model update method?
If we choose to keep the orc's action in the View, then we can simply set a flag in the model (e.g. model.isJumping).
Another thing to note is that the Jump animation takes some amount of time that we don't necessarily know offhand. We should consider some way to keep a tick-counter in the model so we can determine when the jump action should be turned off.
The text was updated successfully, but these errors were encountered: