Added leaderboard, music & respawn screen

This commit is contained in:
Thomas
2020-09-03 16:13:04 +02:00
parent 4d542c1091
commit 832e55c0a3
20 changed files with 259 additions and 113 deletions
+29 -18
View File
@@ -4,8 +4,10 @@ const state = {
y: 100,
angle: 0,
targetAngle: 0,
color: 'red'
color: 'red',
state: 'DEAD'
},
leaderboard: [],
updates: [],
settings: {
playerSize: 10,
@@ -21,19 +23,11 @@ const state = {
}
const getters = {
// Interpolation position des joueurs
currentPlayers: state => {
if (state.updates.length < 2) return state.updates[0].players
else {
const dt = state.updates[0].time - state.updates[1].time
return state.updates[1].players.map(player => interpolatePlayer(player, dt))
}
}
}
const actions = {
socketConnected ({ commit }) {
commit('SET_CONNECTED')
socketConnected ({ commit }, connected) {
commit('SET_CONNECTED', connected)
commit('CLEAR_UPDATE')
},
login ({ commit }, player) {
@@ -45,10 +39,15 @@ const actions = {
},
update ({ commit }, update) {
commit('ADD_UPDATE', update)
commit('SET_LEADERBOARD', update.players)
},
dead ({ commit }, player) {
commit('SET_PLAYER', player)
commit('CLEAR_UPDATE')
// commit('CLEAR_UPDATE')
},
spawn ({ commit }, player) {
commit('SET_PLAYER', player)
// commit('CLEAR_UPDATE')
},
error ({ commit }, error) {
alert('Error: ' + error)
@@ -71,8 +70,8 @@ const mutations = {
SET_PAUSE (state) {
state.paused = !state.paused
},
SET_CONNECTED (state) {
state.socketConnected = !state.socketConnected
SET_CONNECTED (state, connected) {
state.socketConnected = connected
},
ADD_UPDATE (state, update) {
if (state.updates.length > 2) {
@@ -83,11 +82,23 @@ const mutations = {
},
CLEAR_UPDATE (state) {
state.updates = []
}
}
},
SET_LEADERBOARD (state, players) {
state.leaderboard = []
function interpolatePlayer (player, dt) {
return player
players.forEach(player => {
state.leaderboard.push({
name: player.name,
score: player.score,
bestScore: player.bestScore,
color: player.color
})
})
state.leaderboard.sort((a, b) => {
return b.score - a.score
})
}
}
export default {