Skip to content

Commit

Permalink
fix: local 게임 버그 발견 (GunGonGamLee#432)
Browse files Browse the repository at this point in the history
* fix(in-game): 공 속도 상수값 부여 방식 변경

* feat(in-game): 맨 처음 공만 따로 초기화하는 것이 아닌 reset() 함수 호출

* feat(in-game): 공 부딪혔는지 검사하는 조건 추가

* feat(in-game): 랜덤 계수 구하는 로직 수정

* chore(in-game): 불필요한 console.log 제거

* feat: local-game score bar 아바타 대신 닉네임으로 변경

* chore: in-game 이름 local-game으로 변경해줌

* feat: button viewport로

* feat: local-game으로 페이지 이름 변경

* feat: add TODO

* feat: 구글 로그인 URI / 인트라 42 URI 수정함

* fix: 게임 멀티스레딩 GunGonGamLee#312

* fix: 키보드 입력 버그 해결 GunGonGamLee#312

* chore: log 입력

* feat: is_final 변수 생성

* fix: 점수 버그 GunGonGamLee#312

* fix: 버그 수정 GunGonGamLee#312

* chore: log 삭제

* feat: 키보드 입력 GunGonGamLee#312

* feat: 키보드 lock GunGonGamLee#312

* feat: pvp 게임 도중 나갔을 때 처리 GunGonGamLee#312

* chore: 속도 처리

* chore: info를 받는 페이지 새로고침 처리 / online-game에서 game-end 처리 (GunGonGamLee#415)

* chore: add TODO

* feat: 새로고침 시 game-mode로 이동

* feat: game_end 소켓메시지 처리

* chore: add TODO

* feat: docker에서 redoc 사용 가능하게 함 (GunGonGamLee#416)

* build: 백엔드 컨테이너에 프론트엔드의 아바타 폴더 볼륨 연결

- 아바타 업로드를 위함

* build: 백엔드 static 파일은 nginx에 연결

* build: static_volume 대신 backend static 볼륨 마운트

* feat: debug = False여도 redoc은 동작하게 함

* build: init.sh 파일 실행 위치 변경

- backend.src 모듈을 못 찾는 관계로 init.sh을 컨테이너의 루트가 아닌 backend 폴더의 루트로 옮김

* build: 백엔드 daphne 설정 시 필요한 .env 복사

* build: env path 수정

- env path를 기존 /backend/../.env에서 /.env로 수정

* build: static-volume으로 백엔드 static 파일 관리

* chore: 로그 삭제

* fix: 고정 값 choices로 통합

* feat: 응답 데이터 추가 GunGonGamLee#312

* fix: 고정 값 수정

* chore: 로그 삭제

* chore: 값 수정

* refactor: 코드 리팩토링 GunGonGamLee#312

* feat: 게임 프레임 관리 GunGonGamLee#312

* fix: 함수명 변경 GunGonGamLee#312

* fix: 안 쓰는 함수 삭제

* fix: 리팩토링 에러 해결 GunGonGamLee#312

* feat: 값 변경, 프레임 설정 GunGonGamLee#312

* Update backend/games/consumers/GameConsumer.py

ㄱㅅ

Co-authored-by: Sejoon Kim <[email protected]>

* Update backend/games/consumers/GameConsumer.py

ㄱㅅㄱㅅ

Co-authored-by: Sejoon Kim <[email protected]>

* Update backend/games/consumers/GameConsumer.py

ㄱㅅㄱㅅ

Co-authored-by: Sejoon Kim <[email protected]>

* Update backend/games/consumers/GameConsumer.py

ㄱㅅㄱㅅ

Co-authored-by: Sejoon Kim <[email protected]>

* refactor: 필요없는 파일 제거

* feat: warning_modal 구현

* feat: 전송 경고 모달창 띄위기 완료

* refactor: 필요 없어진 경고 모달창 파일 지우기

* feat: 모달창 위치 style을 뷰포트로 변경

* fix: game 시작 시 status 변경 GunGonGamLee#425

* fix: game 종료 status 설정 GunGonGamLee#425

* fix: 버그 수정 GunGonGamLee#425

* feat: 토너먼트 종료 시 status 설정 GunGonGamLee#425

* feat: newWs 받으면 기존웹소켓 바로 닫게

* feat: clickOnce 추가

* feat: clickOnce 사용

* chore: consolelog 추가

* feat: navigate endGame 로직 추가

* feat: 서버성능문제로 keyevent 스트로크 한번만 인정되게 변경

* feat: myNickname myMatch 저장코드 추가

* feat: matchup 페이지 임시 alert 추가

* fix: winner 참조 버그 해결 GunGonGamLee#429

* feat: end message 값 추가 GunGonGamLee#428

* chore: resolve conflict

* feat(in-game): 랜덤 계수 구하는 로직 수정

* chore(in-game): 불필요한 console.log 제거

---------

Co-authored-by: donghyun <[email protected]>
Co-authored-by: sejoonkimmm <[email protected]>
Co-authored-by: 임원정 <[email protected]>
Co-authored-by: 임원정 <[email protected]>
Co-authored-by: Sejoon Kim <[email protected]>
Co-authored-by: chj <[email protected]>
  • Loading branch information
7 people authored Mar 11, 2024
1 parent ef9efcd commit 906ab85
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions frontend/src/pages/local-game/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,15 @@ export default function LocalGame($container, info = null) {
* @param drawFunction {function} 캔버스를 그리는 함수
*/
const runGame = (canvas, bar1, bar2, ball, drawFunction) => {
let isBounced = false;

const moveBall = () => {
if (isBallInsideBar(bar1, ball) || isBallInsideBar(bar2, ball)) {
bounce(true, false);
} else if (isBallHitWall(canvas, ball)) {
bounce(false, true);
} else {
isBounced = false;
}
ball.x = ball.x + ball.direction.x * ball.speed;
ball.y = ball.y + ball.direction.y * ball.speed;
Expand Down Expand Up @@ -251,10 +255,10 @@ export default function LocalGame($container, info = null) {
let topPoint = ball.y - ball.radius;
let bottomPoint = ball.y + ball.radius;

if (topPoint <= 0) {
if (topPoint <= 0 && !isBounced) {
ball.y += Math.abs(topPoint);
return true;
} else if (bottomPoint >= canvas.height) {
} else if (bottomPoint >= canvas.height && !isBounced) {
ball.y -= bottomPoint - canvas.height;
return true;
}
Expand All @@ -269,8 +273,10 @@ export default function LocalGame($container, info = null) {
*/
const isBallInsideBarX = (bar, ball) => {
return (
ball.x + ball.radius >= bar.x &&
ball.x - ball.radius <= bar.x + bar.width
(ball.x + ball.radius > bar.x &&
ball.x + ball.radius < bar.x + bar.width) ||
(ball.x - ball.radius > bar.x &&
ball.x - ball.radius < bar.x + bar.width)
);
};

Expand All @@ -282,8 +288,10 @@ export default function LocalGame($container, info = null) {
*/
const isBallInsideBarY = (bar, ball) => {
return (
ball.y + ball.radius >= bar.y &&
ball.y - ball.radius <= bar.y + bar.height
(ball.y + ball.radius > bar.y &&
ball.y + ball.radius < bar.y + bar.height) ||
(ball.y - ball.radius > bar.y &&
ball.y - ball.radius < bar.y + bar.height)
);
};

Expand All @@ -306,13 +314,13 @@ export default function LocalGame($container, info = null) {
return [false, false];
};

const updateScore = (wheterScoreAGoal) => {
if (wheterScoreAGoal[0]) {
const updateScore = (whetherScoreAGoal) => {
if (whetherScoreAGoal[0]) {
setScore({
player1: getScore().player1 + 1,
player2: getScore().player2,
});
} else if (wheterScoreAGoal[1]) {
} else if (whetherScoreAGoal[1]) {
setScore({
player1: getScore().player1,
player2: getScore().player2 + 1,
Expand All @@ -326,16 +334,18 @@ export default function LocalGame($container, info = null) {
* @param bounceY {boolean} y축으로 부딪혔는지 여부
*/
const bounce = (bounceX, bounceY) => {
if (bounceX) {
if (bounceX && !isBounced) {
[ball.direction.x, ball.direction.y] = normalizeVector(
ball.direction.x * -1 * getRandomCoefficient(0.9, 1.1),
ball.direction.x * -1 * getRandomCoefficient(0.99, 1.01),
ball.direction.y,
);
} else if (bounceY) {
isBounced = true;
} else if (bounceY && !isBounced) {
[ball.direction.x, ball.direction.y] = normalizeVector(
ball.direction.x,
ball.direction.y * -1 * getRandomCoefficient(0.9, 1.1),
ball.direction.y * -1 * getRandomCoefficient(0.99, 1.01),
);
isBounced = true;
}
};

Expand All @@ -353,13 +363,14 @@ export default function LocalGame($container, info = null) {
};
normalizeVector(ball.direction.x, ball.direction.y);
ball.speed = BALL_SPEED;
isBounced = false;
};

/**
* 최소값과 최대값 사이의 랜덤한 수를 반환하는 함수
*/
const getRandomCoefficient = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
return Math.random() * (max - min) + min;
};

/**
Expand All @@ -380,7 +391,7 @@ export default function LocalGame($container, info = null) {
while (Date.now() < end) {}
};

normalizeVector(ball.direction.x, ball.direction.y);
reset(ball, canvas);
moveBar();
moveBall();
};
Expand Down

0 comments on commit 906ab85

Please sign in to comment.