完成1倍靶纸压线就算环数
This commit is contained in:
@@ -60,7 +60,6 @@ const onClick = async (e) => {
|
||||
props.id,
|
||||
newArrow.x / scale.value - rect.value.width * 0.05,
|
||||
newArrow.y / scale.value - rect.value.width * 0.05,
|
||||
rect.value.width * 0.9,
|
||||
rect.value.width * 0.9
|
||||
);
|
||||
arrow.value = {
|
||||
@@ -116,7 +115,6 @@ const onDrag = async (e) => {
|
||||
const deltaX = clientX - dragStartPos.value.x;
|
||||
const deltaY = clientY - dragStartPos.value.y;
|
||||
const side = rect.value.width;
|
||||
|
||||
// 更新坐标
|
||||
arrow.value.x = Math.max(
|
||||
0,
|
||||
@@ -126,12 +124,10 @@ const onDrag = async (e) => {
|
||||
0,
|
||||
Math.min(side * scale.value, arrow.value.y * side + deltaY)
|
||||
);
|
||||
|
||||
arrow.value.ring = calcRing(
|
||||
props.id,
|
||||
arrow.value.x / scale.value - rect.value.width * 0.05,
|
||||
arrow.value.y / scale.value - rect.value.width * 0.05,
|
||||
rect.value.width * 0.9,
|
||||
rect.value.width * 0.9
|
||||
);
|
||||
|
||||
|
||||
@@ -97,6 +97,21 @@ const loadConfig = () => {
|
||||
} else if (props.itemIndex === 2) {
|
||||
data.value = config.targetOption;
|
||||
}
|
||||
if (props.value) {
|
||||
if (props.itemIndex === 0 || props.itemIndex === 2) {
|
||||
selectedIndex.value = data.value.findIndex(
|
||||
(item) => item.name === props.value
|
||||
);
|
||||
}
|
||||
if (props.itemIndex === 1) {
|
||||
selectedIndex.value = distances.findIndex(
|
||||
(item) => item.name === props.value
|
||||
);
|
||||
if (selectedIndex.value === -1) {
|
||||
selectedIndex.value = 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
onMounted(async () => {
|
||||
|
||||
143
src/util.js
143
src/util.js
@@ -300,22 +300,28 @@ export const getElementRect = (classname) => {
|
||||
});
|
||||
};
|
||||
|
||||
const calcNormalBowTarget = (x, y, targetWidth, targetHeight) => {
|
||||
// 计算靶心坐标(靶纸中心)
|
||||
const centerX = targetWidth / 2;
|
||||
const centerY = targetHeight / 2;
|
||||
const calcNormalBowTarget = (x, y, diameter) => {
|
||||
// 弓箭直径为12px,半径为6px
|
||||
const arrowRadius = 6;
|
||||
|
||||
// 计算点击点到靶心的距离
|
||||
const deltaX = x - centerX;
|
||||
const deltaY = y - centerY;
|
||||
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
// 将弓箭左上角坐标转换为圆心坐标
|
||||
const arrowCenterX = x + arrowRadius;
|
||||
const arrowCenterY = y + arrowRadius;
|
||||
|
||||
// 计算靶心坐标(靶纸中心)
|
||||
const centerX = diameter / 2;
|
||||
const centerY = diameter / 2;
|
||||
|
||||
// 计算弓箭圆心到靶心的距离
|
||||
const deltaX = arrowCenterX - centerX;
|
||||
const deltaY = arrowCenterY - centerY;
|
||||
const distanceToCenter = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
// 计算弓箭边缘到靶心的最近距离
|
||||
const distance = Math.max(0, distanceToCenter - arrowRadius);
|
||||
|
||||
// 计算靶纸半径(取宽高中较小值的一半)
|
||||
// const targetRadius = Math.min(targetWidth, targetHeight) / 2;
|
||||
const targetRadius = targetWidth / 2;
|
||||
|
||||
// 如果距离超过靶纸半径,则脱靶
|
||||
if (distance > targetRadius) return 0;
|
||||
const targetRadius = diameter / 2;
|
||||
|
||||
// 计算相对距离(0-1之间)
|
||||
const relativeDistance = distance / targetRadius;
|
||||
@@ -332,26 +338,32 @@ const calcNormalBowTarget = (x, y, targetWidth, targetHeight) => {
|
||||
if (relativeDistance <= 0.7) return 4;
|
||||
if (relativeDistance <= 0.8) return 3;
|
||||
if (relativeDistance <= 0.9) return 2;
|
||||
if (relativeDistance <= 1.0) return 1;
|
||||
|
||||
if (relativeDistance <= 1) return 1;
|
||||
return 0; // 脱靶
|
||||
};
|
||||
|
||||
const calcHalfBowTarget = (x, y, side, noX = false) => {
|
||||
// 计算靶心坐标(靶纸中心)
|
||||
const centerX = side / 2;
|
||||
const centerY = side / 2;
|
||||
const calcHalfBowTarget = (x, y, diameter, noX = false) => {
|
||||
// 弓箭直径为12px,半径为6px
|
||||
const arrowRadius = 6;
|
||||
|
||||
// 计算点击点到靶心的距离
|
||||
const deltaX = x - centerX;
|
||||
const deltaY = y - centerY;
|
||||
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
// 将弓箭左上角坐标转换为圆心坐标
|
||||
const arrowCenterX = x + arrowRadius;
|
||||
const arrowCenterY = y + arrowRadius;
|
||||
|
||||
// 计算靶心坐标(靶纸中心)
|
||||
const centerX = diameter / 2;
|
||||
const centerY = diameter / 2;
|
||||
|
||||
// 计算弓箭圆心到靶心的距离
|
||||
const deltaX = arrowCenterX - centerX;
|
||||
const deltaY = arrowCenterY - centerY;
|
||||
const distanceToCenter = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
// 计算弓箭边缘到靶心的最近距离
|
||||
const distance = Math.max(0, distanceToCenter - arrowRadius);
|
||||
|
||||
// 计算靶纸半径(取宽高中较小值的一半)
|
||||
const targetRadius = side / 2;
|
||||
|
||||
// 如果距离超过靶纸半径,则脱靶
|
||||
if (distance > targetRadius) return 0;
|
||||
const targetRadius = diameter / 2;
|
||||
|
||||
// 计算相对距离(0-1之间)
|
||||
const relativeDistance = distance / targetRadius;
|
||||
@@ -365,62 +377,49 @@ const calcHalfBowTarget = (x, y, side, noX = false) => {
|
||||
return 0; // 脱靶
|
||||
};
|
||||
|
||||
export const calcTripleBowTarget = (
|
||||
x,
|
||||
y,
|
||||
targetWidth,
|
||||
targetHeight,
|
||||
noX = false
|
||||
) => {
|
||||
const side = targetWidth * 0.325;
|
||||
if (x / targetWidth >= 0.337 && x / targetWidth <= 0.663) {
|
||||
if (y / targetHeight <= 0.325) {
|
||||
return calcHalfBowTarget(x - targetWidth * 0.337, y, side, noX);
|
||||
} else if (y / targetHeight >= 0.335 && y / targetHeight <= 0.662) {
|
||||
export const calcTripleBowTarget = (x, y, diameter, noX = false) => {
|
||||
const side = diameter * 0.325;
|
||||
if (x / diameter >= 0.306) {
|
||||
if (y / diameter >= 0.64) {
|
||||
return calcHalfBowTarget(
|
||||
x - targetWidth * 0.337,
|
||||
y - targetHeight * 0.335,
|
||||
x - diameter * 0.342,
|
||||
y - diameter * 0.68,
|
||||
side,
|
||||
noX
|
||||
);
|
||||
} else if (y / targetHeight >= 0.674) {
|
||||
}
|
||||
if (y / diameter >= 0.304) {
|
||||
return calcHalfBowTarget(
|
||||
x - targetWidth * 0.337,
|
||||
y - targetHeight * 0.674,
|
||||
x - diameter * 0.342,
|
||||
y - diameter * 0.34,
|
||||
side,
|
||||
noX
|
||||
);
|
||||
}
|
||||
if (y / diameter >= -0.03) {
|
||||
return calcHalfBowTarget(x - diameter * 0.342, y, side, noX);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
export const calcPinBowTarget = (
|
||||
x,
|
||||
y,
|
||||
targetWidth,
|
||||
targetHeight,
|
||||
noX = false
|
||||
) => {
|
||||
const side = targetWidth * 0.48;
|
||||
if (
|
||||
x / targetWidth >= 0.26 &&
|
||||
x / targetWidth <= 0.74 &&
|
||||
y / targetWidth >= 0.032 &&
|
||||
y / targetHeight <= 0.51
|
||||
) {
|
||||
export const calcPinBowTarget = (x, y, diameter, noX = false) => {
|
||||
const side = diameter * 0.484;
|
||||
if (x / diameter >= 0.488 && y / diameter >= 0.456) {
|
||||
return calcHalfBowTarget(
|
||||
x - targetWidth * 0.26,
|
||||
y - targetHeight * 0.032,
|
||||
x - diameter * 0.52,
|
||||
y - diameter * 0.484,
|
||||
side,
|
||||
noX
|
||||
);
|
||||
} else if (x / targetHeight <= 0.48 && y / targetHeight >= 0.482) {
|
||||
return calcHalfBowTarget(x, y - targetHeight * 0.482, side, noX);
|
||||
} else if (x / targetHeight >= 0.52 && y / targetHeight >= 0.482) {
|
||||
}
|
||||
if (x / diameter >= -0.03 && y / diameter >= 0.456) {
|
||||
return calcHalfBowTarget(x, y - diameter * 0.484, side, noX);
|
||||
}
|
||||
if (x / diameter >= 0.23 && y / diameter >= 0.005) {
|
||||
return calcHalfBowTarget(
|
||||
x - targetWidth * 0.52,
|
||||
y - targetHeight * 0.482,
|
||||
x - diameter * 0.26,
|
||||
y - diameter * 0.036,
|
||||
side,
|
||||
noX
|
||||
);
|
||||
@@ -428,19 +427,19 @@ export const calcPinBowTarget = (
|
||||
return 0;
|
||||
};
|
||||
|
||||
export const calcRing = (bowtargetId, x, y, targetWidth, targetHeight) => {
|
||||
export const calcRing = (bowtargetId, x, y, diameter) => {
|
||||
if (bowtargetId < 4) {
|
||||
return calcNormalBowTarget(x, y, targetWidth, targetHeight);
|
||||
return calcNormalBowTarget(x - 2, y - 2, diameter);
|
||||
} else if (bowtargetId < 7) {
|
||||
return calcHalfBowTarget(x, y, targetWidth);
|
||||
return calcHalfBowTarget(x - 2, y - 2, diameter);
|
||||
} else if (bowtargetId === 7) {
|
||||
return calcTripleBowTarget(x, y, targetWidth, targetHeight);
|
||||
return calcTripleBowTarget(x, y, diameter);
|
||||
} else if (bowtargetId === 8) {
|
||||
return calcPinBowTarget(x, y, targetWidth, targetHeight);
|
||||
return calcPinBowTarget(x, y, diameter);
|
||||
} else if (bowtargetId === 9) {
|
||||
return calcTripleBowTarget(x, y, targetWidth, targetHeight, true);
|
||||
return calcTripleBowTarget(x, y, diameter, true);
|
||||
} else if (bowtargetId === 10) {
|
||||
return calcPinBowTarget(x, y, targetWidth, targetHeight, true);
|
||||
return calcPinBowTarget(x, y, diameter, true);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user