From 47fc63a74585e2118cc55200888d5b94f1654665 Mon Sep 17 00:00:00 2001 From: parameterized Date: Fri, 1 Feb 2019 23:49:45 -0500 Subject: [PATCH] damage numbers, hp & damage affected by stats --- client.lua | 5 +++++ damageText.lua | 38 ++++++++++++++++++++++++++++++++++++++ entityDefs/player.lua | 8 ++++++-- gfx/fonts/stat_font.png | Bin 888 -> 909 bytes hud.lua | 35 ++++++++++++++++++++++++++--------- loadassets.lua | 2 +- main.lua | 2 ++ physics.lua | 3 +++ server.lua | 2 +- slimeBalls.lua | 1 + 10 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 damageText.lua 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 4f6057f9645387d484e7c6e480fee84b0499c9c9..c4d56c4ee2bcd8fc6ace235ea96aa47c5f61f371 100644 GIT binary patch delta 869 zcmV-r1DgE!28{b4G?5`2f4=|# z4!;371ydvd000MZ5%NSL|u&=aQ}U{8|UW615)Hr+T9>|08Qy}#Qi%2`S|(%_<4ap`7E-}xV+1{ zobY>lHs^FWy>+?CvHCvY^1!{>f4MxsnPu{ypP%jxIDJ!xD^3NT>=1H!fV0o`yvw?r z@OyhU=X5x|b-Bs0`aa?Ez`c>n1MgJVc7R^(9E;2orT^_hBsGfJ?^5D*X zaLQZ%_4UOwdAs~TXV8Mb>^%F~MLB~wKoUHJJeP}b+vdmdcb%|5*!US{cs7s#{d zHOvl#KRXq;y90lw++ELpc2Uls9XnmzR~LSM3zYRa^_~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}3(^>{MX4*Eztuci@vA0v&&W?09B@?A7aT_Onxg-CpMa@7=MV z_krqFz~#XypW%GnLl+*%f$jeP;a>;rvy1!c!k_oCoFi@rc)DA-+2`_)e$lRd&gX2+ zO%7c3>}MC{{JouVUtRd~K9+OD?Ep`Ai)kjux%cY3_h9eT=X}oAoOA3~--gc)JoUi& zxT}B8`R1Seq7^wGxt?`7;lAgxHOIbw2ULg4lec{5^OF~T4_yoYV0V}Q(F)GjUD;)J zx$M;Qj_~)s1(+c|8$NP9>vF<<&t+?lef?57XG2;+1=jok(;t} zE<5$SBmAF#E8`sS+3-BGz?Hmkp00av^zRt=`}G^23#w5Gn_!v%0000 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