Skip to content

Commit

Permalink
Merge pull request #320 from zstenger93/gameFixes
Browse files Browse the repository at this point in the history
Game fixes
  • Loading branch information
Lacusch authored Apr 21, 2024
2 parents a909ecc + 33171fd commit 303deaa
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions frontend/src/pages/Games/Multiplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const GameCanvas = () => {
let playerSpeed = 5;
const otherPaddleOffset = 3;
let resize = true;
const defaultSpeedX = 300;
const defaultSpeedX = 200;
const winScore = 10;
const defaultSpeedY = 20;
const [scoreLeftReact, setScoreLeft] = useState(0);
Expand All @@ -37,8 +37,8 @@ const GameCanvas = () => {
let rightPaddleYSecound = canvasRef.current
? canvasRef.current.height / 2 - paddleHeight / 2
: 0;
let ballX = canvasRef.current ? canvasRef.current.width / 2 : 5;
let ballY = canvasRef.current ? canvasRef.current.height / 2 : 5;
let ballX = canvasRef.current ? canvasRef.current.width / 2 : 500;
let ballY = canvasRef.current ? canvasRef.current.height / 2 : 500;
let ballSpeedX = defaultSpeedX;
let ballSpeedY = defaultSpeedY;
let canvasDefaultWidth = 1920;
Expand Down Expand Up @@ -94,17 +94,17 @@ const GameCanvas = () => {
Math.abs(ballSpeedX);
// check for the collision with right paddle
} else if (
ballX < paddleWidth * otherPaddleOffset + ballSize * sizeSpeedRatio &&
ballX >
paddleWidth * (otherPaddleOffset - 1) + ballSize * sizeSpeedRatio &&
ballX <
paddleWidth * (otherPaddleOffset + 1) + ballSize * sizeSpeedRatio &&
ballX > paddleWidth * otherPaddleOffset + ballSize * sizeSpeedRatio &&
ballY > leftPaddleYSecound &&
ballY < leftPaddleYSecound + paddleHeight
) {
const leftPaddleCenterY = leftPaddleYSecound + paddleHeight / 2;
const distanceFromCenter = ballY - leftPaddleCenterY;
// eslint-disable-next-line no-unused-expressions
// eslint-disable-next-line no-unused-expressions
if (ballSpeedX > 0) paddleWidth * (otherPaddleOffset - 1) - 10;
else ballX = paddleWidth * otherPaddleOffset + 10;
else ballX = paddleWidth * (otherPaddleOffset + 1) + 10;
ballSpeedX *= -1;
// updates the balls speed in case of collusion with the paddle X speed
if (ballSpeedX < 0) ballSpeedX -= ballSpeedIncrease;
Expand Down Expand Up @@ -294,7 +294,7 @@ const GameCanvas = () => {
const touchY = event.touches[i].clientY - rect.top - window.scrollY;
// Left paddle controls
if (touch.clientX < window.innerWidth / 2) {
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
leftPaddleY = touchY - paddleHeight / 2;
leftPaddleY = Math.max(
0,
Expand All @@ -303,7 +303,7 @@ const GameCanvas = () => {
}
// Right paddle controls
else {
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
rightPaddleY = touchY - paddleHeight / 2;
rightPaddleY = Math.max(
0,
Expand Down

0 comments on commit 303deaa

Please sign in to comment.