MCPcopy Create free account
hub / github.com/candybox2/candybox2.github.io / handleGravity

Method handleGravity

code/main/QuestEntity.ts:669–711  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

667 }
668
669 private handleGravity(): boolean{
670 // If we're jumping, we handle jumping
671 if(this.jumping == true){
672 // Decrease the jump duration
673 this.jumpDuration -= 1;
674
675 // If this is the last jumping frame, we stop jumping and don't jump at this frame
676 if(this.jumpDuration <= 0){
677 this.jumping = false;
678 this.controlledFalling = true;
679 }
680 // Else, we try to jump
681 else{
682 // If we don't manage to jump, stop jumping
683 if(this.move(new Pos(0, -this.jumpSpeed)) == false){
684 this.jumping = false;
685 this.controlledFalling = true;
686 }
687 }
688
689 // Return false so that we can move while jumping
690 return false;
691 }
692 // Else, we try to handle gravity
693 else{
694 // If we're not affected by anti-gravity and gravity isn't disabled in the whole quest
695 if(this.antiGravity == false && this.getQuest().getGravityDisabled() == false){
696 if(this.questEntityMovement != null && this.questEntityMovement.getGravity()){
697 if(this.move(new Pos(0, 1))){
698 if(this.controlledFalling == false) return true; // If we weren't controlling our falling, then we return true because we can't move
699 }
700 else this.controlledFalling = false; // If we hit the ground above, no mroe controlled falling
701 }
702 }
703 else{
704 this.antiGravityDuration -= 1;
705 if(this.antiGravityDuration <= 0) this.antiGravity = false;
706 }
707 }
708
709 // Gravity had no effect
710 return false;
711 }
712
713 private handleMovement(): void{
714 // If we're not stopped

Callers 1

updateMethod · 0.95

Calls 4

moveMethod · 0.95
getQuestMethod · 0.95
getGravityDisabledMethod · 0.80
getGravityMethod · 0.80

Tested by

no test coverage detected