| 242 | } |
| 243 | |
| 244 | public goTowards(ourPosition: Pos, goalPosition: Pos, minDistance: number = 0, speed: Pos = new Pos(1, 1), dontTakeYInAccount: boolean = false): void{ |
| 245 | // We create the movement |
| 246 | var movement: Pos = new Pos(0, 0); |
| 247 | |
| 248 | // We find the distance between our position and the position where we want to go |
| 249 | var distance: Pos = ourPosition.getDistance(goalPosition); |
| 250 | |
| 251 | // If the x distance is the biggest (we do /2 because characters are thin in the ascii art world!) and big enough (or if we don't take in account y) |
| 252 | if((Math.abs(distance.x)/2 > Math.abs(distance.y) && Math.abs(distance.x) > minDistance*2) || dontTakeYInAccount){ |
| 253 | if(distance.x > 0) movement.x = -speed.x; |
| 254 | else if(distance.x < 0) movement.x = speed.x; |
| 255 | } |
| 256 | // Else, the y distance is the biggest and big enough |
| 257 | else if(Math.abs(distance.y) > minDistance){ |
| 258 | if(distance.y > 0) movement.y = -speed.y; |
| 259 | else if(distance.y < 0) movement.y = speed.y; |
| 260 | } |
| 261 | |
| 262 | // We use this movement to set our quest entity movement's offset |
| 263 | this.getQuestEntityMovement().setOffset(movement); |
| 264 | } |
| 265 | |
| 266 | public heal(hp: number): void{ |
| 267 | this.setHp(this.getHp() + hp); |