Skip to content

Commit

Permalink
documented textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Retrisma committed Nov 20, 2023
1 parent f9aa958 commit 37664c6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Tiled/Maps/Exports/slime.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
return {
version = "1.10",
luaversion = "5.1",
tiledversion = "1.10.1",
tiledversion = "1.10.2",
class = "",
orientation = "orthogonal",
renderorder = "right-down",
Expand All @@ -10,7 +10,7 @@ return {
tilewidth = 16,
tileheight = 16,
nextlayerid = 8,
nextobjectid = 72,
nextobjectid = 73,
properties = {},
tilesets = {
{
Expand Down
2 changes: 1 addition & 1 deletion Tiled/Maps/slime.tmx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="right-down" width="250" height="170" tilewidth="16" tileheight="16" infinite="0" nextlayerid="8" nextobjectid="72">
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="250" height="170" tilewidth="16" tileheight="16" infinite="0" nextlayerid="8" nextobjectid="73">
<editorsettings>
<export target="Exports/slime.lua" format="lua"/>
</editorsettings>
Expand Down
15 changes: 3 additions & 12 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ function love.load()
for _,v in pairs(p) do
if v.user == "player" then player = v break end
end

--[[Button:add(50, 100, "button", function() showdebug = not showdebug end)
Textbox:add(200, 100, "Everyone knows Mario is cool as fuck. Everyone knows Mario is cool as fuck.", {
scroll = true,
shadow = { 1, 0, 0 },
image = images["dialoguebox"],
hpad = 15,
vpad = 10,
font = fonts["ElixiR"]
})]]
end

function love.update(dt)
Expand All @@ -67,13 +57,14 @@ function love.update(dt)

if gamestate.state == gamestate.main then
if showdebug then
if love.keyboard.isDown("q") then window.scale = window.scale + rate * 5 end
--[[if love.keyboard.isDown("q") then window.scale = window.scale + rate * 5 end
if love.keyboard.isDown("e") then window.scale = window.scale - rate * 5 end
if love.keyboard.isDown("d") then camera.x = camera.x + rate * 500 end
if love.keyboard.isDown("a") then camera.x = camera.x - rate * 500 end
if love.keyboard.isDown("w") then camera.y = camera.y - rate * 500 end
if love.keyboard.isDown("s") then camera.y = camera.y + rate * 500 end
if love.keyboard.isDown("s") then camera.y = camera.y + rate * 500 end]]
camfollowsprite(player)
else
camfollowsprite(player)
end
Expand Down
48 changes: 30 additions & 18 deletions ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ local textbox_mt = class(Textbox)

function Textbox:init(x, y, text, opts)
opts = opts or {}

--[[
opts fields:
shadow: text shadow color in { red, green, blue }
hpad/vpad: text position offset within textbox
font: specify font
image: specify image for textbox background
scroll: true if this textbox should have scrolling text
]]

local o = {
x = x, y = y,
text = "",
Expand Down Expand Up @@ -84,24 +94,8 @@ function Textbox:add(x, y, text, opts)
table.insert(p, Textbox:new(x, y, text, opts))
end

function Textbox:update(dt)
if self.pause > 0 then
self.pause = self.pause - dt
return
else
self.pause = 0
end

if self.bank ~= "" then
self.cooldown = self.cooldown + dt
if self.cooldown > self.speed then
self:nextletter()

self.cooldown = self.cooldown - self.speed
end
end
end

-- pull the next character from the text bank and display it in the textbox
-- insert a new line if necessary
function Textbox:nextletter()
local char = self.bank:sub(1, 1)

Expand All @@ -125,6 +119,24 @@ function Textbox:nextletter()
self.bank = self.bank:sub(2)
end

function Textbox:update(dt)
if self.pause > 0 then
self.pause = self.pause - dt
return
else
self.pause = 0
end

if self.bank ~= "" then
self.cooldown = self.cooldown + dt
if self.cooldown > self.speed then
self:nextletter()

self.cooldown = self.cooldown - self.speed
end
end
end

function Textbox:draw()
local textpos = {
x = self.x + (self.hpad or 0),
Expand Down

0 comments on commit 37664c6

Please sign in to comment.