diff --git a/frontend/src/components/world/WorldMap.tsx b/frontend/src/components/world/WorldMap.tsx index 368a9af24..a9571b1de 100644 --- a/frontend/src/components/world/WorldMap.tsx +++ b/frontend/src/components/world/WorldMap.tsx @@ -10,7 +10,7 @@ class CoveyGameScene extends Phaser.Scene { sprite: Phaser.Types.Physics.Arcade.SpriteWithDynamicBody, label: Phaser.GameObjects.Text }; - private id?: string; + private myPlayerID: string; private players: Player[] = []; @@ -33,10 +33,11 @@ class CoveyGameScene extends Phaser.Scene { private emitMovement: (loc: UserLocation) => void; - constructor(video: Video, emitMovement: (loc: UserLocation) => void) { + constructor(video: Video, emitMovement: (loc: UserLocation) => void, myPlayerID : string) { super('PlayGame'); this.video = video; this.emitMovement = emitMovement; + this.myPlayerID = myPlayerID; } preload() { @@ -89,7 +90,7 @@ class CoveyGameScene extends Phaser.Scene { myPlayer = new Player(player.id, player.userName, location); this.players.push(myPlayer); } - if (this.id !== myPlayer.id && this.physics && player.location) { + if (this.myPlayerID !== myPlayer.id && this.physics && player.location) { let { sprite } = myPlayer; if (!sprite) { sprite = this.physics.add @@ -433,7 +434,7 @@ class CoveyGameScene extends Phaser.Scene { export default function WorldMap(): JSX.Element { const video = Video.instance(); const { - emitMovement, players, + emitMovement, players, myPlayerID, } = useCoveyAppState(); const [gameScene, setGameScene] = useState(); useEffect(() => { @@ -452,7 +453,7 @@ export default function WorldMap(): JSX.Element { const game = new Phaser.Game(config); if (video) { - const newGameScene = new CoveyGameScene(video, emitMovement); + const newGameScene = new CoveyGameScene(video, emitMovement, myPlayerID); setGameScene(newGameScene); game.scene.add('coveyBoard', newGameScene, true); video.pauseGame = () => { @@ -465,7 +466,7 @@ export default function WorldMap(): JSX.Element { return () => { game.destroy(true); }; - }, [video, emitMovement]); + }, [video, emitMovement, myPlayerID]); const deepPlayers = JSON.stringify(players); useEffect(() => {