增加实时环数计算
This commit is contained in:
37
src/util.js
37
src/util.js
@@ -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; // 脱靶
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user