Skip to content

Commit

Permalink
feat: pre-define click me asteroid initial location
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronchan32 committed Apr 7, 2024
1 parent 7d1d01d commit 75f85b0
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/components/Asteroid/Asteroid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ export default function Asteroid({ homeRef }: AsteroidProps) {
}
}, [homeRef, numAsteroids]);

const calculateClickMeInitial = () => {
const isLeft = Math.random() > 0.5;
let x, y;
if (isLeft) {
x = -Math.random() * 200 - 10;
y = Math.random() * window.innerHeight;
} else {
x = (Math.random() * window.innerWidth) / 3;
y = -Math.random() * 100 - 10;
}
return { x, y };
};

const clickMeInitial = calculateClickMeInitial();

const clickMeLocation = { x: window.innerWidth / 3 - 50, y: 100 };

const FragmentAsteroidComponents = [
Expand Down Expand Up @@ -189,7 +204,11 @@ export default function Asteroid({ homeRef }: AsteroidProps) {
key={'asteroid' + index}
className="asteroid"
onClick={() => onButtonClick(index)}
initial={asteroidAnimations[index]?.initial}
initial={
index === 0
? clickMeInitial
: asteroidAnimations[index]?.initial
}
animate={
index === 0
? clickMeLocation
Expand Down

0 comments on commit 75f85b0

Please sign in to comment.