semi synced multiplayer

This commit is contained in:
harper
2026-08-29 15:24:43 -05:00
parent c5cb04d760
commit 2ed2daeb25
7 changed files with 148 additions and 152 deletions
+3
View File
@@ -4,11 +4,14 @@ local network = {}
local client
client_id = 0
-- Packet IDs
network.MSG_KEY_PRESS = 1
network.MSG_GAMESTATE = 2
network.MSG_SERVER_STATUS = 3
network.MSG_ON_CONNECT = 4
network.MSG_ON_PLAYER_CONNECT = 5
--------------------------------------------------
-- Packing
+9
View File
@@ -0,0 +1,9 @@
utils = {}
function vec(x, y)
return {x = x, y = y}
end
function utils.round(num)
return num >= 0 and math.floor(num + 0.5) or math.ceil(num - 0.5)
end
+7 -7
View File
@@ -1,9 +1,15 @@
require("client.utils")
world = {}
world.tiles = {}
world.entities = {}
world.entities.com = {}
world.entities.players = {}
world.utils = {}
world.cell_size = 10 -- default
function world.utils.to_tile(x, y)
return vec(util.round(x / world.cell_size) * world.cell_size, util.round(y / world.cell_size) * world.cell_size)
return vec(utils.round(x / world.cell_size) * world.cell_size, utils.round(y / world.cell_size) * world.cell_size)
end
function world.utils.set_tile(x, y, tbl)
@@ -15,9 +21,3 @@ function world.utils.get_tile(x, y)
local key = x .. "," .. y
return world.tiles[key]
end
function world:draw()
for i, v in pairs(world.tiles) do
gfx.rect_fill(v.aabb.x, v.aabb.y, v.aabb.w, v.aabb.h, gfx.COLOR_DARK_GRAY)
end
end