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

Method update

code/main/Wolf.ts:48–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46
47 // update()
48 public update(): void{
49 // Calculate the distance from the player
50 var distanceFromPlayer: Pos = this.getGlobalPosition().plus(new Pos(3, 0)).getDistance(this.getQuest().getGame().getPlayer().getGlobalPosition());
51
52 // If the player is on our left
53 if(distanceFromPlayer.x > 0){
54 // We're looking left
55 this.setIsLookingLeft(true);
56 }
57 // Else, the player is on our right
58 else{
59 // We're looking right
60 this.setIsLookingLeft(false);
61 }
62
63 // If we're standing
64 if(this.isStanding){
65 // If we're not already taking the decision to run BUT the running movement would be possible
66 if(this.takeTheDecisionToRunTimer == null && this.testNewGlobalPosition(this.getGlobalPosition().plus(new Pos(this.getRunningSpeed(), 0)))){
67 // We take the decision to run by setting the timer
68 this.takeTheDecisionToRunTimer = Random.between(2, 6);
69 }
70 // Else, if we already took the decision ro run
71 else if(this.takeTheDecisionToRunTimer != null){
72 // We decrease the timer
73 this.takeTheDecisionToRunTimer -= 1;
74 // If the timer is <= 0 and the running movement would be possible
75 if(this.takeTheDecisionToRunTimer <= 0 && this.testNewGlobalPosition(this.getGlobalPosition().plus(new Pos(this.getRunningSpeed(), 0)))){
76 this.setIsStanding(false); // We run
77 this.takeTheDecisionToRunTimer = null; // Not taking any decision anymore
78 }
79 }
80 }
81 // Else, if we're running
82 else{
83 // If the running movement won't be possible next turn
84 if(this.testNewGlobalPosition(this.getGlobalPosition().plus(new Pos(this.getRunningSpeed(), 0))) == false){
85 // We stand
86 this.setIsStanding(true);
87 }
88 }
89
90 // Call the mother class update
91 super.update();
92 }
93
94 // willDie()
95 public willDie(): void{

Callers

nothing calls this directly

Calls 10

setIsLookingLeftMethod · 0.95
getRunningSpeedMethod · 0.95
setIsStandingMethod · 0.95
plusMethod · 0.80
getGlobalPositionMethod · 0.80
getPlayerMethod · 0.80
getQuestMethod · 0.80
testNewGlobalPositionMethod · 0.80
getDistanceMethod · 0.45
getGameMethod · 0.45

Tested by

no test coverage detected