Skip to content

Commit

Permalink
Fix #50: 캐릭터 안움직이는 문제 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
leewooseong committed May 18, 2024
1 parent ec94824 commit a7d0f72
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const OtherController = ({

useEffect(() => {
// if (!rigidbody.current) return
console.log(pos)
rigidbody.current.setTranslation(vec3({ x: pos.x, y: pos.y, z: pos.z }))
rigidbody.current.setLinvel(vec3({ x: linvel.x, y: linvel.y, z: linvel.z }))
// 캐릭터가 이동할 때마다 좌표 받아오기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IOtherStatus {
nickname: string
team: teamEnum
modelKey: number
direction?: string
}

const samplePlayers: IOtherStatus[] = [
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/(page)/(needProtection)/game/lib/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IUserInfo {
userScore: number
moveState?: playerMoveStateEnum.IDLE
characterType?: number
direction?: 'right'
direction?: string
escapeHistory?: number
winRate?: number
winCnt?: number
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/(page)/(needProtection)/game/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const Game = () => {
</Physics>
</Suspense>
</Canvas>
<GameInfoPanel />
<GameControlPanel />
{/* <GameInfoPanel /> */}
{/* <GameControlPanel /> */}
<GameResult />
</KeyboardControl>
)
Expand Down
34 changes: 34 additions & 0 deletions frontend/app/hooks/useSetupSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useEffect } from 'react'
import { IChat, useChatLogsStore } from '../lib/store'
import { setUserScores } from '../lib/util'
import { AnswerEnum } from '../(page)/(needProtection)/game/lib/store-type'
import { IOtherStatus } from '../(page)/(needProtection)/game/component/OtherPlayers'

// 채팅 관련 소켓 셋팅
// - 대기방 + 게임방 공통으로 사용
Expand Down Expand Up @@ -119,6 +120,7 @@ const useSetUpRoom = (socket: WebSocket | null) => {

default:
console.log('이벤트 코드가 없습니다. 현재는 채팅에 대한 이벤트 코드가 없습니다.')
console.log(responseData)
break
}
}
Expand All @@ -143,6 +145,35 @@ const useSetUpGame = (socket: WebSocket | null) => {
}))
const router = useRouter()

const successOtherUserMove = (otherStatus: {
nickname: string
position: { x: number; y: number; z: number }
linvel: { x: number; y: number; z: number }
moveState: number
characterType: number
team: string
direction: string
}) => {
if (gameUserList === null) return

const newUserList = gameUserList.map((user: IUserInfo) => {
if (user.userNickname === otherStatus.nickname) {
return {
...user,
position: otherStatus.position,
linvel: otherStatus.linvel,
moveState: otherStatus.moveState,
characterType: otherStatus.characterType,
team: otherStatus.team ?? 'NONE',
direction: otherStatus.direction,
}
}
return user
})

setGameUserList(newUserList)
}

const successUpdateRoomInfo = (roomInfo: IRoomOfLobby) => {
console.log('방 정보 업데이트 성공 응답', roomInfo)
setRoomInfo({
Expand Down Expand Up @@ -262,8 +293,11 @@ const useSetUpGame = (socket: WebSocket | null) => {
console.log('매 라운드 퀴즈 정답 및 정답자 순위 발표')
successQuizAnswerRank(responseData.data)
break
case SOCKET_RES_CODE.MOVE_CHARACTER:
successOtherUserMove(responseData.data)
default:
console.log('이벤트 코드가 없습니다. 현재는 채팅에 대한 이벤트 코드가 없습니다.')
console.log(responseData)
break
}
}
Expand Down

0 comments on commit a7d0f72

Please sign in to comment.