Skip to content

Commit

Permalink
Merge pull request #271 from zstenger93/pongai
Browse files Browse the repository at this point in the history
Pongai
  • Loading branch information
zstenger93 authored Feb 5, 2024
2 parents 95f6564 + afaaa82 commit 23954ae
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions frontend/src/pages/Games/PongAi.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import handleResize from "../../components/game/HandleResize";
const GameCanvas = (aiDifficulty) => {
// Default Parameters
const defaultSpeedX = 300;
const playerSpeedIncrease = 0.5;
let playerSpeed = 5;
let resize = true;
const winScore = 10;
const defaultSpeedY = 20;
Expand Down Expand Up @@ -198,7 +200,10 @@ const GameCanvas = (aiDifficulty) => {
ballX = canvas.width - paddleWidth - 10;
ballSpeedX *= -1;
if (ballSpeedX < 0) ballSpeedX -= ballSpeedIncrease;
else ballSpeedX += ballSpeedIncrease;
else {
ballSpeedX += ballSpeedIncrease;
playerSpeed += playerSpeedIncrease;
}
ballSpeedY +=
distanceFromCenter *
ballAngleOffset *
Expand All @@ -210,18 +215,19 @@ const GameCanvas = (aiDifficulty) => {
ballSpeedX = defaultSpeedX;
ballSpeedY = defaultSpeedY;
scoreRight += 1;
playerSpeed = 5;
setScoreRight(scoreRight);
} else if (ballX - ballSize * 3 > canvas.width) {
ballX = canvas.width / 2;
ballY = canvas.height / 2;
ballSpeedX = -defaultSpeedX;
ballSpeedY = -defaultSpeedY;
scoreLeft += 1;
playerSpeed = 5;
setScoreLeft(scoreLeft);
}
};

const playerSpeed = 10;
let keys = {};

const movePaddle = () => {
Expand Down

0 comments on commit 23954ae

Please sign in to comment.