2023-09-04 18:56:14 +00:00
|
|
|
local lg = assert( love.graphics )
|
|
|
|
local scene = assert( require 'client.scene' )
|
|
|
|
local socket = assert( require 'socket' )
|
|
|
|
local shared = assert( require 'shared' )
|
|
|
|
local udp = socket.udp()
|
|
|
|
|
|
|
|
local game = {}
|
|
|
|
local t = 0
|
|
|
|
local tick = 0
|
|
|
|
|
|
|
|
|
|
|
|
function game.draw()
|
2023-09-05 00:40:07 +00:00
|
|
|
|
|
|
|
end
|
2023-09-04 18:56:14 +00:00
|
|
|
|
2023-09-05 00:40:07 +00:00
|
|
|
function game.onPacket( data, msg )
|
|
|
|
if data then print( data, msg ) end
|
2023-09-04 18:56:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function game.update( dt )
|
|
|
|
t = dt + t
|
2023-09-05 00:40:07 +00:00
|
|
|
game.onPacket( udp:receive() )
|
2023-09-04 18:56:14 +00:00
|
|
|
if t > 0.1 then
|
|
|
|
t = 0
|
|
|
|
tick = tick + 1
|
2023-09-05 00:40:07 +00:00
|
|
|
udp:send( tostring(tick) )
|
2023-09-04 18:56:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-09-05 00:40:07 +00:00
|
|
|
function game.newGame( )
|
|
|
|
game.curWorld = shared.NewWorld() --Last world state received from server.
|
|
|
|
game.preWorld = shared.NewWorld() --Current world state predicted by this client.
|
|
|
|
end
|
|
|
|
|
|
|
|
function game.disconnect( )
|
|
|
|
return scene.mainmenu()
|
|
|
|
end
|
|
|
|
|
2023-09-04 18:56:14 +00:00
|
|
|
function game.onLoad( )
|
|
|
|
udp:settimeout( 0 )
|
|
|
|
udp:setpeername( "192.168.2.15", 51312 )
|
|
|
|
end
|
|
|
|
|
2023-09-05 00:40:07 +00:00
|
|
|
function game.keypressed( key, code, isRepeat )
|
|
|
|
if code == "escape" then return game.disconnect() end
|
|
|
|
end
|
|
|
|
|
|
|
|
scene.game = game
|
|
|
|
return game
|