Skip to content

Commit

Permalink
Merge pull request #2399 from andretchen0/hex-hitarea
Browse files Browse the repository at this point in the history
bugfix: hexes should accurately respond to pointer x, y; fixes #2253, fixes #2400
  • Loading branch information
DreadKnight committed Jul 6, 2023
2 parents 3c5cb88 + 7f6b88e commit 23d7b22
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utility/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,13 @@ export class Hex {
// Requires debug or rethink. See:
// https://github.com/FreezingMoon/AncientBeast/issues/2253
const angleStep = Math.PI / 3;
const angles = [0, 1, 2, 3, 4, 5, 6].map((i) => i * angleStep);
const [w, h] = [this.width, this.height];
const angleStart = angleStep * 0.5;
const angles = [0, 1, 2, 3, 4, 5, 6].map((i) => angleStart - i * angleStep);
// NOTE: The coefficients below are "magic".
// They don't make sense but they were tested in-game.
const [radius_w, radius_h] = [this.width * 0.6, this.height * 0.75];
const points = angles.map(
(angle) => new Point(Math.cos(angle) * w + w, Math.sin(angle) * h + h),
(angle) => new Point((Math.cos(angle) + 1) * radius_w, (Math.sin(angle) + 1) * radius_h),
);
this.container.hitArea = new Polygon(points);
}
Expand Down

1 comment on commit 23d7b22

@vercel
Copy link

@vercel vercel bot commented on 23d7b22 Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.