添加支持另外2种靶纸的环数计算
This commit is contained in:
74
src/util.js
74
src/util.js
@@ -307,14 +307,14 @@ export const calcRing = (x, y, targetWidth, targetHeight) => {
|
||||
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
// 计算靶纸半径(取宽高中较小值的一半)
|
||||
const targetRadius = Math.min(targetWidth, targetHeight) / 2;
|
||||
// const targetRadius = Math.min(targetWidth, targetHeight) / 2;
|
||||
const targetRadius = targetWidth / 2;
|
||||
|
||||
// 如果距离超过靶纸半径,则脱靶
|
||||
if (distance > targetRadius) return 0;
|
||||
|
||||
// 计算相对距离(0-1之间)
|
||||
const relativeDistance = distance / targetRadius;
|
||||
|
||||
// 全环靶有10个环,每个环占半径的10%
|
||||
// 从外到内:1环到10环
|
||||
// 距离越近靶心,环数越高
|
||||
@@ -331,3 +331,73 @@ export const calcRing = (x, y, targetWidth, targetHeight) => {
|
||||
|
||||
return 0; // 脱靶
|
||||
};
|
||||
|
||||
const calcSmallBowTarget = (x, y, side) => {
|
||||
// 计算靶心坐标(靶纸中心)
|
||||
const centerX = side / 2;
|
||||
const centerY = side / 2;
|
||||
|
||||
// 计算点击点到靶心的距离
|
||||
const deltaX = x - centerX;
|
||||
const deltaY = y - centerY;
|
||||
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
// 计算靶纸半径(取宽高中较小值的一半)
|
||||
const targetRadius = side / 2;
|
||||
|
||||
// 如果距离超过靶纸半径,则脱靶
|
||||
if (distance > targetRadius) return 0;
|
||||
|
||||
// 计算相对距离(0-1之间)
|
||||
const relativeDistance = distance / targetRadius;
|
||||
if (relativeDistance <= 0.1) return "X"; // 靶心区域
|
||||
if (relativeDistance <= 0.2) return 10;
|
||||
if (relativeDistance <= 0.4) return 9;
|
||||
if (relativeDistance <= 0.6) return 8;
|
||||
if (relativeDistance <= 0.8) return 7;
|
||||
if (relativeDistance <= 1.0) return 6;
|
||||
|
||||
return 0; // 脱靶
|
||||
};
|
||||
|
||||
export const calcRing2 = (x, y, targetWidth, targetHeight) => {
|
||||
const side = targetWidth * 0.48;
|
||||
if (
|
||||
x / targetWidth >= 0.26 &&
|
||||
x / targetWidth <= 0.74 &&
|
||||
y / targetHeight <= 0.48
|
||||
) {
|
||||
return calcSmallBowTarget(x - targetWidth * 0.26, y, side);
|
||||
} else if (x / targetHeight <= 0.48 && y / targetHeight >= 0.456) {
|
||||
return calcSmallBowTarget(x, y - targetHeight * 0.456, side);
|
||||
} else if (x / targetHeight >= 0.52 && y / targetHeight >= 0.456) {
|
||||
return calcSmallBowTarget(
|
||||
x - targetWidth * 0.52,
|
||||
y - targetHeight * 0.456,
|
||||
side
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
export const calcRing3 = (x, y, targetWidth, targetHeight) => {
|
||||
const side = targetWidth * 0.325;
|
||||
if (x / targetWidth >= 0.337 && x / targetWidth <= 0.663) {
|
||||
if (y / targetHeight <= 0.325) {
|
||||
return calcSmallBowTarget(x - targetWidth * 0.337, y, side);
|
||||
} else if (y / targetHeight >= 0.335 && y / targetHeight <= 0.662) {
|
||||
return calcSmallBowTarget(
|
||||
x - targetWidth * 0.337,
|
||||
y - targetHeight * 0.335,
|
||||
side
|
||||
);
|
||||
} else if (y / targetHeight >= 0.674) {
|
||||
return calcSmallBowTarget(
|
||||
x - targetWidth * 0.337,
|
||||
y - targetHeight * 0.674,
|
||||
side
|
||||
);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user