Skip to content

Commit

Permalink
bag ui with draggable placeholder, lume
Browse files Browse the repository at this point in the history
  • Loading branch information
parameterized committed Sep 20, 2018
1 parent bb6e1b4 commit 6e11e98
Show file tree
Hide file tree
Showing 19 changed files with 1,006 additions and 157 deletions.
2 changes: 1 addition & 1 deletion chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ chat = {
log = {},
active = false,
val = '',
lastMsgTime = 0
lastMsgTime = -1
}

function chat.addMsg(v)
Expand Down
17 changes: 9 additions & 8 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ function client.update(dt)
print('clamp up ' .. math.abs(client.stateTime - cs_3.time))
end
]]
client.stateTime = clamp(client.stateTime + dt, cs_3.time, cs_0.time)
client.stateTime = lume.clamp(client.stateTime + dt, cs_3.time, cs_0.time)
if client.stateTime > cs_1.time then
--print('lerp down')
client.stateTime = lerp(client.stateTime, cs_1.time, clamp(dt, 0, 1))
client.stateTime = lume.lerp(client.stateTime, cs_1.time, lume.clamp(dt, 0, 1))
elseif client.stateTime < cs_2.time then
--print('lerp up')
client.stateTime = lerp(client.stateTime, cs_2.time, clamp(dt, 0, 1))
client.stateTime = lume.lerp(client.stateTime, cs_2.time, lume.clamp(dt, 0, 1))
end
--debugger.logVal('interpolation delay', client.serverTime - client.stateTime)
while client.states[client.stateIdx+1] and client.states[client.stateIdx+2]
Expand All @@ -185,7 +185,7 @@ function client.update(dt)
end
local t = (client.stateTime - client.states[client.stateIdx].time)
/ (client.states[client.stateIdx+1].time - client.states[client.stateIdx].time)
--t = clamp(t, 0, 1) -- t>1 = prediction
--t = lume.clamp(t, 0, 1) -- t>1 = prediction
if not client.interpolate then
t = 1
end
Expand All @@ -196,8 +196,8 @@ function client.update(dt)
if v2 then
local obj = client.currentState.players[k]
if obj then
obj.x = lerp(v.x, v2.x, t)
obj.y = lerp(v.y, v2.y, t)
obj.x = lume.lerp(v.x, v2.x, t)
obj.y = lume.lerp(v.y, v2.y, t)

obj.body:setPosition(obj.x, obj.y)

Expand All @@ -216,8 +216,8 @@ function client.update(dt)
if v2 then
local obj = client.currentState.projectiles[k]
if obj then
obj.x = lerp(v.x, v2.x, t)
obj.y = lerp(v.y, v2.y, t)
obj.x = lume.lerp(v.x, v2.x, t)
obj.y = lume.lerp(v.y, v2.y, t)
obj.startedMoving = true
end
end
Expand All @@ -238,6 +238,7 @@ function client.update(dt)
if not (server.running and server.paused) then
gameTime = gameTime + dt
hud.update(dt)
lootBags.client.update(dt)
physics.client.update(dt)
world.update(dt)
player.update(dt)
Expand Down
6 changes: 3 additions & 3 deletions entityDefs/_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
function base.server:new(o)
o = o or {}
local defaults = {
id = uuid(),
id = lume.uuid(),
x = 0, y = 0
}
for k, v in pairs(defaults) do
Expand Down Expand Up @@ -104,7 +104,7 @@ end
function base.client:new(o)
o = o or {}
local defaults = {
id = uuid(),
id = lume.uuid(),
x = 0, y = 0
}
for k, v in pairs(defaults) do
Expand All @@ -128,7 +128,7 @@ end

function base.client:lerpState(a, b, t)
for _, v in pairs{'x', 'y'} do
self[v] = lerp(a[v], b[v], t)
self[v] = lume.lerp(a[v], b[v], t)
end
end

Expand Down
16 changes: 8 additions & 8 deletions entityDefs/slime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end
function slime.server:new(o)
o = o or {}
local defaults = {
id = uuid(),
id = lume.uuid(),
x = 0, y = 0,
xv = 0, yv = 0,
slimeType = math.random() < 0.5 and 'slime1' or 'slime2',
Expand Down Expand Up @@ -92,7 +92,7 @@ function slime.server:damage(d, clientId)
lootBags.server.spawn{
x = self.x, y = self.y,
items = {'apl', 'banan'},
life = 10,
life = 30,
type = type
}
end
Expand Down Expand Up @@ -129,7 +129,7 @@ end
function slime.client:new(o)
o = o or {}
local defaults = {
id = uuid(),
id = lume.uuid(),
x = 0, y = 0,
hpMax = 5,
hp = math.random(1, 5),
Expand Down Expand Up @@ -189,7 +189,7 @@ end
function slime.client:lerpState(a, b, t)
local state = {}
for _, v in pairs{'x', 'y', 'xv', 'yv'} do
state[v] = lerp(a[v], b[v], t)
state[v] = lume.lerp(a[v], b[v], t)
end
for _, v in pairs{'slimeType', 'hpMax', 'hp'} do
state[v] = b[v]
Expand All @@ -211,11 +211,11 @@ function slime.client:drawBody()
shaders.outline:send('stepSize', {1/img:getWidth(), 1/img:getHeight()})
love.graphics.push()
local vx, vy = self.body:getPosition()
love.graphics.translate(math.floor(vx), math.floor(vy))
love.graphics.translate(lume.round(vx), lume.round(vy))
love.graphics.draw(img,
0, 0,
0, 1, 1,
math.floor(img:getWidth()/2), math.floor(img:getHeight()/2))
lume.round(img:getWidth()/2), lume.round(img:getHeight()/2))
love.graphics.pop()
love.graphics.setShader(_shader)
end
Expand All @@ -235,8 +235,8 @@ function slime.client:drawHP()
love.graphics.setShader(_shader)
love.graphics.push()
local vx, vy = self.body:getPosition()
love.graphics.translate(math.floor(vx), math.floor(vy))
love.graphics.draw(canvases.hpBar, math.floor(-canvases.hpBar:getWidth()/2), 10)
love.graphics.translate(lume.round(vx), lume.round(vy))
love.graphics.draw(canvases.hpBar, lume.round(-canvases.hpBar:getWidth()/2), 10)
love.graphics.pop()
end

Expand Down
Binary file added gfx/ui/bagui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 15 additions & 17 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ hud = {}

hud.panels = {}
hud.buttons = {}
hud.buttonDown = false

function hud.addPanel(t)
local defaults = {
Expand All @@ -26,13 +25,13 @@ function hud.addPanel(t)
if not t.update then
t.update = function(self, dt)
if self.open then
self.timer = clamp(self.timer - 3*dt, 0, 1)
self.timer = lume.clamp(self.timer - 3*dt, 0, 1)
else
self.timer = clamp(self.timer + 3*dt, 0, 1)
self.timer = lume.clamp(self.timer + 3*dt, 0, 1)
end
local t = ease.inOutCubic(self.timer)
self.x = lerp(self.openPos.x, self.closedPos.x, t)
self.y = lerp(self.openPos.y, self.closedPos.y, t)
self.x = lume.lerp(self.openPos.x, self.closedPos.x, t)
self.y = lume.lerp(self.openPos.y, self.closedPos.y, t)
end
end
table.insert(hud.panels, t)
Expand Down Expand Up @@ -83,7 +82,7 @@ function hud.load()
img=gfx.hud.buttons.chat, x=16, y=235,
update = function(self, dt)
local t = ease.inOutCubic(hud.chatPanel.timer)
self.y = lerp(132, 235, t)
self.y = lume.lerp(132, 235, t)
end,
action = function(self)
hud.chatPanel.open = not hud.chatPanel.open
Expand All @@ -102,7 +101,7 @@ function hud.load()
local r, g, b = love.graphics.getColor()
love.graphics.setColor(r*0.8, g*0.8, b*0.8)
end
love.graphics.draw(self.img, math.floor(self.x), math.floor(self.y))
love.graphics.draw(self.img, lume.round(self.x), lume.round(self.y))
end
}
hud.addButton{
Expand Down Expand Up @@ -149,12 +148,12 @@ function hud.update(dt)
end

function hud.mousepressed(mx, my, btn)
mx, my = screen2game(mx, my)
mx, my = window2game(mx, my)
local chatFieldPressed = false
for _, v in pairs(hud.buttons) do
if mx > v.x and mx < v.x + v.img:getWidth() and my > v.y and my < v.y + v.img:getHeight() then
if v.action then v.action(v) end
hud.buttonDown = true
uiMouseDown = true
if v.id == 'chatField' then chatFieldPressed = true end
end
end
Expand All @@ -164,12 +163,11 @@ function hud.mousepressed(mx, my, btn)
end

function hud.mousereleased(mx, my, btn)
mx, my = screen2game(mx, my)
hud.buttonDown = false

end

function hud.draw()
local mx, my = screen2game(love.mouse.getPosition())
local mx, my = window2game(love.mouse.getPosition())

love.graphics.setColor(1, 1, 1)
love.graphics.draw(gfx.hud.frame, 0, 0)
Expand All @@ -182,7 +180,7 @@ function hud.draw()

love.graphics.setColor(1, 1, 1)
for _, v in pairs(hud.panels) do
love.graphics.draw(v.img, math.floor(v.x), math.floor(v.y))
love.graphics.draw(v.img, lume.round(v.x), lume.round(v.y))
end
for _, v in pairs(hud.buttons) do
if v.draw then
Expand All @@ -192,21 +190,21 @@ function hud.draw()
if mx > v.x and mx < v.x + v.img:getWidth() and my > v.y and my < v.y + v.img:getHeight() then
love.graphics.setColor(0.8, 0.8, 0.8)
end
love.graphics.draw(v.img, math.floor(v.x), math.floor(v.y))
love.graphics.draw(v.img, lume.round(v.x), lume.round(v.y))
end
end

local l = player.xp2level(player.xp)
x, y = hud.statsPanel.x, hud.statsPanel.y
love.graphics.setColor(221/255, 217/255, 0)
local t = l - math.floor(l)
love.graphics.rectangle('fill', 191, math.floor(y + 20), t*99, 3)
love.graphics.rectangle('fill', 191, lume.round(y + 20), t*99, 3)

love.graphics.setColor(1, 1, 1)
local font = fonts.c17
love.graphics.setFont(font)
local level = tostring(math.floor(l))
love.graphics.print(level, math.floor(240 - font:getWidth(level)/2), math.floor(y))
love.graphics.print(level, lume.round(240 - font:getWidth(level)/2), lume.round(y))

font = fonts.stats
love.graphics.setFont(font)
Expand All @@ -225,7 +223,7 @@ function hud.draw()
sx = x + (sx - hud.statsPanel.openPos.x)
sy = y + (sy - hud.statsPanel.openPos.y)
local txt = tostring(player.stats[col][row])
love.graphics.print(txt, math.floor(sx - font:getWidth(txt)/2), math.floor(sy - font:getHeight()/2))
love.graphics.print(txt, lume.round(sx - font:getWidth(txt)/2), lume.round(sy - font:getHeight()/2))
end
end

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6e11e98

Please sign in to comment.