From c6a13570b43b5bc1443ec2aa3321f2cb55f8aa85 Mon Sep 17 00:00:00 2001 From: mytja Date: Fri, 20 Aug 2021 17:44:49 +0200 Subject: [PATCH 1/7] Added "leaderboard" & added victory at the end... [very bad] --- client/src/index.js | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/client/src/index.js b/client/src/index.js index 8d4ebb9..b9404aa 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -45,6 +45,10 @@ class Game extends Phaser.Scene { this.cursors = this.input.keyboard.createCursorKeys(); this.wasd = this.input.keyboard.addKeys('W,S,A,D'); + this.won = false; + + this.leaderboard = this.add.text(0, 0, 'Leaderboard: \nLoading... Please wait!',); + this.handleLeaderboard(); //this.inputKeys = [ // this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE), @@ -70,9 +74,11 @@ class Game extends Phaser.Scene { velocity.dx = 0; } - if (Phaser.Input.Keyboard.JustDown(this.wasd.W) && this.player.body.velocity.y == 0) { + if ((Phaser.Input.Keyboard.JustDown(this.wasd.W) || this.cursors.up.isDown || this.cursors.space.isDown) && this.player.body.velocity.y == 0) { velocity.dy = -400; - } + } //else if ((Phaser.Input.Keyboard.JustDown(this.wasd.S) || this.cursors.down.isDown) && this.player.body.velocity.y == 0) { + // velocity.dy = 400; + //} this.player.move(this.player.x, this.player.y, velocity.dx, velocity.dy); @@ -82,6 +88,31 @@ class Game extends Phaser.Scene { this.websocket.playerMoveSend(this.player.x, this.player.y, this.player.body.velocity.x, this.player.body.velocity.y); } + this.handleLeaderboard(); + } + + handleLeaderboard() { + let keys = Object.keys(this.players); + let topclient = this.player; + let ppl = "You: "; + keys.forEach(key => { + let client = this.players[key]; + if (topclient.x < client.x) { + topclient = client; + if (topclient == this.player) { + ppl = "You: " + } else { + ppl = "Not you: " + } + } + }); + this.leaderboard.x = this.player.x - 400; + this.leaderboard.y = this.player.y - 500; + this.leaderboard.text = "Leaderboard: \n" + ppl + topclient.x.toString(); + if (this.won == false && topclient.x > 4200) { + this.leaderboard.text = "Victory! Congratulations to " + ppl; + this.leaderboard.setFontSize(50); + } } handleMessage(msg) { @@ -93,6 +124,7 @@ class Game extends Phaser.Scene { } else if (msg.hasLeave()) { this.leaveReceive(msg.getPlayerId()); } + this.handleLeaderboard(); } playerMoveRecieve(player_id, x, y, dx, dy) { From 5c4a4a3ca7a86f74d6df51d40df6204a563c8056 Mon Sep 17 00:00:00 2001 From: mytja Date: Fri, 20 Aug 2021 17:47:16 +0200 Subject: [PATCH 2/7] Added "leaderboard" & added victory at the end... [very bad] - fix linting --- client/src/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/index.js b/client/src/index.js index b9404aa..5697392 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -94,23 +94,23 @@ class Game extends Phaser.Scene { handleLeaderboard() { let keys = Object.keys(this.players); let topclient = this.player; - let ppl = "You: "; + let ppl = 'You: '; keys.forEach(key => { let client = this.players[key]; if (topclient.x < client.x) { topclient = client; if (topclient == this.player) { - ppl = "You: " + ppl = 'You: '; } else { - ppl = "Not you: " + ppl = 'Not you: '; } } }); this.leaderboard.x = this.player.x - 400; this.leaderboard.y = this.player.y - 500; - this.leaderboard.text = "Leaderboard: \n" + ppl + topclient.x.toString(); + this.leaderboard.text = 'Leaderboard: \n' + ppl + topclient.x.toString(); if (this.won == false && topclient.x > 4200) { - this.leaderboard.text = "Victory! Congratulations to " + ppl; + this.leaderboard.text = 'Victory! Congratulations to ' + ppl; this.leaderboard.setFontSize(50); } } From 6f51bea262ff86a7cdd996eeaf64cbff8378547a Mon Sep 17 00:00:00 2001 From: mytja Date: Fri, 20 Aug 2021 17:50:58 +0200 Subject: [PATCH 3/7] Added "leaderboard" & added victory at the end... [very bad] - fix linting --- client/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/index.js b/client/src/index.js index 5697392..6bf7103 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -109,7 +109,7 @@ class Game extends Phaser.Scene { this.leaderboard.x = this.player.x - 400; this.leaderboard.y = this.player.y - 500; this.leaderboard.text = 'Leaderboard: \n' + ppl + topclient.x.toString(); - if (this.won == false && topclient.x > 4200) { + if (this.won == false && topclient.x > 4000) { this.leaderboard.text = 'Victory! Congratulations to ' + ppl; this.leaderboard.setFontSize(50); } From 90a9663dcdac4d885382ca34c7c3467700956d53 Mon Sep 17 00:00:00 2001 From: mytja Date: Fri, 20 Aug 2021 17:53:56 +0200 Subject: [PATCH 4/7] Added "leaderboard" & added victory at the end... [very bad] - better color --- client/src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/src/index.js b/client/src/index.js index 6bf7103..234d3dc 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -92,6 +92,7 @@ class Game extends Phaser.Scene { } handleLeaderboard() { + this.leaderboard.setFontSize(16); let keys = Object.keys(this.players); let topclient = this.player; let ppl = 'You: '; @@ -109,9 +110,11 @@ class Game extends Phaser.Scene { this.leaderboard.x = this.player.x - 400; this.leaderboard.y = this.player.y - 500; this.leaderboard.text = 'Leaderboard: \n' + ppl + topclient.x.toString(); + this.leaderboard.setColor("#000000"); if (this.won == false && topclient.x > 4000) { this.leaderboard.text = 'Victory! Congratulations to ' + ppl; this.leaderboard.setFontSize(50); + this.won == true; } } From 5aeb10bfbcdbe9b9eebbb44c752572bfa13686b8 Mon Sep 17 00:00:00 2001 From: mytja Date: Fri, 20 Aug 2021 17:54:14 +0200 Subject: [PATCH 5/7] Added "leaderboard" & added victory at the end... [very bad] - won == true fix --- client/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/index.js b/client/src/index.js index 234d3dc..ea31e1b 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -114,7 +114,7 @@ class Game extends Phaser.Scene { if (this.won == false && topclient.x > 4000) { this.leaderboard.text = 'Victory! Congratulations to ' + ppl; this.leaderboard.setFontSize(50); - this.won == true; + this.won = true; } } From 443e3a1e950d4fe7e292a96f1f884bc26f0a3633 Mon Sep 17 00:00:00 2001 From: mytja Date: Fri, 20 Aug 2021 18:03:32 +0200 Subject: [PATCH 6/7] Victory --- client/src/index.js | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/client/src/index.js b/client/src/index.js index ea31e1b..cd9ac10 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -92,29 +92,31 @@ class Game extends Phaser.Scene { } handleLeaderboard() { - this.leaderboard.setFontSize(16); - let keys = Object.keys(this.players); - let topclient = this.player; - let ppl = 'You: '; - keys.forEach(key => { - let client = this.players[key]; - if (topclient.x < client.x) { - topclient = client; - if (topclient == this.player) { - ppl = 'You: '; - } else { - ppl = 'Not you: '; + if (this.won == false) { + this.leaderboard.setFontSize(16); + let keys = Object.keys(this.players); + let topclient = this.player; + let ppl = 'You: '; + keys.forEach(key => { + let client = this.players[key]; + if (topclient.x < client.x) { + topclient = client; + if (topclient == this.player) { + ppl = 'You: '; + } else { + ppl = 'Not you: '; + } } + }); + this.leaderboard.x = this.player.x - 400; + this.leaderboard.y = this.player.y - 500; + this.leaderboard.text = 'Leaderboard: \n' + ppl + topclient.x.toString(); + this.leaderboard.setColor("#000000"); + if (topclient.x > 4000) { + this.leaderboard.text = 'Victory! Congratulations to ' + ppl; + this.leaderboard.setFontSize(50); + this.won = true; } - }); - this.leaderboard.x = this.player.x - 400; - this.leaderboard.y = this.player.y - 500; - this.leaderboard.text = 'Leaderboard: \n' + ppl + topclient.x.toString(); - this.leaderboard.setColor("#000000"); - if (this.won == false && topclient.x > 4000) { - this.leaderboard.text = 'Victory! Congratulations to ' + ppl; - this.leaderboard.setFontSize(50); - this.won = true; } } From 20dc39e469fec0ac6666168fd396ff8179e5568e Mon Sep 17 00:00:00 2001 From: mytja Date: Fri, 20 Aug 2021 18:13:36 +0200 Subject: [PATCH 7/7] Fix linting errors -victory --- client/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/index.js b/client/src/index.js index cd9ac10..cc1d426 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -111,7 +111,7 @@ class Game extends Phaser.Scene { this.leaderboard.x = this.player.x - 400; this.leaderboard.y = this.player.y - 500; this.leaderboard.text = 'Leaderboard: \n' + ppl + topclient.x.toString(); - this.leaderboard.setColor("#000000"); + this.leaderboard.setColor('#000000'); if (topclient.x > 4000) { this.leaderboard.text = 'Victory! Congratulations to ' + ppl; this.leaderboard.setFontSize(50);