Skip to content

Commit

Permalink
fix: 歩けるところを賢く探して歩く
Browse files Browse the repository at this point in the history
  • Loading branch information
teramotodaiki committed Jan 13, 2019
1 parent cd52d9e commit 5d5c95d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/hackforplay/object/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,11 +1287,19 @@ export default class RPGObject extends enchant.Sprite implements N.INumbers {
async mayWalkTo(movements: Vector2[], unit8 = false, prioritizeX = false) {
movements = movements.filter(vec => vec.x !== 0 || vec.y !== 0);
movements.sort((a, b) => (prioritizeX ? b.x - a.x : b.y - a.y)); // 優先されている方の差が大きい順
// ちゃんと歩けるところ探す
for (const forward of movements) {
const unit = unit8 ? forward.unit8() : forward.unit();
if (!Vector2.equal(this.forward, unit) || this.canWalk(unit)) {
if (this.canWalk(unit)) {
this.forward = unit;
await this.walk(); // とりあえず歩いてみる
await this.walk();
return;
}
}
for (const forward of movements) {
const unit = unit8 ? forward.unit8() : forward.unit();
if (!Vector2.equal(this.forward, unit)) {
this.forward = unit; // 向きだけ変える
return;
}
}
Expand Down

0 comments on commit 5d5c95d

Please sign in to comment.