From 7df5f0bdf6526f618195f1133070f8bf32df124f Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 28 Jan 2019 13:13:17 +0100 Subject: [PATCH] src/game: add a gui module with a border generator --- sonic-radiance.love/assets/gui/borders.png | Bin 0 -> 425 bytes sonic-radiance.love/game/modules/gui/init.lua | 41 ++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 sonic-radiance.love/assets/gui/borders.png create mode 100644 sonic-radiance.love/game/modules/gui/init.lua diff --git a/sonic-radiance.love/assets/gui/borders.png b/sonic-radiance.love/assets/gui/borders.png new file mode 100644 index 0000000000000000000000000000000000000000..90e4b98583ab1461609a19c40f2ac85ea15263a4 GIT binary patch literal 425 zcmeAS@N?(olHy`uVBq!ia0vp^0YEIm!3HFyZtS`aq}Y`Ki;O^-g5Z=fq&cMJZ=;`7Z5^*@0r#tuWc?b6ow^UmuihTY3`0C26{jPVM zSN)ovdht!tF4nl1Ed9d{%zSZ{t7aW{()ZV$6?;ZN>e;CcRaa;IU$V?8t4V&oe4sf) z{KwFXcP=K)za?Sze&3M?uU8!hs(ANsD$`0? zwKkU|x4oI+xjn?fCP*Pji--GK@{LW&CaiojHx>L?a)42bd*$1Bx2*pDiCj^YWf$AH2FA9foWVXBfkZiGRSWF&tJj7m&(A9wROuEw)Ka0 Q0z;6&)78&qol`;+0BuR3b^rhX literal 0 HcmV?d00001 diff --git a/sonic-radiance.love/game/modules/gui/init.lua b/sonic-radiance.love/game/modules/gui/init.lua new file mode 100644 index 0000000..1cdc4db --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/init.lua @@ -0,0 +1,41 @@ +local gui = {} + +function gui.newBorder(width, height, middlePosition) + local tileset = love.graphics.newImage("assets/gui/borders.png") + local tilequad = {} + local w, h = tileset:getDimensions() + tilequad[1] = love.graphics.newQuad(0, 0, 20, 20, w, h) + tilequad[2] = love.graphics.newQuad(20, 0, 20, 20, w, h) + tilequad[3] = love.graphics.newQuad(40, 0, 20, 20, w, h) + tilequad[4] = love.graphics.newQuad(60, 0, 20, 20, w, h) + + local Texture = love.graphics.newCanvas(width, height) + + love.graphics.setCanvas(Texture) + utils.graphics.resetColor() + + local height = math.ceil(height / 20) + local width = math.ceil(width / 20) + + for i=1, width do + if i < middlePosition then + love.graphics.draw(tileset, tilequad[1], (i-1) * 20, 0) + elseif (i == middlePosition) then + love.graphics.draw(tileset, tilequad[2], (i-1) * 20, 0) + else + love.graphics.draw(tileset, tilequad[3], (i-1) * 20, 0) + end + + if height > 1 then + for j = 2, height do + love.graphics.draw(tileset, tilequad[4], (i-1) * 20, (j-1) * 20) + end + end + end + + love.graphics.setCanvas( ) + + return Texture +end + +return gui