diff --git a/apps/client/src/scenes/GameScene.tsx b/apps/client/src/scenes/GameScene.tsx index d425e65..9c784d9 100644 --- a/apps/client/src/scenes/GameScene.tsx +++ b/apps/client/src/scenes/GameScene.tsx @@ -2,9 +2,10 @@ import { Application, Container } from "pixi.js"; // ネットワーク・入力 -import { socketClient, type PlayerData } from "../network/SocketClient"; +import { socketClient} from "../network/SocketClient"; import { VirtualJoystick, MAX_DIST } from "../input/VirtualJoystick"; import { GAME_CONFIG } from "@repo/shared/src/config/gameConfig"; +import { type PlayerData } from "@repo/shared/src/types/player"; // ゲームオブジェクト import { GameMap } from "../entities/GameMap"; @@ -47,7 +48,7 @@ const playersArray = (Array.isArray(serverPlayers) ? serverPlayers : Object.values(serverPlayers)) as PlayerData[]; playersArray.forEach((p) => { const isMe = p.id === myId; - const playerSprite = new Player(p.color, isMe); + const playerSprite = new Player(GAME_CONFIG.TEAM_COLORS[p.teamId], isMe); playerSprite.position.set(p.x, p.y); worldContainer.addChild(playerSprite); playersRef.current[p.id] = playerSprite; @@ -58,7 +59,7 @@ // 新規参加:新しいプレイヤーを画面に追加 socketClient.onNewPlayer((p: PlayerData) => { console.log("🔥 新規プレイヤー参加:", p); - const playerSprite = new Player(p.color, false); + const playerSprite = new Player(GAME_CONFIG.TEAM_COLORS[p.teamId], false); playerSprite.position.set(p.x, p.y); worldContainer.addChild(playerSprite); playersRef.current[p.id] = playerSprite; diff --git a/apps/server/src/entities/Player.ts b/apps/server/src/entities/Player.ts index efd60a8..62dacae 100644 --- a/apps/server/src/entities/Player.ts +++ b/apps/server/src/entities/Player.ts @@ -1,17 +1,16 @@ -// src/entities/Player.ts -export class Player { +import type { PlayerData } from "@repo/shared/src/types/player"; + +export class Player implements PlayerData { public id: string; public x: number = 0; public y: number = 0; - public color: string; + public teamId: number; constructor(id: string) { this.id = id; - /* - this.x = Math.floor(Math.random() * 1000) + 500; - this.y = Math.floor(Math.random() * 1000) + 500; - */ - // ランダムな色をつけるとおしゃれです - this.color = '#' + Math.floor(Math.random()*16777215).toString(16); + + // 0〜3のランダムなチームIDを割り当てる + // (4チーム制を想定し、Math.randomで一旦仮実装) + this.teamId = Math.floor(Math.random() * 4); } } \ No newline at end of file diff --git a/packages/shared/src/config/gameConfig.ts b/packages/shared/src/config/gameConfig.ts index bd60d31..f326d05 100644 --- a/packages/shared/src/config/gameConfig.ts +++ b/packages/shared/src/config/gameConfig.ts @@ -18,4 +18,8 @@ PLAYER_POSITION_UPDATE_MS: 50, // 座標送信の間隔 (20Hz = 50ms) PLAYER_LERP_SMOOTHNESS: 0.3, // 他プレイヤーの動きの滑らかさ (0.1〜0.5程度で調整) PLAYER_LERP_SNAP_THRESHOLD: 0.5, // これ以下の距離になったら座標を強制的に合わせる + + // チーム設定 + // チームカラー 0:赤, 1:青, 2:緑, 3:黄 + TEAM_COLORS: ['#FF4B4B', '#4B4BFF', '#4BFF4B', '#FFD700'], } as const; \ No newline at end of file diff --git a/packages/shared/src/types/player.ts b/packages/shared/src/types/player.ts index 90b43b2..ecfcb70 100644 --- a/packages/shared/src/types/player.ts +++ b/packages/shared/src/types/player.ts @@ -3,5 +3,5 @@ id: string; x: number; y: number; - color: string; + teamId: number; // 0〜3の数値を想定 } \ No newline at end of file