Skip to content

Commit 22611aa

Browse files
Fixed ball positioning and removed randomness to prevent loops early on
1 parent 1a972a7 commit 22611aa

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

index.html

+8-17
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@
162162
}
163163
}
164164

165-
day.ball.x = Ball.RADIUS + Math.ceil(numSquaresX / 4) * Square.SIZE;
166-
day.ball.y = Ball.RADIUS + Math.floor(numSquaresY / 2) * Square.SIZE;
167-
day.ball.dx = getRandomSign();
168-
day.ball.dy = getRandomSign();
165+
day.ball.x = (numSquaresX / 4) * Square.SIZE;
166+
day.ball.y = (numSquaresY / 4) * Square.SIZE;
167+
day.ball.dx = 1;
168+
day.ball.dy = 1;
169169

170-
night.ball.x = Ball.RADIUS + Math.floor(3 * numSquaresX / 4) * Square.SIZE;
171-
night.ball.y = Ball.RADIUS + Math.floor(numSquaresY / 2) * Square.SIZE;
172-
night.ball.dx = getRandomSign();
173-
night.ball.dy = getRandomSign();
170+
night.ball.x = (3 * numSquaresX / 4) * Square.SIZE;
171+
night.ball.y = (3 * numSquaresY / 4) * Square.SIZE;
172+
night.ball.dx = -1;
173+
night.ball.dy = 1;
174174

175175
function calculateDistance(p1, p2) {
176176
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2))
@@ -271,15 +271,6 @@
271271
}
272272
}
273273

274-
function getRandomSign() {
275-
return Math.sign(Math.random() - 0.5);
276-
}
277-
278-
function getRandomIntInRange(start, end) {
279-
let randomFloatInRange = start + Math.random() * (end - start + 1);
280-
return Math.floor(randomFloatInRange);
281-
}
282-
283274
function drawBall(team) {
284275
ctx.beginPath();
285276
ctx.arc(team.ball.x, team.ball.y, Ball.RADIUS, 0, Math.PI * 2, false);

0 commit comments

Comments
 (0)