添加支持另外2种靶纸的环数计算
This commit is contained in:
@@ -29,7 +29,7 @@ const onClick = async (e) => {
|
||||
newArrow.x,
|
||||
newArrow.y,
|
||||
rect.value.width * 0.9,
|
||||
rect.value.width * 0.9
|
||||
rect.value.height - rect.value.top
|
||||
);
|
||||
arrow.value = newArrow;
|
||||
};
|
||||
@@ -66,17 +66,13 @@ const onDrag = async (e) => {
|
||||
const deltaX = clientX - dragStartPos.value.x;
|
||||
const deltaY = clientY - dragStartPos.value.y;
|
||||
|
||||
const length = rect.value.width * 0.9;
|
||||
const width = rect.value.width * 0.9;
|
||||
const height = rect.value.height - rect.value.top;
|
||||
|
||||
// 更新坐标
|
||||
arrow.value.x = Math.max(0, Math.min(length, arrow.value.x + deltaX));
|
||||
arrow.value.y = Math.max(0, Math.min(length, arrow.value.y + deltaY));
|
||||
arrow.value.ring = calcRing(
|
||||
arrow.value.x,
|
||||
arrow.value.y,
|
||||
rect.value.width * 0.9,
|
||||
rect.value.width * 0.9
|
||||
);
|
||||
arrow.value.x = Math.max(0, Math.min(width, arrow.value.x + deltaX));
|
||||
arrow.value.y = Math.max(0, Math.min(height, arrow.value.y + deltaY));
|
||||
arrow.value.ring = calcRing(arrow.value.x, arrow.value.y, width, height);
|
||||
|
||||
// 更新拖拽起始位置
|
||||
dragStartPos.value = { x: clientX, y: clientY };
|
||||
@@ -101,7 +97,6 @@ onMounted(async () => {
|
||||
@touchend="endDrag"
|
||||
>
|
||||
<image src="../static/bow-target.png" mode="widthFix" />
|
||||
|
||||
<view
|
||||
v-for="(arrow, index) in arrows"
|
||||
:key="index"
|
||||
|
||||
BIN
src/static/bow-target2.png
Normal file
BIN
src/static/bow-target2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
BIN
src/static/bow-target3.png
Normal file
BIN
src/static/bow-target3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
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