Skip to content

Commit

Permalink
Improve font spacing and collision check
Browse files Browse the repository at this point in the history
  • Loading branch information
berkerol committed Dec 13, 2020
1 parent 9866c0f commit a3491c9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions typer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global canvas ctx animation:writable gameLoop label loop paintCircle isIntersectingRectangleWithRectangle generateRandomNumber generateRandomCharCode paintParticles createParticles processParticles */
/* global canvas ctx animation:writable gameLoop label loop paintCircle isIntersectingRectangleWithCircle generateRandomNumber generateRandomCharCode paintParticles createParticles processParticles */
let score = 0;
let lives = 10;
let caseSensitive = true;
Expand All @@ -11,16 +11,19 @@ const center = {
};

const letter = {
font: '20px Arial',
font: '25px Monospace',
color: '#0095DD',
size: 30,
width: 15,
height: 20,
highestSpeed: 1.6,
lowestSpeed: 0.6,
probability: 0.02
};

let letters = [];

ctx.font = label.font;
letter.width = ctx.measureText('0').width;
document.addEventListener('keydown', keyDownHandler);
document.addEventListener('keyup', keyUpHandler);
window.addEventListener('resize', resizeHandler);
Expand Down Expand Up @@ -62,7 +65,7 @@ function createLetters () {

function removeLetters (frames) {
for (const l of letters) {
if (isIntersectingRectangleWithRectangle(l, letter.size, letter.size, center, center.radius, center.radius)) {
if (isIntersectingRectangleWithCircle({ x: l.x, y: l.y - letter.height }, letter.width, letter.height, center, center.radius)) {
if (--lives === 0) {
window.alert('GAME OVER!');
window.location.reload(false);
Expand Down

0 comments on commit a3491c9

Please sign in to comment.