Skip to content

Commit

Permalink
working singleplayer quests, projectile color, armor, inv slot types
Browse files Browse the repository at this point in the history
  • Loading branch information
parameterized committed Feb 26, 2019
1 parent d0c0be9 commit 7c483e0
Show file tree
Hide file tree
Showing 26 changed files with 845 additions and 364 deletions.
4 changes: 3 additions & 1 deletion client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function client.connect(ip, port)
slimeBalls.reset()
items.client.reset()
damageText.reset()
quests.refresh()
collectgarbage()
end
client.currentState = client.newState()
Expand Down Expand Up @@ -237,7 +238,8 @@ function client.sendMessage(msg)
end
end

for _, v in ipairs{'spawnProjectile', 'moveItem', 'dropItem', 'useItem', 'usePortal'} do
for _, v in ipairs{'spawnProjectile', 'moveItem', 'dropItem', 'useItem', 'usePortal',
'setInventorySlot', 'newItem'} do
client[v] = function(data)
client.nutClient:sendRPC(v, bitser.dumps(data))
end
Expand Down
168 changes: 104 additions & 64 deletions entityDefs/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,17 @@ function player.client:swing()
local attackItem = items.client.getItem(self.inventory.items[2])
if attackItem and attackItem.atk then
playerDamage = attackItem.atk + self.stats.atk.total
end
if self.isLocalPlayer then
client.spawnProjectile{
x = px, y = py - 14,
angle = a,
speed = 2e2,
life = 3,
pierce = 2,
damage = playerDamage
}
if self.isLocalPlayer then
client.spawnProjectile{
x = px, y = py - 14,
angle = a,
speed = 2e2,
life = 3,
pierce = 2,
damage = playerDamage,
color = sword2color[attackItem.imageId]
}
end
end
end

Expand All @@ -284,6 +285,12 @@ function player.client:mousepressed(x, y, btn)
end
end

function player.client:drawFrame(anim, frame, x, y, ox)
local quad = anim.quads[frame]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anim.sheet, quad, x, y, 0, self.direction, 1, ox, h)
end

function player.client:draw()
local _canvas = love.graphics.getCanvas()
local _shader = love.graphics.getShader()
Expand Down Expand Up @@ -322,24 +329,36 @@ function player.client:draw()

love.graphics.setColor(1, 1, 1)
local attackItem = items.client.getItem(self.inventory.items[2])
local helmetItem = items.client.getItem(self.inventory.items[1])
local chestItem = items.client.getItem(self.inventory.items[3])
local pantsItem = items.client.getItem(self.inventory.items[6])
if self.swinging then
local swingFrameIdx = math.floor(self.swingTimer*12) + 1
swingFrameIdx = lume.clamp(swingFrameIdx, 1, 5)
if vd < 10 then
-- swinging and standing still
local quad = anims.player.swing.body.quads[swingFrameIdx]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anims.player.swing.body.sheet, quad,
lume.round(px), lume.round(py),
0, self.direction, 1,
23, h)
-- body
self:drawFrame(anims.player.swing.body, swingFrameIdx,
lume.round(px), lume.round(py), 23)
-- pants
if pantsItem then
self:drawFrame(anims.player.armor.armor0.pants.swing, swingFrameIdx,
lume.round(px), lume.round(py), 23)
end
-- chest
if chestItem then
self:drawFrame(anims.player.armor.armor0.chest.swing, swingFrameIdx,
lume.round(px), lume.round(py), 23)
end
-- helmet
if helmetItem then
self:drawFrame(anims.player.armor.armor0.helmet.swing, swingFrameIdx,
lume.round(px), lume.round(py), 23)
end
-- sword
if attackItem and isSword[attackItem.imageId] then
local quad = anims.player.swords[attackItem.imageId].swing.quads[swingFrameIdx]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anims.player.swords[attackItem.imageId].swing.sheet, quad,
lume.round(px), lume.round(py),
0, self.direction, 1,
23, h)
self:drawFrame(anims.player.swords[attackItem.imageId].swing, swingFrameIdx,
lume.round(px), lume.round(py), 23)
end
else
-- swinging and walking
Expand All @@ -348,65 +367,86 @@ function player.client:draw()
or xv < -10 and self.direction == 1 then
walkFrameIdx = math.floor(-self.walkTimer*12) % #anims.player.walk.body.quads + 1
end
local quad = anims.player.walkAndSwing.lowerBody.quads[walkFrameIdx]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anims.player.walkAndSwing.lowerBody.sheet, quad,
lume.round(px), lume.round(py),
0, self.direction, 1,
23, h)
self:drawFrame(anims.player.walkAndSwing.lowerBody, walkFrameIdx,
lume.round(px), lume.round(py), 23)
-- pants
if pantsItem then
self:drawFrame(anims.player.armor.armor0.pants.walkAndSwing, walkFrameIdx,
lume.round(px), lume.round(py), 23)
end
-- upper body
love.graphics.push()
if swingFrameIdx == 4 then love.graphics.translate(0, 1) end
if walkFrameIdx == 4 then love.graphics.translate(0, -1) end
local quad = anims.player.walkAndSwing.upperBody.quads[swingFrameIdx]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anims.player.walkAndSwing.upperBody.sheet, quad,
lume.round(px), lume.round(py),
0, self.direction, 1,
23, h)
self:drawFrame(anims.player.walkAndSwing.upperBody, swingFrameIdx,
lume.round(px), lume.round(py), 23)
-- chest
if chestItem then
self:drawFrame(anims.player.armor.armor0.chest.walkAndSwing, swingFrameIdx,
lume.round(px), lume.round(py), 23)
end
-- helmet
if helmetItem then
self:drawFrame(anims.player.armor.armor0.helmet.walkAndSwing, swingFrameIdx,
lume.round(px), lume.round(py), 23)
end
love.graphics.pop()
-- sword
if attackItem and isSword[attackItem.imageId] then
local quad = anims.player.swords[attackItem.imageId].swing.quads[swingFrameIdx]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anims.player.swords[attackItem.imageId].swing.sheet, quad,
lume.round(px), lume.round(py),
0, self.direction, 1,
23, h)
self:drawFrame(anims.player.swords[attackItem.imageId].swing, swingFrameIdx,
lume.round(px), lume.round(py), 23)
end
end
else
if vd < 10 then
-- standing still
local quad = anims.player.swing.body.quads[1]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anims.player.swing.body.sheet, quad,
lume.round(px), lume.round(py),
0, self.direction, 1,
23, h)
-- body
self:drawFrame(anims.player.swing.body, 1,
lume.round(px), lume.round(py), 23)
-- pants
if pantsItem then
self:drawFrame(anims.player.armor.armor0.pants.swing, 1,
lume.round(px), lume.round(py), 23)
end
-- chest
if chestItem then
self:drawFrame(anims.player.armor.armor0.chest.swing, 1,
lume.round(px), lume.round(py), 23)
end
-- helmet
if helmetItem then
self:drawFrame(anims.player.armor.armor0.helmet.swing, 1,
lume.round(px), lume.round(py), 23)
end
-- sword
if attackItem and isSword[attackItem.imageId] then
local quad = anims.player.swords[attackItem.imageId].swing.quads[1]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anims.player.swords[attackItem.imageId].swing.sheet, quad,
lume.round(px), lume.round(py),
0, self.direction, 1,
23, h)
self:drawFrame(anims.player.swords[attackItem.imageId].swing, 1,
lume.round(px), lume.round(py), 23)
end
else
-- walking
local quad = anims.player.walk.body.quads[walkFrameIdx]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anims.player.walk.body.sheet, quad,
lume.round(px), lume.round(py),
0, self.direction, 1,
8, h)
-- body
self:drawFrame(anims.player.walk.body, walkFrameIdx,
lume.round(px), lume.round(py), 8)
-- pants
if pantsItem then
self:drawFrame(anims.player.armor.armor0.pants.walk, walkFrameIdx,
lume.round(px), lume.round(py), 8)
end
-- chest
if chestItem then
self:drawFrame(anims.player.armor.armor0.chest.walk, walkFrameIdx,
lume.round(px), lume.round(py), 8)
end
-- helmet
if helmetItem then
self:drawFrame(anims.player.armor.armor0.helmet.walk, walkFrameIdx,
lume.round(px), lume.round(py), 8)
end
-- sword
if attackItem and isSword[attackItem.imageId] then
local quad = anims.player.swords[attackItem.imageId].walk.quads[walkFrameIdx]
local _, _, w, h = quad:getViewport()
love.graphics.draw(anims.player.swords[attackItem.imageId].walk.sheet, quad,
lume.round(px), lume.round(py),
0, self.direction, 1,
8, h)
self:drawFrame(anims.player.swords[attackItem.imageId].walk, walkFrameIdx,
lume.round(px), lume.round(py), 8)
end
end
end
Expand Down
Binary file added gfx/items/chest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/items/helmet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/items/pants.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/player/armor/armor0/chest/swing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/player/armor/armor0/chest/walk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/player/armor/armor0/chest/walk_and_swing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/player/armor/armor0/helmet/swing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/player/armor/armor0/helmet/walk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/player/armor/armor0/helmet/walk_and_swing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/player/armor/armor0/pants/swing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/player/armor/armor0/pants/walk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/player/armor/armor0/pants/walk_and_swing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/ui/questui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 7 additions & 122 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function hud.update(dt)
end

function hud.mousepressed(x, y, btn, isTouch, presses)
mx, my = window2game(x, y)
local mx, my = window2game(x, y)
mx, my = lume.round(mx), lume.round(my)

-- deactivate chat if click outside field
Expand All @@ -183,120 +183,11 @@ function hud.mousepressed(x, y, btn, isTouch, presses)
if chat.active and not chatFieldPressed then
chat.active = false
end

-- inventory management
local bag = playerController.player.inventory
local panel = hud.inventoryPanel
local pmx = mx - lume.round(panel.x)
local pmy = my - lume.round(panel.y)
for slotId, slot in ipairs(hud.inventorySlots) do
if pmx >= slot.x and pmx <= slot.x + slot.w
and pmy >= slot.y and pmy <= slot.y + slot.h and panel.open then
uiMouseDown = true
if bag.items[slotId] then
-- use item
if btn == 1 and (love.keyboard.isScancodeDown('lshift') or presses > 1) then
client.useItem{
bagId = bag.id,
slotId = slotId
}
end
-- move items
if btn == 1 then
local heldItem = playerController.heldItem
heldItem.bagId = bag.id
heldItem.slotId = slotId
heldItem.offset.x = slot.x - pmx
heldItem.offset.y = slot.y - pmy
elseif btn == 2 then
local closestBag = playerController.closestBag
if closestBag.id and closestBag.open then
local bagTo = client.currentState.lootBags[closestBag.id]
for bagSlotId, _ in ipairs(lootBagSlots) do
if bagTo.items[bagSlotId] == nil then
client.moveItem{
from = {
bagId = bag.id,
slotId = slotId
},
to = {
bagId = bagTo.id,
slotId = bagSlotId
}
}
break
end
end
end
end
end
end
end
end

function hud.mousereleased(x, y, btn, isTouch, presses)
local mx, my = window2game(x, y)
mx, my = lume.round(mx), lume.round(my)
local heldItem = playerController.heldItem
if heldItem.bagId then
local bagFrom = client.currentState.lootBags[heldItem.bagId]
if heldItem.bagId == 'inventory' then
bagFrom = playerController.player.inventory
end
local bagTo = playerController.player.inventory
local panel = hud.inventoryPanel
local pmx = mx - lume.round(panel.x)
local pmy = my - lume.round(panel.y)
local itemHeld = true
if pmx > 0 and pmx < panel.img:getWidth()
and pmy > 0 and pmy < panel.img:getHeight() then
for slotId, slot in ipairs(hud.inventorySlots) do
if pmx >= slot.x and pmx <= slot.x + slot.w
and pmy >= slot.y and pmy <= slot.y + slot.h then
client.moveItem{
from = {
bagId = bagFrom.id,
slotId = heldItem.slotId
},
to = {
bagId = bagTo.id,
slotId = slotId
}
}
itemHeld = false
-- move clientside before response (will be corrected/affirmed)
local temp = bagTo.items[slotId]
bagTo.items[slotId] = bagFrom.items[heldItem.slotId]
bagFrom.items[heldItem.slotId] = temp
break
end
end
-- move to open slot if dropped in inventory panel
if itemHeld then
for invSlotId, _ in ipairs(hud.inventorySlots) do
if bagTo.items[invSlotId] == nil then
client.moveItem{
from = {
bagId = bagFrom.id,
slotId = heldItem.slotId
},
to = {
bagId = bagTo.id,
slotId = invSlotId
}
}
itemHeld = false
break
end
end
end
elseif bagFrom.id == 'inventory' then
client.dropItem{
slotId = heldItem.slotId
}
itemHeld = false
end
end
end

function hud.keypressed(k, scancode, isrepeat)
Expand Down Expand Up @@ -468,18 +359,12 @@ function hud.draw()

-- held item
local heldItem = playerController.heldItem
if heldItem.bagId then
local bag = client.currentState.lootBags[heldItem.bagId]
if heldItem.bagId == 'inventory' then
bag = p.inventory
end
if bag then
local item = items.client.getItem(bag.items[heldItem.slotId])
if item then
cursor.cursor = cursor.hand
love.graphics.setColor(1, 1, 1)
love.graphics.draw(gfx.items[item.imageId], mx + heldItem.offset.x, my + heldItem.offset.y)
end
if heldItem.itemId then
local item = items.client.getItem(heldItem.itemId)
if item then
cursor.cursor = cursor.hand
love.graphics.setColor(1, 1, 1)
love.graphics.draw(gfx.items[item.imageId], mx + heldItem.offset.x, my + heldItem.offset.y)
end
end
end
Loading

0 comments on commit 7c483e0

Please sign in to comment.