diff --git a/client.lua b/client.lua index d66a637..1325f0c 100644 --- a/client.lua +++ b/client.lua @@ -87,6 +87,9 @@ function client.connect(ip, port) healPlayer = function(self, data) local p = playerController.player p.hp = math.min(p.hp + data.hp, p.hpMax) + end, + damageText = function(self, data) + damageText.add(data) end } for k, v in pairs(bitserRPCs) do @@ -119,6 +122,7 @@ function client.connect(ip, port) clientRealm:destroy() slimeBalls.reset() items.client.reset() + damageText.reset() collectgarbage() end client.currentState = client.newState() @@ -222,6 +226,7 @@ function client.update(dt) playerController.update(dt) entities.client.update(dt) slimeBalls.update(dt) + damageText.update(dt) end end diff --git a/damageText.lua b/damageText.lua new file mode 100644 index 0000000..7ce7bb3 --- /dev/null +++ b/damageText.lua @@ -0,0 +1,38 @@ + +damageText = { + container = {} +} + +function damageText.reset() + damageText.container = {} +end + +-- t = {v=_, x=_, y=_} +function damageText.add(t) + if t.v == nil then t.v = 0 end + if t.x == nil then t.x = 0 end + if t.y == nil then t.y = 0 end + t.v = tostring(t.v) + t.timer = 1 + table.insert(damageText.container, t) +end + +function damageText.update(dt) + for k, v in pairs(damageText.container) do + v.timer = v.timer - dt*0.5 + if v.timer < 0 then + damageText.container[k] = nil + end + end +end + +function damageText.draw() + local font = fonts.stats + love.graphics.setFont(font) + for _, v in pairs(damageText.container) do + local t = ease.outCubic(1 - v.timer) + local y = v.y - t*8 + love.graphics.setColor(1, 0, 0, 1 - t) + love.graphics.print(v.v, lume.round(v.x - font:getWidth(v.v)/2), lume.round(y - font:getHeight()/2)) + end +end diff --git a/entityDefs/player.lua b/entityDefs/player.lua index 5048a86..4c420c3 100644 --- a/entityDefs/player.lua +++ b/entityDefs/player.lua @@ -39,7 +39,7 @@ for _, sc in ipairs{'server', 'client'} do player[sc].newStats = function() local t = { vit = {base = 100, arm = 14}, - atk = {base = 80, arm = 25}, + atk = {base = 10, arm = 5}, spd = {base = 50, arm = 9}, wis = {base = 100, arm = 8}, def = {base = 20, arm = 25}, @@ -122,6 +122,10 @@ for _, sc in ipairs{'server', 'client'} do end end + local _hpMax = self.hpMax + self.hpMax = self.stats.vit.total + self.hp = self.hp + (self.hpMax - _hpMax) + self.x, self.y = self.body:getPosition() self.xv, self.yv = self.body:getLinearVelocity() self.base.update(self, dt) @@ -246,7 +250,7 @@ function player.client:swing() local playerDamage = 5 local attackItem = items.client.getItem(self.inventory.items[2]) if attackItem and attackItem.atk then - playerDamage = attackItem.atk + playerDamage = attackItem.atk + self.stats.atk.total end if self.isLocalPlayer then client.spawnProjectile{ diff --git a/gfx/fonts/stat_font.png b/gfx/fonts/stat_font.png index 4f6057f..c4d56c4 100644 Binary files a/gfx/fonts/stat_font.png and b/gfx/fonts/stat_font.png differ diff --git a/hud.lua b/hud.lua index 9ea756c..8640c59 100644 --- a/hud.lua +++ b/hud.lua @@ -313,16 +313,18 @@ function hud.keypressed(k, scancode, isrepeat) end function hud.draw() + local _canvas = love.graphics.getCanvas() local _shader = love.graphics.getShader() local mx, my = window2game(love.mouse.getPosition()) mx, my = lume.round(mx), lume.round(my) + local p = playerController.player + love.graphics.setColor(1, 1, 1) love.graphics.draw(gfx.hud.frame, 0, 0) -- hp/mana - local p = playerController.player love.graphics.setShader(shaders.lifemana) shaders.lifemana:send('hp', p.hp/p.hpMax) shaders.lifemana:send('mana', 1) @@ -350,7 +352,7 @@ function hud.draw() end -- level bar - local l = playerController.player.xp2level(playerController.player.xp) + local l = p.xp2level(p.xp) local x, y = hud.statsPanel.x, hud.statsPanel.y love.graphics.setColor(221/255, 217/255, 0) local t = l - math.floor(l) @@ -363,7 +365,7 @@ function hud.draw() text.print(level, lume.round(240 - font:getWidth(level)/2), lume.round(y)) -- stats - font = fonts.stats + local font = fonts.stats love.graphics.setFont(font) local stats_x, stats_y = 202, 227 local stats_dx, stats_dy = 20, 11 @@ -379,15 +381,30 @@ function hud.draw() local sy = stats_y + stats_dy*(j-1) sx = x + (sx - hud.statsPanel.openPos.x) sy = y + (sy - hud.statsPanel.openPos.y) - local txt = tostring(playerController.player.stats[col][row]) + local txt = tostring(p.stats[col][row]) text.print(txt, lume.round(sx - font:getWidth(txt)/2), lume.round(sy - font:getHeight()/2)) end end + love.graphics.setCanvas(canvases.tempGame) + love.graphics.clear() + local hpHovered = mx > 39 and mx < 141 and my > 23 and my < 31 + local txt = string.format('%i / %i', p.hp, p.hpMax) + love.graphics.setColor(0, 0, 0) + text.print(txt, lume.round(90 - font:getWidth(txt)/2 - 1), lume.round(27 - font:getHeight()/2 + 1)) love.graphics.setColor(1, 1, 1) - love.graphics.setFont(fonts.c17) - text.print(playerController.player.name, 44, 5) + text.print(txt, lume.round(90 - font:getWidth(txt)/2), lume.round(27 - font:getHeight()/2)) + love.graphics.setCanvas(_canvas) + if hpHovered then + love.graphics.setColor(1, 1, 1, 0.8) + else + love.graphics.setColor(1, 1, 1, 0.4) + end + love.graphics.draw(canvases.tempGame, 0, 0) + love.graphics.setColor(1, 1, 1) + love.graphics.setFont(fonts.c17) + text.print(p.name, 44, 5) -- inventory items love.graphics.push() @@ -396,7 +413,7 @@ function hud.draw() local pmx = mx - lume.round(panel.x) local pmy = my - lume.round(panel.y) for slotId, slot in ipairs(hud.inventorySlots) do - local item = items.client.getItem(playerController.player.inventory.items[slotId]) + local item = items.client.getItem(p.inventory.items[slotId]) if pmx >= slot.x and pmx <= slot.x + slot.w and pmy >= slot.y and pmy <= slot.y + slot.h and panel.open then if item then @@ -433,7 +450,7 @@ function hud.draw() love.graphics.draw(gfx.ui.itemInfo, 0, 0) font = fonts.stats love.graphics.setFont(font) - local playerWeapon = items.client.getItem(playerController.player.inventory.items[2]) + local playerWeapon = items.client.getItem(p.inventory.items[2]) if isSword[item.imageId] and item.atk then if playerWeapon and playerWeapon.atk then if item.atk < playerWeapon.atk then @@ -454,7 +471,7 @@ function hud.draw() if heldItem.bagId then local bag = client.currentState.lootBags[heldItem.bagId] if heldItem.bagId == 'inventory' then - bag = playerController.player.inventory + bag = p.inventory end if bag then local item = items.client.getItem(bag.items[heldItem.slotId]) diff --git a/loadassets.lua b/loadassets.lua index cd909ee..88d3d2d 100644 --- a/loadassets.lua +++ b/loadassets.lua @@ -213,7 +213,7 @@ fonts = { c13 = love.graphics.newImageFont('gfx/fonts/small_font.png', ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`\'*#=[]"|~@$^_{}<>'), c17 = love.graphics.newImageFont('gfx/fonts/big_font.png', ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`\'*#=[]"|~@$^_{}<>'), - stats = love.graphics.newImageFont('gfx/fonts/stat_font.png', ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') + stats = love.graphics.newImageFont('gfx/fonts/stat_font.png', ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/') } -- todo: test -- love.graphics.newFont([filename, ] size, "mono") diff --git a/main.lua b/main.lua index e477f8f..fcf98f9 100644 --- a/main.lua +++ b/main.lua @@ -27,6 +27,7 @@ require 'playerController' require 'items' require 'lootBag' require 'portals' +require 'damageText' require 'realm' require 'chat' @@ -208,6 +209,7 @@ function love.draw() portals.client.draw() scene.draw() + damageText.draw() prof.pop('draw scene') prof.push('draw debug') diff --git a/physics.lua b/physics.lua index fe2da3d..a5e0695 100644 --- a/physics.lua +++ b/physics.lua @@ -76,6 +76,8 @@ function physics.server:load() local swing = projectiles.server.container[uda.id] local enemy = udb if swing and enemy and not enemy.hitBy[swing.id] then + server.nutServer:sendRPC('damageText', bitser.dumps{ + v=swing.damage, x=enemy.x, y=enemy.y-26}) enemy.hitBy[swing.id] = true enemy:damage(swing.damage, swing.playerId) swing.pierce = swing.pierce - 1 @@ -119,6 +121,7 @@ function physics.client:load() local udb = fixb:getUserData() or {} if uda.type == 'slimeBall' and udb.id == playerController.player.id then self:postUpdatePush(function() + damageText.add{v=uda.damage, x=udb.x, y=udb.y-24} udb:damage(uda.damage) slimeBalls.destroy(uda.id) end) diff --git a/server.lua b/server.lua index f786e7d..e1c74a8 100644 --- a/server.lua +++ b/server.lua @@ -273,7 +273,7 @@ function server.addXP(playerId, xp) local l = entities.server.defs.player.xp2level(p.xp) if math.floor(_l) ~= math.floor(l) then -- level increased p.stats.vit.base = math.floor(l*10 + 100) - p.stats.atk.base = math.floor(l*8 + 80) + p.stats.atk.base = math.floor(l*2 + 10) p.stats.spd.base = math.floor(l*5 + 50) p.stats.wis.base = math.floor(l*8 + 100) p.stats.def.base = math.floor(l*4 + 20) diff --git a/slimeBalls.lua b/slimeBalls.lua index 5b3d207..9b0ed6d 100644 --- a/slimeBalls.lua +++ b/slimeBalls.lua @@ -58,6 +58,7 @@ end function slimeBalls.update(dt) for k, v in pairs(slimeBalls.container) do + v.x, v.y = v.body:getPosition() if gameTime - v.spawnTime > v.life then slimeBalls.destroy(k) end