From 60863b34d348f1e933d2d3805932dfbd037ae9a6 Mon Sep 17 00:00:00 2001 From: FajsiEx Date: Sat, 9 Oct 2021 23:37:33 +0200 Subject: [PATCH] + score panel with things --- scripts/gameplay.lua | 9 ++- scripts/gameplay/score_panel.lua | 71 ++++++++++++++++++ .../score_panel/bg.png} | Bin 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 scripts/gameplay/score_panel.lua rename textures/{score_back.png => gameplay/score_panel/bg.png} (100%) diff --git a/scripts/gameplay.lua b/scripts/gameplay.lua index db4053d..5572d39 100644 --- a/scripts/gameplay.lua +++ b/scripts/gameplay.lua @@ -5,6 +5,7 @@ local Banner = require('gameplay.banner') local CritLine = require('gameplay.crit_line') local Console = require('gameplay.console') local UserPanel = require('gameplay.user_panel') +local ScorePanel = require('gameplay.score_panel') local Gauge = require('gameplay.gauge') local Chain = require('gameplay.chain') local LaserAlert = require('gameplay.laser_alert') @@ -13,7 +14,9 @@ local resx, resy = game.GetResolution() local desw, desh; local scale; +local maxChain = 0; local chain = 0; +local score = 0; function resetLayoutInformation() resx, resy = game.GetResolution() @@ -29,6 +32,7 @@ function render(deltaTime) Banner.render(deltaTime); UserPanel.render(deltaTime); + ScorePanel.render(deltaTime, score, maxChain) Gauge.render( deltaTime, @@ -59,11 +63,14 @@ function render_outro(deltaTime, clearState) end function update_score(newScore) - + score = newScore end function update_combo(newCombo) chain = newCombo + if (chain > maxChain) then + maxChain = chain; + end end function near_hit(wasLate) diff --git a/scripts/gameplay/score_panel.lua b/scripts/gameplay/score_panel.lua new file mode 100644 index 0000000..55b9fa7 --- /dev/null +++ b/scripts/gameplay/score_panel.lua @@ -0,0 +1,71 @@ + +local bgImage = gfx.CreateSkinImage("gameplay/score_panel/bg.png", 0) + +local desw = 1080; +local desh = 1920; + +function load_number_image(path) + local images = {} + for i = 0, 9 do + images[i + 1] = gfx.CreateSkinImage(string.format("%s/%d.png", path, i), 0) + end + return images +end + +local scoreNumbers = load_number_image('score_num') + +function draw_number(x, y, alpha, num, digits, images, is_dim, scale, kern) + scale = scale or 1; + kern = kern or 1; + local tw, th = gfx.ImageSize(images[1]) + tw = tw * scale; + th = th * scale; + x = x + (tw * (digits - 1)) / 2 + y = y - th / 2 + for i = 1, digits do + local mul = 10 ^ (i - 1) + local digit = math.floor(num / mul) % 10 + local a = alpha + if is_dim and num < mul then + a = 0.4 + end + gfx.BeginPath() + gfx.ImageRect(x, y, tw, th, images[digit + 1], a, 0) + x = x - (tw * kern) + end +end + +local tickTransitions = function (deltaTime) + +end + +local render = function (deltaTime, score, maxChain) + tickTransitions(deltaTime) + + local x = desw - 740*0.61; -- WHY IS THERE DIFFERENT SCALING FOR THIS TOO???? + local y = 250; + + gfx.BeginPath(); + gfx.ImageRect( + x, + y, + 740*0.61, + 320*0.61, + bgImage, + 1, + 0 + ); + + draw_number(x+142, y + 83, 1.0, score/10000, 4, scoreNumbers, true, 0.38, 1.12) + draw_number(x+338, y + 90, 1.0, score, 4, scoreNumbers, true, 0.28, 1.12) + + -- Draw max chain + gfx.LoadSkinFont('Digital-Serial-Bold.ttf') + gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT + gfx.TEXT_ALIGN_MIDDLE) + gfx.FontSize(30) + gfx.Text(string.format("%04d", maxChain), x+170, y+155); +end + +return { + render=render +} \ No newline at end of file diff --git a/textures/score_back.png b/textures/gameplay/score_panel/bg.png similarity index 100% rename from textures/score_back.png rename to textures/gameplay/score_panel/bg.png