Added leaderboard
This commit is contained in:
@@ -21,6 +21,7 @@ export default {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
},
|
},
|
||||||
|
leaderboard: [],
|
||||||
renderTimer: null
|
renderTimer: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -71,6 +72,11 @@ export default {
|
|||||||
|
|
||||||
if (!this.players) return
|
if (!this.players) return
|
||||||
|
|
||||||
|
this.players.sort((a, b) => {
|
||||||
|
return a.walls.length - b.walls.length
|
||||||
|
})
|
||||||
|
this.leaderboard = []
|
||||||
|
|
||||||
this.players.forEach(player => {
|
this.players.forEach(player => {
|
||||||
if (player.color === this.player.color) {
|
if (player.color === this.player.color) {
|
||||||
this.camera.x = player.x
|
this.camera.x = player.x
|
||||||
@@ -79,7 +85,10 @@ export default {
|
|||||||
}
|
}
|
||||||
this.renderPlayer(player)
|
this.renderPlayer(player)
|
||||||
this.renderWalls(player)
|
this.renderWalls(player)
|
||||||
|
this.leaderboard.push(player.id + ' - ' + player.walls.length)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.renderLeaderboard()
|
||||||
},
|
},
|
||||||
renderBorders () {
|
renderBorders () {
|
||||||
this.context.strokeStyle = 'black'
|
this.context.strokeStyle = 'black'
|
||||||
@@ -116,10 +125,11 @@ export default {
|
|||||||
const canvasX = this.canvas.width / 2
|
const canvasX = this.canvas.width / 2
|
||||||
const canvasY = this.canvas.height / 2
|
const canvasY = this.canvas.height / 2
|
||||||
|
|
||||||
this.context.fillText('player x: ' + player.x + ' y:' + player.y, 10, 10)
|
this.context.textAlign = 'start'
|
||||||
this.context.fillText('a:' + player.angle + ' a_t' + player.targetAngle, 10, 20)
|
this.context.fillText('player x: ' + player.x + ' y:' + player.y, 10, 12)
|
||||||
this.context.fillText('canvasX: ' + canvasX + ' canvasY:' + canvasY, 10, 30)
|
this.context.fillText('a:' + player.angle + ' a_t' + player.targetAngle, 10, 24)
|
||||||
this.context.fillText('walls: ' + player.walls.length, 10, 40)
|
this.context.fillText('canvasX: ' + canvasX + ' canvasY:' + canvasY, 10, 36)
|
||||||
|
this.context.fillText('walls: ' + player.walls.length, 10, 48)
|
||||||
|
|
||||||
this.context.beginPath()
|
this.context.beginPath()
|
||||||
this.context.arc(this.mouse.x, this.mouse.y, 25, 0, 2 * Math.PI, false)
|
this.context.arc(this.mouse.x, this.mouse.y, 25, 0, 2 * Math.PI, false)
|
||||||
@@ -127,6 +137,13 @@ export default {
|
|||||||
this.context.strokeStyle = player.color
|
this.context.strokeStyle = player.color
|
||||||
this.context.stroke()
|
this.context.stroke()
|
||||||
},
|
},
|
||||||
|
renderLeaderboard () {
|
||||||
|
this.context.textAlign = 'end'
|
||||||
|
this.context.fillText('Leaderboard: ', this.canvas.width - 50, 10)
|
||||||
|
for (var i = 0; i < this.leaderboard.length; i++) {
|
||||||
|
this.context.fillText(this.players[i].color + ' - ' + this.players[i].walls.length, this.canvas.width - 50, 15 + (i + 1) * 10)
|
||||||
|
}
|
||||||
|
},
|
||||||
mouseEvent (event) {
|
mouseEvent (event) {
|
||||||
var rect = this.canvas.getBoundingClientRect()
|
var rect = this.canvas.getBoundingClientRect()
|
||||||
this.mouse.x = event.clientX - rect.left
|
this.mouse.x = event.clientX - rect.left
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ public class GameManager implements IGameManager {
|
|||||||
SocketUtils.sendObject(game.getSessions().get(id), "gamePlayerDead",
|
SocketUtils.sendObject(game.getSessions().get(id), "gamePlayerDead",
|
||||||
new ObjectMapper().writeValueAsString(player));
|
new ObjectMapper().writeValueAsString(player));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,14 +148,6 @@ public class GameManager implements IGameManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCrossingLine (double xa, double ya, double xb, double yb, double xc, double yc, double radius) {
|
private boolean isCrossingLine (double xa, double ya, double xb, double yb, double xc, double yc, double radius) {
|
||||||
/*
|
|
||||||
var a = xc - xa;
|
|
||||||
var b = xb - xa;
|
|
||||||
var c = yc - ya;
|
|
||||||
var d = yb - ya;
|
|
||||||
var result = (a * d - b * c) / Math.sqrt(Math.pow(xa - xb, 2) + Math.pow(ya - yb, 2));
|
|
||||||
*/
|
|
||||||
|
|
||||||
var result = Math.abs((yb - ya) * xc - (xb - xa) * yc + xb * ya - yb * xa) / Math.sqrt(Math.pow(xb - xa, 2) + Math.pow(yb - ya, 2));
|
var result = Math.abs((yb - ya) * xc - (xb - xa) * yc + xb * ya - yb * xa) / Math.sqrt(Math.pow(xb - xa, 2) + Math.pow(yb - ya, 2));
|
||||||
|
|
||||||
return result < radius;
|
return result < radius;
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package gltronic.tronio.model;
|
|
||||||
|
|
||||||
public abstract class GameEntity {
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user