| 52 | |
| 53 | // update() |
| 54 | public update(): void{ |
| 55 | super.update(); |
| 56 | |
| 57 | // Is the monkey angry? |
| 58 | var angry: boolean = (this.getHp() < 70 ? true : false); |
| 59 | |
| 60 | // Store the player position |
| 61 | var playerPos: Pos = this.getQuest().getGame().getPlayer().getGlobalPosition(); |
| 62 | |
| 63 | // Handle the timer |
| 64 | if(this.timer < 80) this.timer += 1; |
| 65 | else this.timer = 0; |
| 66 | |
| 67 | // Handle the big timer |
| 68 | if(this.bigTimer < 350) this.bigTimer += 1; |
| 69 | else this.bigTimer = 0; |
| 70 | |
| 71 | // Cast spells depending on the timer |
| 72 | if(this.timer == 80 || |
| 73 | this.timer == 12 || |
| 74 | this.timer == 24 || |
| 75 | this.timer == 36 || |
| 76 | this.timer == 48 || |
| 77 | (angry && this.timer == 6) || |
| 78 | (angry && this.timer == 18) || |
| 79 | (angry && this.timer == 30) || |
| 80 | (angry && this.timer == 42) || |
| 81 | (angry && this.timer == 54) |
| 82 | |
| 83 | ){ |
| 84 | this.castSpell(false); // Not stored |
| 85 | } |
| 86 | else if(this.timer == 60 || this.timer == 64 || this.timer == 68 || this.timer == 72 || this.timer == 76 && this.bigTimer < 300){ |
| 87 | this.castSpell(true); // Stored |
| 88 | } |
| 89 | |
| 90 | // If the player is near us (< 9) horizontally |
| 91 | if(Math.abs(playerPos.x - this.getGlobalPosition().x) < 9){ |
| 92 | // We jump (hoping to jump above the player) |
| 93 | this.jump3(); |
| 94 | } |
| 95 | |
| 96 | // If the player is even more near us (< 15) horizontally |
| 97 | if(Math.abs(playerPos.x - this.getGlobalPosition().x) < 15){ |
| 98 | // If we're going left |
| 99 | if(this.goingLeft){ |
| 100 | // If we're on the right of the quest |
| 101 | if(this.getGlobalPosition().x > 25) |
| 102 | this.goLeft(); |
| 103 | // Else, we're on the left, we go right |
| 104 | else{ |
| 105 | this.goRight(); |
| 106 | this.goingLeft = false; |
| 107 | } |
| 108 | } |
| 109 | // Else, if we're going right |
| 110 | else{ |
| 111 | // If the player is on the left |