增加实时环数计算

This commit is contained in:
kron
2025-08-01 09:20:10 +08:00
parent af888c68be
commit 6798123840
3 changed files with 59 additions and 15 deletions

View File

@@ -296,7 +296,38 @@ export const getElementRect = () => {
});
};
export const calcRing = (x, y) => {
console.log(1111, x, y);
return 8;
export const calcRing = (x, y, targetWidth, targetHeight) => {
// 计算靶心坐标(靶纸中心)
const centerX = targetWidth / 2;
const centerY = targetHeight / 2;
// 计算点击点到靶心的距离
const deltaX = x - centerX;
const deltaY = y - centerY;
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
// 计算靶纸半径(取宽高中较小值的一半)
const targetRadius = Math.min(targetWidth, targetHeight) / 2;
// 如果距离超过靶纸半径,则脱靶
if (distance > targetRadius) return 0;
// 计算相对距离0-1之间
const relativeDistance = distance / targetRadius;
// 全环靶有10个环每个环占半径的10%
// 从外到内1环到10环
// 距离越近靶心,环数越高
if (relativeDistance <= 0.1) return 10; // 靶心区域
if (relativeDistance <= 0.2) return 9;
if (relativeDistance <= 0.3) return 8;
if (relativeDistance <= 0.4) return 7;
if (relativeDistance <= 0.5) return 6;
if (relativeDistance <= 0.6) return 5;
if (relativeDistance <= 0.7) return 4;
if (relativeDistance <= 0.8) return 3;
if (relativeDistance <= 0.9) return 2;
if (relativeDistance <= 1.0) return 1;
return 0; // 脱靶
};