+ basic multiplayer scoreboard to gameplay

This commit is contained in:
FajsiEx 2021-11-27 20:56:39 +01:00
parent 1889fd3e3b
commit 40828199f5
2 changed files with 58 additions and 2 deletions

View File

@ -13,10 +13,14 @@ local LaserAlert = require('gameplay.laser_alert')
local TrackEnd = require('gameplay.track_end') local TrackEnd = require('gameplay.track_end')
local json = require "json"
local resx, resy = game.GetResolution() local resx, resy = game.GetResolution()
local desw, desh; local desw, desh;
local scale; local scale;
local users = nil
local maxChain = 0; local maxChain = 0;
local chain = 0; local chain = 0;
local score = 0; local score = 0;
@ -38,7 +42,7 @@ function render(deltaTime)
resetLayoutInformation(); resetLayoutInformation();
gfx.Scale(scale, scale); gfx.Scale(scale, scale);
Banner.render(deltaTime); Banner.render(deltaTime, users);
UserPanel.render(deltaTime, score, gameplay.scoreReplays[1]); UserPanel.render(deltaTime, score, gameplay.scoreReplays[1]);
SongPanel.render(deltaTime, SongPanel.render(deltaTime,
@ -129,3 +133,25 @@ function practice_end(playCount, successCount)
end end
function init_tcp()
Tcp.SetTopicHandler("game.scoreboard", function(data)
users = {}
for i, u in ipairs(data.users) do
table.insert(users, u)
end
end)
end
-- Update the users in the scoreboard
function score_callback(response)
if response.status ~= 200 then
error()
return
end
local jsondata = json.decode(response.text)
users = {}
for i, u in ipairs(jsondata.users) do
table.insert(users, u)
end
end

View File

@ -4,8 +4,36 @@ local bannerBaseImage = gfx.CreateSkinImage("gameplay/banner/base.png", 0)
local BANNER_W = 1080; local BANNER_W = 1080;
local BANNER_H = 368; local BANNER_H = 368;
local drawScoreboard = function (users)
if (users == nil) then
return
end
local render = function (deltaTime) gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.FontSize(32)
local x = 16;
local y = 500;
gfx.LoadSkinFont("Digital-Serial-Bold.ttf")
for i, u in ipairs(users) do
local y = y + 40;
gfx.FontSize(26)
gfx.Text(u.name, x, y)
gfx.FontSize(26)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.Text(string.format("%04d", math.floor(u.score/10000)), x+128, y)
local lastFourDigits = ((u.score / 10000) - math.floor(u.score / 10000))*10000
gfx.FontSize(22)
gfx.Text(string.format("%04d", math.floor(lastFourDigits)), x+186, y+1)
end
end
local render = function (deltaTime, users)
local resx, resy = game.GetResolution(); local resx, resy = game.GetResolution();
if (resx > resy) then if (resx > resy) then
return return
@ -25,6 +53,8 @@ local render = function (deltaTime)
1, 1,
0 0
); );
drawScoreboard(users);
end end
return { return {