From 3437681a44f0a8f19b1b9465384fb965dbc19473 Mon Sep 17 00:00:00 2001 From: yena <50291995+nyj001012@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:10:47 +0900 Subject: [PATCH 1/9] =?UTF-8?q?refactor(games):=20=EA=B3=B5=EC=9D=B4=20?= =?UTF-8?q?=ED=8A=95=EA=B8=B8=20=EB=95=8C,=20=EB=B3=B4=EC=A0=95=EC=B9=98?= =?UTF-8?q?=20=EA=B3=84=EC=88=98=EC=9D=98=20=EC=B5=9C=EB=8C=80=EA=B0=92?= =?UTF-8?q?=EA=B3=BC=20=EC=B5=9C=EC=86=8C=EA=B0=92=EC=9D=84=20=EC=9D=B8?= =?UTF-8?q?=EC=9E=90=EB=A1=9C=20=EB=B0=9B=EC=95=84=EC=98=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/local-game/page.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/local-game/page.js b/frontend/src/pages/local-game/page.js index 88d59a38..f0e582fe 100644 --- a/frontend/src/pages/local-game/page.js +++ b/frontend/src/pages/local-game/page.js @@ -204,8 +204,10 @@ export default function LocalGame($container, info = null) { const moveBall = () => { if (isBallInsideBar(bar1, ball) || isBallInsideBar(bar2, ball)) { bounce(true, false); + bounce(true, false, 0.99, 1.01); } else if (isBallHitWall(canvas, ball)) { bounce(false, true); + bounce(false, true, 0.99, 1.01); } else { isBounced = false; } @@ -331,18 +333,20 @@ export default function LocalGame($container, info = null) { * 공이 벽에 부딪혔을 때 방향을 바꾸는 함수 * @param bounceX {boolean} x축으로 부딪혔는지 여부 * @param bounceY {boolean} y축으로 부딪혔는지 여부 + * @param cMin {number} 보정치 계수의 최소값 + * @param cMax {number} 보정치 계수의 최대값 */ - const bounce = (bounceX, bounceY) => { + const bounce = (bounceX, bounceY, cMin, cMax) => { if (bounceX && !isBounced) { [ball.direction.x, ball.direction.y] = normalizeVector( - ball.direction.x * -1 * getRandomCoefficient(0.99, 1.01), + ball.direction.x * -1 * getRandomCoefficient(cMin, cMax), ball.direction.y, ); isBounced = true; } else if (bounceY && !isBounced) { [ball.direction.x, ball.direction.y] = normalizeVector( ball.direction.x, - ball.direction.y * -1 * getRandomCoefficient(0.99, 1.01), + ball.direction.y * -1 * getRandomCoefficient(cMin, cMax), ); isBounced = true; } From cf1283bf3fcec0d7475fe41e42dbf172a7f5fe4d Mon Sep 17 00:00:00 2001 From: yena <50291995+nyj001012@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:25:44 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat(games):=20=EA=B3=B5=EC=9D=B4=20?= =?UTF-8?q?=EB=B2=BD=EC=97=90=20=EC=97=B0=EC=86=8D=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=ED=8A=95=EA=B8=B8=20=EB=95=8C=206=EB=B2=88=20=ED=8A=95?= =?UTF-8?q?=EA=B8=B0=EB=A9=B4=20x=EB=B0=A9=ED=96=A5=20=EB=9E=9C=EB=8D=A4?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=ED=81=AC=EA=B8=B0=20=EB=8A=98=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/local-game/page.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/local-game/page.js b/frontend/src/pages/local-game/page.js index f0e582fe..e788a98c 100644 --- a/frontend/src/pages/local-game/page.js +++ b/frontend/src/pages/local-game/page.js @@ -203,11 +203,16 @@ export default function LocalGame($container, info = null) { const moveBall = () => { if (isBallInsideBar(bar1, ball) || isBallInsideBar(bar2, ball)) { - bounce(true, false); bounce(true, false, 0.99, 1.01); + hitCountOfWall = 0; } else if (isBallHitWall(canvas, ball)) { - bounce(false, true); - bounce(false, true, 0.99, 1.01); + hitCountOfWall++; + if (hitCountOfWall % 6 === 5) { + ball.direction.x *= getRandomCoefficient(2, 5); + bounce(false, true, 0.99, 1.01); + } else { + bounce(false, true, 0.99, 1.01); + } } else { isBounced = false; } From 639b93569bc99358d5c96a74293f000a68bb14d1 Mon Sep 17 00:00:00 2001 From: yena <50291995+nyj001012@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:26:10 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat(games):=20moveBallEventId=EB=A5=BC=20t?= =?UTF-8?q?his=EB=A1=9C=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/local-game/page.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/local-game/page.js b/frontend/src/pages/local-game/page.js index e788a98c..1936e053 100644 --- a/frontend/src/pages/local-game/page.js +++ b/frontend/src/pages/local-game/page.js @@ -226,9 +226,9 @@ export default function LocalGame($container, info = null) { pause(1000); } drawFunction(bar1, bar2, ball); - let moveBallEventId = window.requestAnimationFrame(moveBall); + this.moveBallEventId = window.requestAnimationFrame(moveBall); if (getScore().player1 + getScore().player2 >= 5) { - cancelAnimationFrame(moveBallEventId); + cancelAnimationFrame(this.moveBallEventId); // 게임 종료 if (info.finalPlayer1 === null) { info.finalPlayer1 = From 15c2994424dce9d54f19f5efbf3a92119cd35e41 Mon Sep 17 00:00:00 2001 From: yena <50291995+nyj001012@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:27:06 +0900 Subject: [PATCH 4/9] =?UTF-8?q?refactor(games):=20bounce=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20=EB=A1=A4=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/local-game/page.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/local-game/page.js b/frontend/src/pages/local-game/page.js index 1936e053..af65a190 100644 --- a/frontend/src/pages/local-game/page.js +++ b/frontend/src/pages/local-game/page.js @@ -3,6 +3,7 @@ import scoreBar from "./scoreBar.js"; import toast from "./toast.js"; import { navigate } from "../../utils/navigate.js"; import deepCopy from "../../utils/deepCopy.js"; + /** * * @param {HTMLElement} $container @@ -40,6 +41,7 @@ export default function LocalGame($container, info = null) { clearInterval(this.timeIntervalId); cancelAnimationFrame(this.gameAnimationId); cancelAnimationFrame(this.barAnimationId); + cancelAnimationFrame(this.moveBallEventId); document.querySelector("#header").style.display = "block"; document.removeEventListener("keydown", keyEventHandler); }; @@ -200,18 +202,19 @@ export default function LocalGame($container, info = null) { */ const runGame = (canvas, bar1, bar2, ball, drawFunction) => { let isBounced = false; + let hitCountOfWall = 0; const moveBall = () => { if (isBallInsideBar(bar1, ball) || isBallInsideBar(bar2, ball)) { - bounce(true, false, 0.99, 1.01); + bounce(true, false); hitCountOfWall = 0; } else if (isBallHitWall(canvas, ball)) { hitCountOfWall++; if (hitCountOfWall % 6 === 5) { ball.direction.x *= getRandomCoefficient(2, 5); - bounce(false, true, 0.99, 1.01); + bounce(false, true); } else { - bounce(false, true, 0.99, 1.01); + bounce(false, true); } } else { isBounced = false; @@ -338,20 +341,18 @@ export default function LocalGame($container, info = null) { * 공이 벽에 부딪혔을 때 방향을 바꾸는 함수 * @param bounceX {boolean} x축으로 부딪혔는지 여부 * @param bounceY {boolean} y축으로 부딪혔는지 여부 - * @param cMin {number} 보정치 계수의 최소값 - * @param cMax {number} 보정치 계수의 최대값 */ - const bounce = (bounceX, bounceY, cMin, cMax) => { + const bounce = (bounceX, bounceY) => { if (bounceX && !isBounced) { [ball.direction.x, ball.direction.y] = normalizeVector( - ball.direction.x * -1 * getRandomCoefficient(cMin, cMax), + ball.direction.x * -1 * getRandomCoefficient(0.99, 1.01), ball.direction.y, ); isBounced = true; } else if (bounceY && !isBounced) { [ball.direction.x, ball.direction.y] = normalizeVector( ball.direction.x, - ball.direction.y * -1 * getRandomCoefficient(cMin, cMax), + ball.direction.y * -1 * getRandomCoefficient(0.99, 1.01), ); isBounced = true; } @@ -372,6 +373,7 @@ export default function LocalGame($container, info = null) { normalizeVector(ball.direction.x, ball.direction.y); ball.speed = BALL_SPEED; isBounced = false; + hitCountOfWall = 0; }; /** From 394639e60737d0c99aaf6c66e32e3a1b06bdac6a Mon Sep 17 00:00:00 2001 From: yena <50291995+nyj001012@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:30:55 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat(games):=20=EB=B0=A9=ED=96=A5=EB=B2=A1?= =?UTF-8?q?=ED=84=B0=20y=20=EC=84=B1=EB=B6=84=EC=9D=B4=200.001=EB=B3=B4?= =?UTF-8?q?=EB=8B=A4=20=EC=9E=91=EC=9D=84=20=EB=95=8C=20hitCountOfWall=20?= =?UTF-8?q?=EC=A6=9D=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/local-game/page.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/local-game/page.js b/frontend/src/pages/local-game/page.js index af65a190..4db3e421 100644 --- a/frontend/src/pages/local-game/page.js +++ b/frontend/src/pages/local-game/page.js @@ -209,7 +209,9 @@ export default function LocalGame($container, info = null) { bounce(true, false); hitCountOfWall = 0; } else if (isBallHitWall(canvas, ball)) { - hitCountOfWall++; + Math.abs(ball.direction.y) * 1000 === 0 + ? hitCountOfWall++ + : hitCountOfWall; if (hitCountOfWall % 6 === 5) { ball.direction.x *= getRandomCoefficient(2, 5); bounce(false, true); From 83d2fed1fe975ecc1f235e866a91a3f4a09d1f89 Mon Sep 17 00:00:00 2001 From: yena <50291995+nyj001012@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:32:36 +0900 Subject: [PATCH 6/9] =?UTF-8?q?feat(games):=20=EB=B0=A9=ED=96=A5=EB=B2=A1?= =?UTF-8?q?=ED=84=B0=20x=20=EC=84=B1=EB=B6=84=EC=9D=B4=200.001=EB=B3=B4?= =?UTF-8?q?=EB=8B=A4=20=EC=9E=91=EC=9D=84=20=EB=95=8C=20hitCountOfWall=20?= =?UTF-8?q?=EC=A6=9D=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/local-game/page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/local-game/page.js b/frontend/src/pages/local-game/page.js index 4db3e421..ddde5eb3 100644 --- a/frontend/src/pages/local-game/page.js +++ b/frontend/src/pages/local-game/page.js @@ -209,7 +209,7 @@ export default function LocalGame($container, info = null) { bounce(true, false); hitCountOfWall = 0; } else if (isBallHitWall(canvas, ball)) { - Math.abs(ball.direction.y) * 1000 === 0 + Math.abs(ball.direction.x) * 1000 === 0 ? hitCountOfWall++ : hitCountOfWall; if (hitCountOfWall % 6 === 5) { From b9e7099dab6c184cbdece4fd89e3cdbbd05f1da9 Mon Sep 17 00:00:00 2001 From: yena <50291995+nyj001012@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:34:50 +0900 Subject: [PATCH 7/9] =?UTF-8?q?feat(games):=20=EB=B0=A9=ED=96=A5=EB=B2=A1?= =?UTF-8?q?=ED=84=B0=20x=20=EC=84=B1=EB=B6=84=EC=9D=B4=200.01=EB=B3=B4?= =?UTF-8?q?=EB=8B=A4=20=EC=9E=91=EC=9D=84=20=EB=95=8C=20hitCountOfWall=20?= =?UTF-8?q?=EC=A6=9D=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/local-game/page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/local-game/page.js b/frontend/src/pages/local-game/page.js index ddde5eb3..edb99c6e 100644 --- a/frontend/src/pages/local-game/page.js +++ b/frontend/src/pages/local-game/page.js @@ -209,7 +209,7 @@ export default function LocalGame($container, info = null) { bounce(true, false); hitCountOfWall = 0; } else if (isBallHitWall(canvas, ball)) { - Math.abs(ball.direction.x) * 1000 === 0 + Math.abs(ball.direction.x) * 100 === 0 ? hitCountOfWall++ : hitCountOfWall; if (hitCountOfWall % 6 === 5) { From 090352c028ac072f875652995a63cc097a83fbba Mon Sep 17 00:00:00 2001 From: yena <50291995+nyj001012@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:54:41 +0900 Subject: [PATCH 8/9] =?UTF-8?q?feat(games):=20=EB=B0=A9=ED=96=A5=EB=B2=A1?= =?UTF-8?q?=ED=84=B0=20x=20=EC=84=B1=EB=B6=84=EC=9D=98=20=ED=81=AC?= =?UTF-8?q?=EA=B8=B0=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EA=B3=84=EC=88=98=20?= =?UTF-8?q?=EA=B0=80=EC=82=B0=20=EB=B6=84=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/local-game/page.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/local-game/page.js b/frontend/src/pages/local-game/page.js index edb99c6e..1c550f08 100644 --- a/frontend/src/pages/local-game/page.js +++ b/frontend/src/pages/local-game/page.js @@ -209,12 +209,13 @@ export default function LocalGame($container, info = null) { bounce(true, false); hitCountOfWall = 0; } else if (isBallHitWall(canvas, ball)) { - Math.abs(ball.direction.x) * 100 === 0 - ? hitCountOfWall++ - : hitCountOfWall; - if (hitCountOfWall % 6 === 5) { - ball.direction.x *= getRandomCoefficient(2, 5); + Math.abs(ball.direction.x) <= 0.2 ? hitCountOfWall++ : hitCountOfWall; + if (hitCountOfWall % 5 === 4) { + Math.abs(ball.direction.x) <= 0.01 + ? (ball.direction.x *= getRandomCoefficient(60, 80)) + : (ball.direction.x *= getRandomCoefficient(3, 4)); bounce(false, true); + hitCountOfWall = 0; } else { bounce(false, true); } From 903dd34964a9b4b53db6595c0dc1b70a669dfc4e Mon Sep 17 00:00:00 2001 From: yena <50291995+nyj001012@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:03:54 +0900 Subject: [PATCH 9/9] =?UTF-8?q?feat(games):=20=EA=B2=8C=EC=9E=84=20?= =?UTF-8?q?=EB=A6=AC=EC=85=8B=20=EC=8B=9C,=20=EB=B0=A9=ED=96=A5=EB=B2=A1?= =?UTF-8?q?=ED=84=B0=EC=9D=98=20=EC=B4=88=EA=B8=B0=EA=B0=92=EC=9D=84=20?= =?UTF-8?q?=ED=8A=B9=EC=A0=95=20=EB=B2=94=EC=9C=84=20=EB=82=B4=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=95=A0=EB=8B=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/local-game/page.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/local-game/page.js b/frontend/src/pages/local-game/page.js index 1c550f08..f3b01142 100644 --- a/frontend/src/pages/local-game/page.js +++ b/frontend/src/pages/local-game/page.js @@ -370,8 +370,8 @@ export default function LocalGame($container, info = null) { ball.x = canvas.width / 2; ball.y = canvas.height / 2; ball.direction = { - x: Math.random() * 2 - 1, - y: Math.random() * 2 - 1, + x: (Math.random() * 2 - 1) * getRandomCoefficient(0.7, 0.9), + y: (Math.random() * 2 - 1) * getRandomCoefficient(0.7, 0.9), }; normalizeVector(ball.direction.x, ball.direction.y); ball.speed = BALL_SPEED;