diff --git a/Frontend/src/js/pong/classes/GameSession.js b/Frontend/src/js/pong/classes/GameSession.js index 7215036..d8b90ac 100644 --- a/Frontend/src/js/pong/classes/GameSession.js +++ b/Frontend/src/js/pong/classes/GameSession.js @@ -54,8 +54,9 @@ class GameSession { this.scoreBoard = new ScoreBoard(scene); if (isRemote === true) this.scoreBoard.showWaitText(); + else + this.scoreBoard.showLoadingText(); this.playingField.addToScene(); - this.ball.addToScene(); // Always connect to the server if (!this.socket.connected) { @@ -97,6 +98,7 @@ class GameSession { this.inProgress = true; this.leftPaddle.addToScene(); this.rightPaddle.addToScene(); + this.ball.addToScene(); setTimeout(() => { this.paused = false const player1Text = `${this.player1Alias} ${this.player1Score}`; diff --git a/Frontend/src/js/pong/classes/ScoreBoard.js b/Frontend/src/js/pong/classes/ScoreBoard.js index 8a2bee8..1909481 100644 --- a/Frontend/src/js/pong/classes/ScoreBoard.js +++ b/Frontend/src/js/pong/classes/ScoreBoard.js @@ -91,15 +91,18 @@ class ScoreBoard { this.createScoreBoard(player1Text, player2Text); } - showGoalText() { - this.clearScores(); - this.goalMesh = this.createText('GOAL !!!', 100, 0x00FF00, 0.3, 15.0); // green for GOAL text - this.goalMesh.position.set(0, 90.0, 300.0); + placeTextMesh(mesh) { + mesh.position.set(0, 90.0, 300.0); if (globalState.invertedView === true) { - this.goalMesh.rotation.y = THREE.MathUtils.degToRad(180); + mesh.rotation.y = THREE.MathUtils.degToRad(180); } else { - this.goalMesh.position.z = -300.0; + mesh.position.z = -300.0; } + } + showGoalText() { + this.clearScores(); + this.goalMesh = this.createText('GOAL !!!', 100, 0x00FF00, 0.3, 15.0); // green for GOAL text + this.placeTextMesh(this.goalMesh); this.scene.add(this.goalMesh); } @@ -107,25 +110,21 @@ class ScoreBoard { this.clearScores(); this.messageMesh = this.createText('GAME START', 80, 0x00FF00, 0.3, 15.0) this.messageMesh.position.set(0, 90.0, 300.0); - if (globalState.invertedView === true) { - this.messageMesh.rotation.y = THREE.MathUtils.degToRad(180); - } - else { - this.messageMesh.position.z = -300.0 - } + this.placeTextMesh(this.messageMesh); this.scene.add(this.messageMesh); } showWaitText() { this.clearScores(); this.messageMesh = this.createText('Waiting for your opponent..', 50, 0x4455FF, 1.4, 4.0); - this.messageMesh.position.set(0, 90.0, 300.0); - if (globalState.invertedView === true) { - this.messageMesh.rotation.y = THREE.MathUtils.degToRad(180); - } - else { - this.messageMesh.position.z = -300.0 - } + this.placeTextMesh(this.messageMesh); + this.scene.add(this.messageMesh); + } + + showLoadingText() { + this.clearScores(); + this.messageMesh = this.createText('Loading..', 80, 0xAAFF00, 1.4, 4.0); + this.placeTextMesh(this.messageMesh); this.scene.add(this.messageMesh); } @@ -137,13 +136,7 @@ class ScoreBoard { else { this.messageMesh = this.createText('Your opponent has quit the game', 50, 0x2222FF, 1.4, 4.0); } - this.messageMesh.position.set(0, 90.0, 300.0); - if (globalState.invertedView === true) { - this.messageMesh.rotation.y = THREE.MathUtils.degToRad(180); - } - else { - this.messageMesh.position.z = -300.0 - } + this.placeTextMesh(this.messageMesh); this.scene.add(this.messageMesh); }