Skip to content

Commit

Permalink
fix(web/skillcheck): use proper skill check calculations
Browse files Browse the repository at this point in the history
Changed the areaSize to use degrees rather than the length of the arch which was causing issues

Co-authored-by: DokaDoka <[email protected]>
  • Loading branch information
LukeWasTakenn and DokaDoka committed Oct 20, 2022
1 parent 2bb0d68 commit e403310
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 12 additions & 10 deletions web/src/features/skillcheck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ export interface SkillCheckProps {
difficulty: GameDifficulty;
}

export const circleCircumference = 2 * 50 * Math.PI;

const getRandomAngle = (min: number, max: number) => Math.floor(Math.random() * (max - min)) + min;

const difficultyOffsets = {
easy: 275,
medium: 290,
hard: 295,
easy: 50,
medium: 40,
hard: 25,
};

debugData([
{
action: 'startSkillCheck',
data: [{ areaSize: 250, speedMultiplier: 2 }, 'easy', 'hard'],
data: ['hard'],
},
]);

Expand All @@ -39,7 +41,7 @@ const SkillCheck: React.FC = () => {
const dataIndexRef = useRef<number>(0);
const [skillCheck, setSkillCheck] = useState<SkillCheckProps>({
angle: 0,
difficultyOffset: 315,
difficultyOffset: 50,
difficulty: 'easy',
});

Expand All @@ -49,7 +51,7 @@ const SkillCheck: React.FC = () => {
const gameData = Array.isArray(data) ? data[0] : data;
const offset = typeof gameData === 'object' ? gameData.areaSize : difficultyOffsets[gameData];
setSkillCheck({
angle: -90 + getRandomAngle(120, 360 - (315 - offset)),
angle: -90 + getRandomAngle(120, 360 - offset),
difficultyOffset: offset,
difficulty: gameData,
});
Expand All @@ -72,7 +74,7 @@ const SkillCheck: React.FC = () => {
const data = dataRef.current[dataIndexRef.current];
const offset = typeof data === 'object' ? data.areaSize : difficultyOffsets[data];
setSkillCheck({
angle: -90 + getRandomAngle(120, 360 - (315 - offset)),
angle: -90 + getRandomAngle(120, 360 - offset),
difficultyOffset: offset,
difficulty: data,
});
Expand All @@ -91,7 +93,7 @@ const SkillCheck: React.FC = () => {
fill="transparent"
stroke="rgba(0, 0, 0, 0.4)"
strokeWidth={5}
strokeDasharray={360}
strokeDasharray={circleCircumference}
/>
{/*SkillCheck area*/}
<circle
Expand All @@ -100,8 +102,8 @@ const SkillCheck: React.FC = () => {
cy={250}
fill="transparent"
stroke="white"
strokeDasharray={315}
strokeDashoffset={skillCheck.difficultyOffset}
strokeDasharray={circleCircumference}
strokeDashoffset={circleCircumference - (Math.PI * 50 * skillCheck.difficultyOffset) / 180}
strokeWidth={5}
transform={`rotate(${skillCheck.angle}, 250, 250)`}
/>
Expand Down
8 changes: 5 additions & 3 deletions web/src/features/skillcheck/indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
import { useKeyPress } from '../../hooks/useKeyPress';
import { SkillCheckProps } from './index';
import { useInterval } from '@chakra-ui/react';
import { circleCircumference } from './index';

interface Props {
angle: number;
Expand Down Expand Up @@ -41,7 +42,8 @@ const Indicator: React.FC<Props> = ({ angle, offset, multiplier, handleComplete,
if (!isKeyPressed) return;

setGameState(false);
if (indicatorAngle < angle || indicatorAngle > angle + (315 - offset)) handleComplete(false);

if (indicatorAngle < angle || indicatorAngle > angle + offset) handleComplete(false);
else handleComplete(true);
}, [isKeyPressed]);

Expand All @@ -53,8 +55,8 @@ const Indicator: React.FC<Props> = ({ angle, offset, multiplier, handleComplete,
fill="transparent"
stroke="red"
strokeWidth={15}
strokeDasharray={315}
strokeDashoffset={312}
strokeDasharray={circleCircumference}
strokeDashoffset={circleCircumference - 3}
transform={`rotate(${indicatorAngle}, 250, 250)`}
/>
);
Expand Down

0 comments on commit e403310

Please sign in to comment.