Skip to content

Commit

Permalink
love 11.2, ipairs, load menu defaults btn, res fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
parameterized committed Jan 3, 2019
1 parent f419fdf commit 56dee4c
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 169 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

Open World RPG

*Current version: 0.1.0*<br>
*Uses Love2D version 11.1.0*
*Current version: 0.1.1*<br>
*Uses Love2D version 11.2.0*

![](https://i.imgur.com/rF9idF9.png)

Expand Down
2 changes: 1 addition & 1 deletion client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function client.sendMessage(msg)
end
end

for _, v in pairs{'spawnProjectile', 'moveItem', 'dropItem', 'useItem', 'usePortal'} do
for _, v in ipairs{'spawnProjectile', 'moveItem', 'dropItem', 'useItem', 'usePortal'} do
client[v] = function(data)
client.nutClient:sendRPC(v, bitser.dumps(data))
end
Expand Down
6 changes: 3 additions & 3 deletions conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
function love.conf(t)
t.title = 'Tier'
t.identity = t.title
t.window.width = 480*3
t.window.height = 270*3
t.window.width = 480*2
t.window.height = 270*2
t.window.resizable = true
t.window.vsync = false
t.window.vsync = 0
t.console = true
end
2 changes: 1 addition & 1 deletion entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local entityDefs = {
require 'entityDefs.slime'
}

for _, sc in pairs{'server', 'client'} do
for _, sc in ipairs{'server', 'client'} do
-- entities.server.defs.slime = slime.server
for _, v in pairs(entityDefs) do
entities[sc].defs[v.server.type] = v[sc]
Expand Down
15 changes: 8 additions & 7 deletions entityDefs/_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local base = {
client = {}
}

for _, sc in pairs{'server', 'client'} do
for _, sc in ipairs{'server', 'client'} do
base[sc].newDefaults = function()
return {
id = lume.uuid(),
Expand Down Expand Up @@ -44,10 +44,11 @@ function base.server:spawn()
end

function base.server:serialize()
return {
id = self.id, type = self.type,
x = self.x, y = self.y
}
local t = {}
for _, v in ipairs{'id', 'type', 'x', 'y'} do
t[v] = self[v]
end
return t
end

function base.server:update(dt)
Expand Down Expand Up @@ -86,13 +87,13 @@ function base.client:spawn()
end

function base.client:setState(state)
for _, v in pairs{'x', 'y'} do
for _, v in ipairs{'x', 'y'} do
self[v] = state[v]
end
end

function base.client:lerpState(a, b, t)
for _, v in pairs{'x', 'y'} do
for _, v in ipairs{'x', 'y'} do
self[v] = lume.lerp(a[v], b[v], t)
end
end
Expand Down
63 changes: 30 additions & 33 deletions entityDefs/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local player = {
client = base.client:new()
}

for _, sc in pairs{'server', 'client'} do
for _, sc in ipairs{'server', 'client'} do
player[sc].newDefaults = function()
return {
id = lume.uuid(),
Expand Down Expand Up @@ -74,33 +74,30 @@ function player.server:spawn()
end

function player.server:serialize()
return {
id = self.id, type = self.type,
name = self.name,
x = self.x, y = self.y,
xv = self.xv, yv = self.yv,
walkTimer = self.walkTimer,
swingTimer = self.swingTimer,
swinging = self.swinging,
automaticSwing = self.automaticSwing,
direction = self.direction,
spd = self.spd, xp = self.xp,
stats = self.stats,
inventory = self.inventory
}
local t = {}
for _, v in ipairs{
'id', 'type', 'name',
'x', 'y', 'xv', 'yv',
'walkTimer', 'swingTimer', 'swinging', 'automaticSwing',
'direction', 'spd', 'xp',
'stats', 'inventory'
} do
t[v] = self[v]
end
return t
end

function player.server:setInputState(state)
for _, v in pairs{'w', 'a', 's', 'd', 'lshift'} do
for _, v in ipairs{'w', 'a', 's', 'd', 'lshift'} do
self.inputState[v] = state.keyboard[v]
end
for _, v in pairs{'lmb', 'x', 'y'} do
for _, v in ipairs{'lmb', 'x', 'y'} do
self.inputState[v] = state.mouse[v]
end
end

function player.server:setState(state)
for _, v in pairs{
for _, v in ipairs{
'x', 'y', 'xv', 'yv',
'walkTimer', 'swingTimer', 'swinging',
'direction'
Expand Down Expand Up @@ -226,28 +223,28 @@ function player.client:spawn()
end

function player.client:serialize()
return {
x = self.x, y = self.y,
xv = self.xv, yv = self.yv,
walkTimer = self.walkTimer,
swingTimer = self.swingTimer,
swinging = self.swinging,
direction = self.direction,
inputState = self.inputState
}
local t = {}
for _, v in ipairs{
'x', 'y', 'xv', 'yv',
'walkTimer', 'swingTimer', 'swinging',
'direction', 'inputState'
} do
t[v] = self[v]
end
return t
end

function player.client:setInputState(state)
for _, v in pairs{'w', 'a', 's', 'd', 'lshift'} do
for _, v in ipairs{'w', 'a', 's', 'd', 'lshift'} do
self.inputState.keyboard[v] = state.keyboard[v]
end
for _, v in pairs{'lmb', 'x', 'y'} do
for _, v in ipairs{'lmb', 'x', 'y'} do
self.inputState.mouse[v] = state.mouse[v]
end
end

function player.client:setState(state)
for _, v in pairs{
for _, v in ipairs{
'x', 'y', 'xv', 'yv',
'walkTimer', 'swingTimer', 'automaticSwing', 'swinging',
'direction', 'spd', 'xp',
Expand All @@ -263,15 +260,15 @@ end

function player.client:lerpState(a, b, t)
local state = {}
for _, v in pairs{'x', 'y', 'xv', 'yv', 'walkTimer', 'swingTimer'} do
for _, v in ipairs{'x', 'y', 'xv', 'yv', 'walkTimer', 'swingTimer'} do
state[v] = lume.lerp(a[v], b[v], t)
end
-- set instead of interpolate timers if b < a
-- todo: interpolate flag
for _, v in pairs{'walkTimer', 'swingTimer'} do
for _, v in ipairs{'walkTimer', 'swingTimer'} do
if b[v] < a[v] then state[v] = b[v] end
end
for _, v in pairs{'automaticSwing', 'swinging',
for _, v in ipairs{'automaticSwing', 'swinging',
'direction', 'spd', 'xp', 'stats', 'inventory'} do
state[v] = b[v]
end
Expand Down
24 changes: 13 additions & 11 deletions entityDefs/slime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local slime = {
client = base.client:new()
}

for _, sc in pairs{'server', 'client'} do
for _, sc in ipairs{'server', 'client'} do
slime[sc].newDefaults = function()
return {
id = lume.uuid(),
Expand Down Expand Up @@ -64,13 +64,15 @@ function slime.server:spawn()
end

function slime.server:serialize()
return {
id = self.id, type = self.type,
x = self.x, y = self.y,
xv = self.xv, yv = self.yv,
slimeType = self.slimeType,
hpMax = self.hpMax, hp = self.hp
}
local t = {}
for _, v in ipairs{
'id', 'type',
'x', 'y', 'xv', 'yv',
'slimeType', 'hpMax', 'hp'
} do
t[v] = self[v]
end
return t
end

function slime.server:update(dt)
Expand Down Expand Up @@ -179,7 +181,7 @@ function slime.client:spawn()
end

function slime.client:setState(state)
for _, v in pairs{'x', 'y', 'xv', 'yv', 'slimeType', 'hpMax', 'hp'} do
for _, v in ipairs{'x', 'y', 'xv', 'yv', 'slimeType', 'hpMax', 'hp'} do
self[v] = state[v]
end
if self.body and not self.body:isDestroyed() then
Expand All @@ -190,10 +192,10 @@ end

function slime.client:lerpState(a, b, t)
local state = {}
for _, v in pairs{'x', 'y', 'xv', 'yv'} do
for _, v in ipairs{'x', 'y', 'xv', 'yv'} do
state[v] = lume.lerp(a[v], b[v], t)
end
for _, v in pairs{'slimeType', 'hpMax', 'hp'} do
for _, v in ipairs{'slimeType', 'hpMax', 'hp'} do
state[v] = b[v]
end
self:setState(state)
Expand Down
4 changes: 2 additions & 2 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ function hud.draw()
love.graphics.setFont(font)
local stats_x, stats_y = 202, 227
local stats_dx, stats_dy = 20, 11
for j, row in pairs{'base', 'arm', 'total'} do
for j, row in ipairs{'base', 'arm', 'total'} do
local c = ({
{255/255, 175/255, 48/255},
{255/255, 84/255, 252/255},
{48/255, 255/255, 241/255}
})[j]
love.graphics.setColor(c)
for i, col in pairs{'vit', 'atk', 'spd', 'wis', 'def', 'reg'} do
for i, col in ipairs{'vit', 'atk', 'spd', 'wis', 'def', 'reg'} do
local sx = stats_x + stats_dx*(i-1)
local sy = stats_y + stats_dy*(j-1)
sx = x + (sx - hud.statsPanel.openPos.x)
Expand Down
2 changes: 1 addition & 1 deletion loadassets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ love.graphics.clear(0, 0, 0)
love.graphics.setCanvas()
-- black tile
table.insert(tileImgs, love.graphics.newImage(tileCanv:newImageData()))
for _, v in pairs{'grass', 'sand', 'rock', 'water'} do
for _, v in ipairs{'grass', 'sand', 'rock', 'water'} do
love.graphics.setCanvas(tileCanv)
love.graphics.clear()
love.graphics.draw(tileSheets.ts1.sheet, tileSheets.ts1.quads[v], 0, 0)
Expand Down
2 changes: 1 addition & 1 deletion lootBag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lootBag = {
}

local defaults = {server={}, client={}}
for _, sc in pairs{'server', 'client'} do
for _, sc in ipairs{'server', 'client'} do
for k, v in pairs{x=0, y=0, type='lootBag'} do
defaults[sc][k] = function() return v end
end
Expand Down
Loading

0 comments on commit 56dee4c

Please sign in to comment.