Compare commits
12 Commits
26265cfabf
...
8b2a9e4b30
Author | SHA1 | Date |
---|---|---|
Pascal Abresch | 8b2a9e4b30 | |
Pascal Abresch | 1a64cc4334 | |
Pascal Abresch | 1501ee13b1 | |
Pascal Abresch | 72c301c6b4 | |
Pascal Abresch | cbe4755d35 | |
Pascal Abresch | 9ab9d0669c | |
Pascal Abresch | 25c9bf62fb | |
Pascal Abresch | 1d87524d40 | |
Pascal Abresch | 6b50f9a6ca | |
Pascal Abresch | 0a512bf243 | |
Pascal Abresch | c78a94d550 | |
Pascal Abresch | 0ae47972a3 |
2
conf.lua
|
@ -6,7 +6,7 @@ love.conf = function(conf)
|
||||||
conf.window.minwidth = 640
|
conf.window.minwidth = 640
|
||||||
conf.window.resizable = true
|
conf.window.resizable = true
|
||||||
conf.window.vsync = -1
|
conf.window.vsync = -1
|
||||||
conf.window.title = "poppy"
|
conf.window.title = "Poppy"
|
||||||
conf.version = "11.0"
|
conf.version = "11.0"
|
||||||
|
|
||||||
conf.modules.joystick = false
|
conf.modules.joystick = false
|
||||||
|
|
|
@ -2,7 +2,7 @@ local CAM_SPEED = 10
|
||||||
|
|
||||||
camera = {}
|
camera = {}
|
||||||
camera.target = 0
|
camera.target = 0
|
||||||
camera.offset = { x = 0, y = 300 }
|
camera.offset = { x = 0, y = 0 }
|
||||||
local fullscreen = false
|
local fullscreen = false
|
||||||
|
|
||||||
local altPressed, enterPressed = false, false
|
local altPressed, enterPressed = false, false
|
||||||
|
|
|
@ -3,6 +3,7 @@ local player = require("lua.player")
|
||||||
local utils = require("shared.utils")
|
local utils = require("shared.utils")
|
||||||
local fonts = require("shared.fonts")
|
local fonts = require("shared.fonts")
|
||||||
|
|
||||||
|
|
||||||
return function(commands)
|
return function(commands)
|
||||||
commands.init = function(clientID, args)
|
commands.init = function(clientID, args)
|
||||||
local nickname, args = utils.nextStringRecord(args)
|
local nickname, args = utils.nextStringRecord(args)
|
||||||
|
@ -10,15 +11,24 @@ local fonts = require("shared.fonts")
|
||||||
local worldID, args = utils.nextStringRecord(args)
|
local worldID, args = utils.nextStringRecord(args)
|
||||||
local x, args = utils.nextIntRecord(args)
|
local x, args = utils.nextIntRecord(args)
|
||||||
local y = tonumber(args)
|
local y = tonumber(args)
|
||||||
local avatar = love.data.decode("string", "base64", avatarEncoded)
|
local avatarHash = love.data.decode("string", "base64", avatarEncoded)
|
||||||
print("Connected as " .. clientID .. " with name " .. nickname)
|
print("Connected as " .. clientID .. " with name " .. nickname)
|
||||||
print("New world is " .. worldID .. " Size is [" .. x .. "|" .. y .. "]")
|
print("New world is " .. worldID .. " Size is [" .. x .. "|" .. y .. "]")
|
||||||
participants[clientID] = player.newPlayer({name = nickname, avatar = levelloop.avatars[avatar].image})
|
|
||||||
|
participants[clientID] = player.newPlayer(
|
||||||
|
{name = nickname, avatar = levelloop.avatars[avatarHash].image, y=y})
|
||||||
|
|
||||||
|
participants[clientID].y = y - participants[clientID].avatar:getHeight()
|
||||||
camera.target = clientID
|
camera.target = clientID
|
||||||
_G.clientID = clientID
|
levelloop.clientID = clientID
|
||||||
|
|
||||||
local world = { id = worldID, x = x, y = y }
|
local world = { id = worldID, x = x, y = y }
|
||||||
levelloop.loadworld(world)
|
levelloop.loadworld(world)
|
||||||
|
camera.setplayer()
|
||||||
|
end
|
||||||
|
|
||||||
|
commands.serverQuit = function(clientID, message)
|
||||||
|
menu.init(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,8 +96,4 @@ local fonts = require("shared.fonts")
|
||||||
end
|
end
|
||||||
ui.addChatEntry(name, args)
|
ui.addChatEntry(name, args)
|
||||||
end
|
end
|
||||||
|
|
||||||
commands.clearCanvas = function(clientID)
|
|
||||||
drawing.clearAllCanvases()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,7 @@ commands = {}
|
||||||
require("lua.commands")(commands)
|
require("lua.commands")(commands)
|
||||||
require("shared.commands")(commands)
|
require("shared.commands")(commands)
|
||||||
|
|
||||||
|
|
||||||
local socket = require "socket"
|
local socket = require "socket"
|
||||||
|
|
||||||
local utils = require("shared.utils")
|
local utils = require("shared.utils")
|
||||||
|
@ -76,15 +77,15 @@ end
|
||||||
|
|
||||||
|
|
||||||
local function normalNetworkSend(args)
|
local function normalNetworkSend(args)
|
||||||
if clientID == "0" then print("Invalid clientID?") end
|
assert(levelloop.clientID ~= 0 and levelloop.clientID)
|
||||||
local request = constants.protocolVersion ..US.. clientID ..US.. args
|
local request = constants.protocolVersion ..US.. levelloop.clientID ..US.. args
|
||||||
levelloop.client:send(request)
|
levelloop.client:send(request)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function debugNetworkSend(args)
|
local function debugNetworkSend(args)
|
||||||
assert(clientID ~= 0)
|
assert(levelloop.clientID ~= 0 and levelloop.clientID)
|
||||||
local request = constants.protocolVersion ..constants.US.. clientID ..constants.US.. args
|
local request = constants.protocolVersion ..constants.US.. levelloop.clientID ..constants.US.. args
|
||||||
print("=> " .. utils.pprint(request))
|
print("=> " .. utils.pprint(request))
|
||||||
levelloop.client:send(request)
|
levelloop.client:send(request)
|
||||||
end
|
end
|
||||||
|
@ -202,6 +203,8 @@ function levelloop.init(server, nickname, avatarHash)
|
||||||
levelloop.client:setpeername(server.adress, server.port)
|
levelloop.client:setpeername(server.adress, server.port)
|
||||||
levelloop.client:settimeout(0)
|
levelloop.client:settimeout(0)
|
||||||
|
|
||||||
|
CLIENT = true
|
||||||
|
SERVER = false
|
||||||
print("Socketnname: " .. levelloop.client:getsockname())
|
print("Socketnname: " .. levelloop.client:getsockname())
|
||||||
print("Connecting to [" .. server.adress .."]:" .. server.port)
|
print("Connecting to [" .. server.adress .."]:" .. server.port)
|
||||||
|
|
||||||
|
@ -284,6 +287,8 @@ function levelloop.loadworld(world)
|
||||||
levelloop.Canvas.dbg2 = love.graphics.newCanvas(world.x, world.y)
|
levelloop.Canvas.dbg2 = love.graphics.newCanvas(world.x, world.y)
|
||||||
end
|
end
|
||||||
levelloop.Canvas.physics = {}
|
levelloop.Canvas.physics = {}
|
||||||
|
levelloop.world = world
|
||||||
|
|
||||||
|
|
||||||
ui.init()
|
ui.init()
|
||||||
drawing.init()
|
drawing.init()
|
||||||
|
|
|
@ -113,7 +113,7 @@ function layout.drawTexture(container, x, y, simulate)
|
||||||
if not simulate then
|
if not simulate then
|
||||||
love.graphics.draw(texture, x, y, 0, scale, scale)
|
love.graphics.draw(texture, x, y, 0, scale, scale)
|
||||||
end
|
end
|
||||||
return x + texture:getWidth()* scale, y + texture:getHeight() * scale
|
return x + (texture:getWidth() * scale), y + texture:getHeight() * scale
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -241,6 +241,27 @@ function layout.rect(container, x, y, simulate)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function layout.button(container, x, y, simulate)
|
||||||
|
local textObject = love.graphics.newText(fonts.normalFont, container.text)
|
||||||
|
local width = textObject:getWidth()
|
||||||
|
local height = textObject:getHeight()
|
||||||
|
local factor = 1.15
|
||||||
|
local points = {
|
||||||
|
x, y,
|
||||||
|
x + (width *factor), y,
|
||||||
|
x + (width * factor), y + (height * factor),
|
||||||
|
x, y + (height * factor),
|
||||||
|
x, y
|
||||||
|
}
|
||||||
|
if not simulate then
|
||||||
|
love.graphics.rectangle("fill", x, y, width* factor, height* factor)
|
||||||
|
love.graphics.line(points)
|
||||||
|
love.graphics.draw(textObject, x + width * 0.075 , y + height * 0.075)
|
||||||
|
end
|
||||||
|
return x+ (width *factor), y + (height * factor)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function layout.overlayRect(container, x, y, simulate)
|
function layout.overlayRect(container, x, y, simulate)
|
||||||
asserts.number("layout.overlayRect", 2, x, y)
|
asserts.number("layout.overlayRect", 2, x, y)
|
||||||
|
|
||||||
|
@ -254,11 +275,10 @@ function layout.overlayRect(container, x, y, simulate)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function layout.label(container, x, y, simulate)
|
function layout.label(container, x, y, simulate)
|
||||||
if not container.font then container.font = fonts.normalFont end
|
if not container.font then container.font = fonts.normalFont end
|
||||||
local text = love.graphics.newText( container.font, container.text )
|
local text = love.graphics.newText( container.font, container.text )
|
||||||
if not text then text = "Unset text!!" end
|
if not text then text = love.graphics.newText( container.font, "Unset text!!") end
|
||||||
if not simulate then
|
if not simulate then
|
||||||
love.graphics.draw(text, x, y)
|
love.graphics.draw(text, x, y)
|
||||||
end
|
end
|
||||||
|
@ -354,6 +374,11 @@ function layout.vertical(container, x, y, simulate)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function layout.skip(container, x, y, simulate)
|
||||||
|
return x, y
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local depth = -1
|
local depth = -1
|
||||||
function layout.handle(container, x, y, simulate)
|
function layout.handle(container, x, y, simulate)
|
||||||
|
|
||||||
|
@ -361,6 +386,7 @@ function layout.handle(container, x, y, simulate)
|
||||||
assert(container, "layout.handle called without container")
|
assert(container, "layout.handle called without container")
|
||||||
|
|
||||||
local name = container["name"]
|
local name = container["name"]
|
||||||
|
if not name then return end
|
||||||
assert(name, "layout.handle container without name")
|
assert(name, "layout.handle container without name")
|
||||||
assert(layout[name], "Unknown layout function " .. name .. " called")
|
assert(layout[name], "Unknown layout function " .. name .. " called")
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ function menu.mousepressed(mousex, mousey)
|
||||||
local fullName = names[love.math.random(1, #names)] .. " " .. lastNames[love.math.random(1, #lastNames)]
|
local fullName = names[love.math.random(1, #names)] .. " " .. lastNames[love.math.random(1, #lastNames)]
|
||||||
local serverID = v.identifier
|
local serverID = v.identifier
|
||||||
local serverEntry = menu.serverlist[serverID]
|
local serverEntry = menu.serverlist[serverID]
|
||||||
local avatar = love.image.newImageData("textures/player/nephele/dog.png")
|
local avatar = love.image.newImageData("textures/player/noriko/liz.png")
|
||||||
local avatarHash = love.data.hash("sha512", avatar:getString())
|
local avatarHash = love.data.hash("sha512", avatar:getString())
|
||||||
levelloop.init({ adress = serverEntry.host, port = serverEntry.port }, fullName, avatarHash)
|
levelloop.init({ adress = serverEntry.host, port = serverEntry.port }, fullName, avatarHash)
|
||||||
layout.uiState = {}
|
layout.uiState = {}
|
||||||
|
@ -122,13 +122,23 @@ menu.layoutServerList = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
menu.layout = {name ="vertical",
|
menu.menuMessage = function(message)
|
||||||
|
if not message then return {name = "skip"} end
|
||||||
|
return {name = "color",
|
||||||
|
color = { 1, .5, .5, 1},
|
||||||
|
{name = "label", font = fonts.bigFont, text = "Welcome to poppy!"}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
menu.layout = function(message)
|
||||||
|
return {name ="vertical",
|
||||||
{name = "spacer", height = 20},
|
{name = "spacer", height = 20},
|
||||||
{name = "horizontal",
|
{name = "horizontal",
|
||||||
{name = "spacer", width = 20},
|
{name = "spacer", width = 20},
|
||||||
{name = "drawTexture", texture = love.graphics.newImage("ressources/Poppy.png")},
|
{name = "drawTexture", texture = love.graphics.newImage("ressources/Poppy.png")},
|
||||||
{name = "label", font = fonts.bigFont, text = "Welcome to poppy!"},
|
{name = "label", font = fonts.bigFont, text = "Welcome to poppy!"},
|
||||||
},
|
},
|
||||||
|
menu.menuMessage(message),
|
||||||
{name = "horizontal",
|
{name = "horizontal",
|
||||||
{name = "spacer", width = 50},
|
{name = "spacer", width = 50},
|
||||||
{name = "vertical",
|
{name = "vertical",
|
||||||
|
@ -179,14 +189,15 @@ menu.layout = {name ="vertical",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function drawMenu()
|
function drawMenu(message)
|
||||||
utils.color_push()
|
utils.color_push()
|
||||||
love.graphics.setCanvas(menu.Canvas)
|
love.graphics.setCanvas(menu.Canvas)
|
||||||
uiState = {}
|
uiState = {}
|
||||||
love.graphics.clear( )
|
love.graphics.clear( )
|
||||||
layout.handle(menu.layout, 0, 0)
|
layout.handle(menu.layout(message), 0, 0)
|
||||||
love.graphics.setCanvas()
|
love.graphics.setCanvas()
|
||||||
utils.color_pop()
|
utils.color_pop()
|
||||||
end
|
end
|
||||||
|
@ -197,11 +208,11 @@ function menu.draw(w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function menu.init()
|
function menu.init(message)
|
||||||
print("init menu")
|
print("init menu")
|
||||||
menu.width, menu.height = love.window.getMode()
|
menu.width, menu.height = love.window.getMode()
|
||||||
menu.Canvas = love.graphics.newCanvas(menu.width, menu.height)
|
menu.Canvas = love.graphics.newCanvas(menu.width, menu.height)
|
||||||
drawMenu()
|
drawMenu(message)
|
||||||
love.draw = menu.draw
|
love.draw = menu.draw
|
||||||
love.keyreleased = menu.keyreleased
|
love.keyreleased = menu.keyreleased
|
||||||
love.keypressed = menu.keypressed
|
love.keypressed = menu.keypressed
|
||||||
|
|
|
@ -90,7 +90,7 @@ function physics.keypressed( key, code, isrepeat)
|
||||||
if isrepeat then return end
|
if isrepeat then return end
|
||||||
|
|
||||||
if camera.target == 0 then return end
|
if camera.target == 0 then return end
|
||||||
player = participants[camera.target]
|
local player = participants[clientID]
|
||||||
if key == "p" then
|
if key == "p" then
|
||||||
player.flying = not player.flying
|
player.flying = not player.flying
|
||||||
if player.flying then
|
if player.flying then
|
||||||
|
@ -105,7 +105,7 @@ end
|
||||||
|
|
||||||
function physics.input(dt)
|
function physics.input(dt)
|
||||||
if camera.target == 0 then return end
|
if camera.target == 0 then return end
|
||||||
player = participants[camera.target]
|
local player = participants[levelloop.clientID]
|
||||||
local speedModified = dt * 20
|
local speedModified = dt * 20
|
||||||
if love.keyboard.isDown("rshift") or love.keyboard.isDown("lshift")
|
if love.keyboard.isDown("rshift") or love.keyboard.isDown("lshift")
|
||||||
then
|
then
|
||||||
|
@ -195,17 +195,7 @@ function physics.update(dt)
|
||||||
if granularity < 1 then granularity = 1 end
|
if granularity < 1 then granularity = 1 end
|
||||||
assert(currentX and currentY)
|
assert(currentX and currentY)
|
||||||
|
|
||||||
if player.flying then -- skip physics
|
if not player.flying then
|
||||||
player.x, player.y = futureX, futureY
|
|
||||||
|
|
||||||
player.speed.x = new_sx
|
|
||||||
player.speed.y = new_sy
|
|
||||||
if camera.target == i then -- FIXME: uses camera.target
|
|
||||||
physics.send_update(player, dt)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
do -- SCOPE
|
do -- SCOPE
|
||||||
local blocked_x, blocked_y = false, false
|
local blocked_x, blocked_y = false, false
|
||||||
if not SKIP then
|
if not SKIP then
|
||||||
|
@ -276,6 +266,15 @@ function physics.update(dt)
|
||||||
if i == camera.target then -- FIXME: uses camera.target
|
if i == camera.target then -- FIXME: uses camera.target
|
||||||
physics.send_update(player, dt)
|
physics.send_update(player, dt)
|
||||||
end
|
end
|
||||||
|
else -- player.flying
|
||||||
|
player.x, player.y = futureX, futureY
|
||||||
|
|
||||||
|
player.speed.x = new_sx
|
||||||
|
player.speed.y = new_sy
|
||||||
|
if camera.target == i then -- FIXME: uses camera.target
|
||||||
|
physics.send_update(player, dt)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
11
lua/ui.lua
|
@ -372,6 +372,15 @@ function ui.menuDrawer(w, h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{name = "cursorSelectMenu",
|
||||||
|
identifier = "buttonTest",
|
||||||
|
kind = "button",
|
||||||
|
{name = "button",
|
||||||
|
width = 60,
|
||||||
|
height = 10,
|
||||||
|
text = "TestKnopf",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{name = "spacer",
|
{name = "spacer",
|
||||||
|
@ -455,7 +464,7 @@ function ui.mousepressed(mousex, mousey)
|
||||||
return
|
return
|
||||||
elseif v.kind == "colorpicker" then
|
elseif v.kind == "colorpicker" then
|
||||||
print("Picker hit :D")
|
print("Picker hit :D")
|
||||||
local scale = 1.0 / granularity
|
local scale = ui.sidebarScale / granularity
|
||||||
local red = math.floor((mousey - v.y) / v.pointSize) / scale
|
local red = math.floor((mousey - v.y) / v.pointSize) / scale
|
||||||
local green = math.floor((mousex - v.x) / v.pointSize / (scale + 1)) / scale
|
local green = math.floor((mousex - v.x) / v.pointSize / (scale + 1)) / scale
|
||||||
local blue = (math.floor((mousex - v.x) / v.pointSize) % (scale + 1)) / scale
|
local blue = (math.floor((mousex - v.x) / v.pointSize) % (scale + 1)) / scale
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!sh
|
||||||
|
zip -r Poppy.love main.lua conf.lua lua/ shared/ ressources/Poppy.png textures/menu/AddIcon.png textures/menu/serverPlay.png server/ textures/blocks/ textures/menu/serverPlay.png textures/player/
|
|
@ -1,21 +0,0 @@
|
||||||
local util = require("shared.utils")
|
|
||||||
|
|
||||||
local constants = require("server.constants")
|
|
||||||
local rpc = require("server.rpc")
|
|
||||||
|
|
||||||
return function(commands)
|
|
||||||
function commands.drawTexture(clientID, args)
|
|
||||||
sharedCommands.drawTexture(clientID, args)
|
|
||||||
broadcast(clientID, util.unit("drawTexture", args))
|
|
||||||
end
|
|
||||||
function commands.deleteTexture(clientID, args)
|
|
||||||
sharedCommands.deleteTexture(clientID, args)
|
|
||||||
broadcast(clientID, util.unit("deleteTexture", args))
|
|
||||||
end
|
|
||||||
function commands.clearCanvas(clientID)
|
|
||||||
broadcast(clientID, "clearCanvas")
|
|
||||||
end
|
|
||||||
function commands.fillCanvas(clientID, args)
|
|
||||||
broadcast(clientID, util.unit("fillCanvas", args))
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -10,7 +10,6 @@ protocolVersion = constants.protocolVersion
|
||||||
local commands = {}
|
local commands = {}
|
||||||
require("server.commands.players")(commands)
|
require("server.commands.players")(commands)
|
||||||
require("server.commands.physics")(commands)
|
require("server.commands.physics")(commands)
|
||||||
require("server.commands.drawing")(commands)
|
|
||||||
require("server.commands.chat")(commands)
|
require("server.commands.chat")(commands)
|
||||||
require("server.commands.saving")(commands)
|
require("server.commands.saving")(commands)
|
||||||
require("shared.commands")(commands)
|
require("shared.commands")(commands)
|
||||||
|
@ -64,7 +63,8 @@ function loadTextures(directory, container)
|
||||||
return container
|
return container
|
||||||
end
|
end
|
||||||
|
|
||||||
|
love.window.minimize( )
|
||||||
|
love.window.setTitle( "Poppy server" )
|
||||||
function mainloop(dt)
|
function mainloop(dt)
|
||||||
local data, ip, port
|
local data, ip, port
|
||||||
data, ip, port = server:receivefrom()
|
data, ip, port = server:receivefrom()
|
||||||
|
@ -78,7 +78,7 @@ function mainloop(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = rpc.validate(data)
|
local result = rpc.validate(data)
|
||||||
--print("=> " .. util.pprint(data))
|
print("=> " .. util.pprint(data))
|
||||||
|
|
||||||
if not result.errorMsg then
|
if not result.errorMsg then
|
||||||
if result.clientID == 0 then
|
if result.clientID == 0 then
|
||||||
|
@ -104,18 +104,21 @@ function levelloop.init(host)
|
||||||
if not status then
|
if not status then
|
||||||
error("Server could not be started :( " .. value)
|
error("Server could not be started :( " .. value)
|
||||||
end
|
end
|
||||||
print("Server startup. listening on " .. server:getsockname())
|
local ip, port =server:getsockname()
|
||||||
|
print("Server startup. listening on " .. ip .. " [".. port .."]")
|
||||||
loadTextures("textures/blocks", levelloop.textures)
|
loadTextures("textures/blocks", levelloop.textures)
|
||||||
levelloop.world = constants.world
|
levelloop.world = constants.world
|
||||||
levelloop.Canvas = {}
|
levelloop.Canvas = {}
|
||||||
levelloop.Canvas.fg = love.graphics.newCanvas(levelloop.world.x, levelloop.world.y)
|
levelloop.Canvas.fg = love.graphics.newCanvas(levelloop.world.x, levelloop.world.y)
|
||||||
levelloop.Canvas.bg = love.graphics.newCanvas(levelloop.world.x, levelloop.world.y)
|
levelloop.Canvas.bg = love.graphics.newCanvas(levelloop.world.x, levelloop.world.y)
|
||||||
print("Startup!")
|
print("Startup!")
|
||||||
|
SERVER = true
|
||||||
|
CLIENT = false
|
||||||
love.update = mainloop
|
love.update = mainloop
|
||||||
love.draw = function()
|
love.draw = function()
|
||||||
love.graphics.clear(.2, 0, .2)
|
love.graphics.clear(.2, 0, .2)
|
||||||
love.graphics.print("Poppy server is running.", fonts.normalFont, 20, 20)
|
love.graphics.print("Poppy server is running.", fonts.normalFont, 20, 20)
|
||||||
love.graphics.print("listening on " .. server:getsockname(), fonts.normalFont, 20, 50)
|
love.graphics.print("listening on " .. ip .. " [".. port .."]" , fonts.normalFont, 20, 50)
|
||||||
return end
|
return end
|
||||||
love.keyreleased = function() return end
|
love.keyreleased = function() return end
|
||||||
love.keypressed = function() return end
|
love.keypressed = function() return end
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
local player = require("lua.player")
|
local player = require("lua.player")
|
||||||
|
|
||||||
local utils = require("shared.utils")
|
local utils = require("shared.utils")
|
||||||
|
|
||||||
return function(commands)
|
return function(commands)
|
||||||
commands.moveUpdate = function(clientID, args)
|
commands.moveUpdate = function(clientID, args)
|
||||||
|
if SERVER then
|
||||||
|
broadcast(clientID, utils.unit("moveUpdate", args))
|
||||||
|
end
|
||||||
if not participants[clientID] then return end
|
if not participants[clientID] then return end
|
||||||
local x, args = utils.nextIntRecord(args)
|
local x, args = utils.nextIntRecord(args)
|
||||||
local y, args = utils.nextIntRecord(args)
|
local y, args = utils.nextIntRecord(args)
|
||||||
|
@ -19,15 +21,19 @@ return function(commands)
|
||||||
|
|
||||||
|
|
||||||
commands.moveFlying = function(clientID, args)
|
commands.moveFlying = function(clientID, args)
|
||||||
|
if SERVER then
|
||||||
|
broadcast(clientID, utils.unit("moveFlying", args))
|
||||||
|
end
|
||||||
if not participants[clientID] then return end
|
if not participants[clientID] then return end
|
||||||
participants[clientID].flying = (args == "true")
|
participants[clientID].flying = (args == "true")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
commands.drawTexture = function(clientID, args)
|
commands.drawTexture = function(clientID, args)
|
||||||
if _G.camera then
|
if SERVER then
|
||||||
if clientID == camera.target then return end
|
broadcast(clientID, utils.unit("drawTexture", args))
|
||||||
end
|
end
|
||||||
|
if not participants[clientID] then return end
|
||||||
local x, args = utils.nextIntRecord(args)
|
local x, args = utils.nextIntRecord(args)
|
||||||
local y, args = utils.nextIntRecord(args)
|
local y, args = utils.nextIntRecord(args)
|
||||||
local layer, args = utils.nextStringRecord(args)
|
local layer, args = utils.nextStringRecord(args)
|
||||||
|
@ -37,29 +43,30 @@ return function(commands)
|
||||||
local g, args = utils.nextIntRecord(args)
|
local g, args = utils.nextIntRecord(args)
|
||||||
local b, args = utils.nextIntRecord(args)
|
local b, args = utils.nextIntRecord(args)
|
||||||
a = tonumber(args) or 1
|
a = tonumber(args) or 1
|
||||||
if not textures[hash] then error("Failed to find hash!") return end
|
if not levelloop.textures[hash] then error("Failed to find hash!") return end
|
||||||
if not textures[hash].image then
|
if not levelloop.textures[hash].image then
|
||||||
textures[hash].image = love.graphics.newImage(textures[hash].data)
|
levelloop.textures[hash].image = love.graphics.newImage(levelloop.textures[hash].data)
|
||||||
end
|
end
|
||||||
love.graphics.setCanvas(levelloop.Canvas[layer])
|
love.graphics.setCanvas(levelloop.Canvas[layer])
|
||||||
love.graphics.setBlendMode("alpha")
|
love.graphics.setBlendMode("alpha")
|
||||||
utils.color_push()
|
utils.color_push()
|
||||||
love.graphics.setColor(r, g, b ,a )
|
love.graphics.setColor(r, g, b ,a )
|
||||||
love.graphics.draw(textures[hash].image, x, y)
|
love.graphics.draw(levelloop.textures[hash].image, x, y)
|
||||||
utils.color_pop()
|
utils.color_pop()
|
||||||
love.graphics.setCanvas()
|
love.graphics.setCanvas()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
commands.deleteTexture = function(clientID, args)
|
commands.deleteTexture = function(clientID, args)
|
||||||
if _G.camera then
|
if SERVER then
|
||||||
if clientID == camera.target then return end
|
broadcast(clientID, utils.unit("deleteTexture", args))
|
||||||
end
|
end
|
||||||
|
if not participants[clientID] then return end
|
||||||
local x, args = utils.nextIntRecord(args)
|
local x, args = utils.nextIntRecord(args)
|
||||||
local y, args = utils.nextIntRecord(args)
|
local y, args = utils.nextIntRecord(args)
|
||||||
local width, args = utils.nextIntRecord(args)
|
local width, args = utils.nextIntRecord(args)
|
||||||
local height, layer = utils.nextIntRecord(args)
|
local height, layer = utils.nextIntRecord(args)
|
||||||
love.graphics.setCanvas(canvas[layer])
|
love.graphics.setCanvas(levelloop.Canvas[layer])
|
||||||
love.graphics.setBlendMode("replace")
|
love.graphics.setBlendMode("replace")
|
||||||
utils.color_push()
|
utils.color_push()
|
||||||
love.graphics.setColor(0,0,0,0)
|
love.graphics.setColor(0,0,0,0)
|
||||||
|
@ -69,7 +76,12 @@ return function(commands)
|
||||||
love.graphics.setCanvas()
|
love.graphics.setCanvas()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
commands.fillCanvas = function(clientID, args)
|
commands.fillCanvas = function(clientID, args)
|
||||||
|
if SERVER then
|
||||||
|
broadcast(clientID, utils.unit("fillCanvas", args))
|
||||||
|
end
|
||||||
|
if not participants[clientID] then return end
|
||||||
local layer, args = utils.nextStringRecord(args)
|
local layer, args = utils.nextStringRecord(args)
|
||||||
local hashEncoded, args = utils.nextStringRecord(args)
|
local hashEncoded, args = utils.nextStringRecord(args)
|
||||||
hash = love.data.decode("string", "base64", hashEncoded)
|
hash = love.data.decode("string", "base64", hashEncoded)
|
||||||
|
@ -80,9 +92,15 @@ return function(commands)
|
||||||
|
|
||||||
love.graphics.setCanvas(levelloop.Canvas[layer])
|
love.graphics.setCanvas(levelloop.Canvas[layer])
|
||||||
love.graphics.clear()
|
love.graphics.clear()
|
||||||
|
if not levelloop.textures[hash] then error("Failed to find hash!") return end
|
||||||
|
if not levelloop.textures[hash].image then
|
||||||
|
levelloop.textures[hash].image = love.graphics.newImage(levelloop.textures[hash].data)
|
||||||
|
end
|
||||||
utils.color_push()
|
utils.color_push()
|
||||||
love.graphics.setColor({r, g, b, a})
|
love.graphics.setColor({r, g, b, a})
|
||||||
|
if not levelloop.textures[hash].image then
|
||||||
|
love.graphics.newImage(levelloop.textures[hash].data)
|
||||||
|
end
|
||||||
for x = 0, levelloop.world.x -levelloop.textures[hash].image:getPixelWidth(),
|
for x = 0, levelloop.world.x -levelloop.textures[hash].image:getPixelWidth(),
|
||||||
levelloop.textures[hash].image:getPixelWidth() do
|
levelloop.textures[hash].image:getPixelWidth() do
|
||||||
for y = 0, levelloop.world.y -levelloop.textures[hash].image:getPixelHeight(),
|
for y = 0, levelloop.world.y -levelloop.textures[hash].image:getPixelHeight(),
|
||||||
|
@ -94,4 +112,19 @@ return function(commands)
|
||||||
utils.color_pop()
|
utils.color_pop()
|
||||||
love.graphics.setCanvas()
|
love.graphics.setCanvas()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
commands.clearCanvas = function(clientID)
|
||||||
|
if SERVER then
|
||||||
|
broadcast(clientID, "clearCanvas")
|
||||||
|
end
|
||||||
|
love.graphics.setCanvas(levelloop.Canvas.fg)
|
||||||
|
love.graphics.clear()
|
||||||
|
love.graphics.setCanvas(levelloop.Canvas.bg)
|
||||||
|
love.graphics.clear()
|
||||||
|
love.graphics.setCanvas(levelloop.Canvas.dbg)
|
||||||
|
love.graphics.clear()
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
levelloop.Canvas.physics = {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Before Width: | Height: | Size: 129 B After Width: | Height: | Size: 129 B |
Before Width: | Height: | Size: 176 B After Width: | Height: | Size: 176 B |
Before Width: | Height: | Size: 258 B After Width: | Height: | Size: 258 B |
Before Width: | Height: | Size: 413 B After Width: | Height: | Size: 413 B |
Before Width: | Height: | Size: 714 B After Width: | Height: | Size: 714 B |
Before Width: | Height: | Size: 722 B After Width: | Height: | Size: 722 B |
Before Width: | Height: | Size: 731 B After Width: | Height: | Size: 731 B |
Before Width: | Height: | Size: 714 B After Width: | Height: | Size: 714 B |
Before Width: | Height: | Size: 602 B After Width: | Height: | Size: 602 B |
After Width: | Height: | Size: 1.1 KiB |