Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onTouchesBegan = async ({ pageX: x, pageY: y }) => {
if (this.gameEnded) {
this.gameEnded = false;
dispatch.score.reset();
dispatch.game.play();
} else if (Math.round(randomRange(0, 3)) === 0) {
// this.takeScreenshot();
}
this.moveSquare();
};
const cloudHighScore = data.score || 0;
console.log('cloud score', cloudHighScore);
if (Settings.isEveryScoreBest || highScore > cloudHighScore) {
transaction.update(docRef, {
score: highScore,
timestamp: Date.now(),
displayName: _displayName,
photoURL: photoURL || '',
});
} else {
transaction.update(docRef, {
...data,
displayName: _displayName,
photoURL: photoURL || '',
});
dispatch.score.setBest(cloudHighScore);
}
}));
console.log('Successfully wrote score');
if (this.taps % 3 === 0) {
this.animateBackgroundColor(this.taps);
}
if (!this.loaded) {
return;
}
const distanceFromTarget = distance(
this.balls[this.mainBall].position,
this.targets[1].position,
);
if (distanceFromTarget < Settings.epsilon) {
const perfection = 1 - distanceFromTarget / Settings.epsilon;
dispatch.game.play();
dispatch.score.increment();
this.score += 1;
this.runHapticsWithValue(perfection);
if (this.particles) {
this.particles.impulse();
}
this.balls[this.mainBall].x = this.targets[1].x;
this.balls[this.mainBall].z = this.targets[1].z;
this.generateDirection();
const target = this.targets.shift();
if (this.currentTarget) this.currentTarget.updateDirection(this.direction);
target.animateOut();
reset: (props, { score }) => {
if (Settings.isFirebaseEnabled) {
if (Settings.isEveryScoreBest) {
dispatch.score.setHighScore(score.current);
} else if (score.isBest) {
dispatch.score.setHighScore(score.best);
}
}
dispatch.score._reset();
},
setHighScore: async (highScore, { user: { displayName, photoURL } }) => {
scorePoint = () => {
AudioManager.sharedInstance.playAsync(
'pop_0' + Math.round(randomRange(0, 1)),
);
dispatch.score.increment();
};
gameOver = (animate = true) => {
this.takeScreenshot();
this.screenShotTaken = false;
dispatch.score.reset();
this.score = 0;
dispatch.game.menu();
this.cachedRotationVelocity = 0;
if (animate) {
this.balls[this.mainBall].hide({ onComplete: () => this.reset() });
this.balls[1 - this.mainBall].hide({ duration: 0.4 });
for (const target of this.targets) {
target.animateOut();
}
} else {
this.reset();
}
};